Code refactoring
This commit is contained in:
@@ -51,6 +51,8 @@ void displaySplash();
|
|||||||
void displayScreenIndex(uint8_t index, uint8_t count, uint8_t attr);
|
void displayScreenIndex(uint8_t index, uint8_t count, uint8_t attr);
|
||||||
void displayScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible);
|
void displayScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible);
|
||||||
void displayMenuBar(const MenuItem *menu, int index);
|
void displayMenuBar(const MenuItem *menu, int index);
|
||||||
|
void displayProgressBar(const char *label);
|
||||||
|
void updateProgressBar(int num, int den);
|
||||||
|
|
||||||
extern coord_t scrollbar_X;
|
extern coord_t scrollbar_X;
|
||||||
#define SET_SCROLLBAR_X(x) scrollbar_X = (x);
|
#define SET_SCROLLBAR_X(x) scrollbar_X = (x);
|
||||||
|
|||||||
@@ -82,9 +82,7 @@ void flashBootloader(const char * filename)
|
|||||||
UINT count;
|
UINT count;
|
||||||
|
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
lcd_putsLeft(4*FH, STR_WRITING);
|
displayProgressBar(STR_WRITING);
|
||||||
lcd_rect(3, 6*FH+4, 204, 7);
|
|
||||||
lcdRefresh();
|
|
||||||
|
|
||||||
static uint8_t unlocked = 0;
|
static uint8_t unlocked = 0;
|
||||||
if (!unlocked) {
|
if (!unlocked) {
|
||||||
@@ -104,12 +102,9 @@ void flashBootloader(const char * filename)
|
|||||||
}
|
}
|
||||||
for (int j=0; j<1024; j+=FLASH_PAGESIZE) {
|
for (int j=0; j<1024; j+=FLASH_PAGESIZE) {
|
||||||
writeFlash(CONVERT_UINT_PTR(FIRMWARE_ADDRESS+i+j), (uint32_t *)(buffer+j));
|
writeFlash(CONVERT_UINT_PTR(FIRMWARE_ADDRESS+i+j), (uint32_t *)(buffer+j));
|
||||||
lcd_hline(5, 6*FH+6, (200*i)/BOOTLOADER_SIZE, FORCE);
|
|
||||||
lcd_hline(5, 6*FH+7, (200*i)/BOOTLOADER_SIZE, FORCE);
|
|
||||||
lcd_hline(5, 6*FH+8, (200*i)/BOOTLOADER_SIZE, FORCE);
|
|
||||||
lcdRefresh();
|
|
||||||
SIMU_SLEEP(30/*ms*/);
|
|
||||||
}
|
}
|
||||||
|
updateProgressBar(i, BOOTLOADER_SIZE);
|
||||||
|
SIMU_SLEEP(30/*ms*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlocked) {
|
if (unlocked) {
|
||||||
@@ -120,6 +115,13 @@ void flashBootloader(const char * filename)
|
|||||||
f_close(&file);
|
f_close(&file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getSelectionFullPath(char *lfn)
|
||||||
|
{
|
||||||
|
f_getcwd(lfn, _MAX_LFN);
|
||||||
|
strcat(lfn, PSTR("/"));
|
||||||
|
strcat(lfn, reusableBuffer.sdmanager.lines[m_posVert - s_pgOfs]);
|
||||||
|
}
|
||||||
|
|
||||||
void onSdManagerMenu(const char *result)
|
void onSdManagerMenu(const char *result)
|
||||||
{
|
{
|
||||||
TCHAR lfn[_MAX_LFN+1];
|
TCHAR lfn[_MAX_LFN+1];
|
||||||
@@ -157,9 +159,7 @@ void onSdManagerMenu(const char *result)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (result == STR_DELETE_FILE) {
|
else if (result == STR_DELETE_FILE) {
|
||||||
f_getcwd(lfn, _MAX_LFN);
|
getSelectionFullPath(lfn);
|
||||||
strcat(lfn, PSTR("/"));
|
|
||||||
strcat(lfn, line);
|
|
||||||
f_unlink(lfn);
|
f_unlink(lfn);
|
||||||
strncpy(statusLineMsg, line, 13);
|
strncpy(statusLineMsg, line, 13);
|
||||||
strcpy_P(statusLineMsg+min((uint8_t)strlen(statusLineMsg), (uint8_t)13), STR_REMOVED);
|
strcpy_P(statusLineMsg+min((uint8_t)strlen(statusLineMsg), (uint8_t)13), STR_REMOVED);
|
||||||
@@ -169,16 +169,8 @@ void onSdManagerMenu(const char *result)
|
|||||||
m_posVert--;
|
m_posVert--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* TODO else if (result == STR_LOAD_FILE) {
|
|
||||||
f_getcwd(lfn, _MAX_LFN);
|
|
||||||
strcat(lfn, "/");
|
|
||||||
strcat(lfn, line);
|
|
||||||
POPUP_WARNING(eeLoadModelSD(lfn));
|
|
||||||
} */
|
|
||||||
else if (result == STR_PLAY_FILE) {
|
else if (result == STR_PLAY_FILE) {
|
||||||
f_getcwd(lfn, _MAX_LFN);
|
getSelectionFullPath(lfn);
|
||||||
strcat(lfn, "/");
|
|
||||||
strcat(lfn, line);
|
|
||||||
audioQueue.stopAll();
|
audioQueue.stopAll();
|
||||||
audioQueue.playFile(lfn, 0, ID_PLAY_FROM_SD_MANAGER);
|
audioQueue.playFile(lfn, 0, ID_PLAY_FROM_SD_MANAGER);
|
||||||
}
|
}
|
||||||
@@ -188,22 +180,16 @@ void onSdManagerMenu(const char *result)
|
|||||||
eeDirty(EE_MODEL);
|
eeDirty(EE_MODEL);
|
||||||
}
|
}
|
||||||
else if (result == STR_VIEW_TEXT) {
|
else if (result == STR_VIEW_TEXT) {
|
||||||
f_getcwd(lfn, _MAX_LFN);
|
getSelectionFullPath(lfn);
|
||||||
strcat(lfn, "/");
|
|
||||||
strcat(lfn, line);
|
|
||||||
pushMenuTextView(lfn);
|
pushMenuTextView(lfn);
|
||||||
}
|
}
|
||||||
else if (result == STR_FLASH_BOOTLOADER) {
|
else if (result == STR_FLASH_BOOTLOADER) {
|
||||||
f_getcwd(lfn, _MAX_LFN);
|
getSelectionFullPath(lfn);
|
||||||
strcat(lfn, "/");
|
|
||||||
strcat(lfn, line);
|
|
||||||
flashBootloader(lfn);
|
flashBootloader(lfn);
|
||||||
}
|
}
|
||||||
#if defined(LUA)
|
#if defined(LUA)
|
||||||
else if (result == STR_EXECUTE_FILE) {
|
else if (result == STR_EXECUTE_FILE) {
|
||||||
f_getcwd(lfn, _MAX_LFN);
|
getSelectionFullPath(lfn);
|
||||||
strcat(lfn, "/");
|
|
||||||
strcat(lfn, line);
|
|
||||||
luaExec(lfn);
|
luaExec(lfn);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -211,13 +197,6 @@ void onSdManagerMenu(const char *result)
|
|||||||
|
|
||||||
void menuGeneralSdManager(uint8_t _event)
|
void menuGeneralSdManager(uint8_t _event)
|
||||||
{
|
{
|
||||||
FILINFO fno;
|
|
||||||
DIR dir;
|
|
||||||
char *fn; /* This function is assuming non-Unicode cfg. */
|
|
||||||
TCHAR lfn[_MAX_LFN + 1];
|
|
||||||
fno.lfname = lfn;
|
|
||||||
fno.lfsize = sizeof(lfn);
|
|
||||||
|
|
||||||
if (s_warning_result) {
|
if (s_warning_result) {
|
||||||
s_warning_result = 0;
|
s_warning_result = 0;
|
||||||
displayPopup(STR_FORMATTING);
|
displayPopup(STR_FORMATTING);
|
||||||
@@ -316,6 +295,13 @@ void menuGeneralSdManager(uint8_t _event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (reusableBuffer.sdmanager.offset != s_pgOfs) {
|
if (reusableBuffer.sdmanager.offset != s_pgOfs) {
|
||||||
|
FILINFO fno;
|
||||||
|
DIR dir;
|
||||||
|
char *fn; /* This function is assuming non-Unicode cfg. */
|
||||||
|
TCHAR lfn[_MAX_LFN + 1];
|
||||||
|
fno.lfname = lfn;
|
||||||
|
fno.lfsize = sizeof(lfn);
|
||||||
|
|
||||||
if (s_pgOfs == 0) {
|
if (s_pgOfs == 0) {
|
||||||
reusableBuffer.sdmanager.offset = 0;
|
reusableBuffer.sdmanager.offset = 0;
|
||||||
memset(reusableBuffer.sdmanager.lines, 0, sizeof(reusableBuffer.sdmanager.lines));
|
memset(reusableBuffer.sdmanager.lines, 0, sizeof(reusableBuffer.sdmanager.lines));
|
||||||
|
|||||||
@@ -43,11 +43,9 @@ void backupEeprom()
|
|||||||
FIL file;
|
FIL file;
|
||||||
|
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
lcd_putsLeft(4*FH, STR_WRITING);
|
displayProgressBar(STR_WRITING);
|
||||||
lcd_rect(3, 6*FH+4, 204, 7);
|
|
||||||
lcdRefresh();
|
|
||||||
|
|
||||||
//reset unexpectedShutdown to prevent warning when user restores EEPROM backup
|
// reset unexpectedShutdown to prevent warning when user restores EEPROM backup
|
||||||
g_eeGeneral.unexpectedShutdown = 0;
|
g_eeGeneral.unexpectedShutdown = 0;
|
||||||
eeDirty(EE_GENERAL);
|
eeDirty(EE_GENERAL);
|
||||||
eeCheck(true);
|
eeCheck(true);
|
||||||
@@ -76,10 +74,7 @@ void backupEeprom()
|
|||||||
UINT count;
|
UINT count;
|
||||||
eeprom_read_block(buffer, i, 1024);
|
eeprom_read_block(buffer, i, 1024);
|
||||||
f_write(&file, buffer, 1024, &count);
|
f_write(&file, buffer, 1024, &count);
|
||||||
lcd_hline(5, 6*FH+6, (200*i)/EESIZE, FORCE);
|
updateProgressBar(i, EESIZE);
|
||||||
lcd_hline(5, 6*FH+7, (200*i)/EESIZE, FORCE);
|
|
||||||
lcd_hline(5, 6*FH+8, (200*i)/EESIZE, FORCE);
|
|
||||||
lcdRefresh();
|
|
||||||
SIMU_SLEEP(100/*ms*/);
|
SIMU_SLEEP(100/*ms*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,24 @@ void displayMenuBar(const MenuItem *menu, int index)
|
|||||||
lcd_hlineStip(0, 31, LCD_W, SOLID, FORCE);
|
lcd_hlineStip(0, 31, LCD_W, SOLID, FORCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void displayProgressBar(const char *label)
|
||||||
|
{
|
||||||
|
lcd_putsLeft(4*FH, label);
|
||||||
|
lcd_rect(3, 6*FH+4, 204, 7);
|
||||||
|
lcdRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateProgressBar(int num, int den)
|
||||||
|
{
|
||||||
|
if (num > 0 && den > 0) {
|
||||||
|
int width = (200*num)/den;
|
||||||
|
lcd_hline(5, 6*FH+6, width, FORCE);
|
||||||
|
lcd_hline(5, 6*FH+7, width, FORCE);
|
||||||
|
lcd_hline(5, 6*FH+8, width, FORCE);
|
||||||
|
lcdRefresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void title(const pm_char * s)
|
void title(const pm_char * s)
|
||||||
{
|
{
|
||||||
lcd_putsAtt(0, 0, s, INVERS);
|
lcd_putsAtt(0, 0, s, INVERS);
|
||||||
|
|||||||
Reference in New Issue
Block a user