zoukankan      html  css  js  c++  java
  • ble学习笔记十四---------ble协议栈之按键事件

    协议栈按键事件

    修改工程配置,使能按键功能

    添加头文件#include "serial.h"

    协议栈中定义宏开关

    //自定义宏开关

    #if defined( CC2540_MINIDK )||(MT254xboard)

    //函数声明,按键响应

    static void simpleBLEPeripheral_HandleKeys( uint8 shift, uint8 keys );

    //init函数中定义  

    #if defined (MT254xboard)

        // Register for all key events - This app will handle all key events

      RegisterForKeys( simpleBLEPeripheral_TaskID );

    #endif

    static void simpleBLEPeripheral_ProcessOSALMsg( osal_event_hdr_t *pMsg )

    {

      switch ( pMsg->event )

      {

      //

      #if defined( CC2540_MINIDK )||(MT254xboard)

        case KEY_CHANGE:

          simpleBLEPeripheral_HandleKeys( ((keyChange_t *)pMsg)->state, ((keyChange_t *)pMsg)->keys );

          break;

      #endif // #if defined( CC2540_MINIDK )

      default:

        // do nothing

        break;

      }

    }

    //

    #if defined( CC2540_MINIDK )||(MT254xboard)

    /*********************************************************************

     * @fn      simpleBLEPeripheral_HandleKeys

     *

     * @brief   Handles all key events for this device.

     *          按键响应操作

     *

     * @param   shift - true if in shift/alt.

     * @param   keys - bit field for key events. Valid entries:

     *                 HAL_KEY_SW_2

     *                 HAL_KEY_SW_1

     *

     * @return  none

     */

    static void simpleBLEPeripheral_HandleKeys( uint8 shift, uint8 keys )

    {

      //uint8 SK_Keys = 0;

      VOID shift;  // Intentionally unreferenced parameter

      if ( keys & HAL_KEY_UP )

        {

          SerialPrintf("%s ", "Key Up");

        }

        if ( keys & HAL_KEY_RIGHT )

        {

          SerialPrintf("%s ", "Key right");

        }

        if ( keys & HAL_KEY_CENTER )

        {

          SerialPrintf("%s ", "Key center");

        }

        if ( keys & HAL_KEY_LEFT )

        {

          SerialPrintf("%s ", "Key left");

        }

        if ( keys & HAL_KEY_DOWN )

        {

          SerialPrintf("%s ", "Key down");

        }

        if ( keys & HAL_KEY_SW_6 )

        {

          SerialPrintf("%s ", "Button down");

        }

      

    }

    #endif // #if defined( CC2540_MINIDK )

    修改五向按键值的电压范围 在hal_led.c文件中

    #if !defined ( CC2540_MINIDK )

    /**************************************************************************************************

     * @fn      halGetJoyKeyInput

     *

     * @brief   Map the ADC value to its corresponding key.

     *          按键值对应的电压范围

     *

     * @param   None

     *

     * @return  keys - current joy key status

     **************************************************************************************************/

    uint8 halGetJoyKeyInput(void)

    {

      /* The joystick control is encoded as an analog voltage.

       * Read the JOY_LEVEL analog value and map it to joy movement.

       */

      uint16 adc;

      uint8 ksave0 = 0;

      uint8 ksave1;

      /* Keep on reading the ADC until two consecutive key decisions are the same. */

      do

      {

        ksave1 = ksave0;    /* save previouse key reading */

        adc = HalAdcRead (HAL_KEY_JOY_CHN, HAL_ADC_RESOLUTION_10);

         if ((adc >= 2) && (adc <= 160))            // right    172

        {

           

            ksave0 |= HAL_KEY_RIGHT;

        }

        else if ((adc >= 161) && (adc <= 180))     // cen 146

        {

          ksave0 |= HAL_KEY_CENTER;

        }

        else if ((adc >= 181) && (adc <= 220))    // up     204

        {

           ksave0 |= HAL_KEY_UP;       

        }

        else if ((adc >= 221) && (adc <= 270))    // left   256

        {

          ksave0 |= HAL_KEY_LEFT;     

        }

        else if ((adc >= 271) && (adc <= 350))    // down    306

        {

         ksave0 |= HAL_KEY_DOWN;

        }

      } while (ksave0 != ksave1);

      return ksave0;

    }

    #endif

  • 相关阅读:
    C#里List.Sort的用法
    解决在IE中返回JSON格式的数据时提示下载的问题
    关于json语句的相关用法
    vector数组的相关知识
    编程珠矶第一章阅读笔记
    第三周学习进度博客
    echarts以地图形式显示中国疫情情况实现点击省份下钻
    课堂作业,疫情数据统计(柱形图的生成)
    过滤器filter学习进度一
    android开发对应高德地图定位服务进度一
  • 原文地址:https://www.cnblogs.com/retacn-yue/p/6194241.html
Copyright © 2011-2022 走看看