Timer Callback

Hi,

I hope someone can help me out here. Either with a correction to existing code or a new way of implementing a "double push" function.

I have a button connected to a HW unit that I want to initiate different functions, depending if there is a "1 push" or a "double push" (2 pushes within 500 millisec)

I have written these code lines for a function that should detect a 1 push or 2 pushes of the HW button.

the 500 millisec is set in the TIMER_VALUES

S_Button_S is state of button and start as a "0" before any pushes
SPD_Knob = 1 is a 1 push
SPD_Knob = 2 is a 2 push

It doesn't work as expected. What is wrong?

The push of HW button start the Event function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	
			int Event()
{
		
			if (SButton_S == 0)
			{	
				SDouble_S = 0;
				SButton_S = 2; 
				Stimer();
			}

			else
			{
				SDouble_S = 1;
				SButton_S = 0;
				SPD_Knob = 2;
				Sleep(70);
				SPD_Knob = 0;
				DeleteTimerQueueTimer(NULL, hSPDTimer, NULL);
			}
		
}

	void CALLBACK SPDTimerEnds(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
{
	if (SDouble_S == 0)
	{
		SPD_Knob = 1;
		Sleep(70);
		SPD_Knob = 0;
		SButton_S = 0;
	}
	SetEvent(g_hExitEventS);
}

bool Stimer()
{
	HANDLE hSPDTimer = NULL;
	BOOL IsCreated = CreateTimerQueueTimer(&hSPDTimer, NULL, SPDTimerEnds, NULL, TIMER_VALUES , 0, WT_EXECUTELONGFUNCTION);
	g_hExitEventS = CreateEvent(NULL, TRUE, FALSE, NULL);
	
	return true;
}
Last edited on
No replly. I though this was an expert forum
Topic archived. No new replies allowed.