/*********************************************************************
 * @fn      SensorTagKeys_reset
 *
 * @brief   Reset key state to 'not pressed'
 *
 * @param   none
 *
 * @return  none
 */
void SensorTagKeys_reset(void)
{
  keyTimer = 0;
  keys = 0;
  event = 0;
  SK_SetParameter(SK_KEY_ATTR, sizeof(uint8_t), &keys);
}
示例#2
0
/*********************************************************************
 * @fn      ECGSensor_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 ECGSensor_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;
    
    HalLedSet ( HAL_LED_1, HAL_LED_MODE_ON );       //
    
  }
  
  if ( keys & HAL_KEY_SW_2 )
  {
    SK_Keys |= SK_KEY_RIGHT;
    
    // Setup Battery Characteristic Values
    {
      uint8 clientbattLevel;
      Batt_SetParameter( BATT_PARAM_LEVEL, sizeof (uint8 ), &clientbattLevel );
    }
  }

  // Set the value of the keys state to the Simple Keys Profile;
  // This will send out a notification of the keys state if enabled
  SK_SetParameter( SK_KEY_ATTR, sizeof ( uint8 ), &SK_Keys );
}
/*********************************************************************
* @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_SW_1 )
	{
		SK_Keys |= SK_KEY_LEFT;
	}
	
	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
		// Note:  If PLUS_BROADCASTER is define this condition is ignored and
		//        Device may advertise during connections as well. 
#ifndef PLUS_BROADCASTER  
		if( gapProfileState != GAPROLE_CONNECTED )
		{
#endif // PLUS_BROADCASTER
			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 );
#ifndef PLUS_BROADCASTER
		}
#endif // PLUS_BROADCASTER
	}
	
	// Set the value of the keys state to the Simple Keys Profile;
	// This will send out a notification of the keys state if enabled
	SK_SetParameter( SK_KEY_ATTR, sizeof ( uint8 ), &SK_Keys );
}
示例#4
0
/*********************************************************************
 * @fn      sensorTag_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 sensorTag_HandleKeys( uint8 shift, uint8 keys )
{
  uint8 SK_Keys = 0;
  VOID shift;  // Intentionally unreferenced parameter

  if (keys & HAL_KEY_SW_1)
  {
    // Reset the system if side key is pressed for more than 3 seconds
    sysResetRequest = TRUE;
    osal_start_timerEx( sensorTag_TaskID, ST_SYS_RESET_EVT, ST_SYS_RESET_DELAY );

    if (!testMode ) // Side key
    {
      // If device is not in a connection, pressing the side 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 advertising 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 );
      }

      if ( gapProfileState == GAPROLE_CONNECTED )
      {
        uint8 adv_enabled = TRUE;

        // Disconnect
        GAPRole_TerminateConnection();
        // Start advertising
        GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &adv_enabled );
      }
    }
    else
    {
      // Test mode
      if ( keys & HAL_KEY_SW_1 ) // Side key
      {
        SK_Keys |= SK_KEY_SIDE;
      }
    }
  }

  if ( keys & HAL_KEY_SW_2 )   // Carbon S2
  {
    SK_Keys |= SK_KEY_LEFT;
  }

  if ( keys & HAL_KEY_SW_3 )   // Carbon S3
  {
    SK_Keys |= SK_KEY_RIGHT;
  }

  if (!(keys & HAL_KEY_SW_1))
  {
    // Cancel system reset request
    sysResetRequest = FALSE;
  }

  // Set the value of the keys state to the Simple Keys Profile;
  // This will send out a notification of the keys state if enabled
  SK_SetParameter( SK_KEY_ATTR, sizeof ( uint8 ), &SK_Keys );
}
示例#5
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 );
}
/*********************************************************************
 * @fn      SensorTagKeys_processEvent
 *
 * @brief   SensorTag Keys event processor.
 *
 * @param   none
 *
 * @return  none
 */
void SensorTagKeys_processEvent(void)
{
  static uint8_t current_keys = 0;

  // Factory reset by six second simultaneous key press
  if (event & SK_EVT_FACTORY_RESET)
  {
      event &= ~SK_EVT_FACTORY_RESET;

      // Indicate that we're entering factory reset
      SensorTagIO_blinkLed(IOID_RED_LED, 10);

      // Apply factory image and reboot
      SensorTagFactoryReset_applyFactoryImage();
  }

  // Disconnect on three seconds press on the power switch (right key)
  if (event & SK_EVT_DISCONNECT)
  {
      event &= ~SK_EVT_DISCONNECT;
      if (gapProfileState == GAPROLE_CONNECTED)
      {
        processGapStateChange();
      }
  }

  // Set the value of the keys state to the Simple Keys Profile;
  // This will send out a notification of the keys state if enabled
  if (current_keys != keys)
  {
    SK_SetParameter(SK_KEY_ATTR, sizeof(uint8_t), &keys);

    // Insert key state into advertising data
    if (gapProfileState == GAPROLE_ADVERTISING)
    {
      SensorTag_updateAdvertisingData(keys);
    }

    // Check if right key was pressed
    if ((current_keys & SK_KEY_RIGHT)!=0 && (keys & SK_KEY_RIGHT)==0)
    {
      if (gapProfileState != GAPROLE_CONNECTED)
      {
        // Not connected; change state immediately (power/right button)
        processGapStateChange();
      }
    }


    // Has a key been pressed ?
    if ((keys & SK_PUSH_KEYS) && (current_keys == 0))
    {
        if (!Util_isActive(&periodicClock))
        {
            Util_startClock(&periodicClock);
            keyTimer = 0;
        }
    }
  }

  current_keys = keys;
}