-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
50 lines (43 loc) · 1.15 KB
/
main.c
File metadata and controls
50 lines (43 loc) · 1.15 KB
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
44
45
46
47
48
49
/*
* State Pattern Implementation for Menu Navigation
* Author: Panagiotis Argyropoulos - pargyropoulos@gmail.com
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <conio.h>
#include "events.h"
#include "menu.h"
#include "fsm.h"
//--- NON Blocking Button Handler ---//
void GetButton(void) {
if (_kbhit()) {
char ch = _getch();
ch = toupper(ch);
switch (ch) {
case 'Q': RaiseButtonEvent(BTN_UP);return;
case 'W': RaiseButtonEvent(BTN_DOWN);return;
case 'E': RaiseButtonEvent(BTN_SELECT);return;
case 'R': RaiseButtonEvent(BTN_ESC);return;
default: return;
}
}
}
int main(void) {
MENU_Initialize();
while (1) {
GetButton();
button_t btn_event = GetButtonEvent();
if (btn_event!=BTN_NONE){
ClearButtonEvent();
FSM_OnHardwareEvent(btn_event);
}
menu_event_t menu_event= GetMenuEvent();
if (menu_event!=MENU_EVENT_NONE){
ClearMenuEvent();
FSM_OnSoftwareEvent(menu_event);
}
}
return (EXIT_SUCCESS);
}