removed some extra code and made Button 4 be a "quit" function
This commit is contained in:
parent
de84145e55
commit
69c5261ec4
33
src/gpio.c
33
src/gpio.c
|
@ -196,36 +196,3 @@ int Gpio_read_buttons(void)
|
||||||
rc |= STATE_BUTTON4;
|
rc |= STATE_BUTTON4;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Gpio_poll_buttons(void)
|
|
||||||
{
|
|
||||||
int new_state = Gpio_read_buttons();
|
|
||||||
int tmp, ndx, mask;
|
|
||||||
|
|
||||||
if (gpio_input(GLINE_BUTTON1) == 0)
|
|
||||||
new_state |= STATE_BUTTON1;
|
|
||||||
if (gpio_input(GLINE_BUTTON2) == 0)
|
|
||||||
new_state |= STATE_BUTTON2;
|
|
||||||
if (gpio_input(GLINE_BUTTON3) == 0)
|
|
||||||
new_state |= STATE_BUTTON3;
|
|
||||||
if (gpio_input(GLINE_BUTTON4) == 0)
|
|
||||||
new_state |= STATE_BUTTON4;
|
|
||||||
|
|
||||||
if (last_state != new_state)
|
|
||||||
{
|
|
||||||
tmp = last_state & ~new_state;
|
|
||||||
for (ndx = 1, mask = 1; ndx <= 4; ndx++, mask <<= 1)
|
|
||||||
{
|
|
||||||
if (tmp & mask)
|
|
||||||
Log(LDEBUG, "Button %d was released", ndx);
|
|
||||||
}
|
|
||||||
tmp = new_state & ~last_state;
|
|
||||||
for (ndx = 1, mask = 1; ndx <= 4; ndx++, mask <<= 1)
|
|
||||||
{
|
|
||||||
if (tmp & mask)
|
|
||||||
Log(LDEBUG, "Button %d was pressed", ndx);
|
|
||||||
}
|
|
||||||
last_state = new_state;
|
|
||||||
}
|
|
||||||
return new_state;
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,6 +4,5 @@
|
||||||
extern int Gpio_setup(void);
|
extern int Gpio_setup(void);
|
||||||
extern void Gpio_cleanup(void);
|
extern void Gpio_cleanup(void);
|
||||||
extern int Gpio_read_buttons(void);
|
extern int Gpio_read_buttons(void);
|
||||||
extern int Gpio_poll_buttons(void);
|
|
||||||
|
|
||||||
#endif /* __GPIO_H_INCLUDED */
|
#endif /* __GPIO_H_INCLUDED */
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
int running = 1;
|
||||||
MSG msg;
|
MSG msg;
|
||||||
|
|
||||||
TimeInit();
|
TimeInit();
|
||||||
|
@ -18,7 +19,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
Log(LINFO, "System ready.");
|
Log(LINFO, "System ready.");
|
||||||
|
|
||||||
for (;;)
|
while (running)
|
||||||
{
|
{
|
||||||
if (MqPeek(Sys_Queue, &msg, PEEK_REMOVE))
|
if (MqPeek(Sys_Queue, &msg, PEEK_REMOVE))
|
||||||
{
|
{
|
||||||
|
@ -30,6 +31,11 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
case WM_HWBUTTONUP:
|
case WM_HWBUTTONUP:
|
||||||
Log(LINFO, "Button %d was released.", (int)(msg.attrs[0]));
|
Log(LINFO, "Button %d was released.", (int)(msg.attrs[0]));
|
||||||
|
if (msg.attrs[0] == 4)
|
||||||
|
{
|
||||||
|
Log(LINFO, "Quitting the message loop.");
|
||||||
|
running = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -27,16 +27,10 @@ static void *input_thread(void *arg)
|
||||||
for (attr = 1, mask = 1; attr <= 4; attr++, mask <<= 1)
|
for (attr = 1, mask = 1; attr <= 4; attr++, mask <<= 1)
|
||||||
{
|
{
|
||||||
if (up & mask)
|
if (up & mask)
|
||||||
{
|
|
||||||
Log(LDEBUG, "posting WM_HWBUTTONUP(%d)", (int)attr);
|
|
||||||
MqPost1(Sys_Queue, 0, WM_HWBUTTONUP, attr);
|
MqPost1(Sys_Queue, 0, WM_HWBUTTONUP, attr);
|
||||||
}
|
|
||||||
else if (down & mask)
|
else if (down & mask)
|
||||||
{
|
|
||||||
Log(LDEBUG, "posting WM_HWBUTTONDOWN(%d)", (int)attr);
|
|
||||||
MqPost1(Sys_Queue, 0, WM_HWBUTTONDOWN, attr);
|
MqPost1(Sys_Queue, 0, WM_HWBUTTONDOWN, attr);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
last_bstate = st;
|
last_bstate = st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user