Key_user.c 11.7 KB
Newer Older
李俭双's avatar
李俭双 committed
1 2 3 4 5 6

#include "Key\Key_user.h"
#include "Application.h"
#include "Components.h"
__align(4)

时昊's avatar
时昊 committed
7
#define BACK_MENU_TIME		1500
李俭双's avatar
李俭双 committed
8 9
_Menu_Infor MenuInfor;
_Menu_Data MenuData;
时昊's avatar
时昊 committed
10
uint8_t PageType = 0;
11
uint8_t PageMenu = 0;
12 13
uint8_t Hour_Set = 0;
uint8_t Minute_Set = 0;
14
uint8_t Tpms_TX_Flag = 0;
15 16
//RTC_TimeTypeDef RTC_TimeStruct;
//RTC_DateTypeDef RTC_DateStruct;
李俭双's avatar
李俭双 committed
17 18
RTC_CounterTypeDef counter_val;

19
void Data_TCS_Set_OnOff(uint8_t u8Data)
20
{
21 22
    uint8_t u8Data1[1u] = {0};
    u8Data1[0u] = u8Data;    
23
	eeprom_WriteRecord(EEPROM_BLOCK_08, (uint8_t *)u8Data1, 1);
24 25
}

李俭双's avatar
李俭双 committed
26 27 28 29
void Key_Operation_Left(Key_Event_en_t enKeyEvent)//Mode
{
	switch (enKeyEvent)
	{
时昊's avatar
时昊 committed
30
	case KEY_EVENT_SHORT_PRESS_1://1s
31
		if (Common_GetIgnOnTime() >= 3030)
32 33 34
		{
			Key_Left_Short_Press();
		}
35
		Key_Clear_Time();
李俭双's avatar
李俭双 committed
36
		break;
时昊's avatar
时昊 committed
37
	case KEY_EVENT_SHORT_PRESS_2://3-5s	
38
		if (Common_GetIgnOnTime() >= 3030)
39 40 41
		{
			Key_Left_Long_Press();
		}
42
		Key_Clear_Time();
李俭双's avatar
李俭双 committed
43
		break;
时昊's avatar
时昊 committed
44 45 46
	case KEY_EVENT_LONG_PRESS_1:	//7
		break;
	case KEY_EVENT_LONG_PRESS_2:	//8
李俭双's avatar
李俭双 committed
47
		break;
时昊's avatar
时昊 committed
48
	case KEY_EVENT_LONG_PRESS_3:	//9s
李俭双's avatar
李俭双 committed
49 50
		break;
	case KEY_EVENT_LONG_PRESS_4:	//10s
51
		if (Common_GetIgnOnTime() >= 3030)
52
		{
53 54 55
			Maintain_Reset_Service();

			if((PageMenu == Page_TCS) && (PageType == Page_Menu))
56
			{
57 58 59
				if(Get_Dis_Tcs_Val() == 0)
				{
					MenuData.Tcs_Val = 1;//on
60
					Data_TCS_Set_OnOff(MenuData.Tcs_Val);
61 62 63 64
				}
				else
				{
					MenuData.Tcs_Val = 0;//off
65
					Data_TCS_Set_OnOff(MenuData.Tcs_Val);
66
				}
67
			}
68 69
	
			if((PageMenu == Page_Trip) && (PageType == Page_Menu))
70
			{
71
				Data_Clear_Trip_All();
72
			}
73 74 75 76 77 78 79 80 81 82 83 84 85

			if (PageType == Page_Front_Tpms)
			{
				Tpms_TX_Flag = 1;
			}
			else if (PageType == Page_Rear_Tpms)
			{
				Tpms_TX_Flag = 2;
			}
			else
			{
				Tpms_TX_Flag = 0;
			}
86 87
	
			TYW_RESET_ODO();
88
		}
89
		Key_Clear_Time();
李俭双's avatar
李俭双 committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
		break;
	case KEY_EVENT_OFF_TO_ON:		
		break;
	case KEY_EVENT_ON_TO_OFF:
		break;
	case KEY_EVENT_NONE:
	    KEY_LEFT_EVENT_NONE_Service();
		break;
	default:
		break;
	}
}
void Key_Operation_Right(Key_Event_en_t enKeyEvent)//Set
{
	switch (enKeyEvent)
	{
	case KEY_EVENT_SHORT_PRESS_1:	
		break;
	case KEY_EVENT_SHORT_PRESS_2:		
		break;
时昊's avatar
时昊 committed
110
	case KEY_EVENT_LONG_PRESS_1:	
李俭双's avatar
李俭双 committed
111
		break;
时昊's avatar
时昊 committed
112
	case KEY_EVENT_LONG_PRESS_2:	
李俭双's avatar
李俭双 committed
113
		break;
时昊's avatar
时昊 committed
114
	case KEY_EVENT_LONG_PRESS_3:	
李俭双's avatar
李俭双 committed
115
		break;
时昊's avatar
时昊 committed
116
	case KEY_EVENT_LONG_PRESS_4:	
李俭双's avatar
李俭双 committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
		break;
	case KEY_EVENT_OFF_TO_ON:		
		break;
	case KEY_EVENT_ON_TO_OFF:
		break;
	case KEY_EVENT_NONE:
		break;
	default:		
		break;
	}
}


/*---------------------------------------------------------------------------------------*/
Key_Status_en_t Key_Status_Read_Left(void)
{
	Key_Status_en_t enKeyReal = KEY_REALTIME_LOOSEN;
时昊's avatar
时昊 committed
134 135 136 137 138 139 140 141
	if (RTE_GPIO_Get_Level(Key_MCU_IN))
	{
		enKeyReal = KEY_REALTIME_LOOSEN;
	}
	else
	{
		enKeyReal = KEY_REALTIME_PRESS;
	}
李俭双's avatar
李俭双 committed
142 143 144 145 146
	return enKeyReal;
}
Key_Status_en_t Key_Status_Read_Right(void)
{
	Key_Status_en_t enKeyReal = KEY_REALTIME_LOOSEN;
147
	// if (Common_Get_IG_Sts( ) == COMMON_POWER_ON)
时昊's avatar
时昊 committed
148 149 150 151 152 153 154 155 156 157
	// {
	// 	if (RTE_GPIO_Get_Level(SET_P_IN))
	// 	{
	// 		enKeyReal = KEY_REALTIME_LOOSEN;
	// 	}
	// 	else
	// 	{
	// 		enKeyReal = KEY_REALTIME_PRESS;
	// 	}
	// }
李俭双's avatar
李俭双 committed
158 159 160 161 162 163 164 165
	return enKeyReal;
}


/*---------------------------------------------------------------------------------------*/
const Key_Attribute_st_t stKeyAttribute[KEY_NUM_MAX] =
{
	{KEY_NEED_DEBOUNCE_NORMAL, Key_Status_Read_Left, Key_Operation_Left},
时昊's avatar
时昊 committed
166
	//{KEY_NEED_DEBOUNCE_NORMAL, Key_Status_Read_Right, Key_Operation_Right},
李俭双's avatar
李俭双 committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
	//{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);
188
	Key_Parameter_Set_Short_Press_2_Time(3000U,9000U);
李俭双's avatar
李俭双 committed
189

190 191 192
	Key_Parameter_Set_Long_Press_1_Time(9100U);
	Key_Parameter_Set_Long_Press_2_Time(9200U);
	Key_Parameter_Set_Long_Press_3_Time(9300U);
李俭双's avatar
李俭双 committed
193 194 195 196 197 198 199 200 201 202 203
	Key_Parameter_Set_Long_Press_4_Time(10000U);	
}
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);
204
	Key_Parameter_Set_Short_Press_2_Time(3000U,9000U);
时昊's avatar
时昊 committed
205
	
206 207 208
	//Key_Parameter_Set_Long_Press_1_Time(7000U);
	//Key_Parameter_Set_Long_Press_2_Time(8000U);
	//Key_Parameter_Set_Long_Press_3_Time(9000U);
时昊's avatar
时昊 committed
209
	Key_Parameter_Set_Long_Press_4_Time(10000U);
李俭双's avatar
李俭双 committed
210 211 212 213 214 215
}


void KEY_LEFT_EVENT_NONE_Service(void)	
{
	MenuInfor.Back_Time_Left++;
216
	if((MenuInfor.Back_Time_Left > BACK_MENU_TIME) &&(PageType != Page_Menu))
李俭双's avatar
李俭双 committed
217 218
	{
		MenuInfor.Back_Time_Left = BACK_MENU_TIME;
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
		//MenuInfor.Back_Time_Left_Flag = 1;
		if(PageType == Page_Time_Hour)
		{
			if (Hour_Set == 1)
			{
				counter_val.time.RTC_Seconds = 0;
				RTC_SetTime(&counter_val.time);
				Hour_Set = 0;
			}
		}

		if(PageType == Page_Time_Minute)
		{
			if(Minute_Set == 1)
			{
				counter_val.time.RTC_Seconds = 0;
				RTC_SetTime(&counter_val.time);
				Minute_Set = 0;
			}
			
		}
		PageType = Page_Menu ;
李俭双's avatar
李俭双 committed
241 242 243
	}
}

时昊's avatar
时昊 committed
244

李俭双's avatar
李俭双 committed
245 246 247

void Key_Clear_Time(void)
{
248
	//if(Key_Status_Read_Left() == KEY_REALTIME_PRESS)
李俭双's avatar
李俭双 committed
249 250
	{
		MenuInfor.Back_Time_Left = 0;
251
		//MenuInfor.Back_Time_Left_Flag = 0;
李俭双's avatar
李俭双 committed
252 253 254 255 256
	}
}

void Key_Check_Service(void)
{
时昊's avatar
时昊 committed
257

李俭双's avatar
李俭双 committed
258 259 260 261 262 263 264 265
}

void Key_Left_Short_Press(void)
{
	uint8_t updataDir = 0u;
	uint8_t datmax = 0u;
	uint8_t datmin = 0u;

时昊's avatar
时昊 committed
266

267
	if(PageType == Page_Menu)
时昊's avatar
时昊 committed
268
	{
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
		if(PageMenu == Page_Odo)
		{
			PageMenu = Page_Trip;
		}
		else if(PageMenu == Page_Trip)
		{
			PageMenu = Page_DTC;
		}
		else if(PageMenu == Page_DTC)
		{
			PageMenu = Page_TCS;
		}
		else if(PageMenu == Page_TCS)
		{
			PageMenu = Page_Odo;
		}
时昊's avatar
时昊 committed
285
	}
286
	
时昊's avatar
时昊 committed
287 288

	if(PageType == Page_Time_Hour)
李俭双's avatar
李俭双 committed
289 290 291 292 293
	{
		updataDir = 1;
		datmax = 23u;
    	datmin = 0u; 
		Menu_u8Data_Updata_Process(updataDir, datmax, datmin, 1u, (uint8_t*)&(counter_val.time.RTC_Hours));
294
		Hour_Set = 1;
295
		//RTC_SetTime(&counter_val.time);
李俭双's avatar
李俭双 committed
296
	}
时昊's avatar
时昊 committed
297
	else if(PageType == Page_Time_Minute)
李俭双's avatar
李俭双 committed
298 299 300 301 302
	{
		updataDir = 1;
		datmax = 59u;
    	datmin = 0u; 
		Menu_u8Data_Updata_Process(updataDir, datmax, datmin, 1u, (uint8_t*)&(counter_val.time.RTC_Minutes));
303
		//RTC_SetTime(&counter_val.time);
304
		Minute_Set = 1;
李俭双's avatar
李俭双 committed
305
	}
时昊's avatar
时昊 committed
306
	else if(PageType == Page_Km_Unit)
307 308
	{	
		
时昊's avatar
时昊 committed
309
		if(Get_Dis_KM_Unit() == 0)
李俭双's avatar
李俭双 committed
310
		{
时昊's avatar
时昊 committed
311 312 313 314 315
			MenuData.KM_Unit = 1;//mile
		}
		else
		{
			MenuData.KM_Unit = 0;//km
李俭双's avatar
李俭双 committed
316 317 318
		}
		Unit_Convert_Service();
	}
319
#if (IC_Current == TY200_080000b_ty)
320 321 322 323 324 325 326 327 328 329 330 331
	//else if(PageType == Page_Tpms_Unit)
	//{
	//	if(Get_Dis_Tpms_Unit() == 0)
	//	{
	//		MenuData.Tpms_Unit = 1;//psi
	//	}
	//	else
	//	{
	//		MenuData.Tpms_Unit = 0;//bar
	//	}
	//	Unit_Convert_Service();
	//}
332 333
	else if(PageType == Page_Front_Tpms)
	{
334
		PageType = Page_Rear_Tpms;
335 336 337
	}
	else if(PageType == Page_Rear_Tpms)
	{
338
		PageType = Page_Front_Tpms;
339 340 341 342 343 344
	}
	else
	{
		;
	}
#elif (IC_Current == TY200_080000b)
时昊's avatar
时昊 committed
345 346 347 348
	else
	{
		;
	}
349
#endif
李俭双's avatar
李俭双 committed
350 351 352 353
}

void Key_Auto_Save(void)
{
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
	//if((MenuInfor.Back_Time_Left_Flag == 1))
	//{
	//	if(PageType == Page_Time_Hour)
	//	{
	//		if (Hour_Set == 1)
	//		{
	//			counter_val.time.RTC_Seconds = 0;
	//			RTC_SetTime(&counter_val.time);
	//			Hour_Set = 0;
	//		}
	//	}
//
	//	if(PageType == Page_Time_Minute)
	//	{
	//		if(Minute_Set == 1)
	//		{
	//			counter_val.time.RTC_Seconds = 0;
	//			RTC_SetTime(&counter_val.time);
	//			Minute_Set = 0;
	//		}
	//		
	//	}
	//	PageType = Page_Menu ;
	//}
李俭双's avatar
李俭双 committed
378 379 380 381 382
}


void Key_Left_Long_Press(void)
{
383
	if((PageType == Page_Menu) )
李俭双's avatar
李俭双 committed
384
	{
时昊's avatar
时昊 committed
385
		PageType = Page_Time_Hour;
李俭双's avatar
李俭双 committed
386
	}
时昊's avatar
时昊 committed
387
	else if(PageType == Page_Time_Hour)
李俭双's avatar
李俭双 committed
388
	{
389 390 391 392 393 394
		if (Hour_Set == 1)
		{
			counter_val.time.RTC_Seconds = 0;
			RTC_SetTime(&counter_val.time);
			Hour_Set = 0;
		}
时昊's avatar
时昊 committed
395
		PageType = Page_Time_Minute;
李俭双's avatar
李俭双 committed
396
	}
时昊's avatar
时昊 committed
397
	else if(PageType == Page_Time_Minute)
李俭双's avatar
李俭双 committed
398
	{
399 400 401 402 403 404
		if (Minute_Set == 1)
		{
			counter_val.time.RTC_Seconds = 0;
			RTC_SetTime(&counter_val.time);
			Minute_Set = 0;
		}
时昊's avatar
时昊 committed
405
		PageType = Page_Km_Unit;
李俭双's avatar
李俭双 committed
406
	}
407
#if (IC_Current == TY200_080000b_ty)
时昊's avatar
时昊 committed
408
	else if(PageType == Page_Km_Unit)
李俭双's avatar
李俭双 committed
409
	{
410
		//PageType = Page_Tpms_Unit;
411
		PageType = Page_Front_Tpms;
412
	}
413 414 415 416
	//else if(PageType == Page_Tpms_Unit)
	//{
	//	PageType = Page_Front_Tpms;
	//}
417
	else if((PageType == Page_Front_Tpms) || (PageType == Page_Rear_Tpms))
时昊's avatar
时昊 committed
418
	{
419
		PageType = Page_Menu;
420
		Tpms_TX_Flag = 0;
李俭双's avatar
李俭双 committed
421 422 423 424 425
	}
	else
	{
		;
	}
426 427 428 429 430 431 432 433 434 435
#elif (IC_Current == TY200_080000b)
	else if(PageType == Page_Km_Unit)
	{
		PageType = Page_Menu;
	}	
	else
	{
		;
	}
#endif
时昊's avatar
时昊 committed
436

437
	
李俭双's avatar
李俭双 committed
438 439
}

时昊's avatar
时昊 committed
440 441


李俭双's avatar
李俭双 committed
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
void Menu_u8Data_Updata_Process(uint8_t updateDir , uint8_t datMax, uint8_t datMin, uint8_t datStep, uint8_t *dat)
{
	uint8_t temp = *dat;
    if(datMax > datMin)
    {
        if(updateDir == 1u)
        {
            if(temp < datMax)
            {
                if((temp) <= (255u-datStep))
                {
                    temp += datStep;
                }
            } 
            else
            {
                temp = datMin;
            }        
        }
        else if(updateDir == 2u)
        {
            if(temp > datMin)
            {
                if(temp >= datStep)
                {
                    temp -= datStep;
                }
            } 
            else
            {
                temp = datMax;
            }
        }
        else
        {
        }
    }
    else
    {
    }

	*dat = temp;
}

void MenuData_Unit_Init(void)
{
488 489 490
	uint8_t TCS[1] = {0};
	//Data_User_EEPROM_Read(EM_MenuData_Tcs_Val, TCS, 1u);
	eeprom_ReadRecord(EEPROM_BLOCK_08, TCS, 1);
时昊's avatar
时昊 committed
491
	MenuData.KM_Unit = 0;
492
	//MenuData.Tpms_Unit = 0;	
493
	MenuData.Tcs_Val = TCS[0];
494
	
李俭双's avatar
李俭双 committed
495
}
496 497
void MenuData_TCS_Init(void)
{	
498 499 500
	uint8_t TCS[1] = {0};
	//Data_User_EEPROM_Read(EM_MenuData_Tcs_Val, TCS, 1u);
	eeprom_ReadRecord(EEPROM_BLOCK_08, TCS, 1);
501
	MenuData.Tcs_Val = TCS[0];	
502
	PageType = Page_Menu;
503 504
	Hour_Set = 0;
	Minute_Set = 0;
505
}
李俭双's avatar
李俭双 committed
506 507 508 509

uint8_t ClearODO_Flag = 0;
void TYW_RESET_ODO(void)
{
510
	uint8_t Clear_EE[4] = {0xff, 0xff, 0xff, 0xff};
511
	uint8_t Clear_EE_8[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
512
	if(Common_Get_IG_Sts( ) == COMMON_POWER_ON)
李俭双's avatar
李俭双 committed
513 514 515
    {
        if(ClearODO_Flag < 1)
        {
李俭双's avatar
李俭双 committed
516
            if((Get_DispVechileSpeed() >= 1990)&&(Get_DispEngineSpeed() >= 12000))
李俭双's avatar
李俭双 committed
517 518 519
            {
                ClearODO_Flag = 1;
                Data_Mileage_Clear();
520
				Service_Interval_First_Reset( ); /*保养*/
521 522 523 524 525
				eeprom_WriteRecord(EEPROM_BLOCK_00, ( uint8_t * )&Clear_EE, 4);
				eeprom_WriteRecord(EEPROM_BLOCK_01, ( uint8_t * )&Clear_EE, 4);
				eeprom_WriteRecord(EEPROM_BLOCK_02, ( uint8_t * )&Clear_EE, 4);
				eeprom_WriteRecord(EEPROM_BLOCK_03, ( uint8_t * )&Clear_EE, 4);
				eeprom_WriteRecord(EEPROM_BLOCK_04, ( uint8_t * )&Clear_EE, 4);
526
				eeprom_WriteRecord(EEPROM_BLOCK_05, ( uint8_t * )&Clear_EE_8, 8);
527 528 529 530
				eeprom_WriteRecord(EEPROM_BLOCK_06, ( uint8_t * )&Clear_EE, 4);
				eeprom_WriteRecord(EEPROM_BLOCK_07, ( uint8_t * )&Clear_EE, 4);
				eeprom_WriteRecord(EEPROM_BLOCK_08, ( uint8_t * )&Clear_EE, 4);
				eeprom_WriteRecord(EEPROM_BLOCK_09, ( uint8_t * )&Clear_EE, 4);
李俭双's avatar
李俭双 committed
531 532 533
            }
        }
    }
534
    
李俭双's avatar
李俭双 committed
535 536
}

时昊's avatar
时昊 committed
537 538
void Maintain_Reset_Service(void)
{
539
	if((Get_SERVICE_WARNING_ForCan() == 1) && (PageMenu != Page_Trip) && (PageMenu != Page_TCS) && (PageType == Page_Menu))
时昊's avatar
时昊 committed
540
	{
541 542 543 544 545 546 547 548
		if(Get_Interval_SetKm() == 5000)//0.1
		{
			Service_Interval_Second_Reset();
		}
		else
		{
			Service_Interval_SetKm(2000);
		}
时昊's avatar
时昊 committed
549
	}
时昊's avatar
时昊 committed
550 551
}

李俭双's avatar
李俭双 committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565
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;
}
566 567 568 569
uint8_t Get_Current_PageMenu(void)
{
	return PageMenu;
}
李俭双's avatar
李俭双 committed
570

时昊's avatar
时昊 committed
571
uint8_t Get_Dis_KM_Unit(void)
李俭双's avatar
李俭双 committed
572
{
时昊's avatar
时昊 committed
573
	return MenuData.KM_Unit; //0km,1mile
李俭双's avatar
李俭双 committed
574
}
时昊's avatar
时昊 committed
575 576 577

uint8_t Get_Dis_Tpms_Unit(void)
{
578 579
	//return MenuData.Tpms_Unit; //0bar,1psi
	return 0; 
时昊's avatar
时昊 committed
580 581 582 583
}

uint8_t Get_Dis_Tcs_Val(void)
{
584
	return (uint8_t)(MenuData.Tcs_Val); // 0 off, 1 on
585 586 587 588
}
uint8_t Get_Tpms_TX_Flag(void)
{
	return Tpms_TX_Flag;
时昊's avatar
时昊 committed
589
}