第一章 GoKit的板载硬件离线控制:按键长按、短按识别
本帖最后由 Beam. 于 2016-1-4 14:59 编辑第一章 GoKit的板载硬件离线控制:按键长按、短按识别
智能宠物屋 GoKit
Arduino程序:
File Name:protocol.cpp
Path:GoKit_2_MCU_Arduino-master\GoKit_2_MCU_Arduino\protocol.cpp
DownLoad:https://git.oschina.net/dantang/GoKit_2_MCU_Arduino
void Handle_keyeven()
{
/*长按是指按住按键3s以上 */
switch(gokit_keydown())
{
case KEY1_SHORT_PRESS: //Key1 短按识别
#if (DEBUG==1)
Serial.println("KEY1_SHORT_PRESS");
#endif
break;
case KEY1_LONG_PRESS: //Key1 长按识别
#if (DEBUG==1)
Serial.println("KEY1_LONG_PRESS");
#endif
gokit_ResetWiFi(); //重启WiFi配置
break;
case KEY2_SHORT_PRESS: //Key2 短按识别
#if (DEBUG==1)
Serial.println("KEY2_SHORT_PRESS");
#endif
gokit_sendAirlink(); //进入AirLink配置模式
break;
case KEY2_LONG_PRESS: //Key2 长按识别
#if (DEBUG==1)
Serial.println("KEY2_LONG_PRESS");
#endif
gokit_sendApCmd(); //进入SoftAp配置模式
break;
default: break;
}
//KEY1 : D6 Arduino D6引脚设定为Key1
//KEY2 : D7 Arduino D7引脚设定为Key1
}
STM32程序:
File Name:hal_key.c
Path:GoKit_2_MCU_STM-master\GoKit_2_MCU_STM\User\Hal_key\hal_key.c
DownLoad:https://git.oschina.net/dantang/GoKit_2_MCU_STM
void KEY_GPIO_Init(void) //Key GPIO初始化定义
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(GPIO_KEY1_CLK | GPIO_KEY2_CLK | GPIO_KEY3_CLK, ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Pin = GPIO_KEY1_PIN;
GPIO_Init(GPIO_KEY1_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_KEY2_PIN;
GPIO_Init(GPIO_KEY2_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_KEY3_PIN;
GPIO_Init(GPIO_KEY3_PORT, &GPIO_InitStructure);
}
void KEY_LongHandle(uint8_t KeyAction) //Key1 、 Key2 长按处理
{
if(KeyAction== KEY1_Long_Action)
{
Device_WirteStruct.LED_R = 50; //设备写入RGB R色值
Device_WirteStruct.LED_G = 0; //设备写入RGB G色值
Device_WirteStruct.LED_B = 0; //设备写入RGB B色值
LED_RGB_Control(Device_WirteStruct.LED_R,Device_WirteStruct.LED_G,Device_WirteStruct.LED_B);
//LED控制RGB色值
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)
{
Device_WirteStruct.LED_R = 0; //设备写入RGB R色值
Device_WirteStruct.LED_G = 0; //设备写入RGB G色值
Device_WirteStruct.LED_B = 50; //设备写入RGB B色值
LED_RGB_Control(Device_WirteStruct.LED_R,Device_WirteStruct.LED_G,Device_WirteStruct.LED_B);
//LED控制RGB色值
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);
}
}
:lol,大哥,这是逼我给你看专栏的节奏吗? 不贴代码,不加说明,意义不是很大吧
页:
[1]