Key_user.c 11 KB
Newer Older
时昊's avatar
时昊 committed
1 2 3 4 5 6 7 8 9 10 11 12 13

#include "Key_user.h"
#include "Components.h"


__align(4)

#define BACK_MENU_TIME		1000
_Menu_Data MenuData;
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
RTC_CounterTypeDef counter_val;

14
void Key_Operation_Left(Key_Event_en_t enKeyEvent)//选择
时昊's avatar
时昊 committed
15 16 17 18
{
	switch (enKeyEvent)
	{
	case KEY_EVENT_SHORT_PRESS_1:
19
		Key_Event_Short_Press_Left();
时昊's avatar
时昊 committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
		break;
	case KEY_EVENT_SHORT_PRESS_2:	
		break;
	case KEY_EVENT_LONG_PRESS_1:	//2
		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:
36
		KEY_LEFT_EVENT_NONE_Service();
时昊's avatar
时昊 committed
37 38 39 40 41
		break;
	default:
		break;
	}
}
42
void Key_Operation_Right(Key_Event_en_t enKeyEvent)//确认
时昊's avatar
时昊 committed
43 44 45 46
{
	switch (enKeyEvent)
	{
	case KEY_EVENT_SHORT_PRESS_1:	
47
		Key_Event_Short_Press_Right();
时昊's avatar
时昊 committed
48 49 50 51 52 53 54 55 56 57
		break;
	case KEY_EVENT_SHORT_PRESS_2:
		break;
	case KEY_EVENT_LONG_PRESS_1:	//2s
		break;
	case KEY_EVENT_LONG_PRESS_2:	//3s
		break;
	case KEY_EVENT_LONG_PRESS_3:	//5s
		break;
	case KEY_EVENT_LONG_PRESS_4:	//10s
58
		//TYW_RESET_ODO();
时昊's avatar
时昊 committed
59 60 61 62 63 64
		break;
	case KEY_EVENT_OFF_TO_ON:		
		break;
	case KEY_EVENT_ON_TO_OFF:
		break;
	case KEY_EVENT_NONE:
65
		KEY_RIGHT_EVENT_NONE_Service();
时昊's avatar
时昊 committed
66 67 68 69 70 71 72 73 74 75 76
		break;
	default:		
		break;
	}
}


/*---------------------------------------------------------------------------------------*/
Key_Status_en_t Key_Status_Read_Left(void)
{
	Key_Status_en_t enKeyReal = KEY_REALTIME_LOOSEN;
77 78 79 80 81
	if (RTE_GPIO_Get_Level(KEY_SELECT_MCU))//选择
	{
		enKeyReal = KEY_REALTIME_PRESS;
	}
	else
时昊's avatar
时昊 committed
82
	{
83
		enKeyReal = KEY_REALTIME_LOOSEN;
时昊's avatar
时昊 committed
84 85 86
	}
	return enKeyReal;
}
87

时昊's avatar
时昊 committed
88 89 90
Key_Status_en_t Key_Status_Read_Right(void)
{
	Key_Status_en_t enKeyReal = KEY_REALTIME_LOOSEN;
91 92

	if (RTE_GPIO_Get_Level(KEY_OK_MCU))//确认
时昊's avatar
时昊 committed
93
	{
94
		enKeyReal = KEY_REALTIME_PRESS;
时昊's avatar
时昊 committed
95
	}
96 97 98 99 100
	else
	{
		enKeyReal = KEY_REALTIME_LOOSEN;
	}
	
时昊's avatar
时昊 committed
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
	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_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);

128 129
	Key_Parameter_Set_Short_Press_1_Time(50U,2000U);
	Key_Parameter_Set_Short_Press_2_Time(3000U,6000U);
时昊's avatar
时昊 committed
130

131 132 133 134
	Key_Parameter_Set_Long_Press_1_Time(7000U);
	Key_Parameter_Set_Long_Press_2_Time(8000U);
	Key_Parameter_Set_Long_Press_3_Time(9000U);
	Key_Parameter_Set_Long_Press_4_Time(10000U);
时昊's avatar
时昊 committed
135 136 137 138 139 140 141 142 143
}
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);

144 145
	Key_Parameter_Set_Short_Press_1_Time(50U,2000U);
	Key_Parameter_Set_Short_Press_2_Time(3000U,6000U);
时昊's avatar
时昊 committed
146

147 148 149 150
	Key_Parameter_Set_Long_Press_1_Time(7000U);
	Key_Parameter_Set_Long_Press_2_Time(8000U);
	Key_Parameter_Set_Long_Press_3_Time(9000U);
	Key_Parameter_Set_Long_Press_4_Time(10000U);
时昊's avatar
时昊 committed
151 152
}

153
void Key_TimeOut_Service(void)
时昊's avatar
时昊 committed
154
{
155 156 157 158
	if((MenuData.Back_Time_Left_Flag == 1)&&(MenuData.Back_Time_Right_Flag == 1))
	{
		Menu_Service(MENU_KEY_TIMEOUT);
	}
时昊's avatar
时昊 committed
159 160 161 162
}

void Key_Auto_Save(void)
{
163 164 165 166 167 168 169 170 171 172 173 174 175 176
	
	{
		//RTC_SetTime(&counter_val.time);
	}


	{
		//RTC_SetTime(&counter_val.time);
	}

}

void Key_Event_Short_Press_Left(void)//选择
{		
177 178 179 180 181
	if(Menu_Get_Current_Cursor_Information() == MENU_ITEM_MAIN_ITEM)//切换大小计
	{
		Menu_Service(MENU_KEY_FUNCTION_1_SHORT);
	}

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
	if((Menu_Get_Current_Cursor_Information() == MENU_ITEM_DISPLAY_MODE)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_SETTING)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BLUETOOTH_CONNECT)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_SETTING)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_UNIT_SETTING)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_LANGUAGE_SETTING)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_FAULT_INFORMATION)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_PHONE_CONNECT)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_QUIT))
	{
		Menu_Service(MENU_KEY_RIGHT_SHORT);
	}
	else
	{
		if((Menu_Get_Current_Cursor_Information() == MENU_ITEM_SELECT_DAYTIME)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_SELECT_NIGHTTIME)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_SELECT_AUTO)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_5)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_4)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_3)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_2)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_1)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_AUTO)||
205
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BLUETOOTH_OPEN_CLOSE)||
206 207 208 209 210 211 212
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BLUETOOTH_SYNC)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BLUETOOTH_BACK)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_HOUR_TENB)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_HOUR_BIT)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_MIN_TENB)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_MIN_BIT)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_BACK)||
213 214 215 216
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_HOUR_TENB_SET)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_HOUR_BIT_SET)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_MIN_TENB_SET)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_MIN_BIT_SET)||
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
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_UNIT_KM)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_UNIT_MILE)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_LANGUAGE_CHINESE)||
		   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_LANGUAGE_ENGLISH))
		{
			Menu_Service(MENU_KEY_DOWN_SHORT);
		}
	}
}

void Key_Event_Short_Press_Right(void)//确认
{
	if((Menu_Get_Current_Cursor_Information() == MENU_ITEM_MAIN_ITEM)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_DISPLAY_MODE)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_SETTING)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BLUETOOTH_CONNECT)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_SETTING)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_UNIT_SETTING)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_LANGUAGE_SETTING)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_FAULT_INFORMATION)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_PHONE_CONNECT)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_QUIT)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_SELECT_DAYTIME)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_SELECT_NIGHTTIME)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_SELECT_AUTO)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_5)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_4)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_3)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_2)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_1)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BACKLIGHT_AUTO)||
248
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BLUETOOTH_OPEN_CLOSE)||
249 250 251 252 253 254 255
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BLUETOOTH_SYNC)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_BLUETOOTH_BACK)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_HOUR_TENB)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_HOUR_BIT)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_MIN_TENB)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_MIN_BIT)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_BACK)||
256 257 258 259
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_HOUR_TENB_SET)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_HOUR_BIT_SET)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_MIN_TENB_SET)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_CLOCK_MIN_BIT_SET)||
260 261 262 263
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_UNIT_KM)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_UNIT_MILE)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_LANGUAGE_CHINESE)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_LANGUAGE_ENGLISH)||
264 265
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_PHONE_CONNECT_SET)||
	   (Menu_Get_Current_Cursor_Information() == MENU_ITEM_PHONE_CONNECT_APP))
时昊's avatar
时昊 committed
266
	{
267
		Menu_Service(MENU_KEY_CONFIRM_SHORT);
时昊's avatar
时昊 committed
268
	}
269
}
时昊's avatar
时昊 committed
270

271 272 273 274
void KEY_LEFT_EVENT_NONE_Service(void)	
{
	MenuData.Back_Time_Left++;
	if(MenuData.Back_Time_Left > BACK_MENU_TIME)
时昊's avatar
时昊 committed
275
	{
276 277
		MenuData.Back_Time_Left = BACK_MENU_TIME;
		MenuData.Back_Time_Left_Flag = 1;
时昊's avatar
时昊 committed
278 279 280
	}
}

281 282 283 284 285 286 287 288 289
void KEY_RIGHT_EVENT_NONE_Service(void)	
{
	MenuData.Back_Time_Right++;
	if(MenuData.Back_Time_Right > BACK_MENU_TIME)
	{
		MenuData.Back_Time_Right = BACK_MENU_TIME;
		MenuData.Back_Time_Right_Flag = 1;
	}
}
290

291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
void Key_Clear_Time(void)
{
	if(Key_Status_Read_Left() == KEY_REALTIME_PRESS)
	{
		MenuData.Back_Time_Left = 0;
		MenuData.Back_Time_Left_Flag = 0;
		MenuData.Back_Time_Right_Flag = 0;
	}
	if(Key_Status_Read_Right() == KEY_REALTIME_PRESS)
	{
		MenuData.Back_Time_Right = 0;
		MenuData.Back_Time_Left_Flag = 0;
		MenuData.Back_Time_Right_Flag = 0;
	}
}
时昊's avatar
时昊 committed
306 307 308 309 310

uint8_t ClearODO_Flag = 0;
void TYW_RESET_ODO(void)
{
	if(SYS_OPR_STAT_IGN_ON)
311 312 313 314 315 316 317 318 319 320 321 322 323 324
    {
        if(ClearODO_Flag < 1)
        {
            if((Get_DispVechileSpeed() >= 1500)&&(Get_DispEngineSpeed() >= 12000))
            {
                ClearODO_Flag = 1;
                //Data_Mileage_Clear();
            }
        }
    }
    else
    {
        ClearODO_Flag = 0;
    }
时昊's avatar
时昊 committed
325 326
}

327 328 329 330 331 332 333 334 335
void Get_DisTime_Service(void)
{
	if(1)
    {
        RTE_RTC_Get_CounterValue(&counter_val);
        counter_val.time.RTC_Hours = RTC_Bcd2ToByte(counter_val.time.RTC_Hours);
		counter_val.time.RTC_Minutes = RTC_Bcd2ToByte(counter_val.time.RTC_Minutes);
    }
}
336 337


时昊's avatar
时昊 committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351
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_Dis_Unit(void)
{
	return MenuData.Unit; //0km,1mile
}
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366

uint8_t Get_Dis_OdoAndTrip(void)
{
	return MenuData.OdoAndTrip; //0Odo,1Trip
}

uint8_t Get_Dis_Bluetooth_Open_Close(void)
{
	return MenuData.Bluetooth_Open_Close; //0开,1关
}

uint8_t Get_Dis_Language(void)
{
	return MenuData.Language; //0中文,1英文
}