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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#include "Key_user.h"
#include "Components.h"
__align(4)
#define BACK_MENU_TIME 1000
#define MENU_GRADE g_u8Menu_Grade
#define CURSOR_POSITION g_u8Cursor_Posittion
_Menu_Data MenuData;
uint8_t PageType; //设置时间参数(设置小时或者分钟)
uint8_t Key_Right_Long_Press_Flag;
uint8_t Key_Left_Long_Press_Flag;
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
RTC_CounterTypeDef counter_val;
void Key_Operation_Left(Key_Event_en_t enKeyEvent)//Mode
{
switch (enKeyEvent)
{
case KEY_EVENT_SHORT_PRESS_1:
if(MENU_GRADE == 0x00)
{
Menu_Service(MENU_KEY_LEFT_SHORT);
}
else
{
Menu_Service(MENU_KEY_DOWN_SHORT);
}
break;
case KEY_EVENT_SHORT_PRESS_2:
if(MENU_GRADE == 0x00)
{
Menu_Service(MENU_KEY_LEFT_LONG);
}
else
{
Menu_Change_Branch_To_Item(0, MENU_ITEM_DriveInfo);
Menu_Service(MENU_KEY_DOWN_LONG);
}
break;
case KEY_EVENT_LONG_PRESS_1: //2
if(MENU_GRADE == 0x00)
{
Menu_Service(MENU_KEY_LEFT_SUPER_LONG);
}
else
{
Menu_Service(MENU_KEY_DOWN_SUPER_LONG);
}
Key_Left_Long_Press_Flag = 1;
break;
case KEY_EVENT_LONG_PRESS_2: //3
break;
case KEY_EVENT_LONG_PRESS_3: //5s
break;
case KEY_EVENT_LONG_PRESS_4: //10s
break;
case KEY_EVENT_OFF_TO_ON:
break;
case KEY_EVENT_ON_TO_OFF:
break;
case KEY_EVENT_NONE:
Key_Left_Long_Press_Flag = 0;
break;
default:
break;
}
}
void Key_Operation_Right(Key_Event_en_t enKeyEvent)//Set
{
switch (enKeyEvent)
{
case KEY_EVENT_SHORT_PRESS_1:
Menu_Service(MENU_KEY_CONFIRM_SHORT);
break;
case KEY_EVENT_SHORT_PRESS_2:
Menu_Service(MENU_KEY_CONFIRM_LONG);
break;
case KEY_EVENT_LONG_PRESS_1: //2s
Menu_Service(MENU_KEY_CONFIRM_SUPER_LONG);
Key_Right_Long_Press_Flag = 1;
break;
case KEY_EVENT_LONG_PRESS_2: //3s
break;
case KEY_EVENT_LONG_PRESS_3: //5s
break;
case KEY_EVENT_LONG_PRESS_4: //10s
break;
case KEY_EVENT_OFF_TO_ON:
break;
case KEY_EVENT_ON_TO_OFF:
break;
case KEY_EVENT_NONE:
Key_Right_Long_Press_Flag = 0;
break;
default:
break;
}
}
/*---------------------------------------------------------------------------------------*/
Key_Status_en_t Key_Status_Read_Left(void)
{
Key_Status_en_t enKeyReal = KEY_REALTIME_LOOSEN;
if (SYS_OPR_STAT_IGN_ON)
{
// if (RTE_GPIO_Get_Level(MODE_P_IN))
// {
// enKeyReal = KEY_REALTIME_LOOSEN;
// }
// else
// {
// enKeyReal = KEY_REALTIME_PRESS;
// }
}
return enKeyReal;
}
Key_Status_en_t Key_Status_Read_Right(void)
{
Key_Status_en_t enKeyReal = KEY_REALTIME_LOOSEN;
if (SYS_OPR_STAT_IGN_ON)
{
// if (RTE_GPIO_Get_Level(SET_P_IN))
// {
// enKeyReal = KEY_REALTIME_LOOSEN;
// }
// else
// {
// enKeyReal = KEY_REALTIME_PRESS;
// }
}
return enKeyReal;
}
/*---------------------------------------------------------------------------------------*/
const Key_Attribute_st_t stKeyAttribute[KEY_NUM_MAX] =
{
{KEY_NEED_DEBOUNCE_NORMAL, Key_Status_Read_Left, Key_Operation_Left},
{KEY_NEED_DEBOUNCE_NORMAL, Key_Status_Read_Right, Key_Operation_Right},
//{KEY_NEED_DEBOUNCE_NORMAL, Key_Status_Read_FLIP, Key_Operation_FLIP},
//{KEY_NEED_DEBOUNCE_NORMAL, Key_Status_Read_ADJUST, Key_Operation_ADJUST},
};
/*---------------------------------------------------------------------------------------*/
Key_uint8_t u8KeyRamData[KEY_RAM_DATA_LEN];
void Key_KL30_Init_EXample(void)
{
Key_Init_st_t stKeyInitTem;
Key_uint16_t i;
for (i = 0; i < KEY_RAM_DATA_LEN; i++)
{
u8KeyRamData[i] = 0;
}
stKeyInitTem.u8KeyNum = KEY_NUM_MAX;
stKeyInitTem.enKeyIGNRealStatus = KEY_IG_OFF;
Key_KL30_Init(&u8KeyRamData[0], stKeyAttribute, &stKeyInitTem);
Key_Parameter_Set_Short_Press_1_Time(50U,1000U);
Key_Parameter_Set_Short_Press_2_Time(3000U,10000U);
Key_Parameter_Set_Long_Press_1_Time(10000U);
Key_Parameter_Set_Long_Press_2_Time(60000U);
}
void Key_Wakeup_Init_EXample(void)
{
Key_Init_st_t stKeyInitTem;
stKeyInitTem.u8KeyNum = KEY_NUM_MAX;
stKeyInitTem.enKeyIGNRealStatus = KEY_IG_OFF;
Key_Wakeup_Init(&u8KeyRamData[0], stKeyAttribute, &stKeyInitTem);
Key_Parameter_Set_Short_Press_1_Time(50U,1000U);
Key_Parameter_Set_Short_Press_2_Time(3000U,10000U);
Key_Parameter_Set_Long_Press_1_Time(10000U);
Key_Parameter_Set_Long_Press_2_Time(60000U);
}
void Key_Check_Service(void)
{
PageType = Page_Time_Set_Hour;
}
void Key_Auto_Save(void)
{
if(PageType == Page_Time_Set_Hour)
{
RTC_SetTime(&counter_val.time);
}
if(PageType == Page_Time_Set_Minute)
{
RTC_SetTime(&counter_val.time);
}
PageType = Page_Time;
}
void MenuData_Unit_Init(void)
{
MenuData.Unit = 0;
}
uint8_t ClearODO_Flag = 0;
void TYW_RESET_ODO(void)
{
if(SYS_OPR_STAT_IGN_ON)
{
if(ClearODO_Flag < 1)
{
//if((Get_DispVechileSpeed() >= 1200)&&(Get_DispEngineSpeed() >= 11000))
{
ClearODO_Flag = 1;
Data_Mileage_Clear();
}
}
}
else
{
ClearODO_Flag = 0;
}
}
uint8_t Get_Dis_Hour_Time(void)
{
return counter_val.time.RTC_Hours;
}
uint8_t Get_Dis_Minute_Time(void)
{
return counter_val.time.RTC_Minutes;
}
uint8_t Get_Current_PageType(void)
{
return PageType;
}
uint8_t Get_Dis_Unit(void)
{
return MenuData.Unit; //0km,1mile
}