按键检测程序

/*******************************************************************
 *   > File Name: Key_control.c
 *   > Author: fly
 *   > Mail: [email protected]
 *   > Create Time: 2019年03月29日 星期五 11时59分29秒
 ******************************************************************/
#include "Key_control.h"

#if (1)//(_PLATFORM_BOARD == PLATFORM_SAMOON_CARDVR_WIFI) || (_PLATFORM_BOARD == PLATFORM_SAMOON_CARDVR_UVC)
static u32 gkeyon_count[3] = {0};
static u32 glongkey[3]     = {0};
static u32 gsuperlongkey[3] = {0};

#if defined(CUSTOMER_HMVARU_GQ900W) || defined(CUSTOMER_HLUA_RU)
#define LONG_PRESS_TIME       (150)
#else
#define LONG_PRESS_TIME       (300)  //300*10=3sec
#endif

#if defined(CUSTOMER_OWLTECH)
#define	SUPER_LONG_PRESS_TIME		(15*100)
#else
#define	SUPER_LONG_PRESS_TIME		(600)
#endif

#if (1)
void keyFunc_snapshot(void)
{
	if((!syn_status.CardErr) && \
	(gm_sdc_api_action(SD_0,GM_SDC_ACTION_IS_CARD_WRITABLE,NULL,NULL) == 0) \
	        && (gm_sdc_api_action(SD_0,GM_SDC_ACTION_IS_APP_INIT_DONE,NULL,NULL) == 1))
	{
		event_send(EVENT_GPIOKEY, GKEY_SNAPSHOT, FROM_NORMAL);
	}
}
void keyFunc_lockFile(void)
{
	if((!syn_status.CardErr) && \
	(gm_sdc_api_action(SD_0,GM_SDC_ACTION_IS_CARD_WRITABLE,NULL,NULL) == 0) \
	        && (gm_sdc_api_action(SD_0,GM_SDC_ACTION_IS_APP_INIT_DONE,NULL,NULL) == 1))
	{
		if(u32CarDVR_mode == 0)
		{
			event_send(EVENT_GSENSOR,0,FROM_NORMAL);
		}
	}
}
void keyFunc_switchWifi(void)
{
	NetworkLedReset = 1;
	sm_wifi_power_control(!network_state);
}
void keyFunc_defaultSettings(void)
{
	app_default_setting();
}
void keyFunc_Record(void)
{
	if(u32CarDVR_mode == 0)       //0:recording
	{
		ui_send(UI_HANDLE_RECORD_STOP);
		gt_filerecord_stop();
	}
	else
	{
		gt_filerecord_start();
		ui_send(UI_HANDLE_RECORD_START);
	}
}
void gpiokey_check()
{
	int i=0;

	for(i=0; i<3; i++)
	{
		if(!gm_gpio_get_value(KEY_1_GPIO_VALUE+i))
		{
			gkeyon_count[i]++;
			/*printf("FUNC: %s , LINE: %d , gkeyon_count[%d] = %d\n",\
				__func__, __LINE__, gkeyon_count[i], i);*/

			if(gkeyon_count[i] >= LONG_PRESS_TIME)
			{
				if(!glongkey[i])
				{
					glongkey[i] = 1;

					if(i == 2)
					{
						printf("FUNC: %s , LINE: %d , GPIO %d key long press [%d]!", \
						       __func__, __LINE__, (KEY_1_GPIO_VALUE+i), gkeyon_count[i]);

						keyFunc_switchWifi();
					}
				}
				else if(gkeyon_count[i] >= SUPER_LONG_PRESS_TIME)
				{
					if(!gsuperlongkey[i])
					{
						gsuperlongkey[i] = 1;
						if(i == 2)
						{
							printf("FUNC: %s , LINE: %d , GPIO %d key long press [%d]!", \
							       __func__, __LINE__, (KEY_1_GPIO_VALUE+i), gkeyon_count[i]);

							keyFunc_defaultSettings();
						}
					}
				}
			}
		}
		else
		{
			if(glongkey[i])
			{
				glongkey[i] = 0;

				if(gsuperlongkey[i])
				{
					gsuperlongkey[i] = 0;
					if(i == 2)
					{
						__FUNC_TRACK__;
					}
				}
				else if(i == 2)
				{
					__FUNC_TRACK__;
				}
			}
			else
			{
				if(gkeyon_count[i] > 5)  //short key
				{
					if(i == 2)
					{
						printf("FUNC: %s , LINE: %d , GPIO %d key long press [%d]!", \
						       __func__, __LINE__, (KEY_1_GPIO_VALUE+i), gkeyon_count[i]);

						keyFunc_snapshot();
					}
				}
			}
			gkeyon_count[i] = 0;
		}
	}
}
#endif
#endif

#if(DISABLE)
static u32 gkeyon_count=0,glongkey=0;
void gpiokey_check()
{
	if(!gm_gpio_get_value(17))    //press key 1 count++
	{
		gkeyon_count++;
		if(gkeyon_count >= 200)
		{
			if(!glongkey)
			{
				event_send(EVENT_GPIOKEY,GKEY_LONG,FROM_NORMAL);
				glongkey = 1;
			}
		}
	}
	else                 //Release key 0
	{
		if(glongkey)
		{
			event_send(EVENT_GPIOKEY,GKEY_RELEASE,FROM_NORMAL);
			glongkey = 0;
		}
		else
		{
			if(gkeyon_count > 5) //short key
				event_send(EVENT_GPIOKEY,GKEY_SNAPSHOT,FROM_NORMAL);
		}
		gkeyon_count = 0;
	}
}
#endif

 

你可能感兴趣的:(1.C/C++编程,9.嵌入式课程学习,10.IOT(物联网))