feat(ui): runtime joystick rotation independent of display rotation

Add NodePrefs::joystick_rotation (0-3 steps CW), persisted in DataStore
alongside display_rotation. rotateJoystickKey() now takes a runtime rot
parameter instead of compile-time JOYSTICK_ROTATION macro. UITask::loop()
reads joystick_rotation from NodePrefs each frame. Settings screen exposes
"Joystick" rotation item on any build with UI_HAS_JOYSTICK. JOYSTICK_ROTATION
macro still works as compile-time default for legacy/non-prefs builds.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-05-23 15:20:40 +02:00
parent 85cfb6f1af
commit fea1be8e81
5 changed files with 70 additions and 6 deletions

View File

@@ -14,6 +14,36 @@
#define KEY_PREV 0xF2
#define KEY_CONTEXT_MENU 0xF3
#ifndef JOYSTICK_ROTATION
#define JOYSTICK_ROTATION 0
#endif
// Rotate directional key by rot steps clockwise (03).
// Pass NodePrefs::joystick_rotation at runtime; JOYSTICK_ROTATION macro is the compile-time default.
static inline char rotateJoystickKey(char key, uint8_t rot) {
switch (rot & 3) {
case 1:
if ((uint8_t)key == KEY_UP) return KEY_RIGHT;
if ((uint8_t)key == KEY_RIGHT) return KEY_DOWN;
if ((uint8_t)key == KEY_DOWN) return KEY_LEFT;
if ((uint8_t)key == KEY_LEFT) return KEY_UP;
break;
case 2:
if ((uint8_t)key == KEY_UP) return KEY_DOWN;
if ((uint8_t)key == KEY_DOWN) return KEY_UP;
if ((uint8_t)key == KEY_LEFT) return KEY_RIGHT;
if ((uint8_t)key == KEY_RIGHT) return KEY_LEFT;
break;
case 3:
if ((uint8_t)key == KEY_UP) return KEY_LEFT;
if ((uint8_t)key == KEY_LEFT) return KEY_DOWN;
if ((uint8_t)key == KEY_DOWN) return KEY_RIGHT;
if ((uint8_t)key == KEY_RIGHT) return KEY_UP;
break;
}
return key;
}
class UIScreen {
protected:
UIScreen() { }