summaryrefslogtreecommitdiff
path: root/nrf-softdevice
diff options
context:
space:
mode:
authorDaniel Franklin <daniel@danielzfranklin.org>2022-02-11 17:00:22 -0700
committerDaniel Franklin <daniel@danielzfranklin.org>2022-02-11 17:06:21 -0700
commitdd568798094372284fd8334888f07c25d565be83 (patch)
treed12fe3735835e541ed149180140e85bfcd7ce8ad /nrf-softdevice
parentba31fc03d97facc54efb9456901abf02549a4209 (diff)
downloadnrf-softdevice-dd568798094372284fd8334888f07c25d565be83.zip
Add FixedGattValue for bool
0x00 is false, any other byte is true.
Diffstat (limited to 'nrf-softdevice')
-rw-r--r--nrf-softdevice/src/ble/gatt_traits.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/nrf-softdevice/src/ble/gatt_traits.rs b/nrf-softdevice/src/ble/gatt_traits.rs
index 1916687..490e59a 100644
--- a/nrf-softdevice/src/ble/gatt_traits.rs
+++ b/nrf-softdevice/src/ble/gatt_traits.rs
@@ -75,6 +75,21 @@ impl<T: Primitive> FixedGattValue for T {
}
}
+impl FixedGattValue for bool {
+ const SIZE: usize = 1;
+
+ fn from_gatt(data: &[u8]) -> Self {
+ data != [0x00]
+ }
+
+ fn to_gatt(&self) -> &[u8] {
+ match self {
+ true => &[0x01],
+ false => &[0x00],
+ }
+ }
+}
+
impl<const N: usize> GattValue for Vec<u8, N> {
const MIN_SIZE: usize = 0;
const MAX_SIZE: usize = N;