Esempio n. 1
0
/*******************************************************************************
 * Function Name  : HandleKey
 * Description    : The key handler function
 * Input          : None
 * Output         : None
 * Return         : None
 * Attention      : None
 *******************************************************************************/
void HandleKey(void)
{
    // disable reset
    /*
    // long key1 pressure to reset module
    if(key_return & PRESS_KEY1)
    {
        if (key_return & KEY_LONG)
        {
            LED_RGB_Control(0,0,0);
            SendResetModule(uart_msg_sn++);
        }
        else if (key_return & KEY_DOWN)
        {
            LED_RGB_Control(0,0,50);
        }
        else // KEY_DOWN
        {
            LED_RGB_Control(0,0,0);
        }

        key_return = 0;
    }
    */

    // press key2 to config module
    if(key_return & PRESS_KEY2)
    {
        if (key_return & KEY_DOWN)
        {
            LED_RGB_Control(0,0,50);
        }
        else if (key_return & KEY_UP)
        {
            LED_RGB_Control(0,0,0);
            SendSetModuleWorkMode(CONFIG_METHOD_AIRLINK, uart_msg_sn++);
        }

        key_return = 0;
    }

    // press key3 to increase g-value
    if(key_return & PRESS_KEY3)
    {
        if (key_return & KEY_UP)
        {
            IncreaseGValue(1);
        }

        key_return = 0;
    }
}
Esempio n. 2
0
/*******************************************************************************
* Function Name  : KEY_Handle
* Description    : Key processing function
* Input          : None
* Output         : None
* Return         : None
* Attention		 	 : None
*******************************************************************************/
void KEY_Handle(void)
{
	uint8_t Key_return =0;
	
	Key_return = ReadKeyValue();
	
	if(Key_return & KEY_UP)
	{
		if(Key_return & PRESS_KEY1)
		{
			printf("KEY1 PRESS\r\n");
			LED_RGB_Control(0,0,10);
			Motor_status(0);
		}
		if(Key_return & PRESS_KEY2)
		{
			printf("KEY2 PRESS\r\n");
			LED_RGB_Control(0,10,0);
			Motor_status(10);
		}
		if(Key_return & PRESS_KEY3)
		{
			printf("KEY3 PRESS\r\n");
			LED_RGB_Control(10,0,00);
			//DHT11_Read_Data(&Device_ReadStruct.Temperature, &Device_ReadStruct.Humidity);
			//printf("Temperature =%d;Humidity = %d " ,Device_ReadStruct.Temperature,Device_ReadStruct.Humidity);

			Motor_status(5);
			
		}					
	}

	if(Key_return & KEY_LONG)
	{
		if(Key_return & PRESS_KEY1)
		{
			KEY_LongHandle(PRESS_KEY1);
			printf("KEY1 Long PRESS\r\n");
			printf("M2W RESET WIFI\r\n");
		}
		if(Key_return & PRESS_KEY2)
		{
			KEY_LongHandle(PRESS_KEY2);
			printf("KEY2 Long PRESS\r\n");
			printf("M2W  Config WIFI\r\n");
		}
		if(Key_return & PRESS_KEY3)
		{
			printf("KEY3 Long PRESS\r\n");
		}					
	}
}		
Esempio n. 3
0
/*******************************************************************************
* Function Name  : KEY_LongHandle
* Description    : Key Long Press processing function
                   
* Input          : KeyAction :
					RESS_KEY1 ->MCU To WIFI Send Reset command
                    PRESS_KEY2 ->MCU To WIFI Send Config command
* Output         : None
* Return         : None
* Attention		 	 : None
*******************************************************************************/	
void KEY_LongHandle(uint8_t KeyAction)
{
	if(KeyAction  == KEY1_Long_Action)
	{
	#if 0
		Device_WirteStruct.LED_R = 50;
		Device_WirteStruct.LED_G = 0;
		Device_WirteStruct.LED_B = 0;
		LED_RGB_Control(Device_WirteStruct.LED_R,Device_WirteStruct.LED_G,Device_WirteStruct.LED_B);
	#endif		
		LED_RGB_Control(50, 0, 0);
		
		Pro_M2WResetCmdStruct.Pro_HeadPart.SN = SN++;
		Pro_M2WResetCmdStruct.Sum = CheckSum((uint8_t *)&Pro_M2WResetCmdStruct, sizeof(Pro_M2WResetCmdStruct));
		Pro_UART_SendBuf((uint8_t *)&Pro_M2WResetCmdStruct,sizeof(Pro_M2WResetCmdStruct), 0);	

			
	}

	if(KeyAction  == KEY2_Long_Action)
	{
	#if 0
		Device_WirteStruct.LED_R = 0;
		Device_WirteStruct.LED_G = 0;
		Device_WirteStruct.LED_B = 50;
		LED_RGB_Control(Device_WirteStruct.LED_R,Device_WirteStruct.LED_G,Device_WirteStruct.LED_B);		
	#endif	
		LED_RGB_Control(0, 0, 50);		

		Pro_D2WConfigCmdStruct.Pro_HeadPart.SN = SN++;
		Pro_D2WConfigCmdStruct.Config_Method = 0x02;
		Pro_D2WConfigCmdStruct.Sum = CheckSum((uint8_t *)&Pro_D2WConfigCmdStruct, sizeof(Pro_D2WConfigCmdStruct));
		Pro_UART_SendBuf((uint8_t *)&Pro_D2WConfigCmdStruct,sizeof(Pro_D2WConfigCmdStruct), 0);	


	}
	
}	
Esempio n. 4
0
/*******************************************************************************
* Function Name  : KeyHandle
* Description    : The key response function
* Input          : None
* Output         : None
* Return         : None
* Attention		   : None
*******************************************************************************/
void KeyHandle(void)
{
 	if(Key_Return & PRESS_KEY1)
 	{
 		if(Key_Return & KEY_LONG)
		{
			m_pro_commonCmd.head_part.cmd = CMD_RESET_MODULE;
			m_pro_commonCmd.head_part.sn = ++SN;
			m_pro_commonCmd.sum = CheckSum((uint8_t *)&m_pro_commonCmd, sizeof(pro_commonCmd));
			SendToUart((uint8_t *)&m_pro_commonCmd, sizeof(pro_commonCmd), 1);
			
			LED_RGB_Control(0,0,50);
			LED_RGB_Control(0,0,0);
			Key_Return = 0;
		}
 	}
 	if(Key_Return & PRESS_KEY2)
 	{
		if(Key_Return & KEY_LONG) 
		{
			m_m2w_setModule.config_info = 0x01;		//soft ap
			LED_RGB_Control(50,0,0);		
			wait_wifi_status = 1;
		}
		else if(Key_Return & KEY_UP) 
		{
			m_m2w_setModule.config_info = 0x02;		//air link
			LED_RGB_Control(0,50,0);
			wait_wifi_status = 1;
		}
		else
		{
			Key_Return = 0;
			return ;
		}
		
		m_m2w_setModule.head_part.sn = ++SN;
		m_m2w_setModule.sum = CheckSum((uint8_t *)&m_m2w_setModule, sizeof(m2w_setModule));
		SendToUart((uint8_t *)&m_m2w_setModule, sizeof(m2w_setModule), 1);
			
		delay_ms(500);
		Key_Return = 0;
	} 

 	if(Key_Return & PRESS_KEY3)
 	{
		if(Key_Return & KEY_LONG)
		{
			m_m2w_mcuStatus.status_r.alert_byte = 0x01;		//alert 1
			LED_RGB_Control(50,0,0);	
			LED_RGB_Control(0,0,0);	
		}
		else if(Key_Return & KEY_UP)
		{
			m_m2w_mcuStatus.status_r.fault_byte = 0x03;		//fault 1 and 2
			LED_RGB_Control(0,50,0);	
			LED_RGB_Control(0,0,0);	
		}
		else
		{
			Key_Return = 0;
			return ;
		}
	
		ReportStatus(REPORT_STATUS);
		m_m2w_mcuStatus.status_r.alert_byte = 0x00;			//clean the alert
		m_m2w_mcuStatus.status_r.fault_byte = 0x00;			//clean the fault
		delay_ms(500);
		Key_Return = 0;
	}		
	
	 if(Key_Return & PRESS_KEY4)
 	{
		if(Key_Return & KEY_LONG)
		{
			m_m2w_mcuStatus.status_r.alert_byte = 0x02;		//alert 2
			LED_RGB_Control(50,0,0);	
			LED_RGB_Control(0,0,0);	
		}
		else if(Key_Return & KEY_UP)
		{
			m_m2w_mcuStatus.status_r.fault_byte = 0x0C;		//fault 3 and 4
			LED_RGB_Control(0,50,0);	
			LED_RGB_Control(0,0,0);	
		}
		else
		{
			Key_Return = 0;
			return ;
		}
	
		ReportStatus(REPORT_STATUS);
		m_m2w_mcuStatus.status_r.alert_byte = 0x00;			//clean the alert
		m_m2w_mcuStatus.status_r.fault_byte = 0x00;			//clean the fault
		delay_ms(500);
		Key_Return = 0;
	}		
}