@@ -126,19 +126,15 @@ BLEService ioService(SERVICE_UUID_AUTOMATIONIO);
126126
127127#define ARRAY_SIZE (x ) (sizeof (x)/sizeof (x)[0 ])
128128
129- /* Serial port to use for printing informational messages to the user */
130- #define LOG_SERIAL Serial
131-
132129/* For convenience, this macro will invoke a specified function call and will
133130 * check the status value returned to ensure it is successful. If not, it will
134131 * print an error message to the serial port and will return from the current function
135132 */
136133#define CHECK_STATUS (op ) \
137134 do { \
138- BleStatus status = op; \
139- if (BLE_STATUS_SUCCESS != status) { \
140- LOG_SERIAL.print (#op" returned error status: " ); \
141- LOG_SERIAL.println (status); \
135+ bool result = op; \
136+ if (!result) { \
137+ Serial.println (#op" failed " ); \
142138 return ; \
143139 } \
144140 } while (0 )
@@ -147,12 +143,12 @@ BLEService ioService(SERVICE_UUID_AUTOMATIONIO);
147143 * Intel Curie BLE device */
148144void blePeripheralConnectedEventCb (BLECentral &bleCentral)
149145{
150- LOG_SERIAL .println (" Got CONNECTED event" );
146+ Serial .println (" Got CONNECTED event" );
151147}
152148
153149void blePeripheralDisconnectedEventCb (BLECentral &bleCentral)
154150{
155- LOG_SERIAL .println (" Got DISCONNECTED event" );
151+ Serial .println (" Got DISCONNECTED event" );
156152}
157153
158154/* This function will be called when a connected remote peer sets a new value for a digital output characteristic */
@@ -187,19 +183,20 @@ void analogOutputCharWrittenEventCb(BLECentral ¢ral, BLECharacteristic &char
187183}
188184
189185void setup () {
190- LOG_SERIAL.begin (9600 );
186+ while (!Serial);
187+ Serial.begin (9600 );
191188
192189 /* Set a name for the BLE device */
193- CHECK_STATUS ( blePeripheral.setLocalName (LOCAL_NAME) );
190+ blePeripheral.setLocalName (LOCAL_NAME);
194191
195192 /* Set a function to be called whenever a BLE GAP event occurs */
196193 blePeripheral.setEventHandler (BLEConnected, blePeripheralConnectedEventCb);
197194 blePeripheral.setEventHandler (BLEDisconnected, blePeripheralDisconnectedEventCb);
198195
199- CHECK_STATUS ( blePeripheral.setAdvertisedServiceUuid (ioService.uuid () ));
196+ blePeripheral.setAdvertisedServiceUuid (ioService.uuid ());
200197
201198 /* Add the Automation I/O Service, and include the UUID in BLE advertising data */
202- CHECK_STATUS ( blePeripheral.addAttribute (ioService) );
199+ blePeripheral.addAttribute (ioService);
203200
204201 /* Add characteristics for the Digital Inputs */
205202 for (unsigned i = 0 ; i < ARRAY_SIZE (digitalInputPins); i++) {
@@ -209,14 +206,14 @@ void setup() {
209206 pinMode (pin->pin , INPUT);
210207
211208 /* Add the characteristic for this pin */
212- CHECK_STATUS ( blePeripheral.addAttribute (pin->characteristic ) );
209+ blePeripheral.addAttribute (pin->characteristic );
213210 /* Set an initial value for this characteristic; refreshed later in the loop() function */
214211 pin->val = digitalRead (pin->pin );
215212 CHECK_STATUS (pin->characteristic .setValue (DIGITAL_PIN_STATE_TO_VAL (pin->pin , pin->val )));
216213 /* Add a number_of_digitals descriptor for this characteristic */
217- CHECK_STATUS ( blePeripheral.addAttribute (pin->userDescription ) );
218- CHECK_STATUS ( blePeripheral.addAttribute (pin->presentationFormat ) );
219- CHECK_STATUS ( blePeripheral.addAttribute (pin->numDigitalsDesc ) );
214+ blePeripheral.addAttribute (pin->userDescription );
215+ blePeripheral.addAttribute (pin->presentationFormat );
216+ blePeripheral.addAttribute (pin->numDigitalsDesc );
220217 }
221218
222219 /* Add characteristics for the Digital Outputs */
@@ -227,23 +224,23 @@ void setup() {
227224 pinMode (pin->pin , OUTPUT);
228225
229226 /* Add the characteristic for this pin */
230- CHECK_STATUS ( blePeripheral.addAttribute (pin->characteristic ) );
227+ blePeripheral.addAttribute (pin->characteristic );
231228 /* Add a callback to be triggered if the remote device updates the value for this pin */
232229 pin->characteristic .setEventHandler (BLEWritten, digitalOutputCharWrittenEventCb);
233230 /* Add a number_of_digitals descriptor for this characteristic */
234- CHECK_STATUS ( blePeripheral.addAttribute (pin->userDescription ) );
235- CHECK_STATUS ( blePeripheral.addAttribute (pin->presentationFormat ) );
236- CHECK_STATUS ( blePeripheral.addAttribute (pin->numDigitalsDesc ) );
231+ blePeripheral.addAttribute (pin->userDescription );
232+ blePeripheral.addAttribute (pin->presentationFormat );
233+ blePeripheral.addAttribute (pin->numDigitalsDesc );
237234 }
238235
239236 /* Add characteristics for the Analog Inputs */
240237 for (unsigned i = 0 ; i < ARRAY_SIZE (analogInputPins); i++) {
241238 AnalogPinConfig *pin = &analogInputPins[i];
242239
243240 /* Add the characteristic for this pin */
244- CHECK_STATUS ( blePeripheral.addAttribute (pin->characteristic ) );
245- CHECK_STATUS ( blePeripheral.addAttribute (pin->userDescription ) );
246- CHECK_STATUS ( blePeripheral.addAttribute (pin->presentationFormat ) );
241+ blePeripheral.addAttribute (pin->characteristic );
242+ blePeripheral.addAttribute (pin->userDescription );
243+ blePeripheral.addAttribute (pin->presentationFormat );
247244 /* Set an initial value for this characteristic; refreshed later in the loop() function */
248245 pin->val = analogRead (pin->pin );
249246 CHECK_STATUS (pin->characteristic .setValue (pin->val ));
@@ -254,9 +251,9 @@ void setup() {
254251 AnalogPinConfig *pin = &analogOutputPins[i];
255252
256253 /* Add the characteristic for this pin */
257- CHECK_STATUS ( blePeripheral.addAttribute (pin->characteristic ) );
258- CHECK_STATUS ( blePeripheral.addAttribute (pin->userDescription ) );
259- CHECK_STATUS ( blePeripheral.addAttribute (pin->presentationFormat ) );
254+ blePeripheral.addAttribute (pin->characteristic );
255+ blePeripheral.addAttribute (pin->userDescription );
256+ blePeripheral.addAttribute (pin->presentationFormat );
260257 /* Add a callback to be triggered if the remote device updates the value for this pin */
261258 pin->characteristic .setEventHandler (BLEWritten, analogOutputCharWrittenEventCb);
262259 }
@@ -265,7 +262,7 @@ void setup() {
265262 * advertising packets and thus become visible to remote BLE central devices
266263 * (e.g smartphones) until it receives a new connection */
267264 CHECK_STATUS (blePeripheral.begin ());
268- LOG_SERIAL .println (" Bluetooth device active, waiting for connections..." );
265+ Serial .println (" Bluetooth device active, waiting for connections..." );
269266}
270267
271268void loop () {
0 commit comments