-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathopt.c
101 lines (84 loc) · 2.09 KB
/
opt.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "opt.h"
#include "crd.h"
#include "uif.h"
#include "uib.h"
#include "fls.h"
#include "led.h"
#include "print.h"
#include <avr/pgmspace.h>
#define PRINTOptFlash(x) printStr((void*)pgm_read_word(&x), FLASH)
/*-----------------------------START MENU CONFIGURATION */
#define MAX_OPT_SIZE (sizeof(opt_menuFp)/sizeof(fp_t))
// Local Function prototype
static void opt_previous(void);
static void opt_next(void);
static void opt_apply(void);
static void opt_lock(void);
static void opt_printUser(void);
static void opt_printPass(void);
/*Function pointer to loop inside options Menu */
typedef void (*fp_t)(void);
fp_t const opt_menuFp[] PROGMEM ={
opt_printPass,opt_printUser,
};
/* Initialize function pointer to NULL */
fp_t fptr = 0;
/*-------------------------- END OF MENU CONFIGURATION */
/* Options Start Message */
const char opt_startStr[] PROGMEM = OPT_START_STR;
/* Options Finite state machine [Start] */
void OPT_fsmStart(void){
UIF_state = OPTIONS;
UIF_optionsIndex = 0;
print_deleteStr();
printStr((void*)opt_startStr, FLASH);
LED_BlinkBoth();
}
/* Options Finite state machine */
void OPT_fsm(uint8_t button){
switch(button) {
case LEFT:
opt_lock();
break;
case UP:
opt_previous();
break;
case RIGHT:
CRD_fsmStart();
break;
case DOWN:
opt_next();
break;
default:
return;
}
}
static void opt_previous(void){
// select previous credential
print_deleteStr();
UIF_increment(&UIF_optionsIndex, MAX_OPT_SIZE);
opt_apply();
}
static void opt_next(void){
UIF_decrement(&UIF_optionsIndex, MAX_OPT_SIZE);
opt_apply();
}
static void opt_apply(void){
fptr = (fp_t)pgm_read_word(&(opt_menuFp[UIF_optionsIndex]));
fptr();
}
static void opt_lock(void){
print_deleteStr();
UIF_Init();
LED_Off();
}
static void opt_printUser(void){
print_deleteStr();
CRD_printDetail(CRD_USER, CRD_USER+1);
LED_BlinkGreen();
}
static void opt_printPass(void){
print_deleteStr();
CRD_printDetail(CRD_PASS, CRD_PASS+1);
LED_BlinkRed();
}