Skip to content

Commit

Permalink
Icons update from USB fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kisslorand committed Jan 13, 2024
1 parent 6d49c6e commit 6e80e71
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 149 deletions.
218 changes: 99 additions & 119 deletions TFT/src/User/API/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ const char * const iconBmpName[] = {
// add new icons in icon_list.inc only
};

// This List is Auto-Generated. Please add new icons in small_icon_list.inc only
const char * const smallIconBmpName[] = {
#define X_SMALLICON(NAME) #NAME ,
#include "small_icon_list.inc"
#undef X_SMALLICON
// add new icons in small_icon_list.inc only
};

BMPUPDATE_STAT bmpDecode(char * bmp, uint32_t addr)
{
FIL bmpFile;
Expand Down Expand Up @@ -133,6 +125,37 @@ BMPUPDATE_STAT bmpDecode(char * bmp, uint32_t addr)
return BMP_SUCCESS;
}

void dispIconFail(uint8_t * lbl, BMPUPDATE_STAT bmpState)
{
char * stat_txt;
char error_txt[30];

GUI_SetColor(infoSettings.reminder_color);
GUI_ClearPrect(&labelFailedRect);
GUI_DispString(labelFailedRect.x0, labelFailedRect.y0, lbl);

switch (bmpState)
{
case BMP_INVALIDFILE:
stat_txt = "BMP file not valid ";
break;

case BMP_NOT24BIT:
stat_txt = "Format is not 24Bit";
break;

case BMP_NOTFOUND:
default:
stat_txt = "BMP file not found ";
break;
}

sprintf(error_txt, "Error: %s", stat_txt);
GUI_DispString(labelFailedRect.x0, labelFailedRect.y0 + BYTE_HEIGHT + 2, (uint8_t *)error_txt);
GUI_RestoreColorDefault();
Delay_ms(1000); // give some time to the user to read failed icon name.
}

static inline bool updateIcon(char * rootDir)
{
uint16_t found = 0;
Expand Down Expand Up @@ -165,24 +188,25 @@ static inline bool updateIcon(char * rootDir)
for (int i = 0; i < COUNT(iconBmpName); i++)
{
GUI_POINT last_size = bmp_size;
sprintf(curBmpPath, "%s" BMP_UPDATE_DIR "/%s.bmp", rootDir, iconBmpName[i]);
GUI_ClearPrect(&labelUpdateRect);
GUI_DispString(labelUpdateRect.x0, labelUpdateRect.y0, (uint8_t *)curBmpPath);

sprintf(curBmpPath, "%s%s/%s.bmp", rootDir, BMP_UPDATE_DIR, iconBmpName[i]);
bmpState = bmpDecode(curBmpPath, ICON_ADDR(i));

GUI_ClearPrect(&labelUpdateRect);
GUI_DispString(labelUpdateRect.x0, labelUpdateRect.y0, (uint8_t *)curBmpPath);
GUI_ClearRect(iconUpdateRect.x0, iconUpdateRect.y0, iconUpdateRect.x0 + last_size.x, iconUpdateRect.y0 + last_size.y);

if (bmpState == BMP_SUCCESS)
{ // display bmp update success
found++;
GUI_ClearRect(iconUpdateRect.x0, iconUpdateRect.y0, iconUpdateRect.x0 + last_size.x, iconUpdateRect.y0 + last_size.y);
IMAGE_ReadDisplay(iconUpdateRect.x0, iconUpdateRect.y0, ICON_ADDR(i));
}
else
{ // display bmp update fail
notfound++;
GUI_ClearRect(iconUpdateRect.x0, iconUpdateRect.y0, iconUpdateRect.x0 + last_size.x, iconUpdateRect.y0 + last_size.y);
dispIconFail((uint8_t *)curBmpPath, bmpState);
}

// Display icon update progress
sprintf(tempstr, "Updated: %d | Not Updated: %d", found, notfound);
GUI_DispString(statUpdateRect.x0, statUpdateRect.y0, (uint8_t *)tempstr);
Expand All @@ -202,47 +226,14 @@ static inline bool updateIcon(char * rootDir)
dispIconFail((uint8_t *)(curBmpPath), bmpState);
}

if (notfound == 0)
return true;
else
return false;
}

void dispIconFail(uint8_t * lbl, BMPUPDATE_STAT bmpState)
{
char * stat_txt;
char error_txt[30];

GUI_SetColor(infoSettings.reminder_color);
GUI_ClearPrect(&labelFailedRect);
GUI_DispString(labelFailedRect.x0, labelFailedRect.y0, lbl);

switch (bmpState)
{
case BMP_INVALIDFILE:
stat_txt = "BMP file not valid ";
break;
case BMP_NOT24BIT:
stat_txt = "Format is not 24Bit";
break;
case BMP_NOTFOUND:
default:
stat_txt = "BMP file not found ";
break;
}

sprintf(error_txt, "Error: %s", stat_txt);
GUI_DispString(labelFailedRect.x0, labelFailedRect.y0 + BYTE_HEIGHT + 2, (uint8_t *)error_txt);
GUI_RestoreColorDefault();
Delay_ms(1000); // give some time to the user to read failed icon name.
return !notfound;
}

bool updateFont(char * font, uint32_t addr)
static bool updateFont(char * font, uint32_t addr)
{
uint8_t progress = 0;
UINT rnum = 0;
uint32_t offset = 0;
char buffer[128];
FIL myfp;
uint8_t * tempbuf = NULL;

Expand All @@ -255,9 +246,11 @@ bool updateFont(char * font, uint32_t addr)
return false;

GUI_Clear(infoSettings.bg_color);
sprintf((void *)buffer, "%s Size: %dKB", font, (uint32_t)f_size(&myfp) >> 10);
GUI_DispString(0, 100, (uint8_t *)buffer);
GUI_DispString(0, 140, (uint8_t *)"Updating: %");
GUI_DispString(5, PADDING, (uint8_t *)"Updating Fonts");
GUI_DispString(0, BYTE_HEIGHT * 3 + PADDING, (uint8_t *)font);
GUI_DispString(0, BYTE_HEIGHT * 4 + PADDING, (uint8_t *)"Size: KB");
GUI_DispDec(0 + BYTE_WIDTH * 5, BYTE_HEIGHT * 4 + PADDING, (uint32_t)f_size(&myfp) >> 10, 4, RIGHT);
GUI_DispString(0, BYTE_HEIGHT * 5 + PADDING, (uint8_t *)"Updating: %");

while (!f_eof(&myfp))
{
Expand All @@ -270,10 +263,10 @@ bool updateFont(char * font, uint32_t addr)
if (progress != (offset * 100) / f_size(&myfp))
{
progress = (offset * 100) / f_size(&myfp);
GUI_DispDec(0 + BYTE_WIDTH * 9, 140, progress, 3, RIGHT);
GUI_DispDec(0 + BYTE_WIDTH * 9, BYTE_HEIGHT * 5 + PADDING, progress, 3, RIGHT);
}

if (rnum !=W25QXX_SECTOR_SIZE) break;
if (rnum != W25QXX_SECTOR_SIZE) break;
}

f_close(&myfp);
Expand Down Expand Up @@ -371,89 +364,76 @@ void scanUpdates(void)
{
char * rootDir = NULL;

#ifdef USB_FLASH_DRIVE_SUPPORT
bool checkUSBDisk = true;
#endif

if (mountSDCard())
rootDir = SD_ROOT_DIR;
#ifdef USB_FLASH_DRIVE_SUPPORT
// check USB flash drive for update file
else if (mountUSBDisk())
rootDir = USB_ROOT_DIR;
#endif
else
return;

#ifdef USB_FLASH_DRIVE_SUPPORT
checkupdate:
#endif
if (rootDir != NULL)
{
char curfilePath[100];
bool flash_sign_updated = false;
uint32_t saved_flash_sign[sign_count];
char curfilePath[100];
bool flash_sign_updated = false;
uint32_t saved_flash_sign[sign_count];

W25Qxx_ReadBuffer((uint8_t *)&saved_flash_sign, FLASH_SIGN_ADDR, sizeof(saved_flash_sign));
W25Qxx_ReadBuffer((uint8_t *)&saved_flash_sign, FLASH_SIGN_ADDR, sizeof(saved_flash_sign));

// check for font update
GET_FULL_PATH(curfilePath, rootDir, FONT_UPDATE_DIR);
if (f_dir_exists(curfilePath))
{
bool updateOk = true;
for (uint8_t i = 0; i < COUNT(fontAddrList); i++)
{
GET_FULL_PATH(curfilePath, rootDir, fontPathList[i]);
if (!updateFont(curfilePath, fontAddrList[i]))
updateOk = false; // set update to false if any font fails to update
}

if (updateOk && saved_flash_sign[font_sign] != FONT_CHECK_SIGN)
{
saved_flash_sign[font_sign] = FONT_CHECK_SIGN;
flash_sign_updated = true;
}
}

// check for icon/bmp update
GET_FULL_PATH(curfilePath, rootDir, BMP_UPDATE_DIR);
if (f_dir_exists(BMP_UPDATE_DIR))
// check for font update
GET_FULL_PATH(curfilePath, rootDir, FONT_UPDATE_DIR);
if (f_dir_exists(curfilePath))
{
bool updateOK = true;
for (uint8_t i = 0; i < COUNT(fontAddrList); i++)
{
if (updateIcon(rootDir) && (saved_flash_sign[icon_sign] != ICON_CHECK_SIGN))
{
saved_flash_sign[icon_sign] = ICON_CHECK_SIGN;
flash_sign_updated = true;
}
GET_FULL_PATH(curfilePath, rootDir, fontPathList[i]);
if (!updateFont(curfilePath, fontAddrList[i]))
updateOK = false; // set update to false if any font fails to update
}

// check for config update
GET_FULL_PATH(curfilePath, rootDir, CONFIG_FILE_PATH);
if (getConfigFromFile(curfilePath) && (saved_flash_sign[config_sign] != CONFIG_CHECK_SIGN))
if (updateOK && saved_flash_sign[font_sign] != FONT_CHECK_SIGN)
{
saved_flash_sign[config_sign] = CONFIG_CHECK_SIGN;
saved_flash_sign[font_sign] = FONT_CHECK_SIGN;
flash_sign_updated = true;
}
}

// check for language update
if (getLangFromFile(rootDir) && (saved_flash_sign[lang_sign] != LANGUAGE_CHECK_SIGN))
// check for icon/bmp update
GET_FULL_PATH(curfilePath, rootDir, BMP_UPDATE_DIR);
if (f_dir_exists(curfilePath))
{
if (updateIcon(rootDir) && (saved_flash_sign[icon_sign] != ICON_CHECK_SIGN))
{
saved_flash_sign[lang_sign] = LANGUAGE_CHECK_SIGN;
saved_flash_sign[icon_sign] = ICON_CHECK_SIGN;
flash_sign_updated = true;
}
}

// rename files
scanRenameUpdate(rootDir);

// check for reset file
scanResetDir(rootDir);
// check for config update
GET_FULL_PATH(curfilePath, rootDir, CONFIG_FILE_PATH);
if (getConfigFromFile(curfilePath) && (saved_flash_sign[config_sign] != CONFIG_CHECK_SIGN))
{
saved_flash_sign[config_sign] = CONFIG_CHECK_SIGN;
flash_sign_updated = true;
}

// update flash sign
if (flash_sign_updated)
{
saveflashSign((uint8_t *)saved_flash_sign, sizeof(saved_flash_sign));
}
// check for language update
if (getLangFromFile(rootDir) && (saved_flash_sign[lang_sign] != LANGUAGE_CHECK_SIGN))
{
saved_flash_sign[lang_sign] = LANGUAGE_CHECK_SIGN;
flash_sign_updated = true;
}

#ifdef USB_FLASH_DRIVE_SUPPORT
// check USB flash drive for update file
else if (checkUSBDisk && mountUSBDisk())
{
rootDir = USB_ROOT_DIR;
checkUSBDisk = false;
goto checkupdate;
}
#endif
// rename files
scanRenameUpdate(rootDir);

// check for reset file
scanResetDir(rootDir);

// update flash sign
if (flash_sign_updated)
{
saveflashSign((uint8_t *)saved_flash_sign, sizeof(saved_flash_sign));
}
}
13 changes: 0 additions & 13 deletions TFT/src/User/API/boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ enum
ICON_NULL
};

// This List is Auto-Generated. Please add new icons in small_icon_list.inc only
enum
{
#define X_SMALLICON(NAME) SMALL_ICON_##NAME ,
#include "small_icon_list.inc"
#undef X_SMALLICON
// add new icons in small_icon_list.inc only
// Back ground sign
SMALL_ICON_NULL
};

typedef enum
{
BMP_SUCCESS,
Expand All @@ -112,8 +101,6 @@ typedef union
} GUI_COLOR;

void scanUpdates(void);
void dispIconFail(uint8_t * lbl, BMPUPDATE_STAT bmpState);
BMPUPDATE_STAT bmpDecode(char * bmp, uint32_t addr);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/API/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,14 +801,14 @@ void menuDrawTitle(void)
}

// draw title
uint8_t *titleString = labelGetAddress(curTitle);
uint8_t *titleString;
uint16_t start_y = (TITLE_END_Y - BYTE_HEIGHT) / 2;
uint16_t start_x = 10;
uint16_t end_x = drawTemperatureStatus();

GUI_SetBkColor(infoSettings.title_bg_color);

if (titleString)
if ((titleString = labelGetAddress(curTitle)))
{
GUI_SetTextMode(GUI_TEXTMODE_NORMAL);
GUI_DispLenString(10, start_y, titleString, LCD_WIDTH - 20, true);
Expand Down
14 changes: 0 additions & 14 deletions TFT/src/User/API/small_icon_list.inc

This file was deleted.

1 change: 0 additions & 1 deletion TFT/src/User/Menu/PersistentInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ int16_t drawTemperatureStatus(void)
sprintf(tempstr, "%d/%d", heatGetCurrentTemp(tmpHeater[i]), heatGetTargetTemp(tmpHeater[i]));

x_offset -= GUI_StrPixelWidth((uint8_t *)tempstr);
GUI_StrPixelWidth(LABEL_10_PERCENT);

GUI_DispString(x_offset, start_y, (uint8_t *)tempstr); // value
x_offset -= GLOBALICON_INTERVAL;
Expand Down

0 comments on commit 6e80e71

Please sign in to comment.