SD card Models Restore now working!
This commit is contained in:
@@ -577,6 +577,67 @@ const pm_char * eeArchiveModel(uint8_t i_fileSrc)
|
||||
f_close(&archiveFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name)
|
||||
{
|
||||
char *buf = reusableBuffer.model_name;
|
||||
FIL restoreFile;
|
||||
UINT read;
|
||||
|
||||
FRESULT result = f_mount(0, &g_FATFS_Obj);
|
||||
if (result != FR_OK) {
|
||||
return SDCARD_ERROR(result);
|
||||
}
|
||||
|
||||
strcpy_P(buf, PSTR(MODELS_PATH "/")); // TODO Not PSTR everywhere ...
|
||||
strcpy(&buf[sizeof(MODELS_PATH)], model_name);
|
||||
strcpy_P(&buf[strlen(buf)], PSTR(".bin")); // TODO Not PSTR everywhere ...
|
||||
|
||||
result = f_open(&restoreFile, buf, FA_OPEN_EXISTING | FA_READ);
|
||||
if (result != FR_OK) {
|
||||
return SDCARD_ERROR(result);
|
||||
}
|
||||
|
||||
result = f_read(&restoreFile, (uint8_t *)buf, 1, &read);
|
||||
if (result != FR_OK || read != 1) {
|
||||
return SDCARD_ERROR(result);
|
||||
}
|
||||
|
||||
if (buf[0] != g_eeGeneral.myVers) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
theFile.create(FILE_MODEL(i_fileDst), FILE_TYP_MODEL, true);
|
||||
|
||||
do {
|
||||
result = f_read(&restoreFile, (uint8_t *)buf, 15, &read);
|
||||
if (result != FR_OK) {
|
||||
s_sync_write = false;
|
||||
return SDCARD_ERROR(result);
|
||||
}
|
||||
if (read > 0) {
|
||||
theFile.write((uint8_t *)buf, read);
|
||||
if (write_errno() != 0) {
|
||||
s_sync_write = false;
|
||||
return STR_EEPROMOVERFLOW;
|
||||
}
|
||||
}
|
||||
} while (read == 15);
|
||||
|
||||
uint8_t fri=0;
|
||||
if (theFile.m_currBlk && (fri=EeFsGetLink(theFile.m_currBlk)))
|
||||
EeFsSetLink(theFile.m_currBlk, 0);
|
||||
|
||||
if (fri) EeFsFree(fri); //chain in
|
||||
|
||||
eeFs.files[FILE_TMP].size = theFile.m_pos;
|
||||
EFile::swap(theFile.m_fileId, FILE_TMP); // s_sync_write is set to false in swap();
|
||||
|
||||
assert(!theFile.m_write_step);
|
||||
|
||||
f_close(&restoreFile);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RlcFile::writeRlc(uint8_t i_fileId, uint8_t typ, uint8_t*buf, uint16_t i_len, uint8_t sync_write)
|
||||
|
||||
+2
-1
@@ -120,7 +120,7 @@ class EFile
|
||||
|
||||
uint8_t read(uint8_t*buf, uint16_t i_len);
|
||||
|
||||
protected:
|
||||
// protected:
|
||||
|
||||
uint8_t m_fileId; //index of file in directory = filename
|
||||
uint16_t m_pos; //over all filepos
|
||||
@@ -216,6 +216,7 @@ uint16_t evalChkSum();
|
||||
|
||||
#ifdef SDCARD
|
||||
const pm_char * eeArchiveModel(uint8_t i_fileSrc);
|
||||
const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -431,7 +431,7 @@ typedef enum {
|
||||
|
||||
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
|
||||
FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */
|
||||
FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */
|
||||
FRESULT f_read (FIL*, BYTE*, UINT, UINT*); /* Read data from a file */
|
||||
FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
|
||||
FRESULT f_close (FIL*); /* Close an open file object */
|
||||
FRESULT f_opendir (DIR*, const TCHAR*); /* Open an existing directory */
|
||||
|
||||
+23
-25
@@ -425,33 +425,31 @@ void menuProcModelSelect(uint8_t event)
|
||||
if (s_menu_count) {
|
||||
const char * result = displayMenu(event);
|
||||
if (result) {
|
||||
if (s_menu_flags) {
|
||||
// The user choosed a file on SD
|
||||
if (result == STR_LOAD_MODEL || result == STR_CREATE_MODEL) {
|
||||
displayPopup(STR_LOADINGMODEL);
|
||||
eeCheck(true); // force writing of current model data before this is changed
|
||||
if (g_eeGeneral.currModel != sub) {
|
||||
g_eeGeneral.currModel = sub;
|
||||
STORE_GENERALVARS;
|
||||
eeLoadModel(sub);
|
||||
}
|
||||
}
|
||||
else if (result == STR_ARCHIVE_MODEL) {
|
||||
s_sdcard_error = eeArchiveModel(sub);
|
||||
if (!s_sdcard_error)
|
||||
eeDeleteModel(sub); // delete the model, it's archived!
|
||||
}
|
||||
else if (result == STR_RESTORE_MODEL) {
|
||||
if (!listSDcardModels()) {
|
||||
s_sdcard_error = PSTR("No Models on SD");
|
||||
}
|
||||
}
|
||||
else if (result == STR_DELETE_MODEL) {
|
||||
s_warning = STR_DELETEMODEL;
|
||||
}
|
||||
else {
|
||||
if (result == STR_LOAD_MODEL || result == STR_CREATE_MODEL) {
|
||||
displayPopup(STR_LOADINGMODEL);
|
||||
eeCheck(true); // force writing of current model data before this is changed
|
||||
if (g_eeGeneral.currModel != sub) {
|
||||
g_eeGeneral.currModel = sub;
|
||||
STORE_GENERALVARS;
|
||||
eeLoadModel(sub);
|
||||
}
|
||||
}
|
||||
else if (result == STR_ARCHIVE_MODEL) {
|
||||
s_sdcard_error = eeArchiveModel(sub);
|
||||
/* TODO as soon as archive and restore do work! if (!s_sdcard_error)
|
||||
eeDeleteModel(sub); // delete the model, it's archived!
|
||||
*/
|
||||
}
|
||||
else if (result == STR_RESTORE_MODEL) {
|
||||
if (!listSDcardModels()) {
|
||||
s_sdcard_error = PSTR("No Models on SD");
|
||||
}
|
||||
}
|
||||
else if (result == STR_DELETE_MODEL) {
|
||||
s_warning = STR_DELETEMODEL;
|
||||
}
|
||||
// The user choosed a file on SD to restore
|
||||
s_sdcard_error = eeRestoreModel(sub, (char *)result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user