收藏官网首页
查看: 14152|回复: 2

第一章 GoKit的板载硬件离线控制:按键长按、短按识别

14

主题

108

帖子

598

积分

超级版主

Rank: 8Rank: 8

积分
598
跳转到指定楼层
楼主
发表于 2016-1-4 11:56:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
汉枫LPB120模块
本帖最后由 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);        


        }
        
}        




137

主题

414

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12339
沙发
发表于 2016-1-4 12:08:42 | 只看该作者
,大哥,这是逼我给你看专栏的节奏吗?

0

主题

4

帖子

35

积分

新手上路

Rank: 1

积分
35
板凳
发表于 2016-1-4 12:53:05 | 只看该作者
不贴代码,不加说明,意义不是很大吧
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

加入Q群 返回顶部

版权与免责声明 © 2006-2024 Gizwits IoT Technology Co., Ltd. ( 粤ICP备11090211号 )

快速回复 返回顶部 返回列表