/********************************************************************* * @fn accelChangeCB * * @brief Callback from Acceleromter Service indicating a value change * * @param paramID - parameter ID of the value that was changed. * * @return none */ static void accelChangeCB( uint8 paramID ) { uint8 newValue; switch (paramID) { case ACCELEROMETER_CONF: Accel_GetParameter( ACCELEROMETER_CONF, &newValue ); if ( newValue == ST_CFG_SENSOR_DISABLE) { // Put sensor to sleep if (accConfig != ST_CFG_SENSOR_DISABLE) { accConfig = ST_CFG_SENSOR_DISABLE; osal_set_event( sensorTag_TaskID, ST_ACCELEROMETER_SENSOR_EVT); } } else { if (accConfig == ST_CFG_SENSOR_DISABLE) { osal_set_event( sensorTag_TaskID, ST_ACCELEROMETER_SENSOR_EVT); } } accConfig=newValue; HalAccSetRange(accConfig); break; case ACCELEROMETER_PERI: Accel_GetParameter( ACCELEROMETER_PERI, &newValue ); //sensorAccPeriod = newValue*ACCELEROMETER_TIME_UNIT; break; default: // Should not get here break; } }
/********************************************************************* * @fn accelChangeCB * * @brief Callback from Acceleromter Service indicating a value change * * @param paramID - parameter ID of the value that was changed. * * @return none */ static void accelChangeCB( uint8 paramID ) { uint8 newValue; switch (paramID) { case SENSOR_CONF: Accel_GetParameter( SENSOR_CONF, &newValue ); if ( newValue == ST_CFG_SENSOR_DISABLE) { // Put sensor to sleep if (accConfig != ST_CFG_SENSOR_DISABLE) { accConfig = ST_CFG_SENSOR_DISABLE; osal_set_event( sensorTag_TaskID, ST_ACCELEROMETER_SENSOR_EVT); } } else { if (accConfig == ST_CFG_SENSOR_DISABLE) { // Start scheduling only on change disabled -> enabled osal_set_event( sensorTag_TaskID, ST_ACCELEROMETER_SENSOR_EVT); } // Scheduled already, so just change range accConfig = newValue; HalAccSetRange(accConfig); } break; case SENSOR_PERI: Accel_GetParameter( SENSOR_PERI, &newValue ); sensorAccPeriod = newValue*SENSOR_PERIOD_RESOLUTION; break; default: // Should not get here break; } }
/********************************************************************* * @fn accelChangeCB * * @brief Callback from Acceleromter Service indicating a value change * * @param paramID - parameter ID of the value that was changed. * * @return none */ static void accelChangeCB( uint8 paramID ) { uint8 newValue; switch (paramID) { case ACCELEROMETER_CONF: Accel_GetParameter( ACCELEROMETER_CONF, &newValue ); if ( newValue == ST_CFG_SENSOR_DISABLE) { // Put sensor to sleep if (accEnabled) { accEnabled = FALSE; osal_set_event( sensorTag_TaskID, ST_ACCELEROMETER_SENSOR_EVT); } } else if ( newValue == ST_CFG_SENSOR_ENABLE) { if (!accEnabled) { accEnabled = TRUE; osal_set_event( sensorTag_TaskID, ST_ACCELEROMETER_SENSOR_EVT); } } break; case ACCELEROMETER_PERI: Accel_GetParameter( ACCELEROMETER_PERI, &newValue ); sensorAccPeriod = newValue*ACCELEROMETER_TIME_UNIT; break; default: // Should not get here break; } }
/********************************************************************* * @fn accelEnablerChangeCB * * @brief Called by the Accelerometer Profile when the Enabler Attribute * is changed. * * @param none * * @return none */ static void accelEnablerChangeCB( void ) { bStatus_t status = Accel_GetParameter( ACCEL_ENABLER, &accelEnabler ); if (status == SUCCESS){ if (accelEnabler) { // Initialize accelerometer accInit(); // Setup timer for accelerometer task osal_start_timerEx( keyfobapp_TaskID, KFD_ACCEL_READ_EVT, ACCEL_READ_PERIOD ); } else { // Stop the acceleromter osal_stop_timerEx( keyfobapp_TaskID, KFD_ACCEL_READ_EVT); } } else { //?? } }
/********************************************************************* * @fn KeyFobApp_ProcessEvent * * @brief Key Fob Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return none */ uint16 KeyFobApp_ProcessEvent( uint8 task_id, uint16 events ) { if ( events & SYS_EVENT_MSG ) { uint8 *pMsg; if ( (pMsg = osal_msg_receive( keyfobapp_TaskID )) != NULL ) { keyfobapp_ProcessOSALMsg( (osal_event_hdr_t *)pMsg ); // Release the OSAL message VOID osal_msg_deallocate( pMsg ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } if ( events & KFD_START_DEVICE_EVT ) { // Start the Device VOID GAPRole_StartDevice( &keyFob_PeripheralCBs ); // Start Bond Manager VOID GAPBondMgr_Register( &keyFob_BondMgrCBs ); // Start the Proximity Profile VOID ProxReporter_RegisterAppCBs( &keyFob_ProximityCBs ); // Set timer for first battery read event osal_start_timerEx( keyfobapp_TaskID, KFD_BATTERY_CHECK_EVT, BATTERY_CHECK_PERIOD ); // Start the Accelerometer Profile VOID Accel_RegisterAppCBs( &keyFob_AccelCBs ); //Set the proximity attribute values to default ProxReporter_SetParameter( PP_LINK_LOSS_ALERT_LEVEL, sizeof ( uint8 ), &keyfobProxLLAlertLevel ); ProxReporter_SetParameter( PP_IM_ALERT_LEVEL, sizeof ( uint8 ), &keyfobProxIMAlertLevel ); ProxReporter_SetParameter( PP_TX_POWER_LEVEL, sizeof ( int8 ), &keyfobProxTxPwrLevel ); // Set LED1 on to give feedback that the power is on, and a timer to turn off HalLedSet( HAL_LED_1, HAL_LED_MODE_ON ); osal_pwrmgr_device( PWRMGR_ALWAYS_ON ); // To keep the LED on continuously. osal_start_timerEx( keyfobapp_TaskID, KFD_POWERON_LED_TIMEOUT_EVT, 1000 ); return ( events ^ KFD_START_DEVICE_EVT ); } if ( events & KFD_POWERON_LED_TIMEOUT_EVT ) { osal_pwrmgr_device( PWRMGR_BATTERY ); // Revert to battery mode after LED off HalLedSet( HAL_LED_1, HAL_LED_MODE_OFF ); return ( events ^ KFD_POWERON_LED_TIMEOUT_EVT ); } if ( events & KFD_ACCEL_READ_EVT ) { bStatus_t status = Accel_GetParameter( ACCEL_ENABLER, &accelEnabler ); if (status == SUCCESS) { if ( accelEnabler ) { // Restart timer if ( ACCEL_READ_PERIOD ) { osal_start_timerEx( keyfobapp_TaskID, KFD_ACCEL_READ_EVT, ACCEL_READ_PERIOD ); } // Read accelerometer data accelRead(); } else { // Stop the acceleromter osal_stop_timerEx( keyfobapp_TaskID, KFD_ACCEL_READ_EVT); } } else { //?? } return (events ^ KFD_ACCEL_READ_EVT); } if ( events & KFD_BATTERY_CHECK_EVT ) { // Restart timer if ( BATTERY_CHECK_PERIOD ) { osal_start_timerEx( keyfobapp_TaskID, KFD_BATTERY_CHECK_EVT, BATTERY_CHECK_PERIOD ); } // perform battery level check Batt_MeasLevel( ); return (events ^ KFD_BATTERY_CHECK_EVT); } if ( events & KFD_TOGGLE_BUZZER_EVT ) { // if this event was triggered while buzzer is on, turn it off, increment beep_count, // check whether max has been reached, and if not set the OSAL timer for next event to // turn buzzer back on. if ( buzzer_state == BUZZER_ON ) { buzzerStop(); buzzer_state = BUZZER_OFF; buzzer_beep_count++; #if defined ( POWER_SAVING ) osal_pwrmgr_device( PWRMGR_BATTERY ); #endif // check to see if buzzer has beeped maximum number of times // if it has, then don't turn it back on if ( ( buzzer_beep_count < BUZZER_MAX_BEEPS ) && ( ( keyfobProximityState == KEYFOB_PROXSTATE_LINK_LOSS ) || ( keyfobProximityState == KEYFOB_PROXSTATE_PATH_LOSS ) ) ) { osal_start_timerEx( keyfobapp_TaskID, KFD_TOGGLE_BUZZER_EVT, 800 ); } } else if ( keyfobAlertState != ALERT_STATE_OFF ) { // if this event was triggered while the buzzer is off then turn it on if appropriate keyfobapp_PerformAlert(); } return (events ^ KFD_TOGGLE_BUZZER_EVT); } #if defined ( PLUS_BROADCASTER ) if ( events & KFD_ADV_IN_CONNECTION_EVT ) { uint8 turnOnAdv = TRUE; // Turn on advertising while in a connection GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &turnOnAdv ); } #endif // Discard unknown events return 0; }