/** * Initate the read of the characteristic in input. * * The completion of the operation will happens in when_characteristic_read() */ void read_characteristic(const DiscoveredCharacteristic &characteristic) { printf("Initiating read at %u.\r\n", characteristic.getValueHandle()); ble_error_t error = characteristic.read( 0, as_cb(&Self::when_characteristic_read) ); if (error) { printf( "Error: cannot initiate read at %u due to %u\r\n", characteristic.getValueHandle(), error ); stop(); } }
/** * Initiate the discovery of the descriptors of the characteristic in input. * * When a descriptor is discovered, the function when_descriptor_discovered * is invoked. */ void discover_descriptors(const DiscoveredCharacteristic &characteristic) { printf("Initiating descriptor discovery of %u.\r\n", characteristic.getValueHandle()); _descriptor_handle = 0; ble_error_t error = characteristic.discoverDescriptors( as_cb(&Self::when_descriptor_discovered), as_cb(&Self::when_descriptor_discovery_ends) ); if (error) { printf( "Error: cannot initiate discovery of %04X due to %u.\r\n", characteristic.getValueHandle(), error ); stop(); } }
void triggerToggledWrite(const GattReadCallbackParams *response) { if (response->handle == ledCharacteristic.getValueHandle()) { printf("triggerToggledWrite: handle %u, offset %u, len %u\r\n", response->handle, response->offset, response->len); for (unsigned index = 0; index < response->len; index++) { printf("%c[%02x]", response->data[index], response->data[index]); } printf("\r\n"); uint8_t toggledValue = response->data[0] ^ 0x1; ledCharacteristic.write(1, &toggledValue); } }
void triggerRead(const GattWriteCallbackParams *response) { if (response->handle == ledCharacteristic.getValueHandle()) { ledCharacteristic.read(); } }