From 6c2d82599ffbed5db7ee01cdf77a16ad93e4fac0 Mon Sep 17 00:00:00 2001 From: Babz Date: Thu, 2 Sep 2021 19:04:01 +0200 Subject: [PATCH] show battery voltage --- CMakeLists.txt | 1 + src/battery.c | 12 ++++++++++++ src/battery.h | 6 ++++++ src/main.c | 4 +++- src/ui.c | 4 ++-- src/ui.h | 2 +- 6 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/battery.c create mode 100644 src/battery.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a08903..964f68f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ set(SOURCES src/main.c src/term.c src/ui.c + src/battery.c src/syscalls.S # ... ) diff --git a/src/battery.c b/src/battery.c new file mode 100644 index 0000000..b233b6b --- /dev/null +++ b/src/battery.c @@ -0,0 +1,12 @@ +#include "battery.h" +#include + +extern int _battery(int one); + +static volatile int battery_voltage; +static void battery_wrapper(void) { battery_voltage = _battery(1); } + +int get_battery_voltage(void) { + gint_world_switch(GINT_CALL(battery_wrapper)); + return battery_voltage; +} \ No newline at end of file diff --git a/src/battery.h b/src/battery.h new file mode 100644 index 0000000..a337c03 --- /dev/null +++ b/src/battery.h @@ -0,0 +1,6 @@ +#ifndef UNS_BATTERY_H +#define UNS_BATTERY_H + +int get_battery_voltage(void); + +#endif // #ifndef UNS_BATTERY_H \ No newline at end of file diff --git a/src/main.c b/src/main.c index 300efd9..2e05158 100644 --- a/src/main.c +++ b/src/main.c @@ -61,8 +61,10 @@ int main(void) { char buf[128]; sprintf(buf, "tick_ctr=%d key=0x%x mod=%d shift=%d alpha=%d\n", tick_ctr, kev.key, kev.mod, kev.shift, kev.alpha); tgrid_sets(UNS_TERM_ROWS - 2, 0, C_WHITE, C_BLACK, buf); - set_statusbar(tick_ctr, shift_state, alpha_state); + + set_statusbar(tick_ctr, shift_state, alpha_state, get_battery_voltage()); set_menubar(); + tgrid_display(); tick_ctr++; diff --git a/src/ui.c b/src/ui.c index a0c2315..a01302f 100644 --- a/src/ui.c +++ b/src/ui.c @@ -6,7 +6,7 @@ #include #include -void set_statusbar(int tick_ctr, int shift_state, int alpha_state) { +void set_statusbar(int tick_ctr, int shift_state, int alpha_state, int battery) { // set green bar for (int i = 0; i < UNS_TERM_COLS; i++) tgrid_sets(0, i, C_NONE, C_GREEN, " "); @@ -16,7 +16,7 @@ void set_statusbar(int tick_ctr, int shift_state, int alpha_state) { // then add actutal text char statusbar[UNS_TERM_COLS + 1]; - sprintf(statusbar, "%s %s t=%d", shift_symbol, alpha_symbol, tick_ctr); + sprintf(statusbar, "%s %s t=%d, bat=%d% cV", shift_symbol, alpha_symbol, tick_ctr, battery); tgrid_sets(0, 0, C_BLACK, C_GREEN, statusbar); } diff --git a/src/ui.h b/src/ui.h index eb85244..639c36d 100644 --- a/src/ui.h +++ b/src/ui.h @@ -1,7 +1,7 @@ #ifndef UNS_UI_H #define UNS_UI_H -void set_statusbar(int tick_ctr, int shift_state, int alpha_state); +void set_statusbar(int tick_ctr, int shift_state, int alpha_state, int battery); extern char fnkeys[6][11]; void set_menubar(void);