Commit c640f864 authored by Robey Pointer's avatar Robey Pointer
Browse files

add better escape codes to WRIT, for filling in battery info

parent 62f64316
......@@ -93,6 +93,19 @@ void display_scroll(void) {
text_dirty = true;
}
// escape commands to display certain glyphs or change state
#define ESC_CLEAR 'C'
#define ESC_LF 'n'
#define ESC_INVERT 'I'
#define ESC_NORMAL 'N'
#define ESC_BATTERY 'B'
#define ESC_CHARGING 'A'
#define ESC_PERCENT 'P'
#define ESC_FONT_BIG '+'
#define ESC_FONT_NORMAL '-'
#define CHAR_LIGHTNING 0x0c
void display_putc(uint8_t c) {
while (text_cursor >= text_width * text_height) {
text_cursor -= text_width;
......@@ -107,22 +120,64 @@ void display_putc(uint8_t c) {
}
void display_write_len(const char *text, int len) {
bool escaped = false;
char buffer[4];
battery_info_t info;
info.total_percent = 255;
for (int i = 0; i < len; i++) {
if (escaped) {
switch (text[i]) {
case ESC_CLEAR:
display_clear();
break;
case ESC_LF:
text_cursor = ((text_cursor / text_width) + 1) * text_width;
break;
case ESC_INVERT:
text_inverting = true;
break;
case ESC_NORMAL:
text_inverting = false;
break;
case ESC_FONT_BIG:
display_init(&font_bizcat);
break;
case ESC_FONT_NORMAL:
display_init(&font_normal);
break;
case ESC_BATTERY:
if (info.total_percent == 255) controller_probe_batteries(&info);
ux_get_battery_icon(buffer, info.total_percent);
display_putc(buffer[0]);
display_putc(buffer[1]);
break;
case ESC_CHARGING:
if (info.total_percent == 255) controller_probe_batteries(&info);
display_putc(info.total_amps < 0 ? CHAR_LIGHTNING : ' ');
break;
case ESC_PERCENT:
if (info.total_percent == 255) controller_probe_batteries(&info);
sprintf(buffer, "%3d", info.total_percent);
display_putc(buffer[0]);
display_putc(buffer[1]);
display_putc(buffer[2]);
break;
case 0xff:
display_putc(0xff);
break;
}
escaped = false;
continue;
}
switch (text[i]) {
case '\n':
text_cursor = ((text_cursor / text_width) + 1) * text_width;
break;
case 0x0c:
// clear
display_clear();
break;
case 0x0e:
// "shift out": invert
text_inverting = true;
break;
case 0x0f:
// "shift in": normal
text_inverting = false;
case 0xff:
escaped = true;
break;
default:
display_putc(text[i]);
......
......@@ -39,11 +39,16 @@ static uint8_t decivolts_to_percent(uint8_t decivolts) {
return 0;
}
// will fill 2 bytes
void ux_get_battery_icon(char *buffer, uint8_t percent) {
buffer[0] = BATTERY_LEFT(percent);
buffer[1] = BATTERY_RIGHT(percent);
}
static const char *show_one_battery(uint8_t decivolts) {
static char buffer[7];
uint8_t percent = decivolts_to_percent(decivolts);
buffer[0] = BATTERY_LEFT(percent);
buffer[1] = BATTERY_RIGHT(percent);
ux_get_battery_icon(buffer, percent);
buffer[2] = ' ';
buffer[3] = '0' + (decivolts / 10);
buffer[4] = '.';
......
......@@ -9,6 +9,7 @@
void ux_increase_oled_brightness(void);
void ux_decrease_oled_brightness(void);
void ux_get_battery_icon(char *buffer, uint8_t percent);
void ux_show_battery(void);
void ux_show_status(void);
void ux_blink_low_battery(bool blink);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment