Key_user.c 7.63 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;
李俭双's avatar
李俭双 committed
11 12 13 14 15 16 17 18 19

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
20
	case KEY_EVENT_SHORT_PRESS_1://1s
李俭双's avatar
李俭双 committed
21 22
		Key_Left_Short_Press();
		break;
时昊's avatar
时昊 committed
23
	case KEY_EVENT_SHORT_PRESS_2://3-5s	
李俭双's avatar
李俭双 committed
24 25
		Key_Left_Long_Press();
		break;
时昊's avatar
时昊 committed
26 27 28
	case KEY_EVENT_LONG_PRESS_1:	//7
		break;
	case KEY_EVENT_LONG_PRESS_2:	//8
李俭双's avatar
李俭双 committed
29
		break;
时昊's avatar
时昊 committed
30
	case KEY_EVENT_LONG_PRESS_3:	//9s
李俭双's avatar
李俭双 committed
31 32
		break;
	case KEY_EVENT_LONG_PRESS_4:	//10s
时昊's avatar
时昊 committed
33 34
		Maintain_Reset_Service();
		TYW_RESET_ODO();
李俭双's avatar
李俭双 committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
		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
55
	case KEY_EVENT_LONG_PRESS_1:	
李俭双's avatar
李俭双 committed
56
		break;
时昊's avatar
时昊 committed
57
	case KEY_EVENT_LONG_PRESS_2:	
李俭双's avatar
李俭双 committed
58
		break;
时昊's avatar
时昊 committed
59
	case KEY_EVENT_LONG_PRESS_3:	
李俭双's avatar
李俭双 committed
60
		break;
时昊's avatar
时昊 committed
61
	case KEY_EVENT_LONG_PRESS_4:	
李俭双's avatar
李俭双 committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
		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
79 80 81 82 83 84 85 86
	if (RTE_GPIO_Get_Level(Key_MCU_IN))
	{
		enKeyReal = KEY_REALTIME_LOOSEN;
	}
	else
	{
		enKeyReal = KEY_REALTIME_PRESS;
	}
李俭双's avatar
李俭双 committed
87 88 89 90 91
	return enKeyReal;
}
Key_Status_en_t Key_Status_Read_Right(void)
{
	Key_Status_en_t enKeyReal = KEY_REALTIME_LOOSEN;
时昊's avatar
时昊 committed
92 93 94 95 96 97 98 99 100 101 102
	// 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
103 104 105 106 107 108 109 110
	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
111
	//{KEY_NEED_DEBOUNCE_NORMAL, Key_Status_Read_Right, Key_Operation_Right},
李俭双's avatar
李俭双 committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
	//{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);
时昊's avatar
时昊 committed
133
	Key_Parameter_Set_Short_Press_2_Time(3000U,5000U);
李俭双's avatar
李俭双 committed
134

时昊's avatar
时昊 committed
135 136 137
	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
138 139 140 141 142 143 144 145 146 147 148
	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);
时昊's avatar
时昊 committed
149 150 151 152 153 154
	Key_Parameter_Set_Short_Press_2_Time(3000U,5000U);
	
	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
155 156 157 158 159 160 161 162 163 164 165 166 167
}


void KEY_LEFT_EVENT_NONE_Service(void)	
{
	MenuInfor.Back_Time_Left++;
	if(MenuInfor.Back_Time_Left > BACK_MENU_TIME)
	{
		MenuInfor.Back_Time_Left = BACK_MENU_TIME;
		MenuInfor.Back_Time_Left_Flag = 1;
	}
}

时昊's avatar
时昊 committed
168

李俭双's avatar
李俭双 committed
169 170 171 172 173 174 175 176 177 178 179 180

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
181

李俭双's avatar
李俭双 committed
182 183 184 185 186 187 188 189
}

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

时昊's avatar
时昊 committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208

	if(PageType == Page_Odo)
	{
		PageType = Page_Trip;
	}
	else if(PageType == Page_Trip)
	{
		PageType = Page_DTC;
	}
	else if(PageType == Page_DTC)
	{
		PageType = Page_TCS;
	}
	else if(PageType == Page_TCS)
	{
		PageType = Page_Odo;
	}

	if(PageType == Page_Time_Hour)
李俭双's avatar
李俭双 committed
209 210 211 212 213 214
	{
		updataDir = 1;
		datmax = 23u;
    	datmin = 0u; 
		Menu_u8Data_Updata_Process(updataDir, datmax, datmin, 1u, (uint8_t*)&(counter_val.time.RTC_Hours));
	}
时昊's avatar
时昊 committed
215
	else if(PageType == Page_Time_Minute)
李俭双's avatar
李俭双 committed
216 217 218 219 220 221
	{
		updataDir = 1;
		datmax = 59u;
    	datmin = 0u; 
		Menu_u8Data_Updata_Process(updataDir, datmax, datmin, 1u, (uint8_t*)&(counter_val.time.RTC_Minutes));
	}
时昊's avatar
时昊 committed
222
	else if(PageType == Page_Km_Unit)
李俭双's avatar
李俭双 committed
223
	{
时昊's avatar
时昊 committed
224
		if(Get_Dis_KM_Unit() == 0)
李俭双's avatar
李俭双 committed
225
		{
时昊's avatar
时昊 committed
226 227 228 229 230
			MenuData.KM_Unit = 1;//mile
		}
		else
		{
			MenuData.KM_Unit = 0;//km
李俭双's avatar
李俭双 committed
231 232 233
		}
		Unit_Convert_Service();
	}
时昊's avatar
时昊 committed
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
	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
250 251 252 253
}

void Key_Auto_Save(void)
{
时昊's avatar
时昊 committed
254
	if((MenuInfor.Back_Time_Left_Flag == 1))
李俭双's avatar
李俭双 committed
255
	{
时昊's avatar
时昊 committed
256
		if(PageType == Page_Time_Hour)
李俭双's avatar
李俭双 committed
257 258 259 260
		{
			RTC_SetTime(&counter_val.time);
		}

时昊's avatar
时昊 committed
261
		if(PageType == Page_Time_Minute)
李俭双's avatar
李俭双 committed
262 263 264
		{
			RTC_SetTime(&counter_val.time);
		}
时昊's avatar
时昊 committed
265
		PageType = Page_Odo;
李俭双's avatar
李俭双 committed
266 267 268 269 270 271
	}
}


void Key_Left_Long_Press(void)
{
时昊's avatar
时昊 committed
272
	if(PageType == Page_Odo)
李俭双's avatar
李俭双 committed
273
	{
时昊's avatar
时昊 committed
274
		PageType = Page_Time_Hour;
李俭双's avatar
李俭双 committed
275
	}
时昊's avatar
时昊 committed
276
	else if(PageType == Page_Time_Hour)
李俭双's avatar
李俭双 committed
277
	{
时昊's avatar
时昊 committed
278
		PageType = Page_Time_Minute;
李俭双's avatar
李俭双 committed
279
	}
时昊's avatar
时昊 committed
280
	else if(PageType == Page_Time_Minute)
李俭双's avatar
李俭双 committed
281
	{
时昊's avatar
时昊 committed
282
		PageType = Page_Km_Unit;
李俭双's avatar
李俭双 committed
283
	}
时昊's avatar
时昊 committed
284
	else if(PageType == Page_Km_Unit)
李俭双's avatar
李俭双 committed
285
	{
时昊's avatar
时昊 committed
286 287 288 289 290
		PageType = Page_Tpms_Unit;
	}
	else if(PageType == Page_Tpms_Unit)
	{
		PageType = Page_Odo;
李俭双's avatar
李俭双 committed
291 292 293 294 295
	}
	else
	{
		;
	}
时昊's avatar
时昊 committed
296 297 298 299 300 301 302 303 304 305 306 307

	if(PageType == Page_TCS)
	{
		if(Get_Dis_Tcs_Val() == 0)
		{
			MenuData.Tcs_Val = 1;//on
		}
		else
		{
			MenuData.Tcs_Val = 0;//off
		}
	}
李俭双's avatar
李俭双 committed
308 309
}

时昊's avatar
时昊 committed
310 311


李俭双's avatar
李俭双 committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 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
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
358 359 360
	MenuData.KM_Unit = 0;
	MenuData.Tpms_Unit = 0;
	MenuData.Tcs_Val = 1;
李俭双's avatar
李俭双 committed
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
}

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;
    }
}

时昊's avatar
时昊 committed
383 384 385 386 387
void Maintain_Reset_Service(void)
{
	;
}

李俭双's avatar
李俭双 committed
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
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;
}

时昊's avatar
时昊 committed
403
uint8_t Get_Dis_KM_Unit(void)
李俭双's avatar
李俭双 committed
404
{
时昊's avatar
时昊 committed
405
	return MenuData.KM_Unit; //0km,1mile
李俭双's avatar
李俭双 committed
406
}
时昊's avatar
时昊 committed
407 408 409 410 411 412 413 414 415 416

uint8_t Get_Dis_Tpms_Unit(void)
{
	return MenuData.Tpms_Unit; //0km,1mile
}

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