1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 14:25:20 +03:00

CMS currentTime tidy

This commit is contained in:
Martin Budden 2016-11-07 15:37:14 +00:00
parent 7861603c96
commit 1bbc0420ad

View file

@ -99,8 +99,8 @@ static displayPort_t *cmsDisplayPortSelectNext(void)
return cmsDisplayPorts[cmsCurrentDevice]; return cmsDisplayPorts[cmsCurrentDevice];
} }
#define CMS_UPDATE_INTERVAL 50 // Interval of key scans (msec) #define CMS_UPDATE_INTERVAL_US 50000 // Interval of key scans (microsec)
#define CMS_POLL_INTERVAL 100 // Interval of polling dynamic values (msec) #define CMS_POLL_INTERVAL_US 100000 // Interval of polling dynamic values (microsec)
// XXX LEFT_MENU_COLUMN and RIGHT_MENU_COLUMN must be adjusted // XXX LEFT_MENU_COLUMN and RIGHT_MENU_COLUMN must be adjusted
// dynamically depending on size of the active output device, // dynamically depending on size of the active output device,
@ -357,7 +357,7 @@ static int cmsDrawMenuEntry(displayPort_t *pDisplay, OSD_Entry *p, uint8_t row)
return cnt; return cnt;
} }
static void cmsDrawMenu(displayPort_t *pDisplay) static void cmsDrawMenu(displayPort_t *pDisplay, uint32_t currentTimeUs)
{ {
if (!pageTop) if (!pageTop)
return; return;
@ -369,12 +369,11 @@ static void cmsDrawMenu(displayPort_t *pDisplay)
// Polled (dynamic) value display denominator. // Polled (dynamic) value display denominator.
bool drawPolled = false; bool drawPolled = false;
static uint32_t lastPolled = 0; static uint32_t lastPolledUs = 0;
uint32_t now = millis(); // Argh...
if (now > lastPolled + CMS_POLL_INTERVAL) { if (currentTimeUs > lastPolledUs + CMS_POLL_INTERVAL_US) {
drawPolled = true; drawPolled = true;
lastPolled = now; lastPolledUs = currentTimeUs;
} }
uint32_t room = displayTxBytesFree(pDisplay); uint32_t room = displayTxBytesFree(pDisplay);
@ -771,68 +770,69 @@ static uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
return res; return res;
} }
static void cmsUpdate(displayPort_t *pDisplay, uint32_t currentTime) static void cmsUpdate(uint32_t currentTimeUs)
{ {
static int16_t rcDelay = BUTTON_TIME; static int16_t rcDelayMs = BUTTON_TIME;
static uint32_t lastCalled = 0; static uint32_t lastCalledMs = 0;
static uint32_t lastCmsHeartBeat = 0; static uint32_t lastCmsHeartBeatMs = 0;
uint8_t key = 0; const uint32_t currentTimeMs = currentTimeUs / 1000;
if (!cmsInMenu) { if (!cmsInMenu) {
// Detect menu invocation // Detect menu invocation
if (IS_MID(THROTTLE) && IS_LO(YAW) && IS_HI(PITCH) && !ARMING_FLAG(ARMED)) { if (IS_MID(THROTTLE) && IS_LO(YAW) && IS_HI(PITCH) && !ARMING_FLAG(ARMED)) {
cmsMenuOpen(); cmsMenuOpen();
rcDelay = BUTTON_PAUSE; // Tends to overshoot if BUTTON_TIME rcDelayMs = BUTTON_PAUSE; // Tends to overshoot if BUTTON_TIME
} }
} else { } else {
if (rcDelay > 0) { uint8_t key = 0;
rcDelay -= (currentTime - lastCalled); if (rcDelayMs > 0) {
rcDelayMs -= (currentTimeMs - lastCalledMs);
} }
else if (IS_MID(THROTTLE) && IS_LO(YAW) && IS_HI(PITCH) && !ARMING_FLAG(ARMED)) { else if (IS_MID(THROTTLE) && IS_LO(YAW) && IS_HI(PITCH) && !ARMING_FLAG(ARMED)) {
// Double enter = display switching // Double enter = display switching
cmsMenuOpen(); cmsMenuOpen();
rcDelay = BUTTON_PAUSE; rcDelayMs = BUTTON_PAUSE;
} }
else if (IS_HI(PITCH)) { else if (IS_HI(PITCH)) {
key = KEY_UP; key = KEY_UP;
rcDelay = BUTTON_TIME; rcDelayMs = BUTTON_TIME;
} }
else if (IS_LO(PITCH)) { else if (IS_LO(PITCH)) {
key = KEY_DOWN; key = KEY_DOWN;
rcDelay = BUTTON_TIME; rcDelayMs = BUTTON_TIME;
} }
else if (IS_LO(ROLL)) { else if (IS_LO(ROLL)) {
key = KEY_LEFT; key = KEY_LEFT;
rcDelay = BUTTON_TIME; rcDelayMs = BUTTON_TIME;
} }
else if (IS_HI(ROLL)) { else if (IS_HI(ROLL)) {
key = KEY_RIGHT; key = KEY_RIGHT;
rcDelay = BUTTON_TIME; rcDelayMs = BUTTON_TIME;
} }
else if (IS_HI(YAW) || IS_LO(YAW)) else if (IS_HI(YAW) || IS_LO(YAW))
{ {
key = KEY_ESC; key = KEY_ESC;
rcDelay = BUTTON_TIME; rcDelayMs = BUTTON_TIME;
} }
//lastCalled = currentTime; //lastCalled = currentTime;
if (key) { if (key) {
rcDelay = cmsHandleKey(pCurrentDisplay, key); rcDelayMs = cmsHandleKey(pCurrentDisplay, key);
return; return;
} }
cmsDrawMenu(pDisplay); cmsDrawMenu(pCurrentDisplay, currentTimeUs);
if (currentTime > lastCmsHeartBeat + 500) { if (currentTimeMs > lastCmsHeartBeatMs + 500) {
// Heart beat for external CMS display device @ 500msec // Heart beat for external CMS display device @ 500msec
// (Timeout @ 1000msec) // (Timeout @ 1000msec)
displayHeartbeat(pCurrentDisplay); displayHeartbeat(pCurrentDisplay);
lastCmsHeartBeat = currentTime; lastCmsHeartBeatMs = currentTimeMs;
} }
} }
lastCalled = currentTime; lastCalledMs = currentTimeMs;
} }
void cmsHandler(uint32_t currentTime) void cmsHandler(uint32_t currentTime)
@ -841,11 +841,10 @@ void cmsHandler(uint32_t currentTime)
return; return;
static uint32_t lastCalled = 0; static uint32_t lastCalled = 0;
const uint32_t now = currentTime / 1000;
if (now - lastCalled >= CMS_UPDATE_INTERVAL) { if (currentTime >= lastCalled + CMS_UPDATE_INTERVAL_US) {
cmsUpdate(pCurrentDisplay, now); lastCalled = currentTime;
lastCalled = now; cmsUpdate(currentTime);
} }
} }