Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_IKS01A2
Fork of Node_BLE_Switch_Device by
Bluetooth Low Energy enabled device with environmental and inertial features, i.e. "Pressure", "Humidity", "Temperature", "Accelerometer", "Gyroscope", and "Magnetometer", plus "Switch" feature, compatible with BlueST Protocol.
source/main.cpp@6:01d49589410e, 2018-05-22 (annotated)
- Committer:
- Davidroid
- Date:
- Tue May 22 16:35:05 2018 +0000
- Revision:
- 6:01d49589410e
- Parent:
- 5:445024130101
- Child:
- 7:2b5ed57b088c
Add Inertial sensors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Davidroid | 0:6b34c49b5285 | 1 | /** |
Davidroid | 0:6b34c49b5285 | 2 | ******************************************************************************* |
Davidroid | 0:6b34c49b5285 | 3 | * @file main.cpp |
Davidroid | 0:6b34c49b5285 | 4 | * @author Davide Aliprandi, STMicroelectronics |
Davidroid | 0:6b34c49b5285 | 5 | * @version V1.0.0 |
Davidroid | 0:6b34c49b5285 | 6 | * @date March 31st, 2018 |
Davidroid | 0:6b34c49b5285 | 7 | * @brief mbed test application for the STMicroelectronics X-NUCLEO-IDB05A1 |
Davidroid | 0:6b34c49b5285 | 8 | * Bluetooth Low energy Expansion Board. |
Davidroid | 0:6b34c49b5285 | 9 | ******************************************************************************* |
Davidroid | 0:6b34c49b5285 | 10 | * @attention |
Davidroid | 0:6b34c49b5285 | 11 | * |
Davidroid | 0:6b34c49b5285 | 12 | * <h2><center>© COPYRIGHT(c) 2018 STMicroelectronics</center></h2> |
Davidroid | 0:6b34c49b5285 | 13 | * |
Davidroid | 0:6b34c49b5285 | 14 | * Redistribution and use in source and binary forms, with or without |
Davidroid | 0:6b34c49b5285 | 15 | * modification, are permitted provided that the following conditions are met: |
Davidroid | 0:6b34c49b5285 | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
Davidroid | 0:6b34c49b5285 | 17 | * this list of conditions and the following disclaimer. |
Davidroid | 0:6b34c49b5285 | 18 | * 2. Redistributions in binary form must reproduce the above copyright |
Davidroid | 0:6b34c49b5285 | 19 | * notice, this list of conditions and the following disclaimer in the |
Davidroid | 0:6b34c49b5285 | 20 | * documentation and/or other materials provided with the distribution. |
Davidroid | 0:6b34c49b5285 | 21 | * 3. Neither the name of STMicroelectronics nor the names of its |
Davidroid | 0:6b34c49b5285 | 22 | * contributors may be used to endorse or promote products derived from |
Davidroid | 0:6b34c49b5285 | 23 | * this software without specific prior written permission. |
Davidroid | 0:6b34c49b5285 | 24 | * |
Davidroid | 0:6b34c49b5285 | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Davidroid | 0:6b34c49b5285 | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Davidroid | 0:6b34c49b5285 | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
Davidroid | 0:6b34c49b5285 | 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
Davidroid | 0:6b34c49b5285 | 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
Davidroid | 0:6b34c49b5285 | 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
Davidroid | 0:6b34c49b5285 | 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
Davidroid | 0:6b34c49b5285 | 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
Davidroid | 0:6b34c49b5285 | 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
Davidroid | 0:6b34c49b5285 | 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
Davidroid | 0:6b34c49b5285 | 35 | * POSSIBILITY OF SUCH DAMAGE. |
Davidroid | 0:6b34c49b5285 | 36 | * |
Davidroid | 0:6b34c49b5285 | 37 | ******************************************************************************* |
Davidroid | 0:6b34c49b5285 | 38 | */ |
Davidroid | 0:6b34c49b5285 | 39 | |
Davidroid | 0:6b34c49b5285 | 40 | |
Davidroid | 0:6b34c49b5285 | 41 | /* Includes ------------------------------------------------------------------*/ |
Davidroid | 0:6b34c49b5285 | 42 | |
Davidroid | 0:6b34c49b5285 | 43 | /* mbed specific header files. */ |
Davidroid | 0:6b34c49b5285 | 44 | #include <events/mbed_events.h> |
Davidroid | 0:6b34c49b5285 | 45 | #include <mbed.h> |
Davidroid | 0:6b34c49b5285 | 46 | #include "ble/BLE.h" |
Davidroid | 0:6b34c49b5285 | 47 | #include "CustomService.h" |
Davidroid | 4:a10e2c94c8c8 | 48 | #include "XNucleoIKS01A2.h" |
Davidroid | 0:6b34c49b5285 | 49 | |
Davidroid | 0:6b34c49b5285 | 50 | |
Davidroid | 0:6b34c49b5285 | 51 | /* Definitions ---------------------------------------------------------------*/ |
Davidroid | 0:6b34c49b5285 | 52 | |
Davidroid | 0:6b34c49b5285 | 53 | #define BLE_ADVERTISING_INTERVAL_ms 1000 |
Davidroid | 0:6b34c49b5285 | 54 | #define BLUETOOTH_PERIODIC_CALLBACK_ms 500 |
Davidroid | 0:6b34c49b5285 | 55 | #define DELAY_1 100 |
Davidroid | 0:6b34c49b5285 | 56 | |
Davidroid | 0:6b34c49b5285 | 57 | |
Davidroid | 0:6b34c49b5285 | 58 | /* Types ---------------------------------------------------------------------*/ |
Davidroid | 0:6b34c49b5285 | 59 | |
Davidroid | 0:6b34c49b5285 | 60 | /* Toggle state. */ |
Davidroid | 0:6b34c49b5285 | 61 | typedef enum |
Davidroid | 0:6b34c49b5285 | 62 | { |
Davidroid | 0:6b34c49b5285 | 63 | TOGGLE_OFF = 0, |
Davidroid | 0:6b34c49b5285 | 64 | TOGGLE_ON |
Davidroid | 0:6b34c49b5285 | 65 | } toggle_t; |
Davidroid | 0:6b34c49b5285 | 66 | |
Davidroid | 0:6b34c49b5285 | 67 | |
Davidroid | 0:6b34c49b5285 | 68 | /* Variables -----------------------------------------------------------------*/ |
Davidroid | 0:6b34c49b5285 | 69 | |
Davidroid | 0:6b34c49b5285 | 70 | /* Button state. */ |
Davidroid | 0:6b34c49b5285 | 71 | bool toggle_state; |
Davidroid | 0:6b34c49b5285 | 72 | |
Davidroid | 0:6b34c49b5285 | 73 | /* LED to indicate system state. */ |
Davidroid | 0:6b34c49b5285 | 74 | DigitalOut led_state(LED1); //Conflicts with SPI CLK on D13. |
Davidroid | 0:6b34c49b5285 | 75 | |
Davidroid | 0:6b34c49b5285 | 76 | /* Bluetooth. */ |
Davidroid | 6:01d49589410e | 77 | const static char DEVICE_NAME[] = "IOT_DEVICE"; |
Davidroid | 6:01d49589410e | 78 | const static uint8_t MANUFACTURER_SPECIFIC_DATA[]= {0x01,0x80,0x20,0xfc,0x00,0x00}; |
Davidroid | 0:6b34c49b5285 | 79 | static EventQueue event_queue(/* event count */ 10 * EVENTS_EVENT_SIZE); |
Davidroid | 0:6b34c49b5285 | 80 | CustomService *custom_service; |
Davidroid | 0:6b34c49b5285 | 81 | |
Davidroid | 0:6b34c49b5285 | 82 | /* Button event. */ |
Davidroid | 0:6b34c49b5285 | 83 | InterruptIn event(USER_BUTTON); |
Davidroid | 0:6b34c49b5285 | 84 | |
Davidroid | 4:a10e2c94c8c8 | 85 | /* Instantiate the expansion board */ |
Davidroid | 4:a10e2c94c8c8 | 86 | static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); |
Davidroid | 4:a10e2c94c8c8 | 87 | |
Davidroid | 4:a10e2c94c8c8 | 88 | /* Components. */ |
Davidroid | 6:01d49589410e | 89 | static HTS221Sensor *hum_tem = mems_expansion_board->ht_sensor; |
Davidroid | 6:01d49589410e | 90 | static LPS22HBSensor *pre_tem = mems_expansion_board->pt_sensor; |
Davidroid | 6:01d49589410e | 91 | static LSM6DSLSensor *acc_gyr = mems_expansion_board->acc_gyro; |
Davidroid | 6:01d49589410e | 92 | static LSM303AGRMagSensor *mag = mems_expansion_board->magnetometer; |
Davidroid | 6:01d49589410e | 93 | //static LSM303AGRAccSensor *acc = mems_expansion_board->accelerometer; |
Davidroid | 4:a10e2c94c8c8 | 94 | |
Davidroid | 6:01d49589410e | 95 | /* Timestamp. */ |
Davidroid | 4:a10e2c94c8c8 | 96 | static uint16_t time_stamp = 0; |
Davidroid | 4:a10e2c94c8c8 | 97 | |
Davidroid | 4:a10e2c94c8c8 | 98 | |
Davidroid | 4:a10e2c94c8c8 | 99 | /* Custom service related functions ------------------------------------------*/ |
Davidroid | 4:a10e2c94c8c8 | 100 | |
Davidroid | 4:a10e2c94c8c8 | 101 | void button_callback(void) { |
Davidroid | 4:a10e2c94c8c8 | 102 | toggle_state = true; |
Davidroid | 4:a10e2c94c8c8 | 103 | } |
Davidroid | 4:a10e2c94c8c8 | 104 | |
Davidroid | 6:01d49589410e | 105 | void get_and_send_env_sensors() { |
Davidroid | 6:01d49589410e | 106 | float pressure, humidity, temperature; |
Davidroid | 6:01d49589410e | 107 | |
Davidroid | 6:01d49589410e | 108 | pre_tem->get_pressure(&pressure); |
Davidroid | 6:01d49589410e | 109 | hum_tem->get_humidity(&humidity); |
Davidroid | 6:01d49589410e | 110 | hum_tem->get_temperature(&temperature); |
Davidroid | 6:01d49589410e | 111 | |
Davidroid | 6:01d49589410e | 112 | event_queue.call(Callback<void( |
Davidroid | 6:01d49589410e | 113 | uint16_t, |
Davidroid | 6:01d49589410e | 114 | float, float, float |
Davidroid | 6:01d49589410e | 115 | )>(custom_service, &CustomService::send_env_sensors), |
Davidroid | 6:01d49589410e | 116 | time_stamp++, |
Davidroid | 6:01d49589410e | 117 | pressure, humidity, temperature |
Davidroid | 6:01d49589410e | 118 | ); |
Davidroid | 6:01d49589410e | 119 | //printf("Env Sensors: (%d) %d %d %d\r\n", time_stamp, pressure, humidity, temperature); |
Davidroid | 6:01d49589410e | 120 | } |
Davidroid | 6:01d49589410e | 121 | |
Davidroid | 6:01d49589410e | 122 | void get_and_send_ine_sensors() { |
Davidroid | 6:01d49589410e | 123 | static axes_t accelerometer, gyroscope, magnetometer; |
Davidroid | 6:01d49589410e | 124 | |
Davidroid | 6:01d49589410e | 125 | acc_gyr->get_x_axes((int32_t *) &accelerometer); |
Davidroid | 6:01d49589410e | 126 | acc_gyr->get_g_axes((int32_t *) &gyroscope); |
Davidroid | 6:01d49589410e | 127 | mag->get_m_axes((int32_t *) &magnetometer); |
Davidroid | 6:01d49589410e | 128 | //accelerometer->get_x_axes((int32_t *) (&accelerometer)); |
Davidroid | 6:01d49589410e | 129 | |
Davidroid | 6:01d49589410e | 130 | event_queue.call(Callback<void( |
Davidroid | 6:01d49589410e | 131 | uint16_t, |
Davidroid | 6:01d49589410e | 132 | axes_t*, axes_t*, axes_t* |
Davidroid | 6:01d49589410e | 133 | )>(custom_service, &CustomService::send_ine_sensors), |
Davidroid | 6:01d49589410e | 134 | time_stamp++, |
Davidroid | 6:01d49589410e | 135 | &accelerometer, &gyroscope, &magnetometer |
Davidroid | 6:01d49589410e | 136 | ); |
Davidroid | 6:01d49589410e | 137 | //printf("Ine Sensors: (%d) %d %d %d %d %d %d %d %d %d\r\n", time_stamp, accelerometer.x, accelerometer.y, accelerometer.z, gyroscope.x, gyroscope.y, gyroscope.z, magnetometer.x, magnetometer.y, magnetometer.z); |
Davidroid | 4:a10e2c94c8c8 | 138 | } |
Davidroid | 4:a10e2c94c8c8 | 139 | |
Davidroid | 0:6b34c49b5285 | 140 | |
Davidroid | 0:6b34c49b5285 | 141 | /* Bluetooth related functions -----------------------------------------------*/ |
Davidroid | 0:6b34c49b5285 | 142 | |
Davidroid | 0:6b34c49b5285 | 143 | void on_disconnection_callback(const Gap::DisconnectionCallbackParams_t *params) |
Davidroid | 0:6b34c49b5285 | 144 | { |
Davidroid | 0:6b34c49b5285 | 145 | (void) params; |
Davidroid | 0:6b34c49b5285 | 146 | BLE::Instance().gap().startAdvertising(); |
Davidroid | 0:6b34c49b5285 | 147 | } |
Davidroid | 0:6b34c49b5285 | 148 | |
Davidroid | 0:6b34c49b5285 | 149 | /** |
Davidroid | 0:6b34c49b5285 | 150 | * This callback allows the custom service to read updates from the |
Davidroid | 0:6b34c49b5285 | 151 | * characteristic. |
Davidroid | 0:6b34c49b5285 | 152 | * |
Davidroid | 0:6b34c49b5285 | 153 | * @param[in] params |
Davidroid | 0:6b34c49b5285 | 154 | * Information about the characterisitc being updated. |
Davidroid | 0:6b34c49b5285 | 155 | */ |
Davidroid | 0:6b34c49b5285 | 156 | void on_data_read_callback(const GattReadCallbackParams *params) { |
Davidroid | 4:a10e2c94c8c8 | 157 | /* Reading characteristic and sending it via bluetooth. */ |
Davidroid | 6:01d49589410e | 158 | if (params->handle == custom_service->get_env_sensors_handle()) { |
Davidroid | 0:6b34c49b5285 | 159 | if (BLE::Instance().getGapState().connected) { |
Davidroid | 6:01d49589410e | 160 | get_and_send_env_sensors(); |
Davidroid | 6:01d49589410e | 161 | } |
Davidroid | 6:01d49589410e | 162 | } else if (params->handle == custom_service->get_ine_sensors_handle()) { |
Davidroid | 6:01d49589410e | 163 | if (BLE::Instance().getGapState().connected) { |
Davidroid | 6:01d49589410e | 164 | get_and_send_ine_sensors(); |
Davidroid | 0:6b34c49b5285 | 165 | } |
Davidroid | 0:6b34c49b5285 | 166 | } |
Davidroid | 0:6b34c49b5285 | 167 | } |
Davidroid | 0:6b34c49b5285 | 168 | |
Davidroid | 0:6b34c49b5285 | 169 | /** |
Davidroid | 0:6b34c49b5285 | 170 | * This callback allows the custom service to write updates to the |
Davidroid | 0:6b34c49b5285 | 171 | * characteristic. |
Davidroid | 0:6b34c49b5285 | 172 | * |
Davidroid | 0:6b34c49b5285 | 173 | * @param[in] params |
Davidroid | 0:6b34c49b5285 | 174 | * Information about the characterisitc being updated. |
Davidroid | 0:6b34c49b5285 | 175 | */ |
Davidroid | 0:6b34c49b5285 | 176 | void on_data_written_callback(const GattWriteCallbackParams *params) { |
Davidroid | 4:a10e2c94c8c8 | 177 | /* Receiving data via bluetooth and writing it to the characteristic. */ |
Davidroid | 4:a10e2c94c8c8 | 178 | if (params->handle == custom_service->get_state_command_handle()) { |
Davidroid | 0:6b34c49b5285 | 179 | led_state.write(((CustomService::switch_state_t) ((uint8_t *) (params->data))[0])); |
Davidroid | 4:a10e2c94c8c8 | 180 | } |
Davidroid | 0:6b34c49b5285 | 181 | } |
Davidroid | 0:6b34c49b5285 | 182 | |
Davidroid | 0:6b34c49b5285 | 183 | /** |
Davidroid | 4:a10e2c94c8c8 | 184 | * This function is called periodically and sends notifications. |
Davidroid | 0:6b34c49b5285 | 185 | */ |
Davidroid | 0:6b34c49b5285 | 186 | void periodic_callback(void) |
Davidroid | 0:6b34c49b5285 | 187 | { |
Davidroid | 4:a10e2c94c8c8 | 188 | /* Reading toggle command and sending it via bluetooth, if needed. */ |
Davidroid | 0:6b34c49b5285 | 189 | if (toggle_state) { |
Davidroid | 0:6b34c49b5285 | 190 | if (BLE::Instance().getGapState().connected) { |
Davidroid | 0:6b34c49b5285 | 191 | event_queue.call(Callback<void(uint16_t, uint8_t)>(custom_service, &CustomService::send_state), time_stamp++, toggle_state ? TOGGLE_ON : TOGGLE_OFF); |
Davidroid | 0:6b34c49b5285 | 192 | toggle_state = false; |
Davidroid | 0:6b34c49b5285 | 193 | } |
Davidroid | 0:6b34c49b5285 | 194 | } |
Davidroid | 4:a10e2c94c8c8 | 195 | |
Davidroid | 4:a10e2c94c8c8 | 196 | /* Reading sensors and sending data via bluetooth. */ |
Davidroid | 4:a10e2c94c8c8 | 197 | if (BLE::Instance().getGapState().connected) { |
Davidroid | 6:01d49589410e | 198 | get_and_send_env_sensors(); |
Davidroid | 6:01d49589410e | 199 | get_and_send_ine_sensors(); |
Davidroid | 4:a10e2c94c8c8 | 200 | } |
Davidroid | 0:6b34c49b5285 | 201 | } |
Davidroid | 0:6b34c49b5285 | 202 | |
Davidroid | 0:6b34c49b5285 | 203 | /** |
Davidroid | 0:6b34c49b5285 | 204 | * This function is called when the ble initialization process has failled. |
Davidroid | 0:6b34c49b5285 | 205 | */ |
Davidroid | 0:6b34c49b5285 | 206 | void on_ble_init_error_callback(BLE &ble, ble_error_t error) |
Davidroid | 0:6b34c49b5285 | 207 | { |
Davidroid | 0:6b34c49b5285 | 208 | /* Initialization error handling should go here */ |
Davidroid | 0:6b34c49b5285 | 209 | } |
Davidroid | 0:6b34c49b5285 | 210 | |
Davidroid | 0:6b34c49b5285 | 211 | /** |
Davidroid | 0:6b34c49b5285 | 212 | * Callback triggered when the ble initialization process has finished. |
Davidroid | 0:6b34c49b5285 | 213 | */ |
Davidroid | 0:6b34c49b5285 | 214 | void ble_init_complete(BLE::InitializationCompleteCallbackContext *params) |
Davidroid | 0:6b34c49b5285 | 215 | { |
Davidroid | 0:6b34c49b5285 | 216 | BLE& ble = params->ble; |
Davidroid | 0:6b34c49b5285 | 217 | ble_error_t error = params->error; |
Davidroid | 0:6b34c49b5285 | 218 | |
Davidroid | 0:6b34c49b5285 | 219 | if (error != BLE_ERROR_NONE) { |
Davidroid | 0:6b34c49b5285 | 220 | /* In case of error, forward the error handling to on_ble_init_error_callback */ |
Davidroid | 0:6b34c49b5285 | 221 | on_ble_init_error_callback(ble, error); |
Davidroid | 0:6b34c49b5285 | 222 | return; |
Davidroid | 0:6b34c49b5285 | 223 | } |
Davidroid | 0:6b34c49b5285 | 224 | |
Davidroid | 0:6b34c49b5285 | 225 | /* Ensure that it is the default instance of BLE */ |
Davidroid | 0:6b34c49b5285 | 226 | if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { |
Davidroid | 0:6b34c49b5285 | 227 | return; |
Davidroid | 0:6b34c49b5285 | 228 | } |
Davidroid | 0:6b34c49b5285 | 229 | |
Davidroid | 0:6b34c49b5285 | 230 | ble.gap().onDisconnection(on_disconnection_callback); |
Davidroid | 0:6b34c49b5285 | 231 | ble.gattServer().onDataWritten(on_data_written_callback); |
Davidroid | 4:a10e2c94c8c8 | 232 | ble.gattServer().onDataRead(on_data_read_callback); |
Davidroid | 0:6b34c49b5285 | 233 | |
Davidroid | 0:6b34c49b5285 | 234 | custom_service = new CustomService(ble); |
Davidroid | 0:6b34c49b5285 | 235 | |
Davidroid | 0:6b34c49b5285 | 236 | /* Setup advertising data. */ |
Davidroid | 0:6b34c49b5285 | 237 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); |
Davidroid | 4:a10e2c94c8c8 | 238 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (uint8_t *) CUSTOM_SERVICE_UUID, sizeof(CUSTOM_SERVICE_UUID)); |
Davidroid | 0:6b34c49b5285 | 239 | ble.gap().accumulateScanResponse(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, MANUFACTURER_SPECIFIC_DATA, sizeof(MANUFACTURER_SPECIFIC_DATA)); |
Davidroid | 3:b880b9a9ccdf | 240 | ble.gap().accumulateScanResponse(GapAdvertisingData::COMPLETE_LOCAL_NAME, (const uint8_t *) DEVICE_NAME, sizeof(DEVICE_NAME) - 1); |
Davidroid | 0:6b34c49b5285 | 241 | ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
Davidroid | 0:6b34c49b5285 | 242 | ble.gap().setAdvertisingInterval(BLE_ADVERTISING_INTERVAL_ms); |
Davidroid | 0:6b34c49b5285 | 243 | ble.gap().startAdvertising(); |
Davidroid | 0:6b34c49b5285 | 244 | } |
Davidroid | 0:6b34c49b5285 | 245 | |
Davidroid | 0:6b34c49b5285 | 246 | void schedule_ble_events_processing(BLE::OnEventsToProcessCallbackContext* context) { |
Davidroid | 0:6b34c49b5285 | 247 | BLE &ble = BLE::Instance(); |
Davidroid | 0:6b34c49b5285 | 248 | event_queue.call(Callback<void()>(&ble, &BLE::processEvents)); |
Davidroid | 0:6b34c49b5285 | 249 | } |
Davidroid | 0:6b34c49b5285 | 250 | |
Davidroid | 0:6b34c49b5285 | 251 | |
Davidroid | 0:6b34c49b5285 | 252 | /* Main function -------------------------------------------------------------*/ |
Davidroid | 0:6b34c49b5285 | 253 | |
Davidroid | 0:6b34c49b5285 | 254 | int main() |
Davidroid | 0:6b34c49b5285 | 255 | { |
Davidroid | 0:6b34c49b5285 | 256 | /*----- Initialization. -----*/ |
Davidroid | 0:6b34c49b5285 | 257 | |
Davidroid | 0:6b34c49b5285 | 258 | /* Printing to the console. */ |
Davidroid | 4:a10e2c94c8c8 | 259 | printf("Sensors Node Application Example\r\n\n"); |
Davidroid | 0:6b34c49b5285 | 260 | |
Davidroid | 0:6b34c49b5285 | 261 | /* Bluetooth. */ |
Davidroid | 0:6b34c49b5285 | 262 | event_queue.call_every(BLUETOOTH_PERIODIC_CALLBACK_ms, periodic_callback); |
Davidroid | 0:6b34c49b5285 | 263 | BLE &ble = BLE::Instance(); |
Davidroid | 0:6b34c49b5285 | 264 | ble.onEventsToProcess(schedule_ble_events_processing); |
Davidroid | 0:6b34c49b5285 | 265 | ble.init(ble_init_complete); |
Davidroid | 0:6b34c49b5285 | 266 | |
Davidroid | 0:6b34c49b5285 | 267 | /* Attaching and enabling interrupt handlers. */ |
Davidroid | 0:6b34c49b5285 | 268 | event.fall(button_callback); |
Davidroid | 0:6b34c49b5285 | 269 | |
Davidroid | 0:6b34c49b5285 | 270 | /* Setting up initial state: led OFF, no toggle state. */ |
Davidroid | 0:6b34c49b5285 | 271 | led_state.write(CustomService::SWITCH_OFF); |
Davidroid | 0:6b34c49b5285 | 272 | toggle_state = false; |
Davidroid | 4:a10e2c94c8c8 | 273 | |
Davidroid | 4:a10e2c94c8c8 | 274 | /* Enabling sensors. */ |
Davidroid | 6:01d49589410e | 275 | hum_tem->enable(); |
Davidroid | 6:01d49589410e | 276 | pre_tem->enable(); |
Davidroid | 6:01d49589410e | 277 | acc_gyr->enable_x(); |
Davidroid | 6:01d49589410e | 278 | acc_gyr->enable_g(); |
Davidroid | 6:01d49589410e | 279 | mag->enable(); |
Davidroid | 6:01d49589410e | 280 | //acc->enable(); |
Davidroid | 0:6b34c49b5285 | 281 | |
Davidroid | 0:6b34c49b5285 | 282 | /* Start. */ |
Davidroid | 0:6b34c49b5285 | 283 | event_queue.dispatch_forever(); |
Davidroid | 0:6b34c49b5285 | 284 | |
Davidroid | 0:6b34c49b5285 | 285 | return 0; |
Davidroid | 0:6b34c49b5285 | 286 | } |