buttons remap when oled is rotated

the oled display rotates when the addon is physically rotated, so that menus are upright. now the user buttons will remap as well. this was done in the old code...or so I thought, but I can't find the code that did it.
This commit is contained in:
true 2024-10-26 20:22:42 -07:00
parent 390528071c
commit 236359d7e2
3 changed files with 38 additions and 9 deletions

View File

@ -140,6 +140,7 @@ __HIGH_CODE
void oled_update_done()
{
int8_t rot;
uint8_t oldsys;
// reset oled callback, clear screen, and set default pixel mode and font size
oled.callback = 0;
@ -153,6 +154,7 @@ void oled_update_done()
// orientation / flipping flags
rot = accel_get_rotation(&accel);
oldsys = sysflags;
if ((rot > (96+4)) || (rot < (32-4))) {
sysflags &= ~SYS_OLED_ROTATE_X;
} else if ((rot > (32+4)) && (rot < (96-4))) {
@ -165,6 +167,10 @@ void oled_update_done()
sysflags |= SYS_OLED_ROTATE_Y;
}
if (sysflags != oldsys) {
sysflags |= SYS_OLED_ROTATE_CHANGED;
}
if ((rot < 21) || (rot > (64 + 24))) {
sysflags &= ~SYS_OLED_REVERSE_CHARS;
} else if (rot > 24 && rot < (64 + 21)){
@ -240,6 +246,12 @@ void lowprio_task() {
ch32sub_intr_defaults();
btn_commit_hold();
ch32sub_rgb_hwen(1);
} else {
// send button holds any time the orientation of the OLED changes
if (sysflags & SYS_OLED_ROTATE_CHANGED) {
sysflags &= ~SYS_OLED_ROTATE_CHANGED;
btn_commit_hold();
}
}
// process sub MCU interrupt, if pending

View File

@ -11,6 +11,7 @@
#include "btn.h"
#include "hw/ch32sub.h"
#include "user_config.h"
@ -21,7 +22,8 @@ uint8_t btn_held;
static uint8_t btn_map[BTN_COUNT] = {2, 1, 3, 0, 4}; // bot left, top left, bot right, top right
static uint8_t btn_map_upr[BTN_COUNT] = {3, 0, 1, 2, 4}; // bot left, top left, bot right, top right
static uint8_t btn_map_rot[BTN_COUNT] = {2, 1, 3, 0, 4};
@ -56,10 +58,18 @@ void btn_commit_hold()
uint8_t i, x;
uint8_t val[BTN_COUNT*2];
uint8_t *map;
if (sysflags & SYS_OLED_ROTATE_X) {
map = btn_map_rot;
} else {
map = btn_map_upr;
}
x = 0;
for (i = 0; i < BTN_COUNT; i++) {
val[x + 0x00] = btn[btn_map[i]].hold >> 8;
val[x + 0x01] = btn[btn_map[i]].hold & 0xff;
val[x + 0x00] = btn[map[i]].hold >> 8;
val[x + 0x01] = btn[map[i]].hold & 0xff;
x += 2;
}
@ -67,8 +77,8 @@ void btn_commit_hold()
x = 0;
for (i = 0; i < BTN_COUNT; i++) {
val[x + 0x00] = btn[btn_map[i]].repeat >> 8;
val[x + 0x01] = btn[btn_map[i]].repeat & 0xff;
val[x + 0x00] = btn[map[i]].repeat >> 8;
val[x + 0x01] = btn[map[i]].repeat & 0xff;
x += 2;
}
@ -81,7 +91,13 @@ void btn_intr()
{
uint8_t i;
uint8_t btn_state[4]; // [9];
// uint8_t *btn_mask = &btn_state[4];
uint8_t *map;
if (sysflags & SYS_OLED_ROTATE_X) {
map = btn_map_rot;
} else {
map = btn_map_upr;
}
// get button data.
ch32sub_read(REG_BTN_PUSHED_LATCHED, btn_state, sizeof(btn_state));
@ -93,13 +109,13 @@ void btn_intr()
// process callbacks for new events
for (i = 0; i < BTN_COUNT; i++) {
if (btn_state[1] & (1 << i)) {
btn_push_cb(btn_map[i]);
btn_push_cb(map[i]);
}
if (btn_state[2] & (1 << i)) {
btn_hold_cb(btn_map[i]);
btn_hold_cb(map[i]);
}
if (btn_state[3] & (1 << i)) {
btn_release_cb(btn_map[i]);
btn_release_cb(map[i]);
}
}
}

View File

@ -25,6 +25,7 @@
#define SYS_OLED_ROTATE_X (1 << 0)
#define SYS_OLED_ROTATE_Y (1 << 1)
#define SYS_OLED_REVERSE_CHARS (1 << 2) // todo: figure out wtf this is
#define SYS_OLED_ROTATE_CHANGED (1 << 7)
// user configuration stuff
#define UCONF_VER 0x04