Fixed key driver

This commit is contained in:
Raphael Coeffic
2021-08-01 10:00:23 +02:00
parent 704c03a422
commit 89bedc5365
3 changed files with 45 additions and 52 deletions
+13 -3
View File
@@ -55,13 +55,13 @@ class RadioKeyDiagsWindow : public Window
void paint(BitmapBuffer * dc) override
{
#if !defined(PCBNV14)
constexpr coord_t KEY_COLUMN = 6;
#if !defined(PCBNV14)
constexpr coord_t SWITCHES_COLUMN = LCD_W / 2 - 20;
constexpr coord_t TRIM_COLUMN = LCD_W - 120;
#else
constexpr coord_t SWITCHES_COLUMN = LCD_W / 6;
constexpr coord_t TRIM_COLUMN = LCD_W / 2;
constexpr coord_t SWITCHES_COLUMN = LCD_W / 3;
constexpr coord_t TRIM_COLUMN = 2 * LCD_W / 3;
#endif
constexpr coord_t TRIM_MINUS_COLUMN = TRIM_COLUMN + 60;
constexpr coord_t TRIM_PLUS_COLUMN = TRIM_MINUS_COLUMN + 20;
@@ -82,6 +82,16 @@ class RadioKeyDiagsWindow : public Window
dc->drawText(KEY_COLUMN, y, STR_ROTARY_ENCODER);
dc->drawNumber(70, y, rotencValue, 0);
#endif
#else // defined(PCBNV14)
// KEYS
{
coord_t y = 1;
dc->drawTextAtIndex(KEY_COLUMN, y, STR_VKEYS, KEY_ENTER, 0);
displayKeyState(dc, 70, y, KEY_ENTER);
y += FH;
dc->drawTextAtIndex(KEY_COLUMN, y, STR_VKEYS, KEY_EXIT, 0);
displayKeyState(dc, 70, y, KEY_EXIT);
}
#endif
// SWITCHES
for (uint8_t i = 0; i < NUM_SWITCHES; i++) {
+10 -11
View File
@@ -142,18 +142,18 @@ void stop_trainer_capture();
// Keys driver
enum EnumKeys
{
KEY_ENTER,
KEY_EXIT,
KEY_PGUP,
KEY_PGDN,
KEY_UP,
KEY_MODEL = KEY_UP, // TODO: just fixed for compile error, seems this is quite different from horus definition.
KEY_DOWN,
KEY_RIGHT,
KEY_LEFT,
KEY_ENTER,
KEY_MODEL,
KEY_UP = KEY_MODEL,
KEY_EXIT,
KEY_DOWN = KEY_EXIT,
KEY_TELEM,
KEY_MENU,
KEY_RIGHT = KEY_TELEM,
KEY_RADIO,
KEY_LEFT = KEY_RADIO,
TRM_BASE,
TRM_LH_DWN = TRM_BASE,
TRM_LH_UP,
@@ -165,9 +165,8 @@ enum EnumKeys
TRM_RH_UP,
TRM_LS_DWN,
TRM_LS_UP,
TRM_LEFT_CLICK,
TRM_RIGHT_CLICK,
TRM_LAST = TRM_RIGHT_CLICK,
TRM_LAST = TRM_LS_UP,
NUM_KEYS
};
+22 -38
View File
@@ -23,32 +23,25 @@
uint32_t readKeys()
{
uint32_t result = 0;
bool getKeys = true;
/*#if defined(LUA)
getKeys = (luaState & INTERPRETER_RUNNING_STANDALONE_SCRIPT);
#endif*/ //TODO: not sure why has LUA condition here, this construct is not in horus target
if (getKeys) {
if (TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL)
result |= 1 << KEY_PGDN;
if (TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR)
result |= 1 << KEY_PGUP;
if (TRIMS_GPIO_REG_LVD & TRIMS_GPIO_PIN_LVD)
result |= 1 << KEY_TELEM;
if (TRIMS_GPIO_REG_LVU & TRIMS_GPIO_PIN_LVU)
result |= 1 << KEY_MENU;
if (TRIMS_GPIO_REG_RVD & TRIMS_GPIO_PIN_RVD)
result |= 1 << KEY_DOWN;
if (TRIMS_GPIO_REG_RVU & TRIMS_GPIO_PIN_RVU)
result |= 1 << KEY_UP;
if (TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)
result |= 1 << KEY_LEFT;
if (TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
result |= 1 << KEY_RIGHT;
if (TRIMS_GPIO_REG_RPRESS & TRIMS_GPIO_PIN_RPRESS)
result |= 1 << KEY_ENTER;
if (TRIMS_GPIO_REG_LPRESS & TRIMS_GPIO_PIN_LPRESS)
result |= 1 << KEY_EXIT;
}
// Arrow keys on right trim joystick
// is only supported within bootloader
#if defined(BOOT)
if (TRIMS_GPIO_REG_RVD & TRIMS_GPIO_PIN_RVD)
result |= 1 << KEY_DOWN;
if (TRIMS_GPIO_REG_RVU & TRIMS_GPIO_PIN_RVU)
result |= 1 << KEY_UP;
if (TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)
result |= 1 << KEY_LEFT;
if (TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
result |= 1 << KEY_RIGHT;
#endif
// Enter and Exit are always supported
if (TRIMS_GPIO_REG_RPRESS & TRIMS_GPIO_PIN_RPRESS)
result |= 1 << KEY_ENTER;
if (TRIMS_GPIO_REG_LPRESS & TRIMS_GPIO_PIN_LPRESS)
result |= 1 << KEY_EXIT;
return result;
}
@@ -56,13 +49,7 @@ uint32_t readKeys()
uint32_t readTrims()
{
uint32_t result = 0;
bool getTrim = true;
/*#if defined(LUA)
if(luaState & INTERPRETER_RUNNING_STANDALONE_SCRIPT) {
getTrim = false;
}
#endif*/ //TODO: not sure why has LUA condition here, this construct is not in horus target
if(!getTrim) return result;
if (TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL)
result |= 1 << (TRM_LH_DWN - TRM_BASE);
if (TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR)
@@ -79,10 +66,6 @@ uint32_t readTrims()
result |= 1 << (TRM_RH_DWN - TRM_BASE);
if (TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
result |= 1 << (TRM_RH_UP - TRM_BASE);
if (TRIMS_GPIO_REG_RPRESS & TRIMS_GPIO_PIN_RPRESS)
result |= 1 << (TRM_RIGHT_CLICK - TRM_BASE);
if (TRIMS_GPIO_REG_LPRESS & TRIMS_GPIO_PIN_LPRESS)
result |= 1 << (TRM_LEFT_CLICK - TRM_BASE);
return result;
}
@@ -94,7 +77,7 @@ bool trimDown(uint8_t idx)
bool keyDown()
{
return 0;
return readKeys() || readTrims();
}
/* TODO common to ARM */
@@ -105,6 +88,7 @@ void readKeysAndTrims()
uint8_t index = 0;
uint32_t in = readKeys();
uint32_t trims = readTrims();
for (i = 0; i < TRM_BASE; i++) {
keys[index++].input(in & (1 << i));
}