1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 01:35:41 +03:00

OSD - Add support for async screen clearing to display API.

No screen clearing is actually done asynchronously yet.
This commit is contained in:
Dominic Clifton 2022-01-22 14:33:57 +01:00
parent f2559fbfd8
commit e2c0388a6a
17 changed files with 174 additions and 145 deletions

View file

@ -268,7 +268,7 @@ static void cmsPageSelect(displayPort_t *instance, int8_t newpage)
for (p = pageTop, i = 0; (p <= pageTop + pageMaxRow); p++, i++) {
runtimeEntryFlags[i] = p->flags;
}
displayClearScreen(instance);
displayClearScreen(instance, DISPLAY_CLEAR_WAIT);
}
static void cmsPageNext(displayPort_t *instance)
@ -998,7 +998,7 @@ const void *cmsMenuExit(displayPort_t *pDisplay, const void *ptr)
currentCtx.menu = NULL;
if ((exitType == CMS_EXIT_SAVEREBOOT) || (exitType == CMS_POPUP_SAVEREBOOT) || (exitType == CMS_POPUP_EXITREBOOT)) {
displayClearScreen(pDisplay);
displayClearScreen(pDisplay, DISPLAY_CLEAR_WAIT);
cmsDisplayWrite(pDisplay, 5, 3, DISPLAYPORT_ATTR_NONE, "REBOOTING...");
// Flush display
@ -1364,6 +1364,92 @@ uint16_t cmsHandleKeyWithRepeat(displayPort_t *pDisplay, cms_key_e key, int repe
return ret;
}
static uint16_t cmsScanKeys(timeMs_t currentTimeMs, timeMs_t lastCalledMs, int16_t rcDelayMs)
{
static int holdCount = 1;
static int repeatCount = 1;
static int repeatBase = 0;
//
// Scan 'key' first
//
cms_key_e key = CMS_KEY_NONE;
if (externKey != CMS_KEY_NONE) {
rcDelayMs = cmsHandleKey(pCurrentDisplay, externKey);
externKey = CMS_KEY_NONE;
} else {
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_LO(YAW)) {
key = CMS_KEY_ESC;
} else if (IS_HI(YAW)) {
key = CMS_KEY_SAVEMENU;
}
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;
}
if (rcDelayMs > 0) {
rcDelayMs -= (currentTimeMs - lastCalledMs);
} else if (key) {
rcDelayMs = cmsHandleKeyWithRepeat(pCurrentDisplay, key, repeatCount);
// 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 (((key == CMS_KEY_LEFT) || (key == CMS_KEY_RIGHT)) && (holdCount > 20)) {
// Decrease rcDelayMs reciprocally
rcDelayMs /= (holdCount - 20);
// When we reach the scheduling limit,
if (rcDelayMs <= 50) {
// start calling handler multiple times.
if (repeatBase == 0) {
repeatBase = holdCount;
}
repeatCount = repeatCount + (holdCount - repeatBase) / 5;
if (repeatCount > 5) {
repeatCount= 5;
}
}
}
}
}
return rcDelayMs;
}
static void cmsUpdate(uint32_t currentTimeUs)
{
if (IS_RC_MODE_ACTIVE(BOXPARALYZE)
@ -1378,9 +1464,6 @@ static void cmsUpdate(uint32_t currentTimeUs)
}
static int16_t rcDelayMs = BUTTON_TIME;
static int holdCount = 1;
static int repeatCount = 1;
static int repeatBase = 0;
static uint32_t lastCalledMs = 0;
static uint32_t lastCmsHeartBeatMs = 0;
@ -1394,82 +1477,9 @@ static void cmsUpdate(uint32_t currentTimeUs)
rcDelayMs = BUTTON_PAUSE; // Tends to overshoot if BUTTON_TIME
}
} else {
//
// Scan 'key' first
//
displayBeginTransaction(pCurrentDisplay, DISPLAY_TRANSACTION_OPT_RESET_DRAWING);
cms_key_e key = CMS_KEY_NONE;
if (externKey != CMS_KEY_NONE) {
rcDelayMs = cmsHandleKey(pCurrentDisplay, externKey);
externKey = CMS_KEY_NONE;
} else {
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_LO(YAW)) {
key = CMS_KEY_ESC;
} else if (IS_HI(YAW)) {
key = CMS_KEY_SAVEMENU;
}
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;
}
if (rcDelayMs > 0) {
rcDelayMs -= (currentTimeMs - lastCalledMs);
} else if (key) {
rcDelayMs = cmsHandleKeyWithRepeat(pCurrentDisplay, key, repeatCount);
// 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 (((key == CMS_KEY_LEFT) || (key == CMS_KEY_RIGHT)) && (holdCount > 20)) {
// Decrease rcDelayMs reciprocally
rcDelayMs /= (holdCount - 20);
// When we reach the scheduling limit,
if (rcDelayMs <= 50) {
// start calling handler multiple times.
if (repeatBase == 0) {
repeatBase = holdCount;
}
repeatCount = repeatCount + (holdCount - repeatBase) / 5;
if (repeatCount > 5) {
repeatCount= 5;
}
}
}
}
}
rcDelayMs = cmsScanKeys(currentTimeMs, lastCalledMs, rcDelayMs);
cmsDrawMenu(pCurrentDisplay, currentTimeUs);
@ -1479,6 +1489,8 @@ static void cmsUpdate(uint32_t currentTimeUs)
displayHeartbeat(pCurrentDisplay);
lastCmsHeartBeatMs = currentTimeMs;
}
displayCommitTransaction(pCurrentDisplay);
}
// Some key (command), notably flash erase, takes too long to use the