mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 12:25:20 +03:00
Bring the CMS to the HoTT-Textmode.
This commit is contained in:
parent
e260c37be3
commit
31830dc10c
9 changed files with 451 additions and 94 deletions
|
@ -160,6 +160,7 @@ static uint8_t leftMenuColumn;
|
|||
static uint8_t rightMenuColumn;
|
||||
static uint8_t maxMenuItems;
|
||||
static uint8_t linesPerMenuItem;
|
||||
static uint8_t externKey = CMS_KEY_NONE;
|
||||
|
||||
bool cmsInMenu = false;
|
||||
|
||||
|
@ -764,14 +765,6 @@ long cmsMenuExit(displayPort_t *pDisplay, const void *ptr)
|
|||
#define IS_LO(X) (rcData[X] < 1250)
|
||||
#define IS_MID(X) (rcData[X] > 1250 && rcData[X] < 1750)
|
||||
|
||||
#define KEY_NONE 0
|
||||
#define KEY_UP 1
|
||||
#define KEY_DOWN 2
|
||||
#define KEY_LEFT 3
|
||||
#define KEY_RIGHT 4
|
||||
#define KEY_ESC 5
|
||||
#define KEY_MENU 6
|
||||
|
||||
#define BUTTON_TIME 250 // msec
|
||||
#define BUTTON_PAUSE 500 // msec
|
||||
|
||||
|
@ -783,17 +776,17 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
if (!currentCtx.menu)
|
||||
return res;
|
||||
|
||||
if (key == KEY_MENU) {
|
||||
if (key == CMS_KEY_MENU) {
|
||||
cmsMenuOpen();
|
||||
return BUTTON_PAUSE;
|
||||
}
|
||||
|
||||
if (key == KEY_ESC) {
|
||||
if (key == CMS_KEY_ESC) {
|
||||
cmsMenuBack(pDisplay);
|
||||
return BUTTON_PAUSE;
|
||||
}
|
||||
|
||||
if (key == KEY_DOWN) {
|
||||
if (key == CMS_KEY_DOWN) {
|
||||
if (currentCtx.cursorRow < pageMaxRow) {
|
||||
currentCtx.cursorRow++;
|
||||
} else {
|
||||
|
@ -802,7 +795,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
}
|
||||
}
|
||||
|
||||
if (key == KEY_UP) {
|
||||
if (key == CMS_KEY_UP) {
|
||||
currentCtx.cursorRow--;
|
||||
|
||||
// Skip non-title labels
|
||||
|
@ -816,14 +809,14 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
}
|
||||
}
|
||||
|
||||
if (key == KEY_DOWN || key == KEY_UP)
|
||||
if (key == CMS_KEY_DOWN || key == CMS_KEY_UP)
|
||||
return res;
|
||||
|
||||
p = pageTop + currentCtx.cursorRow;
|
||||
|
||||
switch (p->type) {
|
||||
case OME_Submenu:
|
||||
if (key == KEY_RIGHT) {
|
||||
if (key == CMS_KEY_RIGHT) {
|
||||
cmsMenuChange(pDisplay, p->data);
|
||||
res = BUTTON_PAUSE;
|
||||
}
|
||||
|
@ -831,7 +824,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
|
||||
case OME_Funcall:;
|
||||
long retval;
|
||||
if (p->func && key == KEY_RIGHT) {
|
||||
if (p->func && key == CMS_KEY_RIGHT) {
|
||||
retval = p->func(pDisplay, p->data);
|
||||
if (retval == MENU_CHAIN_BACK)
|
||||
cmsMenuBack(pDisplay);
|
||||
|
@ -840,7 +833,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
break;
|
||||
|
||||
case OME_OSD_Exit:
|
||||
if (p->func && key == KEY_RIGHT) {
|
||||
if (p->func && key == CMS_KEY_RIGHT) {
|
||||
p->func(pDisplay, p->data);
|
||||
res = BUTTON_PAUSE;
|
||||
}
|
||||
|
@ -854,7 +847,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
case OME_Bool:
|
||||
if (p->data) {
|
||||
uint8_t *val = p->data;
|
||||
if (key == KEY_RIGHT)
|
||||
if (key == CMS_KEY_RIGHT)
|
||||
*val = 1;
|
||||
else
|
||||
*val = 0;
|
||||
|
@ -867,7 +860,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
if (p->data) {
|
||||
uint16_t *val = (uint16_t *)p->data;
|
||||
|
||||
if (key == KEY_RIGHT)
|
||||
if (key == CMS_KEY_RIGHT)
|
||||
*val |= VISIBLE_FLAG;
|
||||
else
|
||||
*val %= ~VISIBLE_FLAG;
|
||||
|
@ -880,7 +873,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
case OME_FLOAT:
|
||||
if (p->data) {
|
||||
OSD_UINT8_t *ptr = p->data;
|
||||
if (key == KEY_RIGHT) {
|
||||
if (key == CMS_KEY_RIGHT) {
|
||||
if (*ptr->val < ptr->max)
|
||||
*ptr->val += ptr->step;
|
||||
}
|
||||
|
@ -899,7 +892,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
if (p->type == OME_TAB) {
|
||||
OSD_TAB_t *ptr = p->data;
|
||||
|
||||
if (key == KEY_RIGHT) {
|
||||
if (key == CMS_KEY_RIGHT) {
|
||||
if (*ptr->val < ptr->max)
|
||||
*ptr->val += 1;
|
||||
}
|
||||
|
@ -916,7 +909,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
case OME_INT8:
|
||||
if (p->data) {
|
||||
OSD_INT8_t *ptr = p->data;
|
||||
if (key == KEY_RIGHT) {
|
||||
if (key == CMS_KEY_RIGHT) {
|
||||
if (*ptr->val < ptr->max)
|
||||
*ptr->val += ptr->step;
|
||||
}
|
||||
|
@ -934,7 +927,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
case OME_UINT16:
|
||||
if (p->data) {
|
||||
OSD_UINT16_t *ptr = p->data;
|
||||
if (key == KEY_RIGHT) {
|
||||
if (key == CMS_KEY_RIGHT) {
|
||||
if (*ptr->val < ptr->max)
|
||||
*ptr->val += ptr->step;
|
||||
}
|
||||
|
@ -952,7 +945,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
case OME_INT16:
|
||||
if (p->data) {
|
||||
OSD_INT16_t *ptr = p->data;
|
||||
if (key == KEY_RIGHT) {
|
||||
if (key == CMS_KEY_RIGHT) {
|
||||
if (*ptr->val < ptr->max)
|
||||
*ptr->val += ptr->step;
|
||||
}
|
||||
|
@ -981,6 +974,12 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
|||
return res;
|
||||
}
|
||||
|
||||
void cmsSetExternKey(uint8_t extKey)
|
||||
{
|
||||
if (externKey == CMS_KEY_NONE)
|
||||
externKey = extKey;
|
||||
}
|
||||
|
||||
uint16_t cmsHandleKeyWithRepeat(displayPort_t *pDisplay, uint8_t key, int repeatCount)
|
||||
{
|
||||
uint16_t ret = 0;
|
||||
|
@ -1026,72 +1025,77 @@ void cmsUpdate(uint32_t currentTimeUs)
|
|||
// Scan 'key' first
|
||||
//
|
||||
|
||||
uint8_t key = KEY_NONE;
|
||||
uint8_t key = CMS_KEY_NONE;
|
||||
|
||||
if (IS_MID(THROTTLE) && IS_LO(YAW) && IS_HI(PITCH) && !ARMING_FLAG(ARMED)) {
|
||||
key = KEY_MENU;
|
||||
}
|
||||
else if (IS_HI(PITCH)) {
|
||||
key = KEY_UP;
|
||||
}
|
||||
else if (IS_LO(PITCH)) {
|
||||
key = KEY_DOWN;
|
||||
}
|
||||
else if (IS_LO(ROLL)) {
|
||||
key = KEY_LEFT;
|
||||
}
|
||||
else if (IS_HI(ROLL)) {
|
||||
key = KEY_RIGHT;
|
||||
}
|
||||
else if (IS_HI(YAW) || IS_LO(YAW))
|
||||
{
|
||||
key = KEY_ESC;
|
||||
}
|
||||
|
||||
if (key == KEY_NONE) {
|
||||
// No 'key' pressed, reset repeat control
|
||||
holdCount = 1;
|
||||
repeatCount = 1;
|
||||
repeatBase = 0;
|
||||
if (externKey != CMS_KEY_NONE) {
|
||||
rcDelayMs = cmsHandleKey(pCurrentDisplay, externKey);
|
||||
externKey = CMS_KEY_NONE;
|
||||
} else {
|
||||
// The 'key' is being pressed; keep counting
|
||||
++holdCount;
|
||||
}
|
||||
if (IS_MID(THROTTLE) && IS_LO(YAW) && IS_HI(PITCH) && !ARMING_FLAG(ARMED)) {
|
||||
key = CMS_KEY_MENU;
|
||||
}
|
||||
else if (IS_HI(PITCH)) {
|
||||
key = CMS_KEY_UP;
|
||||
}
|
||||
else if (IS_LO(PITCH)) {
|
||||
key = CMS_KEY_DOWN;
|
||||
}
|
||||
else if (IS_LO(ROLL)) {
|
||||
key = CMS_KEY_LEFT;
|
||||
}
|
||||
else if (IS_HI(ROLL)) {
|
||||
key = CMS_KEY_RIGHT;
|
||||
}
|
||||
else if (IS_HI(YAW) || IS_LO(YAW))
|
||||
{
|
||||
key = CMS_KEY_ESC;
|
||||
}
|
||||
|
||||
if (rcDelayMs > 0) {
|
||||
rcDelayMs -= (currentTimeMs - lastCalledMs);
|
||||
} else if (key) {
|
||||
rcDelayMs = cmsHandleKeyWithRepeat(pCurrentDisplay, key, repeatCount);
|
||||
if (key == CMS_KEY_NONE) {
|
||||
// No 'key' pressed, reset repeat control
|
||||
holdCount = 1;
|
||||
repeatCount = 1;
|
||||
repeatBase = 0;
|
||||
} else {
|
||||
// The 'key' is being pressed; keep counting
|
||||
++holdCount;
|
||||
}
|
||||
|
||||
// Key repeat effect is implemented in two phases.
|
||||
// First phldase is to decrease rcDelayMs reciprocal to hold time.
|
||||
// When rcDelayMs reached a certain limit (scheduling interval),
|
||||
// repeat rate will not raise anymore, so we call key handler
|
||||
// multiple times (repeatCount).
|
||||
//
|
||||
// XXX Caveat: Most constants are adjusted pragmatically.
|
||||
// XXX Rewrite this someday, so it uses actual hold time instead
|
||||
// of holdCount, which depends on the scheduling interval.
|
||||
if (rcDelayMs > 0) {
|
||||
rcDelayMs -= (currentTimeMs - lastCalledMs);
|
||||
} else if (key) {
|
||||
rcDelayMs = cmsHandleKeyWithRepeat(pCurrentDisplay, key, repeatCount);
|
||||
|
||||
if (((key == KEY_LEFT) || (key == KEY_RIGHT)) && (holdCount > 20)) {
|
||||
// Key repeat effect is implemented in two phases.
|
||||
// First phldase is to decrease rcDelayMs reciprocal to hold time.
|
||||
// When rcDelayMs reached a certain limit (scheduling interval),
|
||||
// repeat rate will not raise anymore, so we call key handler
|
||||
// multiple times (repeatCount).
|
||||
//
|
||||
// XXX Caveat: Most constants are adjusted pragmatically.
|
||||
// XXX Rewrite this someday, so it uses actual hold time instead
|
||||
// of holdCount, which depends on the scheduling interval.
|
||||
|
||||
// Decrease rcDelayMs reciprocally
|
||||
if (((key == CMS_KEY_LEFT) || (key == CMS_KEY_RIGHT)) && (holdCount > 20)) {
|
||||
|
||||
rcDelayMs /= (holdCount - 20);
|
||||
// Decrease rcDelayMs reciprocally
|
||||
|
||||
// When we reach the scheduling limit,
|
||||
rcDelayMs /= (holdCount - 20);
|
||||
|
||||
if (rcDelayMs <= 50) {
|
||||
// When we reach the scheduling limit,
|
||||
|
||||
// start calling handler multiple times.
|
||||
if (rcDelayMs <= 50) {
|
||||
|
||||
if (repeatBase == 0)
|
||||
repeatBase = holdCount;
|
||||
// start calling handler multiple times.
|
||||
|
||||
repeatCount = repeatCount + (holdCount - repeatBase) / 5;
|
||||
if (repeatBase == 0)
|
||||
repeatBase = holdCount;
|
||||
|
||||
if (repeatCount > 5) {
|
||||
repeatCount= 5;
|
||||
repeatCount = repeatCount + (holdCount - repeatBase) / 5;
|
||||
|
||||
if (repeatCount > 5) {
|
||||
repeatCount= 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue