-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttons.c
More file actions
112 lines (97 loc) · 1.86 KB
/
Copy pathbuttons.c
File metadata and controls
112 lines (97 loc) · 1.86 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
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
102
103
104
105
106
107
108
109
110
111
112
#include "thisoe.h"
#include "flag.h"
// ======= TEST (unusable for EXTI buttons) ======= //
// GPIO_PinState r_multi(void){
// return HAL_GPIO_ReadPin(BTN,Bmulti);
// }
// GPIO_PinState r_min(void){
// return HAL_GPIO_ReadPin(BTN,Bmin);
// }
// GPIO_PinState r_sec(void){
// return HAL_GPIO_ReadPin(BTN,Bsec);
// }
// ======= HANDLE BUTTON ======= //
bool h_combo(uint8_t id){
if(id==1u){
if(
read_btn(&B_MIN) == GPIO_PIN_SET ||
read_btn(&B_SEC) == GPIO_PIN_SET
) return 1u;
}
if(id==2u || id==3u){
if(read_btn(&B_MULTI) == GPIO_PIN_SET)
return 1u;
}
return 0;
}
void h_multi(){
if(GF.countingDown)
GF.countingDown = 0;
else if(GF.countingUp)
GF.countingUp = 0;
else if(GF.countupMode)
GF.countingUp = 1u;
else if(GS.m==0 && GS.s==0){
GF.countupMode = 1u;
GF.countingUp = 1u;
}else
GF.countingDown = 1u;
/*** TEST ***/
// GF.led ^= 1;
// led(GF.led);
// countup();
// settime(1u);
}
static bool h_m_s(){
bool undone = 0;
if(GF.countingDown)
GF.countingDown = 0;
else if(GF.countingUp)
GF.countingUp = 0;
else{
GF.countupMode = 0;
undone = 1u;
}
return undone;
}
void h_min(){
if(h_m_s()){
GS.m = GS.m>=99 ? 0 : GS.m+1;
memo();
}
}
void h_sec(){
if(h_m_s()){
countup();
memo();
}
}
/** handle longpress */
static void h_lp(ButtonState *BS){
uint32_t now = HAL_GetTick();
uint32_t start = BS->useTick + DEBOUNCE_MS + LONGPRESS_MS;
uint32_t step = now % (ONPRESS_BEEP_PULSE_MS * 2);
if((now > start) && (step == 0)){
switch(BS->id){
case 2u:
h_min();
break;
case 3u:
h_sec();
break;
}
settime(1u);
beep();
led(1u);
}
}
void longpress(){
if(read_btn(&B_MIN))
h_lp(&B_MIN);
else if(read_btn(&B_SEC))
h_lp(&B_SEC);
else{
GF.longpress = 0;
led(0);
}
}