From 9e88b1fb41096587c1a01e2a5b2ba1580b07edd1 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Fri, 31 Mar 2023 22:58:55 +0200 Subject: [PATCH] Add osd menu option to preview font file --- src/main/cms/cms.c | 29 ++++++++++-- src/main/cms/cms_menu_osd.c | 105 ++++++++++++++++++++++++++++++++++++++++++++ src/main/cms/cms_types.h | 2 + src/main/target/common.h | 2 + 4 files changed, 135 insertions(+), 3 deletions(-) diff --git a/src/main/cms/cms.c b/src/main/cms/cms.c index 07ab3219a..4f27aec0d 100644 --- a/src/main/cms/cms.c +++ b/src/main/cms/cms.c @@ -276,7 +276,7 @@ static void cmsPagePrev(displayPort_t *instance) static bool cmsElementIsLabel(OSD_MenuElement element) { - return element == OME_Label || element == OME_LabelFunc; + return element == OME_Label || element == OME_LabelFunc || element == OME_Label_PAGE2_DATA; } static void cmsFormatFloat(int32_t value, char *floatString) @@ -577,7 +577,7 @@ static int cmsDrawMenuEntry(displayPort_t *pDisplay, const OSD_Entry *p, uint8_t CLR_PRINTVALUE(p, screenRow); } break; - + case OME_Label_PAGE2_DATA: case OME_OSD_Exit: case OME_END: case OME_Back: @@ -656,7 +656,30 @@ static void cmsDrawMenu(displayPort_t *pDisplay, uint32_t currentTimeUs) if (IS_PRINTLABEL(p, i)) { uint8_t coloff = leftMenuColumn; coloff += cmsElementIsLabel(p->type) ? 0 : 1; - room -= displayWrite(pDisplay, coloff, top + i * linesPerMenuItem, p->text); + + if (p->type == OME_Label_PAGE2_DATA) { +#ifdef USE_CMS_FONT_PREVIEW + // A label with immediately following text in page2 + int printed = 0; + if (p->text) { + size_t textLen = strlen(p->text); + for(size_t k = 0; k < textLen; k++) { + displayWriteChar(pDisplay, + coloff + printed, top + i * linesPerMenuItem, p->text[k]); + printed++; + } + } + if (p->data) { + const char *p2text = (const char *)p->data; + for (size_t k = 0; k < strlen(p2text); ++k) { + displayWriteChar(pDisplay, + coloff + printed + k, top + i * linesPerMenuItem, (p2text[k] | (1 << 8))); + } + } +#endif + } else { + room -= displayWrite(pDisplay, coloff, top + i * linesPerMenuItem, p->text); + } CLR_PRINTLABEL(p, i); if (room < 30) { return; diff --git a/src/main/cms/cms_menu_osd.c b/src/main/cms/cms_menu_osd.c index d482635db..cb7363525 100644 --- a/src/main/cms/cms_menu_osd.c +++ b/src/main/cms/cms_menu_osd.c @@ -461,6 +461,108 @@ static const OSD_Entry menuOsdHudEntries[] = { OSD_END_ENTRY, }; +#ifdef USE_CMS_FONT_PREVIEW + +static const OSD_Entry menuOsdFontPage1Entries[] = { + OSD_LABEL_ENTRY("FONT: 0123456789ABCDEF"), + OSD_LABEL_ENTRY(" 00: \x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"), + OSD_LABEL_ENTRY(" 10: \x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"), + OSD_LABEL_ENTRY(" 20: \x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F"), + OSD_LABEL_ENTRY(" 30: \x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F"), + OSD_LABEL_ENTRY(" 40: \x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F"), + OSD_LABEL_ENTRY(" 50: \x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F"), + OSD_LABEL_ENTRY(" 60: \x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F"), + OSD_LABEL_ENTRY(" 70: \x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F"), + OSD_LABEL_ENTRY(" 80: \x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F"), + OSD_LABEL_ENTRY(" 90: \x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F"), + OSD_LABEL_ENTRY(" A0: \xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF"), + OSD_LABEL_ENTRY(" B0: \xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF"), + OSD_LABEL_ENTRY(" C0: \xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF"), + OSD_LABEL_ENTRY(" "), + OSD_LABEL_ENTRY(" "), + OSD_LABEL_ENTRY(" "), + OSD_LABEL_ENTRY("FONT: 0123456789ABCDEF"), + OSD_LABEL_ENTRY(" D0: \xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF"), + OSD_LABEL_ENTRY(" E0: \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEE"), + OSD_LABEL_ENTRY(" F0: \xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"), + + OSD_BACK_ENTRY, + OSD_END_ENTRY, +}; + +static const OSD_Entry menuOsdFontPage2Entries[] = { + OSD_LABEL_ENTRY( "FONT: 0123456789ABCDEF"), + OSD_LABEL_PAGE2_ENTRY(" 00: ", "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\0"), + OSD_LABEL_PAGE2_ENTRY(" 10: ", "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\0"), + OSD_LABEL_PAGE2_ENTRY(" 20: ", "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\0"), + OSD_LABEL_PAGE2_ENTRY(" 30: ", "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\0"), + OSD_LABEL_PAGE2_ENTRY(" 40: ", "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\0"), + OSD_LABEL_PAGE2_ENTRY(" 50: ", "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\0"), + OSD_LABEL_PAGE2_ENTRY(" 60: ", "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\0"), + OSD_LABEL_PAGE2_ENTRY(" 70: ", "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\0"), + OSD_LABEL_PAGE2_ENTRY(" 80: ", "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\0"), + OSD_LABEL_PAGE2_ENTRY(" 90: ", "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\0"), + OSD_LABEL_PAGE2_ENTRY(" A0: ", "\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\0"), + OSD_LABEL_PAGE2_ENTRY(" B0: ", "\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\0"), + OSD_LABEL_PAGE2_ENTRY(" C0: ", "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\0"), + OSD_LABEL_ENTRY(" "), + OSD_LABEL_ENTRY(" "), + OSD_LABEL_ENTRY(" "), + OSD_LABEL_ENTRY( "FONT: 0123456789ABCDEF"), + OSD_LABEL_PAGE2_ENTRY(" D0: ", "\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\0"), + OSD_LABEL_PAGE2_ENTRY(" E0: ", "\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEE\0"), + OSD_LABEL_PAGE2_ENTRY(" F0: ", "\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF\0"), + OSD_LABEL_ENTRY(" "), + + OSD_BACK_ENTRY, + OSD_END_ENTRY, +}; + + +static const CMS_Menu cmsx_menuOsdFontPage1 = { +#ifdef CMS_MENU_DEBUG + .GUARD_text = "MENUOSDFONTP1", + .GUARD_type = OME_MENU, +#endif + .onEnter = NULL, + .onExit = NULL, + .onGlobalExit = NULL, + .entries = menuOsdFontPage1Entries, +}; + +static const CMS_Menu cmsx_menuOsdFontPage2 = { +#ifdef CMS_MENU_DEBUG + .GUARD_text = "MENUOSDFONTP2", + .GUARD_type = OME_MENU, +#endif + .onEnter = NULL, + .onExit = NULL, + .onGlobalExit = NULL, + .entries = menuOsdFontPage2Entries, +}; + +static const OSD_Entry menuOsdFontEntries[] = { + OSD_LABEL_ENTRY("--- FONT ---"), + OSD_SUBMENU_ENTRY("PAGE 1", &cmsx_menuOsdFontPage1), + OSD_SUBMENU_ENTRY("PAGE 2", &cmsx_menuOsdFontPage2), + + OSD_BACK_ENTRY, + OSD_END_ENTRY, +}; + +static const CMS_Menu cmsx_menuFont = { +#ifdef CMS_MENU_DEBUG + .GUARD_text = "MENUFONT", + .GUARD_type = OME_MENU, +#endif + .onEnter = NULL, + .onExit = NULL, + .onGlobalExit = NULL, + .entries = menuOsdFontEntries, +}; + +#endif // USE_CMS_FONT_PREVIEW + static const CMS_Menu cmsx_menuOsdHud = { #ifdef CMS_MENU_DEBUG .GUARD_text = "MENUOSDH", @@ -479,6 +581,9 @@ static const OSD_Entry menuOsdEntries[] = { OSD_SUBMENU_ENTRY("SETTINGS", &cmsx_menuOsdSettings), OSD_SUBMENU_ENTRY("ALARMS", &cmsx_menuAlarms), OSD_SUBMENU_ENTRY("HUD", &cmsx_menuOsdHud), +#ifdef USE_CMS_FONT_PREVIEW + OSD_SUBMENU_ENTRY("FONT", &cmsx_menuFont), +#endif OSD_BACK_AND_END_ENTRY, }; diff --git a/src/main/cms/cms_types.h b/src/main/cms/cms_types.h index d56ff80e5..6ae5a6101 100644 --- a/src/main/cms/cms_types.h +++ b/src/main/cms/cms_types.h @@ -47,6 +47,7 @@ typedef enum OME_TAB, OME_END, OME_BACK_AND_END, + OME_Label_PAGE2_DATA, // Debug aid OME_MENU, @@ -83,6 +84,7 @@ typedef struct #define OSD_LABEL_DATA_ENTRY(label, data) ((OSD_Entry){ label, {.func = NULL}, data, OME_Label, 0 }) #define OSD_LABEL_DATA_DYN_ENTRY(label, data) ((OSD_Entry){ label, {.func = NULL}, data, OME_Label, DYNAMIC }) #define OSD_LABEL_FUNC_DYN_ENTRY(label, fn) ((OSD_Entry){ label, {.func = NULL}, fn, OME_LabelFunc, DYNAMIC }) +#define OSD_LABEL_PAGE2_ENTRY(label, p2text) ((OSD_Entry){ label, {.func = NULL}, p2text, OME_Label_PAGE2_DATA, 0 }) #define OSD_BACK_ENTRY ((OSD_Entry){ "BACK", {.func = NULL}, NULL, OME_Back, 0 }) #define OSD_BACK_AND_END_ENTRY ((OSD_Entry){ "BACK", {.func = NULL}, NULL, OME_BACK_AND_END, 0 }) #define OSD_SUBMENU_ENTRY(label, menu) ((OSD_Entry){ label, {.func = NULL}, menu, OME_Submenu, 0 }) diff --git a/src/main/target/common.h b/src/main/target/common.h index 0e08fd100..e5968f2e8 100644 --- a/src/main/target/common.h +++ b/src/main/target/common.h @@ -178,6 +178,8 @@ #define USE_SIMULATOR #define USE_PITOT_VIRTUAL +#define USE_CMS_FONT_PREVIEW + //Designed to free space of F722 and F411 MCUs #if (MCU_FLASH_SIZE > 512) #define USE_VTX_FFPV -- 2.11.4.GIT