From e6dd0e6c5ce1b47efa02386f71848c87d8efb246 Mon Sep 17 00:00:00 2001 From: jflyper Date: Sat, 5 Nov 2016 14:24:18 +0900 Subject: [PATCH] DYNAMIC bit is added to entry flags This will stash the special type OME_Polled_INT16 for RC preview menu, and add capability to all value types to be polled dynamically. --- src/main/io/cms.c | 43 ++++++++++++++++++++++++++++++----------- src/main/io/cms_imu.c | 16 +++++++-------- src/main/io/cms_types.h | 7 +++++-- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/main/io/cms.c b/src/main/io/cms.c index 1bc51778eb..b2dc9a4a99 100644 --- a/src/main/io/cms.c +++ b/src/main/io/cms.c @@ -120,7 +120,8 @@ static cmsDeviceInitFuncPtr cmsDeviceSelectNext(void) return cmsDeviceInitFunc[cmsCurrentDevice]; } -#define CMS_UPDATE_INTERVAL 50 // msec +#define CMS_UPDATE_INTERVAL 50 // Interval of key scans (msec) +#define CMS_POLL_INTERVAL 100 // Interval of polling dynamic values (msec) static void cmsScreenInit(displayPort_t *pDisp, cmsDeviceInitFuncPtr cmsDeviceInitFunc) { @@ -261,7 +262,7 @@ static void cmsPadToSize(char *buf, int size) buf[size] = 0; } -static int cmsDrawMenuEntry(displayPort_t *pDisplay, OSD_Entry *p, uint8_t row, bool drawPolled) +static int cmsDrawMenuEntry(displayPort_t *pDisplay, OSD_Entry *p, uint8_t row) { char buff[10]; int cnt = 0; @@ -351,6 +352,7 @@ static int cmsDrawMenuEntry(displayPort_t *pDisplay, OSD_Entry *p, uint8_t row, CLR_PRINTVALUE(p); } break; +#if 0 case OME_Poll_INT16: if (p->data && drawPolled) { OSD_UINT16_t *ptr = p->data; @@ -360,6 +362,7 @@ static int cmsDrawMenuEntry(displayPort_t *pDisplay, OSD_Entry *p, uint8_t row, // PRINTVALUE not cleared on purpose } break; +#endif case OME_FLOAT: if (IS_PRINTVALUE(p) && p->data) { OSD_FLOAT_t *ptr = p->data; @@ -387,20 +390,26 @@ static int cmsDrawMenuEntry(displayPort_t *pDisplay, OSD_Entry *p, uint8_t row, static void cmsDrawMenu(displayPort_t *pDisplay) { + if (!pageTop) + return; + uint8_t i; OSD_Entry *p; uint8_t top = (pDisplay->rows - maxRow) / 2 - 1; // Polled (dynamic) value display denominator. - // XXX Need to denom based on absolute time - static uint8_t pollDenom = 0; - bool drawPolled = (++pollDenom % 8 == 0); + + bool drawPolled = false; + static uint32_t lastPolled = 0; + uint32_t now = millis(); // Argh... + + if (now > lastPolled + CMS_POLL_INTERVAL) { + drawPolled = true; + lastPolled = now; + } uint32_t room = displayTxBytesFree(pDisplay); - if (!pageTop) - return; - if (pDisplay->cleared) { for (p = pageTop, i= 0; p->type != OME_END; p++, i++) { SET_PRINTLABEL(p); @@ -415,6 +424,11 @@ static void cmsDrawMenu(displayPort_t *pDisplay) } pDisplay->cleared = false; + } else if (drawPolled) { + for (p = pageTop ; p <= pageTop + maxRow ; p++) { + if (IS_DYNAMIC(p)) + SET_PRINTVALUE(p); + } } // Cursor manipulation @@ -454,7 +468,7 @@ static void cmsDrawMenu(displayPort_t *pDisplay) for (i = 0, p = pageTop; i < MAX_MENU_ITEMS(pDisplay) && p->type != OME_END; i++, p++) { if (IS_PRINTVALUE(p)) { - room -= cmsDrawMenuEntry(pDisplay, p, top + i, drawPolled); + room -= cmsDrawMenuEntry(pDisplay, p, top + i); if (room < 30) return; } @@ -505,6 +519,8 @@ long cmsMenuChange(displayPort_t *pDisplay, void *ptr) static long cmsMenuBack(displayPort_t *pDisplay) { + // Let onExit function decide whether to allow exit or not. + if (currentMenu->onExit && currentMenu->onExit(pageTop + cursorRow) < 0) return -1; @@ -513,13 +529,19 @@ static long cmsMenuBack(displayPort_t *pDisplay) menuStackIdx--; currentMenu = menuStack[menuStackIdx]; cursorRow = menuStackHistory[menuStackIdx]; + + // cursorRow is absolute offset of a focused entry when stacked. + // Convert it back to page and relative offset. + pageTop = currentMenu->entries; // Temporary for cmsUpdateMaxRow() cmsUpdateMaxRow(pDisplay); + if (cursorRow > maxRow) { + // Cursor was in the second page. pageTopAlt = currentMenu->entries; pageTop = pageTopAlt + maxRow + 1; cursorRow -= (maxRow + 1); - cmsUpdateMaxRow(pDisplay); + cmsUpdateMaxRow(pDisplay); // Update maxRow for the second page } } @@ -758,7 +780,6 @@ static uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key) break; case OME_String: break; - case OME_Poll_INT16: case OME_Label: case OME_END: break; diff --git a/src/main/io/cms_imu.c b/src/main/io/cms_imu.c index 385c462398..c4a71aa3f5 100644 --- a/src/main/io/cms_imu.c +++ b/src/main/io/cms_imu.c @@ -194,14 +194,14 @@ static OSD_INT16_t entryRcAux4 = {&rcData[AUX4], 1, 2500, 0}; OSD_Entry cmsx_menuRcEntries[] = { {"--- RC PREV ---", OME_Label, NULL, NULL, 0}, - {"ROLL", OME_Poll_INT16, NULL, &entryRcRoll, 0}, - {"PITCH", OME_Poll_INT16, NULL, &entryRcPitch, 0}, - {"THR", OME_Poll_INT16, NULL, &entryRcThr, 0}, - {"YAW", OME_Poll_INT16, NULL, &entryRcYaw, 0}, - {"AUX1", OME_Poll_INT16, NULL, &entryRcAux1, 0}, - {"AUX2", OME_Poll_INT16, NULL, &entryRcAux2, 0}, - {"AUX3", OME_Poll_INT16, NULL, &entryRcAux3, 0}, - {"AUX4", OME_Poll_INT16, NULL, &entryRcAux4, 0}, + {"ROLL", OME_INT16, NULL, &entryRcRoll, DYNAMIC}, + {"PITCH", OME_INT16, NULL, &entryRcPitch, DYNAMIC}, + {"THR", OME_INT16, NULL, &entryRcThr, DYNAMIC}, + {"YAW", OME_INT16, NULL, &entryRcYaw, DYNAMIC}, + {"AUX1", OME_INT16, NULL, &entryRcAux1, DYNAMIC}, + {"AUX2", OME_INT16, NULL, &entryRcAux2, DYNAMIC}, + {"AUX3", OME_INT16, NULL, &entryRcAux3, DYNAMIC}, + {"AUX4", OME_INT16, NULL, &entryRcAux4, DYNAMIC}, {"BACK", OME_Back, NULL, NULL, 0}, {NULL, OME_END, NULL, NULL, 0} }; diff --git a/src/main/io/cms_types.h b/src/main/io/cms_types.h index 3243e05bd5..a09f62895d 100644 --- a/src/main/io/cms_types.h +++ b/src/main/io/cms_types.h @@ -20,7 +20,6 @@ typedef enum OME_UINT8, OME_UINT16, OME_INT16, - OME_Poll_INT16, OME_String, OME_FLOAT, //only up to 255 value and cant be 2.55 or 25.5, just for PID's //wlasciwosci elementow @@ -46,6 +45,7 @@ typedef struct // Bits in flags #define PRINT_VALUE 0x01 // Value has been changed, need to redraw #define PRINT_LABEL 0x02 // Text label should be printed +#define DYNAMIC 0x04 // Value should be updated dynamically #define IS_PRINTVALUE(p) ((p)->flags & PRINT_VALUE) #define SET_PRINTVALUE(p) { (p)->flags |= PRINT_VALUE; } @@ -55,13 +55,16 @@ typedef struct #define SET_PRINTLABEL(p) { (p)->flags |= PRINT_LABEL; } #define CLR_PRINTLABEL(p) { (p)->flags &= ~PRINT_LABEL; } +#define IS_DYNAMIC(p) ((p)->flags & DYNAMIC) + + typedef long (*CMSMenuFuncPtr)(void); /* onExit function is called with self: (1) Pointer to an OSD_Entry when cmsMenuBack() was called. Point to an OSD_Entry with type == OME_Back if BACK was selected. -(2) 0 if called from menu exit (forced exit). +(2) NULL if called from menu exit (forced exit at top level). */ typedef long (*CMSMenuOnExitPtr)(OSD_Entry *self);