Key_user.c 8.38 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;
李俭双's avatar
李俭双 committed
12

13

李俭双's avatar
李俭双 committed
14 15 16 17 18 19 20 21
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
RTC_CounterTypeDef counter_val;

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

		if((PageMenu == Page_TCS) && (PageType == Page_Menu))
		{
			if(Get_Dis_Tcs_Val() == 0)
			{
				MenuData.Tcs_Val = 1;//on
			}
			else
			{
				MenuData.Tcs_Val = 0;//off
			}
		}

		if((PageMenu == Page_Trip) && (PageType == Page_Menu))
		{
			Data_Clear_Trip_All();
		}

时昊's avatar
时昊 committed
54
		TYW_RESET_ODO();
李俭双's avatar
李俭双 committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
		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
75
	case KEY_EVENT_LONG_PRESS_1:	
李俭双's avatar
李俭双 committed
76
		break;
时昊's avatar
时昊 committed
77
	case KEY_EVENT_LONG_PRESS_2:	
李俭双's avatar
李俭双 committed
78
		break;
时昊's avatar
时昊 committed
79
	case KEY_EVENT_LONG_PRESS_3:	
李俭双's avatar
李俭双 committed
80
		break;
时昊's avatar
时昊 committed
81
	case KEY_EVENT_LONG_PRESS_4:	
李俭双's avatar
李俭双 committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
		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
99 100 101 102 103 104 105 106
	if (RTE_GPIO_Get_Level(Key_MCU_IN))
	{
		enKeyReal = KEY_REALTIME_LOOSEN;
	}
	else
	{
		enKeyReal = KEY_REALTIME_PRESS;
	}
李俭双's avatar
李俭双 committed
107 108 109 110 111
	return enKeyReal;
}
Key_Status_en_t Key_Status_Read_Right(void)
{
	Key_Status_en_t enKeyReal = KEY_REALTIME_LOOSEN;
时昊's avatar
时昊 committed
112 113 114 115 116 117 118 119 120 121 122
	// 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
123 124 125 126 127 128 129 130
	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
131
	//{KEY_NEED_DEBOUNCE_NORMAL, Key_Status_Read_Right, Key_Operation_Right},
李俭双's avatar
李俭双 committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
	//{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);
153
	Key_Parameter_Set_Short_Press_2_Time(3000U,9000U);
李俭双's avatar
李俭双 committed
154

155 156 157
	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
158 159 160 161 162 163 164 165 166 167 168
	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);
169
	Key_Parameter_Set_Short_Press_2_Time(3000U,9000U);
时昊's avatar
时昊 committed
170
	
171 172 173
	//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
174
	Key_Parameter_Set_Long_Press_4_Time(10000U);
李俭双's avatar
李俭双 committed
175 176 177 178 179 180
}


void KEY_LEFT_EVENT_NONE_Service(void)	
{
	MenuInfor.Back_Time_Left++;
181
	if((MenuInfor.Back_Time_Left > BACK_MENU_TIME) &&(PageType != Page_Menu))
李俭双's avatar
李俭双 committed
182 183 184 185 186 187
	{
		MenuInfor.Back_Time_Left = BACK_MENU_TIME;
		MenuInfor.Back_Time_Left_Flag = 1;
	}
}

时昊's avatar
时昊 committed
188

李俭双's avatar
李俭双 committed
189 190 191 192 193 194 195 196 197 198 199 200

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
201

李俭双's avatar
李俭双 committed
202 203 204 205 206 207 208 209
}

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

时昊's avatar
时昊 committed
210

211
	if(PageType == Page_Menu)
时昊's avatar
时昊 committed
212
	{
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
		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
229
	}
230
	
时昊's avatar
时昊 committed
231 232

	if(PageType == Page_Time_Hour)
李俭双's avatar
李俭双 committed
233 234 235 236 237
	{
		updataDir = 1;
		datmax = 23u;
    	datmin = 0u; 
		Menu_u8Data_Updata_Process(updataDir, datmax, datmin, 1u, (uint8_t*)&(counter_val.time.RTC_Hours));
238
		RTC_SetTime(&counter_val.time);
李俭双's avatar
李俭双 committed
239
	}
时昊's avatar
时昊 committed
240
	else if(PageType == Page_Time_Minute)
李俭双's avatar
李俭双 committed
241 242 243 244 245
	{
		updataDir = 1;
		datmax = 59u;
    	datmin = 0u; 
		Menu_u8Data_Updata_Process(updataDir, datmax, datmin, 1u, (uint8_t*)&(counter_val.time.RTC_Minutes));
246 247
		RTC_SetTime(&counter_val.time);
		
李俭双's avatar
李俭双 committed
248
	}
时昊's avatar
时昊 committed
249
	else if(PageType == Page_Km_Unit)
250 251
	{	
		
时昊's avatar
时昊 committed
252
		if(Get_Dis_KM_Unit() == 0)
李俭双's avatar
李俭双 committed
253
		{
时昊's avatar
时昊 committed
254 255 256 257 258
			MenuData.KM_Unit = 1;//mile
		}
		else
		{
			MenuData.KM_Unit = 0;//km
李俭双's avatar
李俭双 committed
259 260 261
		}
		Unit_Convert_Service();
	}
时昊's avatar
时昊 committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
	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();
	}
	else
	{
		;
	}
李俭双's avatar
李俭双 committed
278 279 280 281
}

void Key_Auto_Save(void)
{
时昊's avatar
时昊 committed
282
	if((MenuInfor.Back_Time_Left_Flag == 1))
李俭双's avatar
李俭双 committed
283
	{
时昊's avatar
时昊 committed
284
		if(PageType == Page_Time_Hour)
李俭双's avatar
李俭双 committed
285 286 287 288
		{
			RTC_SetTime(&counter_val.time);
		}

时昊's avatar
时昊 committed
289
		if(PageType == Page_Time_Minute)
李俭双's avatar
李俭双 committed
290 291 292
		{
			RTC_SetTime(&counter_val.time);
		}
293
		PageType = Page_Menu ;
李俭双's avatar
李俭双 committed
294 295 296 297 298 299
	}
}


void Key_Left_Long_Press(void)
{
300
	if((PageType == Page_Menu) )
李俭双's avatar
李俭双 committed
301
	{
时昊's avatar
时昊 committed
302
		PageType = Page_Time_Hour;
李俭双's avatar
李俭双 committed
303
	}
时昊's avatar
时昊 committed
304
	else if(PageType == Page_Time_Hour)
李俭双's avatar
李俭双 committed
305
	{
时昊's avatar
时昊 committed
306
		PageType = Page_Time_Minute;
李俭双's avatar
李俭双 committed
307
	}
时昊's avatar
时昊 committed
308
	else if(PageType == Page_Time_Minute)
李俭双's avatar
李俭双 committed
309
	{
时昊's avatar
时昊 committed
310
		PageType = Page_Km_Unit;
李俭双's avatar
李俭双 committed
311
	}
时昊's avatar
时昊 committed
312
	else if(PageType == Page_Km_Unit)
李俭双's avatar
李俭双 committed
313
	{
时昊's avatar
时昊 committed
314 315 316 317
		PageType = Page_Tpms_Unit;
	}
	else if(PageType == Page_Tpms_Unit)
	{
318
		PageType = Page_Menu;
李俭双's avatar
李俭双 committed
319 320 321 322 323
	}
	else
	{
		;
	}
时昊's avatar
时昊 committed
324

325
	
李俭双's avatar
李俭双 committed
326 327
}

时昊's avatar
时昊 committed
328 329


李俭双's avatar
李俭双 committed
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
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)
{
时昊's avatar
时昊 committed
376 377 378
	MenuData.KM_Unit = 0;
	MenuData.Tpms_Unit = 0;
	MenuData.Tcs_Val = 1;
379
	
李俭双's avatar
李俭双 committed
380
}
381 382
void MenuData_TCS_Init(void)
{	
383 384
	MenuData.Tcs_Val = 1;	
	PageType = Page_Menu;
385
}
李俭双's avatar
李俭双 committed
386 387 388 389

uint8_t ClearODO_Flag = 0;
void TYW_RESET_ODO(void)
{
时昊's avatar
时昊 committed
390 391
	uint8_t Clear_EE[1] = {0xff};
	uint32_t EE_Count = 0U;
李俭双's avatar
李俭双 committed
392 393 394 395
	if(SYS_OPR_STAT_IGN_ON)
    {
        if(ClearODO_Flag < 1)
        {
李俭双's avatar
李俭双 committed
396
            if((Get_DispVechileSpeed() >= 1990)&&(Get_DispEngineSpeed() >= 12000))
李俭双's avatar
李俭双 committed
397 398 399
            {
                ClearODO_Flag = 1;
                Data_Mileage_Clear();
时昊's avatar
时昊 committed
400 401 402 403
				for(EE_Count = 0 ; EE_Count < 255; EE_Count++)
      			{
      			    eeprom_WriteRecord(EE_Count, ( uint8_t * )&Clear_EE, 1);
      			}
李俭双's avatar
李俭双 committed
404 405 406
            }
        }
    }
407
    
李俭双's avatar
李俭双 committed
408 409
}

时昊's avatar
时昊 committed
410 411
void Maintain_Reset_Service(void)
{
412
	if((Get_Data_Maintenace_Interval_Processing() == 0) && (PageMenu == Page_TCS) && (PageType == Page_Menu))
时昊's avatar
时昊 committed
413 414 415
	{
		Data_Maintenance_Interval_Reset();
	}
时昊's avatar
时昊 committed
416 417
}

李俭双's avatar
李俭双 committed
418 419 420 421 422 423 424 425 426 427 428 429 430 431
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;
}
432 433 434 435
uint8_t Get_Current_PageMenu(void)
{
	return PageMenu;
}
李俭双's avatar
李俭双 committed
436

时昊's avatar
时昊 committed
437
uint8_t Get_Dis_KM_Unit(void)
李俭双's avatar
李俭双 committed
438
{
时昊's avatar
时昊 committed
439
	return MenuData.KM_Unit; //0km,1mile
李俭双's avatar
李俭双 committed
440
}
时昊's avatar
时昊 committed
441 442 443

uint8_t Get_Dis_Tpms_Unit(void)
{
444
	return MenuData.Tpms_Unit; //0bar,1psi
时昊's avatar
时昊 committed
445 446 447 448 449 450
}

uint8_t Get_Dis_Tcs_Val(void)
{
	return MenuData.Tcs_Val; // 0 off, 1 on
}