Skip to content

Commit

Permalink
Add batt command (#62)
Browse files Browse the repository at this point in the history
```bash
uart:~$ batt
Battery: 82%, 4048 mV, charging
```
  • Loading branch information
noahp authored Sep 16, 2024
1 parent d1c1a3f commit bb6bda5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/modules/debug_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <adp536x.h>
#endif

#include <zephyr/shell/shell.h>

#define MODULE debug_module

#if defined(CONFIG_WATCHDOG_APPLICATION)
Expand Down Expand Up @@ -467,6 +469,27 @@ void memfault_metrics_heartbeat_collect_data(void)
memfault_ncs_metrics_collect_data();
}

static int prv_batt_cmd(const struct shell *shell, size_t argc, char **argv) {
ARG_UNUSED(argc);
ARG_UNUSED(argv);

const int discharging = prv_adp536x_is_discharging();
uint8_t percentage;
uint16_t millivolts;

if (adp536x_fg_soc(&percentage) || adp536x_fg_volts(&millivolts) ) {
shell_print(shell, "Failed to get battery info");
return -1;
}

shell_print(shell, "Battery: %d%%, %d mV, %s",
percentage, millivolts, discharging ? "discharging" : "charging");

return 0;
}

SHELL_CMD_REGISTER(batt, NULL, "Print battery info", prv_batt_cmd);

APP_EVENT_LISTENER(MODULE, app_event_handler);
APP_EVENT_SUBSCRIBE_EARLY(MODULE, app_module_event);
APP_EVENT_SUBSCRIBE_EARLY(MODULE, modem_module_event);
Expand Down

0 comments on commit bb6bda5

Please sign in to comment.