/
model_contral.c
168 lines (141 loc) · 2.94 KB
/
model_contral.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "juma_sdk_api.h"
#include "model_contral.h"
#include "jump.h"
uint8_t model;
#define MODEL_MAX 5
uint8_t button_state1;
uint8_t button_state2;
uint8_t button_count;
uint8_t button_off_count;
uint8_t screen_is_on;
void (* two_click_function_point) (void);
#define NORMAL_MODEL 0
#define TIME_MODEL 1
#define TRAIN1_MODEL 2
#define TRAIN2_MODEL 3
#define TRAIN3_MODEL 4
#define TRAIN4_MODEL 5
#define COUNT_MODEL 6
void model_change()
{
switch(model)
{
case NORMAL_MODEL: normal_model_exit(); break;
case TIME_MODEL: timer_model_exit(); break;
case TRAIN1_MODEL: train1_model_exit(); break;
case TRAIN2_MODEL: train2_model_exit(); break;
case TRAIN3_MODEL: train3_model_exit(); break;
case TRAIN4_MODEL: train4_model_exit(); break;
case COUNT_MODEL: count_model_exit(); break;
}
model ++;
if(model > COUNT_MODEL)
{
model = NORMAL_MODEL;
}
switch(model)
{
case NORMAL_MODEL: normal_model_enter(); break;
case TIME_MODEL: timer_model_enter(); break;
case TRAIN1_MODEL: train1_model_enter(); break;
case TRAIN2_MODEL: train2_model_enter(); break;
case TRAIN3_MODEL: train3_model_enter(); break;
case TRAIN4_MODEL: train4_model_enter(); break;
case COUNT_MODEL: count_model_enter(); break;
}
}
void system_off(void);
static void button_one_click()
{
model_change();
}
static void button_two_click()
{
if(two_click_function_point) two_click_function_point();
}
static void button_long_push()
{
if(system_off) system_off();
}
void hall_change_for_contral(void)
{
}
void button_scan(void * args);
void button_init()
{
button_state1 = 1;
button_state2 = 1;
button_count = 0;
button_off_count = 0;
gpio_setup(BUTTON, GPIO_INPUT_PULLUP);
run_after_delay(button_scan, NULL, 2000);
}
void button_is_long_push(void * args)
{
if((!gpio_read(BUTTON)) && (button_count == 1))
{//
button_long_push();
}
button_count = 0;
}
void button_event_one_two(void * args)
{
if(button_count >= 2)
{//two click
button_two_click();
button_count = 0;
}
else
{
if(gpio_read(BUTTON))
{//one click
button_one_click();
button_count = 0;
}
else
{
run_after_delay(button_is_long_push, NULL, 2000);
}
}
}
void button_scan(void * args)
{
if(gpio_read(BUTTON))
{
button_state2 = 1;
}
else
{
button_state2 = 0;
}
if((button_state1 == 1) && (button_state2 == 0))
{//fall
if(button_count == 0)
{
button_count ++;
run_after_delay(button_event_one_two, NULL, 500);
}
else
{
button_count ++;
}
}
button_state1 = button_state2;
run_after_delay(button_scan, NULL, 50);
}
void screen_on()
{
screen_is_on = 1;
}
void screen_off()
{
screen_is_on = 0;
}
void model_contral_init(void)
{
button_init();
screen_is_on = 1;
model = COUNT_MODEL;
two_click_function_point = NULL;
model_change();
}