[Horus] S.PORT devices update should work (not tested)

[Horus] SD Manager files renaming fixed (quick & dirty, I would prefer a popup)
This commit is contained in:
Bertrand Songis
2016-09-05 19:33:06 +02:00
parent fd138cf22a
commit cc2c2b094e
22 changed files with 585 additions and 500 deletions
+4 -73
View File
@@ -61,75 +61,6 @@ inline bool isFilenameLower(bool isfile, const char * fn, const char * line)
return (!isfile && IS_FILE(line)) || (isfile==IS_FILE(line) && strcasecmp(fn, line) < 0);
}
bool isBootloader(const char * filename)
{
FIL file;
f_open(&file, filename, FA_READ);
uint8_t buffer[1024];
UINT count;
if (f_read(&file, buffer, 1024, &count) != FR_OK || count != 1024) {
return false;
}
return isBootloaderStart((uint32_t *)buffer);
}
void flashBootloader(const char * filename)
{
FIL file;
f_open(&file, filename, FA_READ);
uint8_t buffer[1024];
UINT count;
lcdClear();
drawProgressBar(STR_WRITING);
static uint8_t unlocked = 0;
if (!unlocked) {
unlocked = 1;
unlockFlash();
}
for (int i=0; i<BOOTLOADER_SIZE; i+=1024) {
watchdogSuspend(100/*1s*/);
if (f_read(&file, buffer, 1024, &count) != FR_OK || count != 1024) {
POPUP_WARNING(STR_SDCARD_ERROR);
break;
}
if (i==0 && !isBootloaderStart((uint32_t *)buffer)) {
POPUP_WARNING(STR_INCOMPATIBLE);
break;
}
for (int j=0; j<1024; j+=FLASH_PAGESIZE) {
writeFlash(CONVERT_UINT_PTR(FIRMWARE_ADDRESS+i+j), (uint32_t *)(buffer+j));
}
updateProgressBar(i, BOOTLOADER_SIZE);
SIMU_SLEEP(30/*ms*/);
}
if (unlocked) {
lockFlash();
unlocked = 0;
}
f_close(&file);
}
void flashSportDevice(ModuleIndex module, const char *filename)
{
pausePulses();
watchdogSuspend(60*60*100/*1h*/);
lcdClear();
drawProgressBar(STR_WRITING);
sportFirmwareUpdate(module, filename);
watchdogSuspend(100/*1s*/);
resumePulses();
}
void getSelectionFullPath(char *lfn)
{
f_getcwd(lfn, _MAX_LFN);
@@ -137,7 +68,7 @@ void getSelectionFullPath(char *lfn)
strcat(lfn, reusableBuffer.sdmanager.lines[menuVerticalPosition - menuVerticalOffset]);
}
void onSdManagerMenu(const char *result)
void onSdManagerMenu(const char * result)
{
TCHAR lfn[_MAX_LFN+1];
@@ -209,15 +140,15 @@ void onSdManagerMenu(const char *result)
}
else if (result == STR_FLASH_BOOTLOADER) {
getSelectionFullPath(lfn);
flashBootloader(lfn);
bootloaderFlash(lfn);
}
else if (result == STR_FLASH_INTERNAL_MODULE) {
getSelectionFullPath(lfn);
flashSportDevice(INTERNAL_MODULE, lfn);
sportFlashDevice(INTERNAL_MODULE, lfn);
}
else if (result == STR_FLASH_EXTERNAL_DEVICE) {
getSelectionFullPath(lfn);
flashSportDevice(EXTERNAL_MODULE, lfn);
sportFlashDevice(EXTERNAL_MODULE, lfn);
}
#if defined(LUA)
else if (result == STR_EXECUTE_FILE) {
+25 -15
View File
@@ -128,23 +128,18 @@ void onSdManagerMenu(const char * result)
audioQueue.stopAll();
audioQueue.playFile(lfn, 0, ID_PLAY_FROM_SD_MANAGER);
}
#if 0
else if (result == STR_ASSIGN_BITMAP) {
strAppendFilename(g_model.header.bitmap, line, sizeof(g_model.header.bitmap));
memcpy(modelHeaders[g_eeGeneral.currModel].bitmap, g_model.header.bitmap, sizeof(g_model.header.bitmap));
storageDirty(EE_MODEL);
}
#endif
else if (result == STR_VIEW_TEXT) {
getSelectionFullPath(lfn);
pushMenuTextView(lfn);
}
#if 0
else if (result == STR_FLASH_BOOTLOADER) {
else if (result == STR_FLASH_INTERNAL_MODULE) {
getSelectionFullPath(lfn);
flashBootloader(lfn);
sportFlashDevice(INTERNAL_MODULE, lfn);
}
else if (result == STR_FLASH_EXTERNAL_DEVICE) {
getSelectionFullPath(lfn);
sportFlashDevice(EXTERNAL_MODULE, lfn);
}
#endif
#if defined(LUA)
else if (result == STR_EXECUTE_FILE) {
getSelectionFullPath(lfn);
@@ -276,7 +271,7 @@ bool menuRadioSdManager(event_t _event)
reusableBuffer.sdmanager.count = 0;
FRESULT res = f_opendir(&dir, "."); /* Open the directory */
FRESULT res = f_opendir(&dir, "."); // Open the directory
if (res == FR_OK) {
for (;;) {
res = f_readdir(&dir, &fno); /* Read a directory item */
@@ -294,8 +289,8 @@ bool menuRadioSdManager(event_t _event)
bool isfile = !(fno.fattrib & AM_DIR);
if (menuVerticalOffset == 0) {
for (int i=0; i<NUM_BODY_LINES; i++) {
char *line = reusableBuffer.sdmanager.lines[i];
for (uint8_t i=0; i<NUM_BODY_LINES; i++) {
char * line = reusableBuffer.sdmanager.lines[i];
if (line[0] == '\0' || isFilenameLower(isfile, fn, line)) {
if (i < NUM_BODY_LINES-1) memmove(reusableBuffer.sdmanager.lines[i+1], line, sizeof(reusableBuffer.sdmanager.lines[i]) * (NUM_BODY_LINES-1-i));
memset(line, 0, sizeof(reusableBuffer.sdmanager.lines[0]));
@@ -341,7 +336,22 @@ bool menuRadioSdManager(event_t _event)
coord_t y = MENU_CONTENT_TOP + i*FH;
LcdFlags attr = (index == i ? INVERS : 0);
if (reusableBuffer.sdmanager.lines[i][0]) {
if (IS_DIRECTORY(reusableBuffer.sdmanager.lines[i])) {
if (s_editMode == EDIT_MODIFY_STRING && attr) {
editName(MENUS_MARGIN_LEFT, y, reusableBuffer.sdmanager.lines[i], SD_SCREEN_FILE_LENGTH-4, _event, attr, 0);
if (s_editMode == 0) {
unsigned int len = effectiveLen(reusableBuffer.sdmanager.lines[i], SD_SCREEN_FILE_LENGTH-LEN_FILE_EXTENSION);
char * ext = getFileExtension(reusableBuffer.sdmanager.originalName, sizeof(reusableBuffer.sdmanager.originalName));
if (ext) {
strAppend(&reusableBuffer.sdmanager.lines[i][len], ext);
}
else {
reusableBuffer.sdmanager.lines[i][len] = 0;
}
f_rename(reusableBuffer.sdmanager.originalName, reusableBuffer.sdmanager.lines[i]);
REFRESH_FILES();
}
}
else if (IS_DIRECTORY(reusableBuffer.sdmanager.lines[i])) {
char s[sizeof(reusableBuffer.sdmanager.lines[0])+2];
char * ptr = s;
*ptr++ = '[';