First Revision of sample code for interfacing ROHM Multi-Sensor Shield board with Nordic Semiconductor's nRF51-DK Development Kit Host BTLE Board

Dependencies:   BLE_API mbed nRF51822 Nordic_UART_TEMPLATE_ROHM

Dependents:   Nordic_UART_TEMPLATE_ROHM

Fork of UART_TEMPLATE by daniel veilleux

Code Example for ROHM Multi-Sensor Shield on the Nordic Semiconductor nRF51-DK

This code was written to be used with the Nordic Semiconductor nRF51-DK.

This is the basic example code for interfacing ROHM's Multi-sensor Shield Board onto this board.

Additional information about the ROHM MultiSensor Shield Board can be found at the following link: https://github.com/ROHMUSDC/ROHM_SensorPlatform_Multi-Sensor-Shield

For code example for the ROHM SENSORSHLD1-EVK-101, please see the following link: https://developer.mbed.org/teams/ROHMUSDC/code/Nordic_UART_TEMPLATE_ROHM_SHLD1Update/

Operation

Ultimately, this code will initialize all the sensors on the Multi-sensor shield board and then poll the sensors. The sensor data will then be returned to the BTLE COM port link and will be view-able on any BTLE enabled phone that can connect to the Nordic UART Application.

Supported ROHM Sensor Devices

  • BDE0600G Temperature Sensor
  • BM1383GLV Pressure Sensor
  • BU52014 Hall Sensor
  • ML8511 UV Sensor
  • RPR-0521 ALS/PROX Sensor
  • BH1745NUC Color Sensor
  • KMX62 Accel/Mag Sensor
  • KX122 Accel Sensor
  • KXG03 Gyro/Accel Sensor

Sensor Applicable Code Sections

  • Added a Section in "Main" to act as initialization
  • Added to the "Periodic Callback" to read sensor data and return to Phone/Host

Questions/Feedback

Please feel free to let us know any questions/feedback/comments/concerns on the shield implementation by contacting the following e-mail:

Committer:
kbahar3
Date:
Thu Aug 13 18:24:14 2015 +0000
Revision:
4:eabae2996ecc
Parent:
3:c3ee9d663fb8
Child:
5:d39ffc5638a3
Updated Code to show I2C Usage

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Daniel Veilleux 0:442c7a6f1978 1 /* mbed Microcontroller Library
Daniel Veilleux 0:442c7a6f1978 2 * Copyright (c) 2006-2013 ARM Limited
Daniel Veilleux 0:442c7a6f1978 3 *
Daniel Veilleux 0:442c7a6f1978 4 * Licensed under the Apache License, Version 2.0 (the "License");
Daniel Veilleux 0:442c7a6f1978 5 * you may not use this file except in compliance with the License.
Daniel Veilleux 0:442c7a6f1978 6 * You may obtain a copy of the License at
Daniel Veilleux 0:442c7a6f1978 7 *
Daniel Veilleux 0:442c7a6f1978 8 * http://www.apache.org/licenses/LICENSE-2.0
Daniel Veilleux 0:442c7a6f1978 9 *
Daniel Veilleux 0:442c7a6f1978 10 * Unless required by applicable law or agreed to in writing, software
Daniel Veilleux 0:442c7a6f1978 11 * distributed under the License is distributed on an "AS IS" BASIS,
Daniel Veilleux 0:442c7a6f1978 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Daniel Veilleux 0:442c7a6f1978 13 * See the License for the specific language governing permissions and
Daniel Veilleux 0:442c7a6f1978 14 * limitations under the License.
Daniel Veilleux 0:442c7a6f1978 15 */
kbahar3 2:c7b9d588c80f 16
kbahar3 2:c7b9d588c80f 17 /*
kbahar3 2:c7b9d588c80f 18 * Added Functions for ROHM's Multi-Sensor Shield Board
kbahar3 2:c7b9d588c80f 19 * Supports the following Sensor Devices
kbahar3 2:c7b9d588c80f 20 * > BDE0600G Temperature Sensor
kbahar3 2:c7b9d588c80f 21 * > BM1383GLV Pressure Sensor
kbahar3 2:c7b9d588c80f 22 * > BU52014 Hall Sensor
kbahar3 2:c7b9d588c80f 23 * > ML8511 UV Sensor
kbahar3 2:c7b9d588c80f 24 * > RPR-0521 ALS/PROX Sensor
kbahar3 2:c7b9d588c80f 25 * > BH1745NUC Color Sensor
kbahar3 2:c7b9d588c80f 26 * > KMX62 Accel/Mag Sensor
kbahar3 2:c7b9d588c80f 27 * > KX122 Accel Sensor
kbahar3 2:c7b9d588c80f 28 * > KXG03 Gyro (Currently Unavailable as IC hasn't docked yet)
kbahar3 2:c7b9d588c80f 29 *
kbahar3 2:c7b9d588c80f 30 * New Code:
kbahar3 2:c7b9d588c80f 31 * Added a Section in "Main" to act as initialization
kbahar3 2:c7b9d588c80f 32 * Added to the "Periodic Callback" to read sensor data and return to Phone/Host
kbahar3 2:c7b9d588c80f 33 */
kbahar3 2:c7b9d588c80f 34
Daniel Veilleux 0:442c7a6f1978 35
kbahar3 2:c7b9d588c80f 36 //#define AnalogALS //BH1620 //Change 0: Remove this completely
kbahar3 1:2c0ab5cd1a7f 37 #define AnalogTemp //BDE0600
kbahar3 1:2c0ab5cd1a7f 38 #define AnalogUV //ML8511
kbahar3 3:c3ee9d663fb8 39 #define HallSensor //BU52011 //Change 1: Change to use GPIO for BU52014
kbahar3 2:c7b9d588c80f 40 #define RPR0521 //RPR0521 //Change 2: Remove This and add in the RPR-0521
kbahar3 3:c3ee9d663fb8 41 #define KMX62 //Change 3: Add Code For BH1745, KX022, BM1383GLV, KMX62
kbahar3 3:c3ee9d663fb8 42
kbahar3 3:c3ee9d663fb8 43 //Devices To Add
kbahar3 3:c3ee9d663fb8 44 // PRessure Sensor
kbahar3 3:c3ee9d663fb8 45 // Accel Only - KX122
kbahar3 3:c3ee9d663fb8 46 // Check Functions for KMX62
kbahar3 3:c3ee9d663fb8 47 // Color Sensor
kbahar3 3:c3ee9d663fb8 48
kbahar3 3:c3ee9d663fb8 49 // Gyro last...
kbahar3 3:c3ee9d663fb8 50
kbahar3 1:2c0ab5cd1a7f 51
Daniel Veilleux 0:442c7a6f1978 52 #include "mbed.h"
Daniel Veilleux 0:442c7a6f1978 53 #include "BLEDevice.h"
Daniel Veilleux 0:442c7a6f1978 54 #include "UARTService.h"
Daniel Veilleux 0:442c7a6f1978 55 #include "nrf_temp.h"
kbahar3 2:c7b9d588c80f 56 #include "I2C.h"
Daniel Veilleux 0:442c7a6f1978 57
kbahar3 1:2c0ab5cd1a7f 58 #define MAX_REPLY_LEN (UARTService::BLE_UART_SERVICE_MAX_DATA_LEN) //Actually equal to 20
kbahar3 3:c3ee9d663fb8 59 #define SENSOR_READ_INTERVAL_S (10.0F)
Daniel Veilleux 0:442c7a6f1978 60 #define ADV_INTERVAL_MS (1000UL)
Daniel Veilleux 0:442c7a6f1978 61 #define UART_BAUD_RATE (19200UL)
Daniel Veilleux 0:442c7a6f1978 62 #define DEVICE_NAME ("DEMO SENSOR") // This can be read AFTER connecting to the device.
kbahar3 1:2c0ab5cd1a7f 63 #define SHORT_NAME ("ROHMKRIS") // Keep this short: max 8 chars if a 128bit UUID is also advertised.
Daniel Veilleux 0:442c7a6f1978 64
Daniel Veilleux 0:442c7a6f1978 65 #define DEBUG(...) { m_serial_port.printf(__VA_ARGS__); }
Daniel Veilleux 0:442c7a6f1978 66
kbahar3 1:2c0ab5cd1a7f 67 // Function Prototypes
kbahar3 1:2c0ab5cd1a7f 68 void PBTrigger(); //Interrupt function for PB4
Daniel Veilleux 0:442c7a6f1978 69
kbahar3 1:2c0ab5cd1a7f 70 // Global Variables
Daniel Veilleux 0:442c7a6f1978 71 BLEDevice m_ble;
Daniel Veilleux 0:442c7a6f1978 72 Serial m_serial_port(p9, p11); // TX pin, RX pin
Daniel Veilleux 0:442c7a6f1978 73 DigitalOut m_cmd_led(LED1);
Daniel Veilleux 0:442c7a6f1978 74 DigitalOut m_error_led(LED2);
Daniel Veilleux 0:442c7a6f1978 75 UARTService *m_uart_service_ptr;
kbahar3 1:2c0ab5cd1a7f 76 DigitalIn testButton(p20);
kbahar3 1:2c0ab5cd1a7f 77 InterruptIn sw4Press(p20);
kbahar3 1:2c0ab5cd1a7f 78 I2C i2c(p30,p7);
Daniel Veilleux 0:442c7a6f1978 79
kbahar3 1:2c0ab5cd1a7f 80 //Sensor Variables
kbahar3 2:c7b9d588c80f 81 /*
kbahar3 2:c7b9d588c80f 82 AnalogIn BH1620_ALS(p1); //No Analog ALS on the shield
kbahar3 1:2c0ab5cd1a7f 83 uint16_t BH1620_ALS_value;
kbahar3 1:2c0ab5cd1a7f 84 float BH1620_output;
kbahar3 2:c7b9d588c80f 85 */
kbahar3 1:2c0ab5cd1a7f 86
kbahar3 2:c7b9d588c80f 87 AnalogIn BDE0600_Temp(p3); //p2 on the prior evk, p3 on the shield
kbahar3 1:2c0ab5cd1a7f 88 uint16_t BDE0600_Temp_value;
kbahar3 1:2c0ab5cd1a7f 89 float BDE0600_output;
kbahar3 1:2c0ab5cd1a7f 90
kbahar3 2:c7b9d588c80f 91 AnalogIn ML8511_UV(p5); //p3 on prior EVK, p5 on the shield
kbahar3 1:2c0ab5cd1a7f 92 uint16_t ML8511_UV_value;
kbahar3 1:2c0ab5cd1a7f 93 float ML8511_output;
kbahar3 1:2c0ab5cd1a7f 94
kbahar3 2:c7b9d588c80f 95 DigitalIn Hall_GPIO0(p14); //
kbahar3 2:c7b9d588c80f 96 DigitalIn Hall_GPIO1(p15); //
kbahar3 1:2c0ab5cd1a7f 97 int Hall_Return1;
kbahar3 1:2c0ab5cd1a7f 98 int Hall_Return0;
kbahar3 1:2c0ab5cd1a7f 99
kbahar3 2:c7b9d588c80f 100 bool RepStart = true;
kbahar3 2:c7b9d588c80f 101 bool NoRepStart = false;
kbahar3 2:c7b9d588c80f 102
kbahar3 2:c7b9d588c80f 103 #ifdef RPR0521
kbahar3 2:c7b9d588c80f 104 int RPR0521_addr_w = 0x70; //7bit addr = 0x38, with write bit 0
kbahar3 2:c7b9d588c80f 105 int RPR0521_addr_r = 0x71; //7bit addr = 0x38, with read bit 1
kbahar3 2:c7b9d588c80f 106
kbahar3 2:c7b9d588c80f 107 char RPR0521_ModeControl[2] = {0x41, 0xE6};
kbahar3 2:c7b9d588c80f 108 char RPR0521_ALSPSControl[2] = {0x42, 0x03};
kbahar3 2:c7b9d588c80f 109 char RPR0521_Persist[2] = {0x43, 0x20};
kbahar3 2:c7b9d588c80f 110 char RPR0521_Addr_ReadData = 0x44;
kbahar3 2:c7b9d588c80f 111 char RPR0521_Content_ReadData[6];
kbahar3 2:c7b9d588c80f 112
kbahar3 2:c7b9d588c80f 113 int RPR0521_PS_RAWOUT = 0;
kbahar3 2:c7b9d588c80f 114 float RPR0521_PS_OUT = 0;
kbahar3 2:c7b9d588c80f 115 int RPR0521_ALS_D0_RAWOUT = 0;
kbahar3 2:c7b9d588c80f 116 int RPR0521_ALS_D1_RAWOUT = 0;
kbahar3 2:c7b9d588c80f 117 float RPR0521_ALS_DataRatio = 0;
kbahar3 2:c7b9d588c80f 118 float RPR0521_ALS_OUT = 0;
kbahar3 2:c7b9d588c80f 119 #endif
Daniel Veilleux 0:442c7a6f1978 120
kbahar3 3:c3ee9d663fb8 121 #ifdef KMX62
kbahar3 3:c3ee9d663fb8 122 int KMX62_addr_w = 0x1C; //7bit addr = 0x38, with write bit 0
kbahar3 3:c3ee9d663fb8 123 int KMX62_addr_r = 0x1D; //7bit addr = 0x38, with read bit 1
kbahar3 3:c3ee9d663fb8 124
kbahar3 3:c3ee9d663fb8 125 char KMX62_CNTL2[2] = {0x3A, 0x5F};
kbahar3 3:c3ee9d663fb8 126 char KMX62_Addr_Accel_ReadData = 0x0A;
kbahar3 3:c3ee9d663fb8 127 char KMX62_Content_Accel_ReadData[6];
kbahar3 3:c3ee9d663fb8 128 char KMX62_Addr_Mag_ReadData = 0x10;
kbahar3 3:c3ee9d663fb8 129 char KMX62_Content_Mag_ReadData[6];
kbahar3 3:c3ee9d663fb8 130
kbahar3 3:c3ee9d663fb8 131 int MEMS_Accel_Xout = 0;
kbahar3 3:c3ee9d663fb8 132 int MEMS_Accel_Yout = 0;
kbahar3 3:c3ee9d663fb8 133 int MEMS_Accel_Zout = 0;
kbahar3 3:c3ee9d663fb8 134 float MEMS_Accel_Conv_Xout = 0;
kbahar3 3:c3ee9d663fb8 135 float MEMS_Accel_Conv_Yout = 0;
kbahar3 3:c3ee9d663fb8 136 float MEMS_Accel_Conv_Zout = 0;
kbahar3 3:c3ee9d663fb8 137 int MEMS_Mag_Xout = 0;
kbahar3 3:c3ee9d663fb8 138 int MEMS_Mag_Yout = 0;
kbahar3 3:c3ee9d663fb8 139 int MEMS_Mag_Zout = 0;
kbahar3 3:c3ee9d663fb8 140 float MEMS_Mag_Conv_Xout = 0;
kbahar3 3:c3ee9d663fb8 141 float MEMS_Mag_Conv_Yout = 0;
kbahar3 3:c3ee9d663fb8 142 float MEMS_Mag_Conv_Zout = 0;
kbahar3 3:c3ee9d663fb8 143 #endif
kbahar3 3:c3ee9d663fb8 144
Daniel Veilleux 0:442c7a6f1978 145 /**
Daniel Veilleux 0:442c7a6f1978 146 * This callback is used whenever a disconnection occurs.
Daniel Veilleux 0:442c7a6f1978 147 */
Daniel Veilleux 0:442c7a6f1978 148 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
Daniel Veilleux 0:442c7a6f1978 149 {
Daniel Veilleux 0:442c7a6f1978 150 switch (reason) {
Daniel Veilleux 0:442c7a6f1978 151 case Gap::REMOTE_USER_TERMINATED_CONNECTION:
Daniel Veilleux 0:442c7a6f1978 152 DEBUG("Disconnected (REMOTE_USER_TERMINATED_CONNECTION)\n\r");
Daniel Veilleux 0:442c7a6f1978 153 break;
Daniel Veilleux 0:442c7a6f1978 154 case Gap::LOCAL_HOST_TERMINATED_CONNECTION:
Daniel Veilleux 0:442c7a6f1978 155 DEBUG("Disconnected (LOCAL_HOST_TERMINATED_CONNECTION)\n\r");
Daniel Veilleux 0:442c7a6f1978 156 break;
Daniel Veilleux 0:442c7a6f1978 157 case Gap::CONN_INTERVAL_UNACCEPTABLE:
Daniel Veilleux 0:442c7a6f1978 158 DEBUG("Disconnected (CONN_INTERVAL_UNACCEPTABLE)\n\r");
Daniel Veilleux 0:442c7a6f1978 159 break;
Daniel Veilleux 0:442c7a6f1978 160 }
Daniel Veilleux 0:442c7a6f1978 161
Daniel Veilleux 0:442c7a6f1978 162 DEBUG("Restarting the advertising process\n\r");
Daniel Veilleux 0:442c7a6f1978 163 m_ble.startAdvertising();
Daniel Veilleux 0:442c7a6f1978 164 }
Daniel Veilleux 0:442c7a6f1978 165
Daniel Veilleux 0:442c7a6f1978 166
Daniel Veilleux 0:442c7a6f1978 167 /**
Daniel Veilleux 0:442c7a6f1978 168 * This callback is used whenever the host writes data to one of our GATT characteristics.
Daniel Veilleux 0:442c7a6f1978 169 */
Daniel Veilleux 0:442c7a6f1978 170 void dataWrittenCallback(const GattCharacteristicWriteCBParams *params)
Daniel Veilleux 0:442c7a6f1978 171 {
Daniel Veilleux 0:442c7a6f1978 172 // Ensure that initialization is finished and the host has written to the TX characteristic.
Daniel Veilleux 0:442c7a6f1978 173 if ((m_uart_service_ptr != NULL) && (params->charHandle == m_uart_service_ptr->getTXCharacteristicHandle())) {
Daniel Veilleux 0:442c7a6f1978 174 uint8_t buf[MAX_REPLY_LEN];
Daniel Veilleux 0:442c7a6f1978 175 uint32_t len = 0;
Daniel Veilleux 0:442c7a6f1978 176
Daniel Veilleux 0:442c7a6f1978 177 if (1 == params->len) {
Daniel Veilleux 0:442c7a6f1978 178 switch (params->data[0]) {
Daniel Veilleux 0:442c7a6f1978 179 case '0':
kbahar3 1:2c0ab5cd1a7f 180 m_cmd_led = m_cmd_led ^ 1;
kbahar3 1:2c0ab5cd1a7f 181 len = snprintf((char*) buf, MAX_REPLY_LEN, "OK... LED ON");
Daniel Veilleux 0:442c7a6f1978 182 break;
Daniel Veilleux 0:442c7a6f1978 183 case '1':
kbahar3 1:2c0ab5cd1a7f 184 m_cmd_led = m_cmd_led ^ 1;
kbahar3 1:2c0ab5cd1a7f 185 len = snprintf((char*) buf, MAX_REPLY_LEN, "OK... LED OFF");
Daniel Veilleux 0:442c7a6f1978 186 break;
Daniel Veilleux 0:442c7a6f1978 187 case 'a':
kbahar3 2:c7b9d588c80f 188 //len = snprintf((char*) buf, MAX_REPLY_LEN, "ALSRaw = %d", BH1620_ALS_value);
kbahar3 1:2c0ab5cd1a7f 189 break;
kbahar3 1:2c0ab5cd1a7f 190 case 'b':
kbahar3 2:c7b9d588c80f 191 //len = snprintf((char*) buf, MAX_REPLY_LEN, "ALS = %.2f lx", BH1620_output);
Daniel Veilleux 0:442c7a6f1978 192 break;
Daniel Veilleux 0:442c7a6f1978 193 default:
kbahar3 1:2c0ab5cd1a7f 194 len = snprintf((char*) buf, MAX_REPLY_LEN, "ERROR");
Daniel Veilleux 0:442c7a6f1978 195 break;
Daniel Veilleux 0:442c7a6f1978 196 }
Daniel Veilleux 0:442c7a6f1978 197 }
Daniel Veilleux 0:442c7a6f1978 198 else
Daniel Veilleux 0:442c7a6f1978 199 {
kbahar3 1:2c0ab5cd1a7f 200 len = snprintf((char*) buf, MAX_REPLY_LEN, "ERROR");
kbahar3 4:eabae2996ecc 201 }
Daniel Veilleux 0:442c7a6f1978 202
Daniel Veilleux 0:442c7a6f1978 203 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
Daniel Veilleux 0:442c7a6f1978 204
Daniel Veilleux 0:442c7a6f1978 205 DEBUG("%d bytes received from host\n\r", params->len);
Daniel Veilleux 0:442c7a6f1978 206 }
Daniel Veilleux 0:442c7a6f1978 207 }
Daniel Veilleux 0:442c7a6f1978 208
Daniel Veilleux 0:442c7a6f1978 209
Daniel Veilleux 0:442c7a6f1978 210 /**
Daniel Veilleux 0:442c7a6f1978 211 * This callback is used whenever a write to a GATT characteristic causes data to be sent to the host.
Daniel Veilleux 0:442c7a6f1978 212 */
Daniel Veilleux 0:442c7a6f1978 213 void dataSentCallback(unsigned count)
Daniel Veilleux 0:442c7a6f1978 214 {
Daniel Veilleux 0:442c7a6f1978 215 // NOTE: The count always seems to be 1 regardless of data.
Daniel Veilleux 0:442c7a6f1978 216 DEBUG("%d bytes sent to host\n\r", count);
Daniel Veilleux 0:442c7a6f1978 217 }
Daniel Veilleux 0:442c7a6f1978 218
Daniel Veilleux 0:442c7a6f1978 219
Daniel Veilleux 0:442c7a6f1978 220 /**
Daniel Veilleux 0:442c7a6f1978 221 * This callback is scheduled to be called periodically via a low-priority interrupt.
Daniel Veilleux 0:442c7a6f1978 222 */
Daniel Veilleux 0:442c7a6f1978 223 void periodicCallback(void)
Daniel Veilleux 0:442c7a6f1978 224 {
kbahar3 1:2c0ab5cd1a7f 225 uint8_t buf[MAX_REPLY_LEN];
kbahar3 1:2c0ab5cd1a7f 226 uint32_t len = 0;
kbahar3 1:2c0ab5cd1a7f 227
kbahar3 2:c7b9d588c80f 228
kbahar3 2:c7b9d588c80f 229 /*
kbahar3 2:c7b9d588c80f 230 #ifdef AnalogALS
kbahar3 1:2c0ab5cd1a7f 231 if (m_ble.getGapState().connected) {
kbahar3 1:2c0ab5cd1a7f 232 BH1620_ALS_value = BH1620_ALS.read_u16();
kbahar3 1:2c0ab5cd1a7f 233 BH1620_output = (float)BH1620_ALS_value * 1.543;
kbahar3 1:2c0ab5cd1a7f 234
kbahar3 1:2c0ab5cd1a7f 235 len = snprintf((char*) buf, MAX_REPLY_LEN, "ALS = %.2f lx", BH1620_output);
kbahar3 1:2c0ab5cd1a7f 236 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 1:2c0ab5cd1a7f 237 }
kbahar3 1:2c0ab5cd1a7f 238 #endif
kbahar3 2:c7b9d588c80f 239 */
kbahar3 1:2c0ab5cd1a7f 240
kbahar3 1:2c0ab5cd1a7f 241 #ifdef AnalogTemp
kbahar3 1:2c0ab5cd1a7f 242 if (m_ble.getGapState().connected) {
kbahar3 1:2c0ab5cd1a7f 243 BDE0600_Temp_value = BDE0600_Temp.read_u16();
kbahar3 1:2c0ab5cd1a7f 244 BDE0600_output = (float)BDE0600_Temp_value * 0.00283; //(value * (2.9V/1024))
kbahar3 1:2c0ab5cd1a7f 245 BDE0600_output = (BDE0600_output-1.753)/(-0.01068) + 30;
kbahar3 1:2c0ab5cd1a7f 246
kbahar3 1:2c0ab5cd1a7f 247 len = snprintf((char*) buf, MAX_REPLY_LEN, "Temp = %.2f C", BDE0600_output);
kbahar3 1:2c0ab5cd1a7f 248 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 1:2c0ab5cd1a7f 249 }
kbahar3 1:2c0ab5cd1a7f 250 #endif
kbahar3 1:2c0ab5cd1a7f 251
kbahar3 1:2c0ab5cd1a7f 252 #ifdef AnalogUV
kbahar3 1:2c0ab5cd1a7f 253 if (m_ble.getGapState().connected) {
kbahar3 1:2c0ab5cd1a7f 254 ML8511_UV_value = ML8511_UV.read_u16();
kbahar3 1:2c0ab5cd1a7f 255 ML8511_output = (float)ML8511_UV_value * 0.00283; //(value * (2.9V/1024)) //Note to self: when playing with this, a negative value is seen... Honestly, I think this has to do with my ADC converstion...
kbahar3 1:2c0ab5cd1a7f 256 ML8511_output = (ML8511_output-2.2)/(0.129) + 15; // Added +5 to the offset so when inside (aka, no UV, readings show 0)... this is the wrong approach... and the readings don't make sense... Fix this.
kbahar3 1:2c0ab5cd1a7f 257
kbahar3 1:2c0ab5cd1a7f 258 len = snprintf((char*) buf, MAX_REPLY_LEN, "UV = %.1f mW/cm2", ML8511_output);
kbahar3 1:2c0ab5cd1a7f 259 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 1:2c0ab5cd1a7f 260 }
kbahar3 1:2c0ab5cd1a7f 261 #endif
kbahar3 1:2c0ab5cd1a7f 262
kbahar3 1:2c0ab5cd1a7f 263 #ifdef HallSensor
kbahar3 1:2c0ab5cd1a7f 264 if (m_ble.getGapState().connected) {
kbahar3 1:2c0ab5cd1a7f 265 Hall_Return0 = Hall_GPIO0;
kbahar3 1:2c0ab5cd1a7f 266 Hall_Return1 = Hall_GPIO1;
kbahar3 1:2c0ab5cd1a7f 267
kbahar3 1:2c0ab5cd1a7f 268 len = snprintf((char*) buf, MAX_REPLY_LEN, "H0 = %d, H1 = %d", Hall_Return0, Hall_Return1);
kbahar3 1:2c0ab5cd1a7f 269 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 1:2c0ab5cd1a7f 270 }
kbahar3 1:2c0ab5cd1a7f 271 #endif
kbahar3 1:2c0ab5cd1a7f 272
kbahar3 1:2c0ab5cd1a7f 273 #ifdef DigitalALS
kbahar3 1:2c0ab5cd1a7f 274 if (m_ble.getGapState().connected) {
kbahar3 1:2c0ab5cd1a7f 275 i2c.read(ALS_addr_r, ALS_ReturnData_raw, 2);
kbahar3 1:2c0ab5cd1a7f 276 ALS_Return = (ALS_ReturnData_raw[0]<<8) | ALS_ReturnData_raw[1];
kbahar3 1:2c0ab5cd1a7f 277 ALS_Return = ALS_Return/1.2;
kbahar3 1:2c0ab5cd1a7f 278
kbahar3 1:2c0ab5cd1a7f 279 len = snprintf((char*) buf, MAX_REPLY_LEN, "DALS= %0.2f lx", ALS_Return);
kbahar3 1:2c0ab5cd1a7f 280 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 1:2c0ab5cd1a7f 281 }
kbahar3 1:2c0ab5cd1a7f 282 #endif
kbahar3 1:2c0ab5cd1a7f 283
kbahar3 2:c7b9d588c80f 284 #ifdef RPR0521
kbahar3 2:c7b9d588c80f 285 if (m_ble.getGapState().connected) {
kbahar3 2:c7b9d588c80f 286
kbahar3 2:c7b9d588c80f 287 i2c.write(RPR0521_addr_w, &RPR0521_Addr_ReadData, 1, RepStart);
kbahar3 2:c7b9d588c80f 288 i2c.read(RPR0521_addr_r, &RPR0521_Content_ReadData[0], 6, NoRepStart);
kbahar3 2:c7b9d588c80f 289
kbahar3 2:c7b9d588c80f 290 RPR0521_PS_RAWOUT = (RPR0521_Content_ReadData[1]<<8) | (RPR0521_Content_ReadData[0]);
kbahar3 2:c7b9d588c80f 291 RPR0521_ALS_D0_RAWOUT = (RPR0521_Content_ReadData[3]<<8) | (RPR0521_Content_ReadData[2]);
kbahar3 2:c7b9d588c80f 292 RPR0521_ALS_D1_RAWOUT = (RPR0521_Content_ReadData[5]<<8) | (RPR0521_Content_ReadData[4]);
kbahar3 2:c7b9d588c80f 293 RPR0521_ALS_DataRatio = (float)RPR0521_ALS_D1_RAWOUT / (float)RPR0521_ALS_D0_RAWOUT;
kbahar3 2:c7b9d588c80f 294
kbahar3 2:c7b9d588c80f 295 if(RPR0521_ALS_DataRatio < 0.595){
kbahar3 2:c7b9d588c80f 296 RPR0521_ALS_OUT = (1.682*(float)RPR0521_ALS_D0_RAWOUT - 1.877*(float)RPR0521_ALS_D1_RAWOUT);
kbahar3 2:c7b9d588c80f 297 }
kbahar3 2:c7b9d588c80f 298 else if(RPR0521_ALS_DataRatio < 1.015){
kbahar3 2:c7b9d588c80f 299 RPR0521_ALS_OUT = (0.644*(float)RPR0521_ALS_D0_RAWOUT - 0.132*(float)RPR0521_ALS_D1_RAWOUT);
kbahar3 2:c7b9d588c80f 300 }
kbahar3 2:c7b9d588c80f 301 else if(RPR0521_ALS_DataRatio < 1.352){
kbahar3 2:c7b9d588c80f 302 RPR0521_ALS_OUT = (0.756*(float)RPR0521_ALS_D0_RAWOUT - 0.243*(float)RPR0521_ALS_D1_RAWOUT);
kbahar3 2:c7b9d588c80f 303 }
kbahar3 2:c7b9d588c80f 304 else if(RPR0521_ALS_DataRatio < 3.053){
kbahar3 2:c7b9d588c80f 305 RPR0521_ALS_OUT = (0.766*(float)RPR0521_ALS_D0_RAWOUT - 0.25*(float)RPR0521_ALS_D1_RAWOUT);
kbahar3 2:c7b9d588c80f 306 }
kbahar3 2:c7b9d588c80f 307 else{
kbahar3 2:c7b9d588c80f 308 RPR0521_ALS_OUT = 0;
kbahar3 2:c7b9d588c80f 309 }
kbahar3 2:c7b9d588c80f 310
kbahar3 2:c7b9d588c80f 311 len = snprintf((char*) buf, MAX_REPLY_LEN, "DALS= %0.2f lx", RPR0521_ALS_OUT);
kbahar3 2:c7b9d588c80f 312 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 2:c7b9d588c80f 313 }
kbahar3 2:c7b9d588c80f 314 #endif
kbahar3 1:2c0ab5cd1a7f 315
kbahar3 3:c3ee9d663fb8 316 #ifdef KMX62
kbahar3 1:2c0ab5cd1a7f 317 if (m_ble.getGapState().connected) {
kbahar3 3:c3ee9d663fb8 318 //Read Accel Portion from the IC
kbahar3 3:c3ee9d663fb8 319 i2c.write(KMX62_addr_w, &KMX62_Addr_Accel_ReadData, 1, RepStart);
kbahar3 3:c3ee9d663fb8 320 i2c.read(KMX62_addr_r, &KMX62_Content_Accel_ReadData[0], 6, NoRepStart);
kbahar3 3:c3ee9d663fb8 321
kbahar3 3:c3ee9d663fb8 322 //Note: The highbyte and low byte return a 14bit value, dropping the two LSB in the Low byte.
kbahar3 3:c3ee9d663fb8 323 // However, because we need the signed value, we will adjust the value when converting to "g"
kbahar3 3:c3ee9d663fb8 324 MEMS_Accel_Xout = (KMX62_Content_Accel_ReadData[1]<<8) | (KMX62_Content_Accel_ReadData[0]);
kbahar3 3:c3ee9d663fb8 325 MEMS_Accel_Yout = (KMX62_Content_Accel_ReadData[3]<<8) | (KMX62_Content_Accel_ReadData[2]);
kbahar3 3:c3ee9d663fb8 326 MEMS_Accel_Zout = (KMX62_Content_Accel_ReadData[5]<<8) | (KMX62_Content_Accel_ReadData[4]);
kbahar3 3:c3ee9d663fb8 327
kbahar3 3:c3ee9d663fb8 328 //Note: Conversion to G is as follows:
kbahar3 3:c3ee9d663fb8 329 // Axis_ValueInG = MEMS_Accel_axis / 1024
kbahar3 3:c3ee9d663fb8 330 // However, since we did not remove the LSB previously, we need to divide by 4 again
kbahar3 3:c3ee9d663fb8 331 // Thus, we will divide the output by 4095 (1024*4) to convert and cancel out the LSB
kbahar3 3:c3ee9d663fb8 332 MEMS_Accel_Conv_Xout = (float)MEMS_Accel_Xout/4096/2;
kbahar3 3:c3ee9d663fb8 333 MEMS_Accel_Conv_Yout = (float)MEMS_Accel_Yout/4096/2;
kbahar3 3:c3ee9d663fb8 334 MEMS_Accel_Conv_Zout = (float)MEMS_Accel_Zout/4096/2;
kbahar3 3:c3ee9d663fb8 335
kbahar3 3:c3ee9d663fb8 336 //Read MAg portion from the IC
kbahar3 3:c3ee9d663fb8 337 i2c.write(KMX62_addr_w, &KMX62_Addr_Mag_ReadData, 1, RepStart);
kbahar3 3:c3ee9d663fb8 338 i2c.read(KMX62_addr_r, &KMX62_Content_Mag_ReadData[0], 6, NoRepStart);
kbahar3 3:c3ee9d663fb8 339
kbahar3 3:c3ee9d663fb8 340 //Note: The highbyte and low byte return a 14bit value, dropping the two LSB in the Low byte.
kbahar3 3:c3ee9d663fb8 341 // However, because we need the signed value, we will adjust the value when converting to "g"
kbahar3 3:c3ee9d663fb8 342 MEMS_Mag_Xout = (KMX62_Content_Mag_ReadData[1]<<8) | (KMX62_Content_Mag_ReadData[0]);
kbahar3 3:c3ee9d663fb8 343 MEMS_Mag_Yout = (KMX62_Content_Mag_ReadData[3]<<8) | (KMX62_Content_Mag_ReadData[2]);
kbahar3 3:c3ee9d663fb8 344 MEMS_Mag_Zout = (KMX62_Content_Mag_ReadData[5]<<8) | (KMX62_Content_Mag_ReadData[4]);
kbahar3 3:c3ee9d663fb8 345
kbahar3 3:c3ee9d663fb8 346 //Note: Conversion to G is as follows:
kbahar3 3:c3ee9d663fb8 347 // Axis_ValueInG = MEMS_Accel_axis / 1024
kbahar3 3:c3ee9d663fb8 348 // However, since we did not remove the LSB previously, we need to divide by 4 again
kbahar3 3:c3ee9d663fb8 349 // Thus, we will divide the output by 4095 (1024*4) to convert and cancel out the LSB
kbahar3 3:c3ee9d663fb8 350 MEMS_Mag_Conv_Xout = (float)MEMS_Mag_Xout*0.146;
kbahar3 3:c3ee9d663fb8 351 MEMS_Mag_Conv_Yout = (float)MEMS_Mag_Yout*0.146;
kbahar3 3:c3ee9d663fb8 352 MEMS_Mag_Conv_Zout = (float)MEMS_Mag_Zout*0.146;
kbahar3 3:c3ee9d663fb8 353
kbahar3 3:c3ee9d663fb8 354 len = snprintf((char*) buf, MAX_REPLY_LEN, "KMX61SensorData:");
kbahar3 3:c3ee9d663fb8 355 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 3:c3ee9d663fb8 356 wait_ms(1000);
kbahar3 3:c3ee9d663fb8 357
kbahar3 3:c3ee9d663fb8 358 len = snprintf((char*) buf, MAX_REPLY_LEN, " AccX= %0.2f g", MEMS_Accel_Conv_Xout);
kbahar3 3:c3ee9d663fb8 359 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 3:c3ee9d663fb8 360 wait_ms(1000);
kbahar3 3:c3ee9d663fb8 361
kbahar3 3:c3ee9d663fb8 362 len = snprintf((char*) buf, MAX_REPLY_LEN, " AccY= %0.2f g", MEMS_Accel_Conv_Yout);
kbahar3 3:c3ee9d663fb8 363 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 3:c3ee9d663fb8 364 wait_ms(1000);
kbahar3 3:c3ee9d663fb8 365
kbahar3 3:c3ee9d663fb8 366 len = snprintf((char*) buf, MAX_REPLY_LEN, " AccZ= %0.2f g", MEMS_Accel_Conv_Zout);
kbahar3 3:c3ee9d663fb8 367 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 3:c3ee9d663fb8 368 wait_ms(1000);
kbahar3 3:c3ee9d663fb8 369
kbahar3 3:c3ee9d663fb8 370 len = snprintf((char*) buf, MAX_REPLY_LEN, " MagX= %0.2f g", MEMS_Mag_Conv_Xout);
kbahar3 3:c3ee9d663fb8 371 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 3:c3ee9d663fb8 372 wait_ms(1000);
kbahar3 3:c3ee9d663fb8 373
kbahar3 3:c3ee9d663fb8 374 len = snprintf((char*) buf, MAX_REPLY_LEN, " MagY= %0.2f g", MEMS_Mag_Conv_Yout);
kbahar3 3:c3ee9d663fb8 375 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 3:c3ee9d663fb8 376 wait_ms(1000);
kbahar3 3:c3ee9d663fb8 377
kbahar3 3:c3ee9d663fb8 378 len = snprintf((char*) buf, MAX_REPLY_LEN, " MagZ= %0.2f g", MEMS_Mag_Conv_Zout);
kbahar3 3:c3ee9d663fb8 379 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 3:c3ee9d663fb8 380 wait_ms(1000);
kbahar3 3:c3ee9d663fb8 381 }
kbahar3 3:c3ee9d663fb8 382 #endif
kbahar3 3:c3ee9d663fb8 383
kbahar3 3:c3ee9d663fb8 384 if (m_ble.getGapState().connected) {
kbahar3 3:c3ee9d663fb8 385 len = snprintf((char*) buf, MAX_REPLY_LEN, " "); //Print and Extra Line to show new data
kbahar3 1:2c0ab5cd1a7f 386 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 1:2c0ab5cd1a7f 387 }
Daniel Veilleux 0:442c7a6f1978 388 }
Daniel Veilleux 0:442c7a6f1978 389
Daniel Veilleux 0:442c7a6f1978 390
Daniel Veilleux 0:442c7a6f1978 391 void error(ble_error_t err, uint32_t line)
Daniel Veilleux 0:442c7a6f1978 392 {
Daniel Veilleux 0:442c7a6f1978 393 m_error_led = 1;
Daniel Veilleux 0:442c7a6f1978 394 DEBUG("Error %d on line number %d\n\r", err, line);
Daniel Veilleux 0:442c7a6f1978 395 }
Daniel Veilleux 0:442c7a6f1978 396
kbahar3 1:2c0ab5cd1a7f 397 void PBTrigger()
kbahar3 1:2c0ab5cd1a7f 398 {
kbahar3 1:2c0ab5cd1a7f 399 uint8_t buf[MAX_REPLY_LEN];
kbahar3 1:2c0ab5cd1a7f 400 uint32_t len = 0;
kbahar3 1:2c0ab5cd1a7f 401
kbahar3 1:2c0ab5cd1a7f 402 m_cmd_led = !m_cmd_led;
kbahar3 1:2c0ab5cd1a7f 403
kbahar3 2:c7b9d588c80f 404
kbahar3 1:2c0ab5cd1a7f 405 if (m_ble.getGapState().connected) {
kbahar3 2:c7b9d588c80f 406 /*
kbahar3 1:2c0ab5cd1a7f 407 BH1620_ALS_value = BH1620_ALS.read_u16();
kbahar3 1:2c0ab5cd1a7f 408 BH1620_output = (float)BH1620_ALS_value * 1.543;
kbahar3 1:2c0ab5cd1a7f 409
kbahar3 1:2c0ab5cd1a7f 410 len = snprintf((char*) buf, MAX_REPLY_LEN, "ALS = %.2f lx", BH1620_output);
kbahar3 1:2c0ab5cd1a7f 411 m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
kbahar3 2:c7b9d588c80f 412 */
kbahar3 1:2c0ab5cd1a7f 413 }
kbahar3 1:2c0ab5cd1a7f 414 }
Daniel Veilleux 0:442c7a6f1978 415
Daniel Veilleux 0:442c7a6f1978 416 int main(void)
Daniel Veilleux 0:442c7a6f1978 417 {
Daniel Veilleux 0:442c7a6f1978 418 ble_error_t err;
Daniel Veilleux 0:442c7a6f1978 419 Ticker ticker;
Daniel Veilleux 0:442c7a6f1978 420
Daniel Veilleux 0:442c7a6f1978 421 m_serial_port.baud(UART_BAUD_RATE);
Daniel Veilleux 0:442c7a6f1978 422
kbahar3 2:c7b9d588c80f 423 DEBUG("Initialising...\n\r");
Daniel Veilleux 0:442c7a6f1978 424
Daniel Veilleux 0:442c7a6f1978 425 m_cmd_led = 0;
Daniel Veilleux 0:442c7a6f1978 426 m_error_led = 0;
kbahar3 2:c7b9d588c80f 427 //BH1620_ALS_value = 0;
Daniel Veilleux 0:442c7a6f1978 428
Daniel Veilleux 0:442c7a6f1978 429 ticker.attach(periodicCallback, SENSOR_READ_INTERVAL_S);
Daniel Veilleux 0:442c7a6f1978 430
kbahar3 1:2c0ab5cd1a7f 431 sw4Press.fall(&PBTrigger);
kbahar3 1:2c0ab5cd1a7f 432
kbahar3 2:c7b9d588c80f 433 #ifdef RPR0521
kbahar3 2:c7b9d588c80f 434 // 1. Mode Control (0x41), write (0xC6): ALS EN, PS EN, 100ms measurement for ALS and PS, PS_PULSE=1
kbahar3 2:c7b9d588c80f 435 // 2. ALS_PS_CONTROL (0x42), write (0x03): LED Current = 200mA
kbahar3 2:c7b9d588c80f 436 // 3. PERSIST (0x43), write (0x20): PS Gain x4
kbahar3 2:c7b9d588c80f 437 i2c.write(RPR0521_addr_w, &RPR0521_ModeControl[0], 2, false);
kbahar3 2:c7b9d588c80f 438 i2c.write(RPR0521_addr_w, &RPR0521_ALSPSControl[0], 2, false);
kbahar3 2:c7b9d588c80f 439 i2c.write(RPR0521_addr_w, &RPR0521_Persist[0], 2, false);
kbahar3 1:2c0ab5cd1a7f 440 #endif
kbahar3 1:2c0ab5cd1a7f 441
kbahar3 3:c3ee9d663fb8 442 #ifdef KMX62
kbahar3 3:c3ee9d663fb8 443 // 1. CNTL2 (0x3A), write (0x5F): 4g, Max RES, EN temp mag and accel
kbahar3 3:c3ee9d663fb8 444 i2c.write(KMX62_addr_w, &KMX62_CNTL2[0], 2, false);
kbahar3 3:c3ee9d663fb8 445 #endif
kbahar3 3:c3ee9d663fb8 446
kbahar3 2:c7b9d588c80f 447 //Start BTLE Initialization Section
Daniel Veilleux 0:442c7a6f1978 448 m_ble.init();
Daniel Veilleux 0:442c7a6f1978 449 m_ble.onDisconnection(disconnectionCallback);
Daniel Veilleux 0:442c7a6f1978 450 m_ble.onDataWritten(dataWrittenCallback);
Daniel Veilleux 0:442c7a6f1978 451 m_ble.onDataSent(dataSentCallback);
Daniel Veilleux 0:442c7a6f1978 452
Daniel Veilleux 0:442c7a6f1978 453 // Set the TX power in dBm units.
Daniel Veilleux 0:442c7a6f1978 454 // Possible values (in decreasing order): 4, 0, -4, -8, -12, -16, -20.
Daniel Veilleux 0:442c7a6f1978 455 err = m_ble.setTxPower(4);
Daniel Veilleux 0:442c7a6f1978 456 if (BLE_ERROR_NONE != err) {
Daniel Veilleux 0:442c7a6f1978 457 error(err, __LINE__);
Daniel Veilleux 0:442c7a6f1978 458 }
Daniel Veilleux 0:442c7a6f1978 459
Daniel Veilleux 0:442c7a6f1978 460 // Setup advertising (GAP stuff).
Daniel Veilleux 0:442c7a6f1978 461 err = m_ble.setDeviceName(DEVICE_NAME);
Daniel Veilleux 0:442c7a6f1978 462 if (BLE_ERROR_NONE != err) {
Daniel Veilleux 0:442c7a6f1978 463 error(err, __LINE__);
Daniel Veilleux 0:442c7a6f1978 464 }
Daniel Veilleux 0:442c7a6f1978 465
Daniel Veilleux 0:442c7a6f1978 466 err = m_ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
Daniel Veilleux 0:442c7a6f1978 467 if (BLE_ERROR_NONE != err) {
Daniel Veilleux 0:442c7a6f1978 468 error(err, __LINE__);
Daniel Veilleux 0:442c7a6f1978 469 }
Daniel Veilleux 0:442c7a6f1978 470
Daniel Veilleux 0:442c7a6f1978 471 m_ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
Daniel Veilleux 0:442c7a6f1978 472
Daniel Veilleux 0:442c7a6f1978 473 err = m_ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
Daniel Veilleux 0:442c7a6f1978 474 (const uint8_t *)SHORT_NAME,
Daniel Veilleux 0:442c7a6f1978 475 (sizeof(SHORT_NAME) - 1));
Daniel Veilleux 0:442c7a6f1978 476 if (BLE_ERROR_NONE != err) {
Daniel Veilleux 0:442c7a6f1978 477 error(err, __LINE__);
Daniel Veilleux 0:442c7a6f1978 478 }
Daniel Veilleux 0:442c7a6f1978 479
Daniel Veilleux 0:442c7a6f1978 480 err = m_ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
Daniel Veilleux 0:442c7a6f1978 481 (const uint8_t *)UARTServiceUUID_reversed,
Daniel Veilleux 0:442c7a6f1978 482 sizeof(UARTServiceUUID_reversed));
Daniel Veilleux 0:442c7a6f1978 483 if (BLE_ERROR_NONE != err) {
Daniel Veilleux 0:442c7a6f1978 484 error(err, __LINE__);
Daniel Veilleux 0:442c7a6f1978 485 }
Daniel Veilleux 0:442c7a6f1978 486
Daniel Veilleux 0:442c7a6f1978 487 m_ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(ADV_INTERVAL_MS));
Daniel Veilleux 0:442c7a6f1978 488 m_ble.startAdvertising();
Daniel Veilleux 0:442c7a6f1978 489
Daniel Veilleux 0:442c7a6f1978 490 // Create a UARTService object (GATT stuff).
Daniel Veilleux 0:442c7a6f1978 491 UARTService uartService(m_ble);
Daniel Veilleux 0:442c7a6f1978 492 m_uart_service_ptr = &uartService;
Daniel Veilleux 0:442c7a6f1978 493
Daniel Veilleux 0:442c7a6f1978 494 while (true) {
Daniel Veilleux 0:442c7a6f1978 495 m_ble.waitForEvent();
Daniel Veilleux 0:442c7a6f1978 496 }
Daniel Veilleux 0:442c7a6f1978 497 }