Key_user.c 11.1 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 20 21 22 23 24 25
void Data_TCS_Set_OnOff(uint32_t u32Data)
{
    uint32_t u32Data1[1u] = {0};
    u32Data1[0u] = u32Data;
    Data_User_EEPROM_Write(EM_MenuData_Tcs_Val, u32Data1, 1u);
}

李俭双'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 32 33 34 35
		if (Common_GetIgnOnTime() >= 3000)
		{
			Key_Left_Short_Press();
		}
		
李俭双's avatar
李俭双 committed
36
		break;
时昊's avatar
时昊 committed
37
	case KEY_EVENT_SHORT_PRESS_2://3-5s	
38 39 40 41 42
		if (Common_GetIgnOnTime() >= 3000)
		{
			Key_Left_Long_Press();
		}
		
李俭双'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() >= 3000)
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
		
李俭双'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;
时昊's avatar
时昊 committed
147 148 149 150 151 152 153 154 155 156 157
	// if (SYS_OPR_STAT_IGN_ON)
	// {
	// 	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 219 220 221 222
	{
		MenuInfor.Back_Time_Left = BACK_MENU_TIME;
		MenuInfor.Back_Time_Left_Flag = 1;
	}
}

时昊's avatar
时昊 committed
223

李俭双's avatar
李俭双 committed
224 225 226 227 228 229 230 231 232 233 234 235

void Key_Clear_Time(void)
{
	if(Key_Status_Read_Left() == KEY_REALTIME_PRESS)
	{
		MenuInfor.Back_Time_Left = 0;
		MenuInfor.Back_Time_Left_Flag = 0;
	}
}

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

李俭双's avatar
李俭双 committed
237 238 239 240 241 242 243 244
}

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

时昊's avatar
时昊 committed
245

246
	if(PageType == Page_Menu)
时昊's avatar
时昊 committed
247
	{
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
		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
264
	}
265
	
时昊's avatar
时昊 committed
266 267

	if(PageType == Page_Time_Hour)
李俭双's avatar
李俭双 committed
268 269 270 271 272
	{
		updataDir = 1;
		datmax = 23u;
    	datmin = 0u; 
		Menu_u8Data_Updata_Process(updataDir, datmax, datmin, 1u, (uint8_t*)&(counter_val.time.RTC_Hours));
273
		Hour_Set = 1;
274
		//RTC_SetTime(&counter_val.time);
李俭双's avatar
李俭双 committed
275
	}
时昊's avatar
时昊 committed
276
	else if(PageType == Page_Time_Minute)
李俭双's avatar
李俭双 committed
277 278 279 280 281
	{
		updataDir = 1;
		datmax = 59u;
    	datmin = 0u; 
		Menu_u8Data_Updata_Process(updataDir, datmax, datmin, 1u, (uint8_t*)&(counter_val.time.RTC_Minutes));
282
		//RTC_SetTime(&counter_val.time);
283
		Minute_Set = 1;
李俭双's avatar
李俭双 committed
284
	}
时昊's avatar
时昊 committed
285
	else if(PageType == Page_Km_Unit)
286 287
	{	
		
时昊's avatar
时昊 committed
288
		if(Get_Dis_KM_Unit() == 0)
李俭双's avatar
李俭双 committed
289
		{
时昊's avatar
时昊 committed
290 291 292 293 294
			MenuData.KM_Unit = 1;//mile
		}
		else
		{
			MenuData.KM_Unit = 0;//km
李俭双's avatar
李俭双 committed
295 296 297
		}
		Unit_Convert_Service();
	}
298
#if (IC_Current == TY200_080000b_ty)
299 300 301 302 303 304 305 306 307 308 309 310
	//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();
	//}
311 312
	else if(PageType == Page_Front_Tpms)
	{
313
		PageType = Page_Rear_Tpms;
314 315 316
	}
	else if(PageType == Page_Rear_Tpms)
	{
317
		PageType = Page_Front_Tpms;
318 319 320 321 322 323
	}
	else
	{
		;
	}
#elif (IC_Current == TY200_080000b)
时昊's avatar
时昊 committed
324 325 326 327
	else
	{
		;
	}
328
#endif
李俭双's avatar
李俭双 committed
329 330 331 332
}

void Key_Auto_Save(void)
{
时昊's avatar
时昊 committed
333
	if((MenuInfor.Back_Time_Left_Flag == 1))
李俭双's avatar
李俭双 committed
334
	{
时昊's avatar
时昊 committed
335
		if(PageType == Page_Time_Hour)
李俭双's avatar
李俭双 committed
336
		{
337 338 339 340 341 342
			if (Hour_Set == 1)
			{
				counter_val.time.RTC_Seconds = 0;
				RTC_SetTime(&counter_val.time);
				Hour_Set = 0;
			}
李俭双's avatar
李俭双 committed
343 344
		}

时昊's avatar
时昊 committed
345
		if(PageType == Page_Time_Minute)
李俭双's avatar
李俭双 committed
346
		{
347 348 349 350 351 352 353
			if(Minute_Set == 1)
			{
				counter_val.time.RTC_Seconds = 0;
				RTC_SetTime(&counter_val.time);
				Minute_Set = 0;
			}
			
李俭双's avatar
李俭双 committed
354
		}
355
		PageType = Page_Menu ;
李俭双's avatar
李俭双 committed
356 357 358 359 360 361
	}
}


void Key_Left_Long_Press(void)
{
362
	if((PageType == Page_Menu) )
李俭双's avatar
李俭双 committed
363
	{
时昊's avatar
时昊 committed
364
		PageType = Page_Time_Hour;
李俭双's avatar
李俭双 committed
365
	}
时昊's avatar
时昊 committed
366
	else if(PageType == Page_Time_Hour)
李俭双's avatar
李俭双 committed
367
	{
368 369 370 371 372 373
		if (Hour_Set == 1)
		{
			counter_val.time.RTC_Seconds = 0;
			RTC_SetTime(&counter_val.time);
			Hour_Set = 0;
		}
时昊's avatar
时昊 committed
374
		PageType = Page_Time_Minute;
李俭双's avatar
李俭双 committed
375
	}
时昊's avatar
时昊 committed
376
	else if(PageType == Page_Time_Minute)
李俭双's avatar
李俭双 committed
377
	{
378 379 380 381 382 383
		if (Minute_Set == 1)
		{
			counter_val.time.RTC_Seconds = 0;
			RTC_SetTime(&counter_val.time);
			Minute_Set = 0;
		}
时昊's avatar
时昊 committed
384
		PageType = Page_Km_Unit;
李俭双's avatar
李俭双 committed
385
	}
386
#if (IC_Current == TY200_080000b_ty)
时昊's avatar
时昊 committed
387
	else if(PageType == Page_Km_Unit)
李俭双's avatar
李俭双 committed
388
	{
389
		//PageType = Page_Tpms_Unit;
390
		PageType = Page_Front_Tpms;
391
	}
392 393 394 395
	//else if(PageType == Page_Tpms_Unit)
	//{
	//	PageType = Page_Front_Tpms;
	//}
396
	else if((PageType == Page_Front_Tpms) || (PageType == Page_Rear_Tpms))
时昊's avatar
时昊 committed
397
	{
398
		PageType = Page_Menu;
399
		Tpms_TX_Flag = 0;
李俭双's avatar
李俭双 committed
400 401 402 403 404
	}
	else
	{
		;
	}
405 406 407 408 409 410 411 412 413 414
#elif (IC_Current == TY200_080000b)
	else if(PageType == Page_Km_Unit)
	{
		PageType = Page_Menu;
	}	
	else
	{
		;
	}
#endif
时昊's avatar
时昊 committed
415

416
	
李俭双's avatar
李俭双 committed
417 418
}

时昊's avatar
时昊 committed
419 420


李俭双's avatar
李俭双 committed
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 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
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)
{
467 468
	uint32_t TCS[1] = {0};
	Data_User_EEPROM_Read(EM_MenuData_Tcs_Val, TCS, 1u);
时昊's avatar
时昊 committed
469
	MenuData.KM_Unit = 0;
470
	//MenuData.Tpms_Unit = 0;	
471
	MenuData.Tcs_Val = TCS[0];
472
	
李俭双's avatar
李俭双 committed
473
}
474 475
void MenuData_TCS_Init(void)
{	
476 477 478
	uint32_t TCS[1] = {0};
	Data_User_EEPROM_Read(EM_MenuData_Tcs_Val, TCS, 1u);
	MenuData.Tcs_Val = TCS[0];	
479
	PageType = Page_Menu;
480 481
	Hour_Set = 0;
	Minute_Set = 0;
482
}
李俭双's avatar
李俭双 committed
483 484 485 486

uint8_t ClearODO_Flag = 0;
void TYW_RESET_ODO(void)
{
487
	uint8_t Clear_EE[4] = {0xff, 0xff, 0xff, 0xff};
488
	uint8_t Clear_EE_8[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
李俭双's avatar
李俭双 committed
489 490 491 492
	if(SYS_OPR_STAT_IGN_ON)
    {
        if(ClearODO_Flag < 1)
        {
李俭双's avatar
李俭双 committed
493
            if((Get_DispVechileSpeed() >= 1990)&&(Get_DispEngineSpeed() >= 12000))
李俭双's avatar
李俭双 committed
494 495 496
            {
                ClearODO_Flag = 1;
                Data_Mileage_Clear();
497
				Service_Interval_First_Reset( ); /*保养*/
498 499 500 501 502
				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);
503
				eeprom_WriteRecord(EEPROM_BLOCK_05, ( uint8_t * )&Clear_EE_8, 8);
504 505 506 507
				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
508 509 510
            }
        }
    }
511
    
李俭双's avatar
李俭双 committed
512 513
}

时昊's avatar
时昊 committed
514 515
void Maintain_Reset_Service(void)
{
516
	if((Get_SERVICE_WARNING_ForCan() == 1) && (PageMenu != Page_Trip) && (PageMenu != Page_TCS) && (PageType == Page_Menu))
时昊's avatar
时昊 committed
517
	{
518 519 520 521 522 523 524 525
		if(Get_Interval_SetKm() == 5000)//0.1
		{
			Service_Interval_Second_Reset();
		}
		else
		{
			Service_Interval_SetKm(2000);
		}
时昊's avatar
时昊 committed
526
	}
时昊's avatar
时昊 committed
527 528
}

李俭双's avatar
李俭双 committed
529 530 531 532 533 534 535 536 537 538 539 540 541 542
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;
}
543 544 545 546
uint8_t Get_Current_PageMenu(void)
{
	return PageMenu;
}
李俭双's avatar
李俭双 committed
547

时昊's avatar
时昊 committed
548
uint8_t Get_Dis_KM_Unit(void)
李俭双's avatar
李俭双 committed
549
{
时昊's avatar
时昊 committed
550
	return MenuData.KM_Unit; //0km,1mile
李俭双's avatar
李俭双 committed
551
}
时昊's avatar
时昊 committed
552 553 554

uint8_t Get_Dis_Tpms_Unit(void)
{
555 556
	//return MenuData.Tpms_Unit; //0bar,1psi
	return 0; 
时昊's avatar
时昊 committed
557 558 559 560 561
}

uint8_t Get_Dis_Tcs_Val(void)
{
	return MenuData.Tcs_Val; // 0 off, 1 on
562 563 564 565
}
uint8_t Get_Tpms_TX_Flag(void)
{
	return Tpms_TX_Flag;
时昊's avatar
时昊 committed
566
}