removed some extra code and made Button 4 be a "quit" function

This commit is contained in:
Amy G. Bowersox 2019-12-01 01:40:28 -07:00
parent de84145e55
commit 69c5261ec4
4 changed files with 7 additions and 41 deletions

View File

@ -196,36 +196,3 @@ int Gpio_read_buttons(void)
rc |= STATE_BUTTON4;
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;
}

View File

@ -4,6 +4,5 @@
extern int Gpio_setup(void);
extern void Gpio_cleanup(void);
extern int Gpio_read_buttons(void);
extern int Gpio_poll_buttons(void);
#endif /* __GPIO_H_INCLUDED */

View File

@ -6,6 +6,7 @@
int main(int argc, char *argv[])
{
int running = 1;
MSG msg;
TimeInit();
@ -18,7 +19,7 @@ int main(int argc, char *argv[])
Log(LINFO, "System ready.");
for (;;)
while (running)
{
if (MqPeek(Sys_Queue, &msg, PEEK_REMOVE))
{
@ -30,6 +31,11 @@ int main(int argc, char *argv[])
case WM_HWBUTTONUP:
Log(LINFO, "Button %d was released.", (int)(msg.attrs[0]));
if (msg.attrs[0] == 4)
{
Log(LINFO, "Quitting the message loop.");
running = 0;
}
break;
default:

View File

@ -27,15 +27,9 @@ static void *input_thread(void *arg)
for (attr = 1, mask = 1; attr <= 4; attr++, mask <<= 1)
{
if (up & mask)
{
Log(LDEBUG, "posting WM_HWBUTTONUP(%d)", (int)attr);
MqPost1(Sys_Queue, 0, WM_HWBUTTONUP, attr);
}
else if (down & mask)
{
Log(LDEBUG, "posting WM_HWBUTTONDOWN(%d)", (int)attr);
MqPost1(Sys_Queue, 0, WM_HWBUTTONDOWN, attr);
}
}
last_bstate = st;
}