Add an exit function
@@ -85,7 +85,7 @@ void Button_Init(void)
ProfileState_CreateService(&button, 0, "button", revision);
// set_fl(STDOUT_FILENO, O_NONBLOCK);
clear_screen();
- printf("Button service running.\n\n\tUse the SPACE button to swap the button state.\n");
+ printf("Button service running. Press Q to quit.\n\n\tUse the SPACE button to swap the button state.\n");
printf("%s", button_OFF);
}
#ifndef _WIN32
@@ -124,12 +124,15 @@ int kbhit(void)
******************************************************************************/
void Button_Loop(void)
{
- if (kbhit())
+ static bool stop_loop = false;
+ int c;
+ if ((kbhit()) && (!stop_loop))
{
- if (getchar() == ' ')
+ c = get_character();
+ if (c == ' ')
{
clear_screen();
- printf("Button service running.\n\n\tUse the SPACE button to swap the button state.\n");
+ printf("Button service is running. Press Q to quit.\n\n\tUse the SPACE button to swap the button state.\n");
button.state = !button.state;
if (button.state)
{
@@ -140,5 +143,11 @@ void Button_Loop(void)
printf("%s", button_OFF);
}
}
+ else if ((c == 'q') || (c == 'Q'))
+ {
+ clear_screen();
+ printf("\n\n--- Quit button service ---\n(press \"CTRL + C\" to close program)\n\n");
+ stop_loop = true;
+ }
}
}
