refactor: cleanup
This commit is contained in:
parent
f3923c037b
commit
a8d7e2c460
1 changed files with 6 additions and 13 deletions
|
@ -32,27 +32,20 @@ static void blvl_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value
|
||||||
|
|
||||||
static ssize_t read_blvl(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf,
|
static ssize_t read_blvl(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf,
|
||||||
uint16_t len, uint16_t offset) {
|
uint16_t len, uint16_t offset) {
|
||||||
uint8_t lvl8 = last_state_of_charge;
|
const char *lvl8 = attr->user_data;
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &lvl8, sizeof(lvl8));
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, lvl8, sizeof(uint8_t));
|
||||||
}
|
|
||||||
|
|
||||||
static ssize_t read_peripheral_blvl(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
|
||||||
void *buf, uint16_t len, uint16_t offset) {
|
|
||||||
uint8_t lvl8 = last_state_of_peripheral_charge;
|
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &lvl8, sizeof(lvl8));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BT_GATT_SERVICE_DEFINE(
|
BT_GATT_SERVICE_DEFINE(
|
||||||
bas, BT_GATT_PRIMARY_SERVICE(BT_UUID_BAS),
|
bas, BT_GATT_PRIMARY_SERVICE(BT_UUID_BAS),
|
||||||
BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
|
BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
|
||||||
BT_GATT_PERM_READ, read_blvl, NULL, &last_state_of_charge),
|
BT_GATT_PERM_READ, read_blvl, NULL, &last_state_of_charge),
|
||||||
BT_GATT_CUD("Central", BT_GATT_PERM_READ),
|
|
||||||
BT_GATT_CCC(blvl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
|
BT_GATT_CCC(blvl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
|
||||||
|
BT_GATT_CUD("Central", BT_GATT_PERM_READ),
|
||||||
BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
|
BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
|
||||||
BT_GATT_PERM_READ, read_peripheral_blvl, NULL,
|
BT_GATT_PERM_READ, read_blvl, NULL, &last_state_of_peripheral_charge),
|
||||||
&last_state_of_peripheral_charge),
|
BT_GATT_CCC(blvl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
|
||||||
BT_GATT_CUD("Peripheral", BT_GATT_PERM_READ),
|
BT_GATT_CUD("Peripheral", BT_GATT_PERM_READ));
|
||||||
BT_GATT_CCC(blvl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE));
|
|
||||||
|
|
||||||
const struct device *battery;
|
const struct device *battery;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue