Пример #1
0
/*********************************************************************
 * @fn      proximityAttrCB
 *
 * @brief   Notification from the profile of an atrribute change by
 *          a connected device.
 *
 * @param   attrParamID - Profile's Attribute Parameter ID
 *            PP_LINK_LOSS_ALERT_LEVEL  - The link loss alert level value
 *            PP_IM_ALERT_LEVEL  - The immediate alert level value
 *
 * @return  none
 */
static void proximityAttrCB( uint8 attrParamID )
{
  switch( attrParamID )
  {

  case PP_LINK_LOSS_ALERT_LEVEL:
    ProxReporter_GetParameter( PP_LINK_LOSS_ALERT_LEVEL, &keyfobProxLLAlertLevel );
    break;

  case PP_IM_ALERT_LEVEL:
    {
      ProxReporter_GetParameter( PP_IM_ALERT_LEVEL, &keyfobProxIMAlertLevel );

      // if proximity monitor set the immediate alert level to low or high, then
      // the monitor calculated that the path loss to the keyfob (proximity observer)
      // has exceeded the threshold
      if( keyfobProxIMAlertLevel != PP_ALERT_LEVEL_NO )
      {
        keyfobProximityState = KEYFOB_PROXSTATE_PATH_LOSS;
        keyfobapp_PerformAlert();
        buzzer_beep_count = 0;
      }
      else // proximity monitor turned off alert because the path loss is below threshold
      {
        keyfobProximityState = KEYFOB_PROXSTATE_CONNECTED_IN_RANGE;
        keyfobapp_StopAlert();
      }
    }
    break;

  default:
    // should not reach here!
    break;
  }

}
Пример #2
0
/*********************************************************************
 * @fn      performPeriodicTask
 *
 * @brief   Perform a periodic application task. This function gets
 *          called every five seconds as a result of the SBP_PERIODIC_EVT
 *          OSAL event. In this example, the value of the third
 *          characteristic in the SimpleGATTProfile service is retrieved
 *          from the profile, and then copied into the value of the
 *          the fourth characteristic.
 *
 * @param   none
 *
 * @return  none
 */
static void performPeriodicTask( void )
{
  uint8 pos = FALSE, txpwr = 0;

  Batt_MeasLevel( );
  GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8), &pos);

  advertData[11] = Battery2Asc(battLevel);
  advertData[12] = (P0 & 1<<4) ? 0x31 : 0x30;
  advertData[13] = (P0 & 1<<5) ? 0x31 : 0x30;
  advertData[14] = (P0 & 1<<6) ? 0x31 : 0x30;
  advertData[15] = '0' + advert_internal/100;
  advertData[16] = '0' + (advert_internal/10)%10;
  advertData[17] = '0' + advert_internal%10;
  ProxReporter_GetParameter(PP_TX_POWER_LEVEL, &txpwr);
  advertData[18] = txpwr + '0';

  HCI_LE_SetAdvDataCmd( sizeof( advertData ), advertData );
  pos = TRUE;
  GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8), &pos);
}
Пример #3
0
/*********************************************************************
 * @fn      keyfobapp_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 keyfobapp_HandleKeys( uint8 shift, uint8 keys )
{
  uint8 SK_Keys = 0;

  (void)shift;  // Intentionally unreferenced parameter

  if ( keys & HAL_KEY_SW_1 )
  {
    SK_Keys |= SK_KEY_LEFT;

    // if is active, pressing the left key should toggle
    // stop the alert
    if( keyfobAlertState != ALERT_STATE_OFF )
    {
      keyfobapp_StopAlert();
    }

    // if device is in a connection, toggle the Tx power level between 0 and
    // -6 dBm
    if( gapProfileState == GAPROLE_CONNECTED )
    {
      int8 currentTxPowerLevel;
      int8 newTxPowerLevel;

      ProxReporter_GetParameter( PP_TX_POWER_LEVEL, &currentTxPowerLevel );

      switch ( currentTxPowerLevel )
      {
      case 0:
        newTxPowerLevel = -6;
        // change power to -6 dBm
        HCI_EXT_SetTxPowerCmd( HCI_EXT_TX_POWER_MINUS_6_DBM );
        // Update Tx powerl level in Proximity Reporter (and send notification)
        // if enabled)
        ProxReporter_SetParameter( PP_TX_POWER_LEVEL, sizeof ( int8 ), &newTxPowerLevel );
        break;

      case (-6):
        newTxPowerLevel = 0;
        // change power to 0 dBm
        HCI_EXT_SetTxPowerCmd( HCI_EXT_TX_POWER_0_DBM );
        // Update Tx powerl level in Proximity Reporter (and send notification)
        // if enabled)
        ProxReporter_SetParameter( PP_TX_POWER_LEVEL, sizeof ( int8 ), &newTxPowerLevel );
        break;

      default:
        // do nothing
        break;
      }
    }

  }

  if ( keys & HAL_KEY_SW_2 )
  {

    SK_Keys |= SK_KEY_RIGHT;

    // if device is not in a connection, pressing the right key should toggle
    // advertising on and off
    if( gapProfileState != GAPROLE_CONNECTED )
    {
      uint8 current_adv_enabled_status;
      uint8 new_adv_enabled_status;

      //Find the current GAP advertisement status
      GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, &current_adv_enabled_status );

      if( current_adv_enabled_status == FALSE )
      {
        new_adv_enabled_status = TRUE;
      }
      else
      {
        new_adv_enabled_status = FALSE;
      }

      //change the GAP advertisement status to opposite of current status
      GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status );
    }

  }

  SK_SetParameter( SK_KEY_ATTR, sizeof ( uint8 ), &SK_Keys );
}