Battery measurement, basic version

This commit is contained in:
2026-05-19 17:08:00 +02:00
parent dd51f45084
commit 52bab32309
19 changed files with 611 additions and 17 deletions

View File

@@ -4,11 +4,28 @@
#include "buzz_proto.h"
#include "settings_mgmt.h"
#include "batt_mgmt.h"
// #include "fw_mgmt.h"
// #include "audio.h"
LOG_MODULE_REGISTER(main);
static const char *battery_state_to_str(batt_mgmt_state_t state)
{
switch (state) {
case BATT_STATE_DISCHARGING:
return "discharging";
case BATT_STATE_FULL:
return "full";
case BATT_STATE_CHARGING:
return "charging";
case BATT_STATE_ERROR:
return "error";
default:
return "unknown";
}
}
#if IS_ENABLED(CONFIG_BLE_MGMT)
#include "ble_mgmt.h"
void ble_rx_cb(const uint8_t *data, uint16_t len)
@@ -49,6 +66,7 @@ void ble_rx_cb(const uint8_t *data, uint16_t len)
int main(void)
{
#if IS_ENABLED(CONFIG_BLE_MGMT)
/* BLE-Subsystem initialisieren und RX-Callback registrieren */
int rc = ble_mgmt_init(ble_rx_cb, app_cfg.dev_name);
@@ -56,17 +74,25 @@ int main(void)
LOG_ERR("Failed to initialize BLE management: %d", rc);
return rc;
}
LOG_WRN("After BLE init");
#else
LOG_WRN("BLE not enabled");
#endif
LOG_WRN("Main park loop active");
// k_sleep(K_MSEC(500));
// LOG_INF("Playing test audio files...");
// audio_queue_play("/lfs/sys/update", false);
// audio_queue_play("/lfs/sys/confirm", false);
#if IS_ENABLED(CONFIG_BATT_MGMT)
k_sleep(K_MSEC(100));
int32_t batt_mv;
int batt_rc = batt_mgmt_measure_vddh_mv(BATT_MGMT_OVERSAMPLING_16X, &batt_mv);
if (batt_rc == 0) {
LOG_INF("Battery after boot: %d mV", batt_mv);
} else {
LOG_WRN("Battery measurement after boot failed: %d", batt_rc);
}
k_sleep(K_SECONDS(1));
batt_mgmt_state_t batt_state = batt_mgmt_get_battery_state();
LOG_INF("Battery state after 1s: %s (%d)", battery_state_to_str(batt_state), batt_state);
#endif
for (;;) {
int32_t rem_ms = k_sleep(K_FOREVER);
LOG_WRN("main woke unexpectedly (remaining=%d ms)", rem_ms);