Skip to content

Commit 1212ff2

Browse files
committed
Icons update from USB fix
1 parent 6d49c6e commit 1212ff2

File tree

5 files changed

+101
-149
lines changed

5 files changed

+101
-149
lines changed

TFT/src/User/API/boot.c

+99-119
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ const char * const iconBmpName[] = {
3434
// add new icons in icon_list.inc only
3535
};
3636

37-
// This List is Auto-Generated. Please add new icons in small_icon_list.inc only
38-
const char * const smallIconBmpName[] = {
39-
#define X_SMALLICON(NAME) #NAME ,
40-
#include "small_icon_list.inc"
41-
#undef X_SMALLICON
42-
// add new icons in small_icon_list.inc only
43-
};
44-
4537
BMPUPDATE_STAT bmpDecode(char * bmp, uint32_t addr)
4638
{
4739
FIL bmpFile;
@@ -133,6 +125,37 @@ BMPUPDATE_STAT bmpDecode(char * bmp, uint32_t addr)
133125
return BMP_SUCCESS;
134126
}
135127

128+
void dispIconFail(uint8_t * lbl, BMPUPDATE_STAT bmpState)
129+
{
130+
char * stat_txt;
131+
char error_txt[30];
132+
133+
GUI_SetColor(infoSettings.reminder_color);
134+
GUI_ClearPrect(&labelFailedRect);
135+
GUI_DispString(labelFailedRect.x0, labelFailedRect.y0, lbl);
136+
137+
switch (bmpState)
138+
{
139+
case BMP_INVALIDFILE:
140+
stat_txt = "BMP file not valid ";
141+
break;
142+
143+
case BMP_NOT24BIT:
144+
stat_txt = "Format is not 24Bit";
145+
break;
146+
147+
case BMP_NOTFOUND:
148+
default:
149+
stat_txt = "BMP file not found ";
150+
break;
151+
}
152+
153+
sprintf(error_txt, "Error: %s", stat_txt);
154+
GUI_DispString(labelFailedRect.x0, labelFailedRect.y0 + BYTE_HEIGHT + 2, (uint8_t *)error_txt);
155+
GUI_RestoreColorDefault();
156+
Delay_ms(1000); // give some time to the user to read failed icon name.
157+
}
158+
136159
static inline bool updateIcon(char * rootDir)
137160
{
138161
uint16_t found = 0;
@@ -165,24 +188,25 @@ static inline bool updateIcon(char * rootDir)
165188
for (int i = 0; i < COUNT(iconBmpName); i++)
166189
{
167190
GUI_POINT last_size = bmp_size;
168-
sprintf(curBmpPath, "%s" BMP_UPDATE_DIR "/%s.bmp", rootDir, iconBmpName[i]);
169-
GUI_ClearPrect(&labelUpdateRect);
170-
GUI_DispString(labelUpdateRect.x0, labelUpdateRect.y0, (uint8_t *)curBmpPath);
171191

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

195+
GUI_ClearPrect(&labelUpdateRect);
196+
GUI_DispString(labelUpdateRect.x0, labelUpdateRect.y0, (uint8_t *)curBmpPath);
197+
GUI_ClearRect(iconUpdateRect.x0, iconUpdateRect.y0, iconUpdateRect.x0 + last_size.x, iconUpdateRect.y0 + last_size.y);
198+
174199
if (bmpState == BMP_SUCCESS)
175200
{ // display bmp update success
176201
found++;
177-
GUI_ClearRect(iconUpdateRect.x0, iconUpdateRect.y0, iconUpdateRect.x0 + last_size.x, iconUpdateRect.y0 + last_size.y);
178202
IMAGE_ReadDisplay(iconUpdateRect.x0, iconUpdateRect.y0, ICON_ADDR(i));
179203
}
180204
else
181205
{ // display bmp update fail
182206
notfound++;
183-
GUI_ClearRect(iconUpdateRect.x0, iconUpdateRect.y0, iconUpdateRect.x0 + last_size.x, iconUpdateRect.y0 + last_size.y);
184207
dispIconFail((uint8_t *)curBmpPath, bmpState);
185208
}
209+
186210
// Display icon update progress
187211
sprintf(tempstr, "Updated: %d | Not Updated: %d", found, notfound);
188212
GUI_DispString(statUpdateRect.x0, statUpdateRect.y0, (uint8_t *)tempstr);
@@ -202,47 +226,14 @@ static inline bool updateIcon(char * rootDir)
202226
dispIconFail((uint8_t *)(curBmpPath), bmpState);
203227
}
204228

205-
if (notfound == 0)
206-
return true;
207-
else
208-
return false;
209-
}
210-
211-
void dispIconFail(uint8_t * lbl, BMPUPDATE_STAT bmpState)
212-
{
213-
char * stat_txt;
214-
char error_txt[30];
215-
216-
GUI_SetColor(infoSettings.reminder_color);
217-
GUI_ClearPrect(&labelFailedRect);
218-
GUI_DispString(labelFailedRect.x0, labelFailedRect.y0, lbl);
219-
220-
switch (bmpState)
221-
{
222-
case BMP_INVALIDFILE:
223-
stat_txt = "BMP file not valid ";
224-
break;
225-
case BMP_NOT24BIT:
226-
stat_txt = "Format is not 24Bit";
227-
break;
228-
case BMP_NOTFOUND:
229-
default:
230-
stat_txt = "BMP file not found ";
231-
break;
232-
}
233-
234-
sprintf(error_txt, "Error: %s", stat_txt);
235-
GUI_DispString(labelFailedRect.x0, labelFailedRect.y0 + BYTE_HEIGHT + 2, (uint8_t *)error_txt);
236-
GUI_RestoreColorDefault();
237-
Delay_ms(1000); // give some time to the user to read failed icon name.
229+
return !notfound;
238230
}
239231

240-
bool updateFont(char * font, uint32_t addr)
232+
static bool updateFont(char * font, uint32_t addr)
241233
{
242234
uint8_t progress = 0;
243235
UINT rnum = 0;
244236
uint32_t offset = 0;
245-
char buffer[128];
246237
FIL myfp;
247238
uint8_t * tempbuf = NULL;
248239

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

257248
GUI_Clear(infoSettings.bg_color);
258-
sprintf((void *)buffer, "%s Size: %dKB", font, (uint32_t)f_size(&myfp) >> 10);
259-
GUI_DispString(0, 100, (uint8_t *)buffer);
260-
GUI_DispString(0, 140, (uint8_t *)"Updating: %");
249+
GUI_DispString(5, PADDING, (uint8_t *)"Updating Fonts");
250+
GUI_DispString(0, BYTE_HEIGHT * 3 + PADDING, (uint8_t *)font);
251+
GUI_DispString(0, BYTE_HEIGHT * 4 + PADDING, (uint8_t *)"Size: KB");
252+
GUI_DispDec(0 + BYTE_WIDTH * 5, BYTE_HEIGHT * 4 + PADDING, (uint32_t)f_size(&myfp) >> 10, 4, RIGHT);
253+
GUI_DispString(0, BYTE_HEIGHT * 5 + PADDING, (uint8_t *)"Updating: %");
261254

262255
while (!f_eof(&myfp))
263256
{
@@ -270,10 +263,10 @@ bool updateFont(char * font, uint32_t addr)
270263
if (progress != (offset * 100) / f_size(&myfp))
271264
{
272265
progress = (offset * 100) / f_size(&myfp);
273-
GUI_DispDec(0 + BYTE_WIDTH * 9, 140, progress, 3, RIGHT);
266+
GUI_DispDec(0 + BYTE_WIDTH * 9, BYTE_HEIGHT * 5 + PADDING, progress, 3, RIGHT);
274267
}
275268

276-
if (rnum !=W25QXX_SECTOR_SIZE) break;
269+
if (rnum != W25QXX_SECTOR_SIZE) break;
277270
}
278271

279272
f_close(&myfp);
@@ -371,89 +364,76 @@ void scanUpdates(void)
371364
{
372365
char * rootDir = NULL;
373366

374-
#ifdef USB_FLASH_DRIVE_SUPPORT
375-
bool checkUSBDisk = true;
376-
#endif
377-
378367
if (mountSDCard())
379368
rootDir = SD_ROOT_DIR;
369+
#ifdef USB_FLASH_DRIVE_SUPPORT
370+
// check USB flash drive for update file
371+
else if (mountUSBDisk())
372+
rootDir = USB_ROOT_DIR;
373+
#endif
374+
else
375+
return;
380376

381-
#ifdef USB_FLASH_DRIVE_SUPPORT
382-
checkupdate:
383-
#endif
384-
if (rootDir != NULL)
385-
{
386-
char curfilePath[100];
387-
bool flash_sign_updated = false;
388-
uint32_t saved_flash_sign[sign_count];
377+
char curfilePath[100];
378+
bool flash_sign_updated = false;
379+
uint32_t saved_flash_sign[sign_count];
389380

390-
W25Qxx_ReadBuffer((uint8_t *)&saved_flash_sign, FLASH_SIGN_ADDR, sizeof(saved_flash_sign));
381+
W25Qxx_ReadBuffer((uint8_t *)&saved_flash_sign, FLASH_SIGN_ADDR, sizeof(saved_flash_sign));
391382

392-
// check for font update
393-
GET_FULL_PATH(curfilePath, rootDir, FONT_UPDATE_DIR);
394-
if (f_dir_exists(curfilePath))
395-
{
396-
bool updateOk = true;
397-
for (uint8_t i = 0; i < COUNT(fontAddrList); i++)
398-
{
399-
GET_FULL_PATH(curfilePath, rootDir, fontPathList[i]);
400-
if (!updateFont(curfilePath, fontAddrList[i]))
401-
updateOk = false; // set update to false if any font fails to update
402-
}
403-
404-
if (updateOk && saved_flash_sign[font_sign] != FONT_CHECK_SIGN)
405-
{
406-
saved_flash_sign[font_sign] = FONT_CHECK_SIGN;
407-
flash_sign_updated = true;
408-
}
409-
}
410-
411-
// check for icon/bmp update
412-
GET_FULL_PATH(curfilePath, rootDir, BMP_UPDATE_DIR);
413-
if (f_dir_exists(BMP_UPDATE_DIR))
383+
// check for font update
384+
GET_FULL_PATH(curfilePath, rootDir, FONT_UPDATE_DIR);
385+
if (f_dir_exists(curfilePath))
386+
{
387+
bool updateOK = true;
388+
for (uint8_t i = 0; i < COUNT(fontAddrList); i++)
414389
{
415-
if (updateIcon(rootDir) && (saved_flash_sign[icon_sign] != ICON_CHECK_SIGN))
416-
{
417-
saved_flash_sign[icon_sign] = ICON_CHECK_SIGN;
418-
flash_sign_updated = true;
419-
}
390+
GET_FULL_PATH(curfilePath, rootDir, fontPathList[i]);
391+
if (!updateFont(curfilePath, fontAddrList[i]))
392+
updateOK = false; // set update to false if any font fails to update
420393
}
421394

422-
// check for config update
423-
GET_FULL_PATH(curfilePath, rootDir, CONFIG_FILE_PATH);
424-
if (getConfigFromFile(curfilePath) && (saved_flash_sign[config_sign] != CONFIG_CHECK_SIGN))
395+
if (updateOK && saved_flash_sign[font_sign] != FONT_CHECK_SIGN)
425396
{
426-
saved_flash_sign[config_sign] = CONFIG_CHECK_SIGN;
397+
saved_flash_sign[font_sign] = FONT_CHECK_SIGN;
427398
flash_sign_updated = true;
428399
}
400+
}
429401

430-
// check for language update
431-
if (getLangFromFile(rootDir) && (saved_flash_sign[lang_sign] != LANGUAGE_CHECK_SIGN))
402+
// check for icon/bmp update
403+
GET_FULL_PATH(curfilePath, rootDir, BMP_UPDATE_DIR);
404+
if (f_dir_exists(curfilePath))
405+
{
406+
if (updateIcon(rootDir) && (saved_flash_sign[icon_sign] != ICON_CHECK_SIGN))
432407
{
433-
saved_flash_sign[lang_sign] = LANGUAGE_CHECK_SIGN;
408+
saved_flash_sign[icon_sign] = ICON_CHECK_SIGN;
434409
flash_sign_updated = true;
435410
}
411+
}
436412

437-
// rename files
438-
scanRenameUpdate(rootDir);
439-
440-
// check for reset file
441-
scanResetDir(rootDir);
413+
// check for config update
414+
GET_FULL_PATH(curfilePath, rootDir, CONFIG_FILE_PATH);
415+
if (getConfigFromFile(curfilePath) && (saved_flash_sign[config_sign] != CONFIG_CHECK_SIGN))
416+
{
417+
saved_flash_sign[config_sign] = CONFIG_CHECK_SIGN;
418+
flash_sign_updated = true;
419+
}
442420

443-
// update flash sign
444-
if (flash_sign_updated)
445-
{
446-
saveflashSign((uint8_t *)saved_flash_sign, sizeof(saved_flash_sign));
447-
}
421+
// check for language update
422+
if (getLangFromFile(rootDir) && (saved_flash_sign[lang_sign] != LANGUAGE_CHECK_SIGN))
423+
{
424+
saved_flash_sign[lang_sign] = LANGUAGE_CHECK_SIGN;
425+
flash_sign_updated = true;
448426
}
449427

450-
#ifdef USB_FLASH_DRIVE_SUPPORT
451-
// check USB flash drive for update file
452-
else if (checkUSBDisk && mountUSBDisk())
453-
{
454-
rootDir = USB_ROOT_DIR;
455-
checkUSBDisk = false;
456-
goto checkupdate;
457-
}
458-
#endif
428+
// rename files
429+
scanRenameUpdate(rootDir);
430+
431+
// check for reset file
432+
scanResetDir(rootDir);
433+
434+
// update flash sign
435+
if (flash_sign_updated)
436+
{
437+
saveflashSign((uint8_t *)saved_flash_sign, sizeof(saved_flash_sign));
438+
}
459439
}

TFT/src/User/API/boot.h

-13
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,6 @@ enum
8181
ICON_NULL
8282
};
8383

84-
// This List is Auto-Generated. Please add new icons in small_icon_list.inc only
85-
enum
86-
{
87-
#define X_SMALLICON(NAME) SMALL_ICON_##NAME ,
88-
#include "small_icon_list.inc"
89-
#undef X_SMALLICON
90-
// add new icons in small_icon_list.inc only
91-
// Back ground sign
92-
SMALL_ICON_NULL
93-
};
94-
9584
typedef enum
9685
{
9786
BMP_SUCCESS,
@@ -112,8 +101,6 @@ typedef union
112101
} GUI_COLOR;
113102

114103
void scanUpdates(void);
115-
void dispIconFail(uint8_t * lbl, BMPUPDATE_STAT bmpState);
116-
BMPUPDATE_STAT bmpDecode(char * bmp, uint32_t addr);
117104

118105
#ifdef __cplusplus
119106
}

TFT/src/User/API/menu.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -801,14 +801,14 @@ void menuDrawTitle(void)
801801
}
802802

803803
// draw title
804-
uint8_t *titleString = labelGetAddress(curTitle);
804+
uint8_t *titleString;
805805
uint16_t start_y = (TITLE_END_Y - BYTE_HEIGHT) / 2;
806806
uint16_t start_x = 10;
807807
uint16_t end_x = drawTemperatureStatus();
808808

809809
GUI_SetBkColor(infoSettings.title_bg_color);
810810

811-
if (titleString)
811+
if ((titleString = labelGetAddress(curTitle)))
812812
{
813813
GUI_SetTextMode(GUI_TEXTMODE_NORMAL);
814814
GUI_DispLenString(10, start_y, titleString, LCD_WIDTH - 20, true);

TFT/src/User/API/small_icon_list.inc

-14
This file was deleted.

TFT/src/User/Menu/PersistentInfo.c

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ int16_t drawTemperatureStatus(void)
112112
sprintf(tempstr, "%d/%d", heatGetCurrentTemp(tmpHeater[i]), heatGetTargetTemp(tmpHeater[i]));
113113

114114
x_offset -= GUI_StrPixelWidth((uint8_t *)tempstr);
115-
GUI_StrPixelWidth(LABEL_10_PERCENT);
116115

117116
GUI_DispString(x_offset, start_y, (uint8_t *)tempstr); // value
118117
x_offset -= GLOBALICON_INTERVAL;

0 commit comments

Comments
 (0)