/********************************************************************* * @fn resetSensorSetup * * @brief Turn off all sensors that are on * * @param none * * @return none */ static void resetSensorSetup (void) { if (HalIRTempStatus()!=TMP006_OFF || irTempEnabled) { HalIRTempTurnOff(); irTempEnabled = FALSE; } if (accEnabled) { accEnabled = FALSE; } if (HalMagStatus()!=MAG3110_OFF || magEnabled) { HalMagTurnOff(); magEnabled = FALSE; } if (gyroEnabled) { HalGyroTurnOff(); gyroEnabled = FALSE; } if (barEnabled) { HalBarInit(); barEnabled = FALSE; } if (humiEnabled) { HalHumiInit(); humiEnabled = FALSE; } // Reset internal states sensorMagPeriod = MAG_DEFAULT_PERIOD; sensorAccPeriod = ACC_DEFAULT_PERIOD; sensorGyroAxes = 0; sensorGyroUpdateAxes = FALSE; testMode = FALSE; // Reset all characteristics values resetCharacteristicValues(); }
/********************************************************************* * @fn resetSensorSetup * * @brief Turn off all sensors that are on * * @param none * * @return none */ static void resetSensorSetup (void) { if (HalIRTempStatus()!=TMP006_OFF || irTempEnabled) { HalIRTempTurnOff(); irTempEnabled = FALSE; } if (accConfig != ST_CFG_SENSOR_DISABLE) { accConfig = ST_CFG_SENSOR_DISABLE; } if (HalMagStatus()!=MAG3110_OFF || magEnabled) { HalMagTurnOff(); magEnabled = FALSE; } if (gyroEnabled) { HalGyroTurnOff(); gyroEnabled = FALSE; } if (barEnabled) { HalBarInit(); barEnabled = FALSE; } if (humiEnabled) { HalHumiInit(); humiEnabled = FALSE; } // Reset internal states sensorGyroAxes = 0; sensorGyroUpdateAxes = FALSE; testMode = FALSE; // Reset all characteristics values resetCharacteristicValues(); }
/********************************************************************* * @fn SensorTag_Init * * @brief Initialization function for the Simple BLE Peripheral App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void SensorTag_Init( uint8 task_id ) { sensorTag_TaskID = task_id; // Setup the GAP VOID GAP_SetParamValue( TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL ); // Setup the GAP Peripheral Role Profile { // Device starts advertising upon initialization uint8 initial_advertising_enable = FALSE; // By setting this to zero, the device will go into the waiting state after // being discoverable for 30.72 second, and will not being advertising again // until the enabler is set back to TRUE uint16 gapRole_AdvertOffTime = 0; uint8 enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST; uint16 desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL; uint16 desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL; uint16 desired_slave_latency = DEFAULT_DESIRED_SLAVE_LATENCY; uint16 desired_conn_timeout = DEFAULT_DESIRED_CONN_TIMEOUT; // Set the GAP Role Parameters GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable ); GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &gapRole_AdvertOffTime ); GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( scanRspData ), scanRspData ); GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData ); GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request ); GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval ); GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval ); GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &desired_slave_latency ); GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &desired_conn_timeout ); } // Set the GAP Characteristics GGS_SetParameter( GGS_DEVICE_NAME_ATT, sizeof(attDeviceName), attDeviceName ); // Set advertising interval { uint16 advInt = DEFAULT_ADVERTISING_INTERVAL; GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt ); GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt ); } // Setup the GAP Bond Manager { uint32 passkey = 0; // passkey "000000" uint8 pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ; uint8 mitm = TRUE; uint8 ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY; uint8 bonding = TRUE; GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof ( uint32 ), &passkey ); GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof ( uint8 ), &pairMode ); GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof ( uint8 ), &mitm ); GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof ( uint8 ), &ioCap ); GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof ( uint8 ), &bonding ); } // Add services GGS_AddService( GATT_ALL_SERVICES ); // GAP GATTServApp_AddService( GATT_ALL_SERVICES ); // GATT attributes DevInfo_AddService(); // Device Information Service IRTemp_AddService (GATT_ALL_SERVICES ); // IR Temperature Service Accel_AddService (GATT_ALL_SERVICES ); // Accelerometer Service Humidity_AddService (GATT_ALL_SERVICES ); // Humidity Service Magnetometer_AddService( GATT_ALL_SERVICES ); // Magnetometer Service Barometer_AddService( GATT_ALL_SERVICES ); // Barometer Service Gyro_AddService( GATT_ALL_SERVICES ); // Gyro Service SK_AddService( GATT_ALL_SERVICES ); // Simple Keys Profile Test_AddService( GATT_ALL_SERVICES ); // Test Profile CcService_AddService( GATT_ALL_SERVICES ); // Connection Control Service #if defined FEATURE_OAD VOID OADTarget_AddService(); // OAD Profile #endif // Setup the Seensor Profile Characteristic Values resetCharacteristicValues(); // Register for all key events - This app will handle all key events RegisterForKeys( sensorTag_TaskID ); // makes sure LEDs are off HalLedSet( (HAL_LED_1 | HAL_LED_2), HAL_LED_MODE_OFF ); // Initialise sensor drivers HALIRTempInit(); HalHumiInit(); HalMagInit(); HalAccInit(); HalBarInit(); HalGyroInit(); // Register callbacks with profile VOID IRTemp_RegisterAppCBs( &sensorTag_IrTempCBs ); VOID Magnetometer_RegisterAppCBs( &sensorTag_MagnetometerCBs ); VOID Accel_RegisterAppCBs( &sensorTag_AccelCBs ); VOID Humidity_RegisterAppCBs( &sensorTag_HumidCBs ); VOID Barometer_RegisterAppCBs( &sensorTag_BarometerCBs ); VOID Gyro_RegisterAppCBs( &sensorTag_GyroCBs ); VOID Test_RegisterAppCBs( &sensorTag_TestCBs ); VOID CcService_RegisterAppCBs( &sensorTag_ccCBs ); VOID GAPRole_RegisterAppCBs( ¶mUpdateCB ); // Enable clock divide on halt // This reduces active current while radio is active and CC254x MCU // is halted HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_ENABLE_CLK_DIVIDE_ON_HALT ); // Setup a delayed profile startup osal_set_event( sensorTag_TaskID, ST_START_DEVICE_EVT ); }
/********************************************************************* * @fn resetSensorSetup * * @brief Turn off all sensors that are on * * @param none * * @return none */ static void resetSensorSetup (void) { HalLedSet(HAL_LED_3, HAL_LED_MODE_OFF); // Reset all characteristics values resetCharacteristicValues(); }
/********************************************************************* * @fn PIRSensor_Init * * @brief Initialization function for the Simple BLE Peripheral App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void PIRSensor_Init( uint8 task_id ) { PIRSensor_TaskID = task_id; // Setup the GAP VOID GAP_SetParamValue( TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL ); // Setup the GAP Peripheral Role Profile { #if defined( CC2540_MINIDK ) // For the CC2540DK-MINI keyfob, device doesn't start advertising until button is pressed uint8 initial_advertising_enable = FALSE; #else // For other hardware platforms, device starts advertising upon initialization uint8 initial_advertising_enable = TRUE; #endif // By setting this to zero, the device will go into the waiting state after // being discoverable for 30.72 second, and will not being advertising again // until the enabler is set back to TRUE uint16 gapRole_AdvertOffTime = 0; uint8 enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST; uint16 desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL; uint16 desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL; uint16 desired_slave_latency = DEFAULT_DESIRED_SLAVE_LATENCY; uint16 desired_conn_timeout = DEFAULT_DESIRED_CONN_TIMEOUT; // Set the GAP Role Parameters GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable ); GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &gapRole_AdvertOffTime ); GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( scanRspData ), scanRspData ); GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData ); GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request ); GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval ); GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval ); GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &desired_slave_latency ); GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &desired_conn_timeout ); } // Set the GAP Characteristics GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName ); // Set advertising interval { uint16 advInt = DEFAULT_ADVERTISING_INTERVAL; GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt ); GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt ); } // Setup the GAP Bond Manager { uint32 passkey = 0; // passkey "000000" uint8 pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ; uint8 mitm = TRUE; uint8 ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY; uint8 bonding = TRUE; GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof ( uint32 ), &passkey ); GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof ( uint8 ), &pairMode ); GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof ( uint8 ), &mitm ); GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof ( uint8 ), &ioCap ); GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof ( uint8 ), &bonding ); } // Add services GGS_AddService( GATT_ALL_SERVICES ); // GAP GATTServApp_AddService( GATT_ALL_SERVICES ); // GATT attributes DevInfo_AddService(); // Device Information Service Pir_AddService( GATT_ALL_SERVICES ); Ain_AddService( GATT_ALL_SERVICES ); // Analog Input Service #if defined FEATURE_OAD VOID OADTarget_AddService(); // OAD Profile #endif // Setup the Seensor Profile Characteristic Values resetCharacteristicValues(); // Initialise sensor drivers HalPirInit(); // Register callback with SimpleGATTprofile VOID Ain_RegisterAppCBs( &PIRSensor_AinCBs ); // Enable clock divide on halt // This reduces active current while radio is active and CC254x MCU // is halted // HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_ENABLE_CLK_DIVIDE_ON_HALT ); // Setup a delayed profile startup osal_set_event( PIRSensor_TaskID, SBP_START_DEVICE_EVT ); HalLedSet (HAL_LED_1, HAL_LED_MODE_ON); }