Skip to content

Commit b6eea74

Browse files
committed
Use bool for public API's return types instead of BleStatus type
1 parent 1596dc1 commit b6eea74

File tree

12 files changed

+81
-94
lines changed

12 files changed

+81
-94
lines changed

libraries/CurieBle/examples/AutomationIO/AutomationIO.ino

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */
148144
void blePeripheralConnectedEventCb(BLECentral &bleCentral)
149145
{
150-
LOG_SERIAL.println("Got CONNECTED event");
146+
Serial.println("Got CONNECTED event");
151147
}
152148

153149
void 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 &central, BLECharacteristic &char
187183
}
188184

189185
void 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

271268
void loop() {

libraries/CurieBle/src/BLECentral.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ BLECentral::poll() {
8383
_peripheral->poll();
8484
}
8585

86-
BleStatus
86+
bool
8787
BLECentral::disconnect() {
8888
if (connected()) {
8989
return _peripheral->disconnect();
9090
}
9191

92-
return BLE_STATUS_WRONG_STATE;
92+
return false;
9393
}
9494

9595
void

libraries/CurieBle/src/BLECentral.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ class BLECentral {
4545
/**
4646
* Disconnect the central if it is connected
4747
*
48-
* @return BleStatus result of operation
4948
*/
50-
BleStatus disconnect(void);
49+
bool disconnect(void);
5150

5251
/**
5352
* Poll the central for events

libraries/CurieBle/src/BLECharacteristic.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ BLECharacteristic::properties() const
5555
return _properties;
5656
}
5757

58-
BleStatus
58+
bool
5959
BLECharacteristic::setValue(const unsigned char value[], uint16_t length)
6060
{
6161
BleStatus status;
@@ -65,20 +65,20 @@ BLECharacteristic::setValue(const unsigned char value[], uint16_t length)
6565
if (_value_handle) {
6666
status = ble_client_gatts_set_attribute_value(_value_handle, _data_len, _data, 0);
6767
if (BLE_STATUS_SUCCESS != status) {
68-
return status;
68+
return false;
6969
}
7070

7171
if (subscribed()) {
7272
boolean_t indication = (_cccd_value & BLE_CCCD_INDICATE_EN_MASK);
7373

7474
status = ble_client_gatts_send_notif_ind(_value_handle, _data_len, _data, 0, indication);
7575
if (BLE_STATUS_SUCCESS != status) {
76-
return status;
76+
return false;
7777
}
7878
}
7979
}
8080

81-
return BLE_STATUS_SUCCESS;
81+
return true;
8282
}
8383

8484
void
@@ -143,7 +143,7 @@ BLECharacteristic::setEventHandler(BLECharacteristicEvent event, BLECharacterist
143143
interrupts();
144144
}
145145

146-
BleStatus
146+
bool
147147
BLECharacteristic::add(uint16_t serviceHandle)
148148
{
149149
bt_uuid uuid = btUuid();
@@ -199,7 +199,7 @@ BLECharacteristic::add(uint16_t serviceHandle)
199199
_cccd_handle = handles.cccd_handle;
200200
}
201201

202-
return status;
202+
return (BLE_STATUS_SUCCESS == status);
203203
}
204204

205205
uint16_t

libraries/CurieBle/src/BLECharacteristic.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ class BLECharacteristic : public BLEAttribute {
8888
* @param length Length, in bytes, of valid data in the array to write.
8989
* Must not exceed maxLength set for this characteristic.
9090
*
91-
* @return BleStatus indicating success or error
91+
* @return bool true set value success, false on error
9292
*/
93-
BleStatus setValue(const unsigned char value[], unsigned short length);
93+
bool setValue(const unsigned char value[], unsigned short length);
9494

9595
/**
9696
* Get the property mask of the Characteristic
9797
*
98-
* @return uint8_t property mask of the Characteristic
98+
* @return unsigned char property mask of the Characteristic
9999
*/
100100
unsigned char properties(void) const;
101101

@@ -145,7 +145,7 @@ class BLECharacteristic : public BLEAttribute {
145145
void setEventHandler(BLECharacteristicEvent event, BLECharacteristicEventHandler callback);
146146

147147
protected:
148-
BleStatus add(uint16_t serviceHandle);
148+
bool add(uint16_t serviceHandle);
149149

150150
uint16_t valueHandle(void);
151151

libraries/CurieBle/src/BLEDescriptor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ BLEDescriptor::operator[] (int offset) const
5555
return _data[offset];
5656
}
5757

58-
BleStatus
58+
bool
5959
BLEDescriptor::add(uint16_t serviceHandle)
6060
{
6161
bt_uuid uuid = btUuid();
@@ -73,5 +73,5 @@ BLEDescriptor::add(uint16_t serviceHandle)
7373
desc.perms.rd = GAP_SEC_MODE_1 | GAP_SEC_LEVEL_1;
7474
desc.perms.wr = GAP_SEC_NO_PERMISSION;
7575

76-
return ble_client_gatts_add_descriptor(serviceHandle, &desc, &handle);
76+
return (ble_client_gatts_add_descriptor(serviceHandle, &desc, &handle) == BLE_STATUS_SUCCESS);
7777
}

libraries/CurieBle/src/BLEDescriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class BLEDescriptor : public BLEAttribute {
6363
unsigned char operator[] (int offset) const;
6464

6565
protected:
66-
BleStatus add(uint16_t serviceHandle);
66+
bool add(uint16_t serviceHandle);
6767

6868
friend BLEPeripheral;
6969

0 commit comments

Comments
 (0)