@@ -156,34 +156,34 @@ void blePeripheralDisconnectedEventCb(BleCentral &bleCentral)
156
156
}
157
157
158
158
/* This function will be called when a connected remote peer sets a new value for a digital output characteristic */
159
- void digitalOutputCharEventCb (BleUnsignedCharCharacteristic &characteristic, BleCharacteristicEvent event, void *arg )
159
+ void digitalOutputCharWrittenEventCb (BleCharacteristic &characteristic)
160
160
{
161
- unsigned pin = (unsigned )arg;
162
- unsigned char val;
163
-
164
- if (BLE_CHAR_EVENT_WRITE == event) {
165
- /* The remote client has updated the value for this pin, get the current value */
166
- val = characteristic.value ();
167
- /* Update the state of the pin to reflect the new value */
168
- digitalWrite (pin, VAL_TO_DIGITAL_PIN_STATE (pin, val));
169
- } else
170
- LOG_SERIAL.println (" Got UNKNOWN characteristic event" );
161
+ for (unsigned int i = 0 ; i < ARRAY_SIZE (digitalOutputPins); i++) {
162
+ if (&digitalOutputPins[i].characteristic == &characteristic) {
163
+ unsigned pin = digitalOutputPins[i].pin ;
164
+ /* The remote client has updated the value for this pin, get the current value */
165
+ unsigned char val = digitalOutputPins[i].characteristic .value ();
166
+
167
+ /* Update the state of the pin to reflect the new value */
168
+ digitalWrite (pin, VAL_TO_DIGITAL_PIN_STATE (pin, val));
169
+ break ;
170
+ }
171
+ }
171
172
}
172
173
173
174
/* This function will be called when a connected remote peer sets a new value for an analog output characteristic */
174
- void analogOutputCharEventCb (BleUnsignedShortCharacteristic &characteristic, BleCharacteristicEvent event, void *arg )
175
+ void analogOutputCharWrittenEventCb (BleCharacteristic &characteristic)
175
176
{
176
- unsigned pin = (unsigned )arg;
177
- unsigned short val;
178
-
179
- if (BLE_CHAR_EVENT_WRITE == event) {
180
- /* The remote client has updated the value for this pin, get the current value */
181
- val = characteristic.value ();
182
- /* Update the state of the pin to reflect the new value */
183
- analogWrite (pin, val);
177
+ for (unsigned int i = 0 ; i < ARRAY_SIZE (analogOutputPins); i++) {
178
+ if (&analogOutputPins[i].characteristic == &characteristic) {
179
+ unsigned pin = analogOutputPins[i].pin ;
180
+ /* The remote client has updated the value for this pin, get the current value */
181
+ unsigned short val = analogOutputPins[i].characteristic .value ();
182
+ /* Update the state of the pin to reflect the new value */
183
+ analogWrite (pin, val);
184
+ break ;
185
+ }
184
186
}
185
- else
186
- LOG_SERIAL.println (" Got UNKNOWN characteristic event" );
187
187
}
188
188
189
189
void setup () {
@@ -230,7 +230,7 @@ void setup() {
230
230
/* Add the characteristic for this pin */
231
231
CHECK_STATUS (blePeripheral.addAttribute (pin->characteristic ));
232
232
/* Add a callback to be triggered if the remote device updates the value for this pin */
233
- pin->characteristic .setEventCallback (( void (*)(BleCharacteristic&, BleCharacteristicEvent, void *))digitalOutputCharEventCb, ( void *)pin-> pin );
233
+ pin->characteristic .setEventHandler (BleWritten, digitalOutputCharWrittenEventCb );
234
234
/* Add a number_of_digitals descriptor for this characteristic */
235
235
CHECK_STATUS (blePeripheral.addAttribute (pin->userDescription ));
236
236
CHECK_STATUS (blePeripheral.addAttribute (pin->presentationFormat ));
@@ -260,7 +260,7 @@ void setup() {
260
260
CHECK_STATUS (blePeripheral.addAttribute (pin->userDescription ));
261
261
CHECK_STATUS (blePeripheral.addAttribute (pin->presentationFormat ));
262
262
/* Add a callback to be triggered if the remote device updates the value for this pin */
263
- pin->characteristic .setEventCallback (( void (*)(BleCharacteristic&, BleCharacteristicEvent, void *))analogOutputCharEventCb, ( void *)pin-> pin );
263
+ pin->characteristic .setEventHandler (BleWritten, analogOutputCharWrittenEventCb );
264
264
}
265
265
266
266
/* Now activate the BLE device. It will start continuously transmitting BLE
0 commit comments