• 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

  • 相关阅读:
    31 整数中1出现的次数(从1到n整数中1出现的次数)
    算法寒假实习面试经过之 十一贝(offer) 联想研究院(电话一面 被拒)
    百度feed 寒假实习 一面二面(offer)
    30连续子数组的最大和
    29最小的K个数
    28数组中出现次数超过一半的数字
    MySQL操作数据库和表的基本语句(DDL)
    Oracle————存储过程与函数
    Oracle清空数据库中数据表数据的方法
    Linux之常用Shell脚本总结
  • 原文地址:https://www.cnblogs.com/retacn-yue/p/6194241.html
Copyright © 2020-2023  润新知