report battery levels with bluetooth
Some checks failed
Build / Build (push) Failing after 3m29s
Build / build (ubuntu-22.04) (push) Failing after 20s
Documentation / build (push) Failing after -1m6s

This commit is contained in:
2025-05-31 19:55:18 -06:00
parent 3ac0d2f52a
commit 4574ee3088
3 changed files with 11 additions and 1 deletions

View File

@ -23,6 +23,7 @@ CONFIG_BT_SMP=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_DEVICE_NAME="Mellifera"
CONFIG_BT_BAS=y
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251

View File

@ -2,6 +2,7 @@
#include <zephyr/drivers/sensor.h>
#include <zephyr/logging/log.h>
#include <zephyr/display/cfb.h>
#include <zephyr/bluetooth/services/bas.h>
#include <app/drivers/blink.h>
@ -312,7 +313,11 @@ int thread_sensors(void)
LOG_ERR("Could not get sample");
}
sprintf(str_v, "V :%7.5f", voltage.val1 + voltage.val2 * 1e-6);
double vbat = voltage.val1 + voltage.val2 * 1e-6;
uint8_t pct_bat = 100.0 * (vbat - 3.3) / (4.2 - 3.3);
bt_bas_set_battery_level(pct_bat);
sprintf(str_v, "V :%7.5f", vbat);
sprintf(str_i, "I :%7.5f", current.val1 + current.val2 * 1e-6);
sprintf(str_p, "P :%7.4f", pressure.val1 + pressure.val2 * 1e-6);
sprintf(str_t, "T :%7.4f", temperature.val1 + temperature.val2 * 1e-6);

View File

@ -11,6 +11,7 @@
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/services/bas.h>
extern int mtu_exchange(struct bt_conn *conn);
extern int write_cmd(struct bt_conn *conn);
@ -19,6 +20,9 @@ extern uint32_t last_write_rate;
static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA_BYTES(BT_DATA_UUID16_ALL,
BT_UUID_16_ENCODE(BT_UUID_BAS_VAL), // battery service
),
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), // -1 to strip \0
};