chore(radio): unify the bootloader UI code (#6189)
Co-authored-by: Richard Li <richard.li@ces.hk>
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "board.h"
|
||||
#include "lcd.h"
|
||||
|
||||
#include "translations.h"
|
||||
|
||||
#include "fw_version.h"
|
||||
#include "translations/bl_translations.h"
|
||||
#include "bootloader/boot.h"
|
||||
#include "bootloader/firmware_files.h"
|
||||
|
||||
void bootloaderInitScreen()
|
||||
{
|
||||
lcdInit();
|
||||
lcdSetContrast(true);
|
||||
|
||||
backlightInit();
|
||||
#if defined(LCD_BRIGHTNESS_DEFAULT)
|
||||
backlightEnable(LCD_BRIGHTNESS_DEFAULT);
|
||||
#else
|
||||
backlightFullOn();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void bootloaderDrawMsg(const char *str, uint8_t line, bool inverted)
|
||||
{
|
||||
lcdDrawSizedText(LCD_W / 2, (line + 2) * FH, str, DISPLAY_CHAR_WIDTH, (inverted ? INVERS : 0) | CENTERED);
|
||||
}
|
||||
|
||||
void bootloaderDrawFilename(const char *str, uint8_t line, bool selected)
|
||||
{
|
||||
lcdDrawSizedText(INDENT_WIDTH, (line + 2) * FH, str, DISPLAY_CHAR_WIDTH, selected ? INVERS : 0);
|
||||
}
|
||||
|
||||
bool checkFirmwareFlavor(const char * flavour)
|
||||
{
|
||||
if (strncmp(flavour,FLAVOUR, sizeof(FLAVOUR) - 1) != 0)
|
||||
return false;
|
||||
|
||||
char * tmp = (char *) flavour;
|
||||
while (*tmp != 0) tmp++;
|
||||
if ((tmp - flavour) != (sizeof(FLAVOUR) - 1))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void bootloaderDrawScreen(BootloaderState st, int opt, const char *str)
|
||||
{
|
||||
lcdClear();
|
||||
lcdDrawText(LCD_W / 2, 0, BOOTLOADER_TITLE, CENTERED);
|
||||
lcdInvertLine(0);
|
||||
|
||||
if (st == ST_START) {
|
||||
lcdDrawText(3*FW, 2*FH, TR_BL_WRITE_FW, opt == 0 ? INVERS : 0);
|
||||
lcdDrawText(3*FW, 3*FH, TR_BL_EXIT, opt == 1 ? INVERS : 0);
|
||||
|
||||
lcdDrawText(LCD_W / 2, 5 * FH + FH / 2, TR_BL_OR_PLUGIN_USB_CABLE, CENTERED);
|
||||
|
||||
const char * vers = getFirmwareVersion();
|
||||
#if LCD_W < 212
|
||||
// Remove "edgetx-" from string
|
||||
if (strncmp(vers, "edgetx-", 7) == 0)
|
||||
vers += 7;
|
||||
#endif
|
||||
lcdDrawCenteredText(7 * FH, vers);
|
||||
lcdInvertLine(7);
|
||||
}
|
||||
else if (st == ST_USB) {
|
||||
lcdDrawCenteredText(4 * FH, TR_BL_USB_CONNECTED);
|
||||
}
|
||||
else if (st == ST_DIR_CHECK) {
|
||||
if (opt == FR_NO_PATH) {
|
||||
bootloaderDrawMsg(TR_BL_DIR_MISSING, 1, false);
|
||||
bootloaderDrawMsg(getFirmwarePath(), 2, false);
|
||||
}
|
||||
else {
|
||||
bootloaderDrawMsg(TR_BL_DIR_EMPTY, 1, false);
|
||||
}
|
||||
}
|
||||
else if (st == ST_FLASH_CHECK) {
|
||||
if (opt == FC_ERROR) {
|
||||
bootloaderDrawMsg(TR_BL_INVALID_FIRMWARE, 2, false);
|
||||
}
|
||||
else if (opt == FC_OK) {
|
||||
bool flavorCheck = false;
|
||||
VersionTag tag;
|
||||
getFileFirmwareVersion(&tag);
|
||||
#if LCD_W < 212
|
||||
// Remove "edgetx-" from string
|
||||
flavorCheck = checkFirmwareFlavor(tag.flavour);
|
||||
#else
|
||||
flavorCheck = checkFirmwareFlavor(tag.flavour);
|
||||
#endif
|
||||
bootloaderDrawMsg(tag.version, 0, false);
|
||||
if (flavorCheck)
|
||||
bootloaderDrawMsg(TR_BL_HOLD_ENTER_TO_START, 2, false);
|
||||
else
|
||||
bootloaderDrawMsg(TR_BL_INVALID_FIRMWARE, 2, false);
|
||||
}
|
||||
}
|
||||
else if (st == ST_FLASHING) {
|
||||
lcdDrawCenteredText(4 * FH, TR_BL_WRITING_FW);
|
||||
|
||||
lcdDrawRect(3, 6 * FH + 4, (LCD_W - 8), 7);
|
||||
lcdDrawSolidHorizontalLine(5, 6 * FH + 6, (LCD_W - 12) * opt / 100, FORCE);
|
||||
lcdDrawSolidHorizontalLine(5, 6 * FH + 7, (LCD_W - 12) * opt / 100, FORCE);
|
||||
lcdDrawSolidHorizontalLine(5, 6 * FH + 8, (LCD_W - 12) * opt / 100, FORCE);
|
||||
}
|
||||
else if (st == ST_FLASH_DONE) {
|
||||
lcdDrawCenteredText(4 * FH, TR_BL_WRITING_COMPL);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t bootloaderGetMenuItemCount(int baseCount)
|
||||
{
|
||||
return baseCount;
|
||||
}
|
||||
|
||||
bool bootloaderRadioMenu(uint32_t menuItem, event_t event)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void blExit(void)
|
||||
{
|
||||
#if defined(RADIO_COMMANDO8)
|
||||
lcdClear();
|
||||
lcdDrawText(2, 22, TR_BL_POWER_KEY);
|
||||
lcdDrawText(2, 33, TR_BL_FLASH_EXIT);
|
||||
lcdRefresh();
|
||||
lcdRefreshWait();
|
||||
while(1);
|
||||
#else
|
||||
lcdClear();
|
||||
lcdRefresh();
|
||||
lcdRefreshWait();
|
||||
#endif
|
||||
}
|
||||
@@ -56,9 +56,9 @@ const unsigned char font_5x7[] = {
|
||||
#include "font_da_05x07.lbm"
|
||||
#elif defined(TRANSLATIONS_CZ)
|
||||
#include "font_cz_05x07.lbm"
|
||||
#elif defined(TRANSLATIONS_ES)
|
||||
#elif defined(TRANSLATIONS_ES) && !defined(BOOT)
|
||||
#include "font_es_05x07.lbm"
|
||||
#elif defined(TRANSLATIONS_FI)
|
||||
#elif defined(TRANSLATIONS_FI) && !defined(BOOT)
|
||||
#include "font_fi_05x07.lbm"
|
||||
#elif defined(TRANSLATIONS_FR)
|
||||
#include "font_fr_05x07.lbm"
|
||||
@@ -68,11 +68,11 @@ const unsigned char font_5x7[] = {
|
||||
#include "font_pl_05x07.lbm"
|
||||
#elif defined(TRANSLATIONS_PT)
|
||||
#include "font_pt_05x07.lbm"
|
||||
#elif defined(TRANSLATIONS_RU)
|
||||
#elif defined(TRANSLATIONS_RU) && !defined(BOOT)
|
||||
#include "font_ru_05x07.lbm"
|
||||
#elif defined(TRANSLATIONS_SE)
|
||||
#include "font_se_05x07.lbm"
|
||||
#elif defined(TRANSLATIONS_UA)
|
||||
#elif defined(TRANSLATIONS_UA) && !defined(BOOT)
|
||||
#include "font_ua_05x07.lbm"
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -30,7 +30,6 @@ static uint16_t _utf8_lut[] = {
|
||||
L'é', L'è', L'à', L'î', L'ç',
|
||||
};
|
||||
|
||||
#if !defined(COLORLCD)
|
||||
#define UTF8_SUBS_LUT
|
||||
static uint16_t _utf8_substitution_lut[] = {
|
||||
L'Â', L'A',
|
||||
@@ -48,7 +47,6 @@ static uint16_t _utf8_substitution_lut[] = {
|
||||
L'Ù', L'U',
|
||||
*/
|
||||
};
|
||||
#endif
|
||||
#elif defined(TRANSLATIONS_DA)
|
||||
static uint16_t _utf8_lut[] = {
|
||||
L'å', L'æ', L'ø', L'Å', L'Æ', L'Ø',
|
||||
@@ -64,7 +62,6 @@ static uint16_t _utf8_lut[] = {
|
||||
L'Ý', L'ž', L'É', L'ň',
|
||||
};
|
||||
|
||||
#if !defined(COLORLCD)
|
||||
#define UTF8_SUBS_LUT
|
||||
static uint16_t _utf8_substitution_lut[] = {
|
||||
L'Ě', L'ě',
|
||||
@@ -76,8 +73,7 @@ static uint16_t _utf8_substitution_lut[] = {
|
||||
L'Ó', L'ó',
|
||||
L'Ň', L'ň',
|
||||
};
|
||||
#endif
|
||||
#elif defined(TRANSLATIONS_ES)
|
||||
#elif defined(TRANSLATIONS_ES) && !defined(BOOT)
|
||||
static uint16_t _utf8_lut[] = {
|
||||
L'Ñ', L'ñ', L'Á', L'á', L'É', L'é', L'Í',
|
||||
L'í', L'Ó', L'ó', L'ú',
|
||||
@@ -89,7 +85,7 @@ static uint16_t _utf8_lut[] = {
|
||||
L'Í', L'í', L'Ó', L'ó', L'Ô', L'ô', L'Õ',
|
||||
L'õ', L'Ú', L'ú',
|
||||
};
|
||||
#elif defined(TRANSLATIONS_FI)
|
||||
#elif defined(TRANSLATIONS_FI) && !defined(BOOT)
|
||||
static uint16_t _utf8_lut[] = {
|
||||
L'å', L'ä', L'ö', L'Å', L'Ä', L'Ö',
|
||||
};
|
||||
@@ -103,7 +99,7 @@ static uint16_t _utf8_lut[] = {
|
||||
L'ż', L'ź', L'Ą', L'Ć', L'Ę', L'Ł', L'Ń',
|
||||
L'Ó', L'Ś', L'Ż', L'Ź',
|
||||
};
|
||||
#elif defined(TRANSLATIONS_RU)
|
||||
#elif defined(TRANSLATIONS_RU) && !defined(BOOT)
|
||||
static uint16_t _utf8_lut[] = {
|
||||
L'А', L'Б', L'В', L'Г', L'Д', L'Е', L'Ж',
|
||||
L'З', L'И', L'Й', L'К', L'Л', L'М', L'Н',
|
||||
@@ -116,8 +112,7 @@ static uint16_t _utf8_lut[] = {
|
||||
L'ш', L'щ', L'ъ', L'ы', L'ь', L'э', L'ю',
|
||||
L'я',
|
||||
};
|
||||
#elif defined(TRANSLATIONS_UA)
|
||||
#if !defined(COLORLCD)
|
||||
#elif defined(TRANSLATIONS_UA) && !defined(BOOT)
|
||||
#define UTF8_SUBS_LUT
|
||||
// Warning, albeit the following table looks useless
|
||||
// It does translate Cyrillic to Latin
|
||||
@@ -144,7 +139,6 @@ static uint16_t _utf8_substitution_lut[] = {
|
||||
L'х', L'x',
|
||||
L'у', L'y'
|
||||
};
|
||||
#endif
|
||||
|
||||
static uint16_t _utf8_lut[] = {
|
||||
L'Б', L'Г', L'Ґ', L'Д', L'Є', L'Ж', L'З',
|
||||
|
||||
Reference in New Issue
Block a user