nshell/src/ui.c

65 lines
1.7 KiB
C

#include "ui.h"
#include "term.h"
#include <gint/display.h>
#include <gint/rtc.h>
#include <printf.h>
#include <string.h>
static void date_str(char *buf) {
rtc_time_t t;
rtc_get_time(&t);
sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d", t.year, t.month, t.week_day, t.hours, t.minutes, t.seconds);
}
void set_statusbar(int tick_ctr, int cycle_ctr, int shift_state, int alpha_state, int battery) {
// set green bar
for (int i = 0; i < UNS_TERM_COLS; i++)
term_writeat(0, i, C_NONE, C_GREEN, " ");
char *shift_symbol = shift_state ? "" : " ";
char *alpha_symbol = alpha_state ? (shift_state ? "A" : "a") : "1";
char now[32];
date_str(now);
// then add actutal text
char statusbar[UNS_TERM_COLS + 1];
sprintf(statusbar, "%s%s t=%dk c=%d bat=%.2fV %s", shift_symbol, alpha_symbol, tick_ctr / 1000, cycle_ctr, (float)battery / 100, now);
term_writeat(0, 0, C_BLACK, C_GREEN, statusbar);
}
static void center_str(int len, char buf[len], const char *s) {
const int l = strlen(s);
const int before = len / 2 - l / 2;
int i;
for (i = 0; i < before; i++)
buf[i] = ' ';
for (int j = 0; j < l; j++)
buf[i++] = s[j];
for (; i < len; i++)
buf[i] = ' ';
}
char fnkeys[6][11] = {"opt 1-", "opt 2--", "opt 3---", "opt 4----", "opt 5-----", "opt 6"};
void set_menubar(void) {
int col = 0;
for (int i = 0; i < 6; i++) {
char buf[11] = "";
center_str(10, buf, fnkeys[i]);
buf[10] = '\0';
term_writeat(UNS_TERM_ROWS - 1, col, C_WHITE, C_BLUE, buf);
// print spacers
if (i < 6 - 1)
term_writeat(UNS_TERM_ROWS - 1, col + 10, C_WHITE, C_BLACK, " ");
col += 10 + 1;
}
}