show battery voltage

This commit is contained in:
Babz 2021-09-02 19:04:01 +02:00
parent 9722873b8f
commit 6c2d82599f
6 changed files with 25 additions and 4 deletions

View File

@ -18,6 +18,7 @@ set(SOURCES
src/main.c
src/term.c
src/ui.c
src/battery.c
src/syscalls.S
# ...
)

12
src/battery.c Normal file
View File

@ -0,0 +1,12 @@
#include "battery.h"
#include <gint/gint.h>
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;
}

6
src/battery.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef UNS_BATTERY_H
#define UNS_BATTERY_H
int get_battery_voltage(void);
#endif // #ifndef UNS_BATTERY_H

View File

@ -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++;

View File

@ -6,7 +6,7 @@
#include <stdio.h>
#include <string.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) {
// 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);
}

View File

@ -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);