Commit 272fbcc1 authored by Robey Pointer's avatar Robey Pointer
Browse files

remember if we're showing some ux (the battery status, splash screen, or...

remember if we're showing some ux (the battery status, splash screen, or system status) and clear it after 15 seconds
parent b8da7cee
......@@ -60,23 +60,28 @@ void CALLBACK_HID_Device_ProcessHIDReport(
if (command == CMD_TEXT_FRAME) {
if (!menu_is_active()) {
if (ux_is_on()) ux_clear();
display_clear();
for (int i = 4; i < report_size; i++) display_putc(data[i]);
display_flush();
}
} else if (command == CMD_TEXT_WRITE) {
if (!menu_is_active()) {
if (ux_is_on()) ux_clear();
display_write_len((const char *)&data[4], report_size - 4);
display_flush();
}
} else if (command == CMD_TEXT_FONT) {
if (!menu_is_active()) {
if (ux_is_on()) ux_clear();
display_init(report_size > 4 && data[4] == '1' ? &font_bizcat : &font_normal);
display_flush();
}
} else if (command == CMD_REPORT_POWER) {
if (!menu_is_active()) {
if (ux_is_on()) ux_clear();
const char *report = controller_request("0c");
display_clear();
if (report) display_write(report);
display_flush();
}
......@@ -86,16 +91,19 @@ void CALLBACK_HID_Device_ProcessHIDReport(
ux_show_status();
} else if (command == CMD_OLED_CLEAR) {
if (!menu_is_active()) {
if (ux_is_on()) ux_clear();
display_clear();
display_flush();
}
} else if (command == CMD_OLED_BITMAP) {
if (!menu_is_active() && report_size > 6) {
if (ux_is_on()) ux_clear();
uint16_t offset = (uint16_t)data[4] + (((uint16_t)data[5]) << 8);
display_bitmap(offset, data + 6, report_size - 6);
}
} else if (command == CMD_OLED_RLE) {
if (!menu_is_active() && report_size > 6) {
if (ux_is_on()) ux_clear();
uint16_t offset = (uint16_t)data[4] + (((uint16_t)data[5]) << 8);
display_packed_bitmap(offset, data + 6, report_size - 6);
}
......
......@@ -63,6 +63,8 @@
// how long to let the menu display before idling out
#define MENU_IDLE_MSEC 15000
// same, but for UX displays like the keyboard status or the splash screen
#define UX_IDLE_MSEC 15000
/** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */
static uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)];
......@@ -366,6 +368,8 @@ int main(void) {
uint32_t last_battery_check = 0, last_low_battery_blink = 0;
bool low_battery_alert_active = false;
#endif
uint32_t ux_started = 0;
while (true) {
// do our own (non-usb) scan, too, so we can handle the circle menu
// when the laptop is off :)
......@@ -380,8 +384,21 @@ int main(void) {
sleep_mode();
while ((timer_tick & 31) != 0) sleep_mode();
#ifndef KBD_VARIANT_STANDALONE
uint32_t now = timer_get_ticks();
// check if we should clear the display after a UX screen
if (ux_is_on()) {
if (ux_started == 0) {
ux_started = now;
} else if (timer_diff_msec(ux_started, now) >= UX_IDLE_MSEC) {
ux_clear();
ux_started = 0;
}
} else {
ux_started = 0;
}
#ifndef KBD_VARIANT_STANDALONE
if (timer_diff_msec(last_battery_check, now) >= BATTERY_CHECK_MSEC) {
last_battery_check = now;
int was_low = low_battery;
......
......@@ -16,6 +16,9 @@
static uint8_t oled_brightness = 0;
// track this so the main loop can clear the screen after some time has passed
static bool display_on = false;
void ux_increase_oled_brightness(void) {
if (oled_brightness < 0xff) oled_brightness += 0x11;
oled_contrast(oled_brightness);
......@@ -77,6 +80,7 @@ void ux_show_battery(void) {
show_one_battery(info.decivolts[3]), show_one_battery(info.decivolts[7]), info.total_volts);
display_write(str);
display_flush();
display_on = true;
}
void ux_show_status(void) {
......@@ -92,6 +96,7 @@ void ux_show_status(void) {
display_move(0, 3);
display_write(KBD_FW_REV);
display_flush();
display_on = true;
}
void ux_blink_low_battery(bool blink) {
......@@ -115,10 +120,22 @@ void ux_splash(void) {
oled_contrast(0xff - i);
Delay_MS(2);
}
display_on = true;
}
// wipe away the boot logo
void ux_unsplash(void) {
display_packed_bitmap_pgm(0, logo_bitmap, sizeof(logo_bitmap), false);
display_packed_bitmap_pgm(0, empty_bitmap, sizeof(empty_bitmap), true);
display_on = false;
}
bool ux_is_on(void) {
return display_on;
}
void ux_clear(void) {
display_clear();
display_flush();
display_on = false;
}
......@@ -15,3 +15,5 @@ void ux_show_status(void);
void ux_blink_low_battery(bool blink);
void ux_splash(void);
void ux_unsplash(void);
bool ux_is_on(void);
void ux_clear(void);
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