Commit 06b948e5 authored by Robey Pointer's avatar Robey Pointer
Browse files

add hid commands for switching font, clearing the screen, and uploading a bitmap

parent 63eaf98a
......@@ -9,16 +9,21 @@
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Platform/Platform.h>
#include "controller.h"
#include "text_display.h"
#include "display.h"
#include "ux.h"
// hid commands are all 4-letter
#define cmd(_s) (*(uint32_t *)(_s))
#define CMD_TEXT_FRAME cmd("OLED") // fill the screen with a single wall of text
#define CMD_TEXT_WRITE cmd("WRIT") // write to the oled as if it's a console
#define CMD_TEXT_FONT cmd("FONT") // ("0" or "1") switch between text fonts
#define CMD_REPORT_POWER cmd("RPRT") // ask for power stats
#define CMD_UX_POWER cmd("UXPW") // display detailed power screen as if user hit circle-B
#define CMD_UX_STATUS cmd("UXST") // display status screen as if user hit circle-S
#define CMD_OLED_CLEAR cmd("WCLR") // clear the oled display
#define CMD_OLED_BITMAP cmd("WBIT") // (u16 offset, u8 bytes...) write raw bytes into the oled framebuffer
#define CMD_OLED_RLE cmd("WRLE") // (u16 offset, u8 bytes...) write RLE-encoded bytes into the oled framebuffer
#define CMD_POWER_OFF cmd("PWR0") // turn off power rails
#define CMD_TEST cmd("test")
......@@ -47,46 +52,52 @@ void CALLBACK_HID_Device_ProcessHIDReport(
const uint32_t command = *(uint32_t *)data;
if (command == CMD_TEXT_FRAME) {
display_init(&font_oranj);
display_clear();
for (int i = 4; i < report_size; i++) display_putc(data[i]);
display_flush();
if (!menu_is_active()) {
display_init(&font_oranj);
display_clear();
for (int i = 4; i < report_size; i++) display_putc(data[i]);
display_flush();
}
} else if (command == CMD_TEXT_WRITE) {
display_write_len((const char *)&data[4], report_size - 4);
display_flush();
if (!menu_is_active()) {
display_write_len((const char *)&data[4], report_size - 4);
display_flush();
}
} else if (command == CMD_TEXT_FONT) {
if (!menu_is_active()) {
display_init(report_size > 4 && data[4] == '1' ? &font_bizcat : &font_oranj);
display_flush();
}
} else if (command == CMD_REPORT_POWER) {
const char *report = controller_request("0c");
if (report) display_write(report);
display_flush();
if (!menu_is_active()) {
const char *report = controller_request("0c");
if (report) display_write(report);
display_flush();
}
} else if (command == CMD_UX_POWER) {
ux_show_battery();
} else if (command == CMD_UX_STATUS) {
ux_show_status();
} else if (command == CMD_TEST) {
display_init(&font_bizcat);
display_write("This is a test.");
display_flush();
} else if (command == CMD_OLED_CLEAR) {
if (!menu_is_active()) {
display_clear();
display_flush();
}
} else if (command == CMD_OLED_BITMAP) {
if (!menu_is_active() && report_size > 6) {
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) {
uint16_t offset = (uint16_t)data[4] + (((uint16_t)data[5]) << 8);
display_packed_bitmap(offset, data + 6, report_size - 6);
}
} else if (command == CMD_POWER_OFF) {
controller_turn_off_som();
}
#if 0
if (memcmp(data, "SIZE", 4) == 0) {
gfx_on();
gfx_poke(0, 0, '0' + (ReportSize / 1000));
gfx_poke(1, 0, '0' + ((ReportSize / 100) % 10));
gfx_poke(2, 0, '0' + ((ReportSize / 10) % 10));
gfx_poke(3, 0, '0' + ((ReportSize) % 10));
gfx_flush();
}
if (memcmp(data, "test", 4) == 0) {
text_display_write(&display, "This is a test of\nthe oranj font on a\ntiny OLED.\n");
text_display_putc(&display, 0);
text_display_putc(&display, 6);
text_display_putc(&display, ' ');
text_display_putc(&display, 5);
text_display_putc(&display, 7);
text_display_flush(&display);
}
if (data[0]=='O' && data[1]=='I' && data[2]=='N' && data[3]=='V') {
gfx_clear_invert();
gfx_invert_row(data[4]-'0');
......@@ -98,10 +109,6 @@ void CALLBACK_HID_Device_ProcessHIDReport(
if (brite>9) brite=9;
kbd_brightness_set(brite);
}
else if (data[0]=='P' && data[1]=='W' && data[2]=='R' && data[3]=='0') {
// PWR0: shutdown (turn off power rails)
remote_turn_off_som();
}
else if (data[0]=='P' && data[1]=='W' && data[2]=='R' && data[3]=='3') {
// PWR3: aux power off
remote_turn_off_aux();
......
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