@@ -126,19 +126,15 @@ BLEService ioService(SERVICE_UUID_AUTOMATIONIO);
126
126
127
127
#define ARRAY_SIZE (x ) (sizeof (x)/sizeof (x)[0 ])
128
128
129
- /* Serial port to use for printing informational messages to the user */
130
- #define LOG_SERIAL Serial
131
-
132
129
/* For convenience, this macro will invoke a specified function call and will
133
130
* check the status value returned to ensure it is successful. If not, it will
134
131
* print an error message to the serial port and will return from the current function
135
132
*/
136
133
#define CHECK_STATUS (op ) \
137
134
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 " ); \
142
138
return ; \
143
139
} \
144
140
} while (0 )
@@ -147,12 +143,12 @@ BLEService ioService(SERVICE_UUID_AUTOMATIONIO);
147
143
* Intel Curie BLE device */
148
144
void blePeripheralConnectedEventCb (BLECentral &bleCentral)
149
145
{
150
- LOG_SERIAL .println (" Got CONNECTED event" );
146
+ Serial .println (" Got CONNECTED event" );
151
147
}
152
148
153
149
void blePeripheralDisconnectedEventCb (BLECentral &bleCentral)
154
150
{
155
- LOG_SERIAL .println (" Got DISCONNECTED event" );
151
+ Serial .println (" Got DISCONNECTED event" );
156
152
}
157
153
158
154
/* 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
187
183
}
188
184
189
185
void setup () {
190
- LOG_SERIAL.begin (9600 );
186
+ while (!Serial);
187
+ Serial.begin (9600 );
191
188
192
189
/* Set a name for the BLE device */
193
- CHECK_STATUS ( blePeripheral.setLocalName (LOCAL_NAME) );
190
+ blePeripheral.setLocalName (LOCAL_NAME);
194
191
195
192
/* Set a function to be called whenever a BLE GAP event occurs */
196
193
blePeripheral.setEventHandler (BLEConnected, blePeripheralConnectedEventCb);
197
194
blePeripheral.setEventHandler (BLEDisconnected, blePeripheralDisconnectedEventCb);
198
195
199
- CHECK_STATUS ( blePeripheral.setAdvertisedServiceUuid (ioService.uuid () ));
196
+ blePeripheral.setAdvertisedServiceUuid (ioService.uuid ());
200
197
201
198
/* Add the Automation I/O Service, and include the UUID in BLE advertising data */
202
- CHECK_STATUS ( blePeripheral.addAttribute (ioService) );
199
+ blePeripheral.addAttribute (ioService);
203
200
204
201
/* Add characteristics for the Digital Inputs */
205
202
for (unsigned i = 0 ; i < ARRAY_SIZE (digitalInputPins); i++) {
@@ -209,14 +206,14 @@ void setup() {
209
206
pinMode (pin->pin , INPUT);
210
207
211
208
/* Add the characteristic for this pin */
212
- CHECK_STATUS ( blePeripheral.addAttribute (pin->characteristic ) );
209
+ blePeripheral.addAttribute (pin->characteristic );
213
210
/* Set an initial value for this characteristic; refreshed later in the loop() function */
214
211
pin->val = digitalRead (pin->pin );
215
212
CHECK_STATUS (pin->characteristic .setValue (DIGITAL_PIN_STATE_TO_VAL (pin->pin , pin->val )));
216
213
/* 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 );
220
217
}
221
218
222
219
/* Add characteristics for the Digital Outputs */
@@ -227,23 +224,23 @@ void setup() {
227
224
pinMode (pin->pin , OUTPUT);
228
225
229
226
/* Add the characteristic for this pin */
230
- CHECK_STATUS ( blePeripheral.addAttribute (pin->characteristic ) );
227
+ blePeripheral.addAttribute (pin->characteristic );
231
228
/* Add a callback to be triggered if the remote device updates the value for this pin */
232
229
pin->characteristic .setEventHandler (BLEWritten, digitalOutputCharWrittenEventCb);
233
230
/* 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 );
237
234
}
238
235
239
236
/* Add characteristics for the Analog Inputs */
240
237
for (unsigned i = 0 ; i < ARRAY_SIZE (analogInputPins); i++) {
241
238
AnalogPinConfig *pin = &analogInputPins[i];
242
239
243
240
/* 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 );
247
244
/* Set an initial value for this characteristic; refreshed later in the loop() function */
248
245
pin->val = analogRead (pin->pin );
249
246
CHECK_STATUS (pin->characteristic .setValue (pin->val ));
@@ -254,9 +251,9 @@ void setup() {
254
251
AnalogPinConfig *pin = &analogOutputPins[i];
255
252
256
253
/* 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 );
260
257
/* Add a callback to be triggered if the remote device updates the value for this pin */
261
258
pin->characteristic .setEventHandler (BLEWritten, analogOutputCharWrittenEventCb);
262
259
}
@@ -265,7 +262,7 @@ void setup() {
265
262
* advertising packets and thus become visible to remote BLE central devices
266
263
* (e.g smartphones) until it receives a new connection */
267
264
CHECK_STATUS (blePeripheral.begin ());
268
- LOG_SERIAL .println (" Bluetooth device active, waiting for connections..." );
265
+ Serial .println (" Bluetooth device active, waiting for connections..." );
269
266
}
270
267
271
268
void loop () {
0 commit comments