r632 continued. Still needs tests.

This commit is contained in:
bsongis
2012-04-27 08:12:56 +00:00
parent 075fed796b
commit 0aa0f96346
8 changed files with 40 additions and 31 deletions
+19 -20
View File
@@ -539,12 +539,17 @@ const pm_char * eeArchiveModel(uint8_t i_fileSrc)
return SDCARD_ERROR(result); return SDCARD_ERROR(result);
} }
strcpy_P(buf, PSTR(MODELS_PATH "/")); // TODO Not PSTR everywhere ... // check and create folder here
strcpy_P(buf, STR_MODELS_PATH);
result = f_opendir(&archiveFolder, buf);
if (result != FR_OK) {
result = f_mkdir(buf);
if (result != FR_OK)
return SDCARD_ERROR(result);
}
buf[sizeof(MODELS_PATH)-1] = '/';
eeLoadModelName(i_fileSrc, &buf[sizeof(MODELS_PATH)]); eeLoadModelName(i_fileSrc, &buf[sizeof(MODELS_PATH)]);
if(buf[sizeof(MODELS_PATH)] == '\0'){//no model name loaded
strcpy_P(&buf[sizeof(MODELS_PATH)], PSTR("\x0d\x0f\x04\x05\x0c\x18\x18"));//temporary fix as "MODELXX", itoa(i_fileSrc-1) need to be appended
}
buf[sizeof(MODELS_PATH)+sizeof(g_model.name)] = '\0'; buf[sizeof(MODELS_PATH)+sizeof(g_model.name)] = '\0';
uint8_t i = sizeof(MODELS_PATH)+sizeof(g_model.name)-1; uint8_t i = sizeof(MODELS_PATH)+sizeof(g_model.name)-1;
@@ -556,23 +561,16 @@ const pm_char * eeArchiveModel(uint8_t i_fileSrc)
buf[i] = idx2char(buf[i]); buf[i] = idx2char(buf[i]);
i--; i--;
} }
strcpy_P(&buf[len], PSTR(".bin")); // TODO Not PSTR everywhere ...
//check and create folder here if (len == sizeof(MODELS_PATH)) {
//temporary truncate for folder name only uint8_t num = i_fileSrc + 1;
buf[sizeof(MODELS_PATH)-1] = '\0'; strcpy_P(&buf[sizeof(MODELS_PATH)], STR_MODEL);
buf[sizeof(MODELS_PATH) + PSIZE(TR_MODEL)] = (char)((num / 10) + '0');
result = f_opendir(&archiveFolder, buf); buf[sizeof(MODELS_PATH) + PSIZE(TR_MODEL) + 1] = (char)((num % 10) + '0');
if(result != FR_OK){ len = sizeof(MODELS_PATH) + PSIZE(TR_MODEL) + 2;
result = f_mkdir(buf);
if(result != FR_OK){
return SDCARD_ERROR(result);
}
} }
//return back / char to get full model name strcpy_P(&buf[len], STR_MODELS_EXT);
buf[sizeof(MODELS_PATH)-1] = '/';
//folder ready to write here
result = f_open(&archiveFile, buf, FA_OPEN_ALWAYS | FA_WRITE); result = f_open(&archiveFile, buf, FA_OPEN_ALWAYS | FA_WRITE);
if (result != FR_OK) { if (result != FR_OK) {
@@ -609,9 +607,10 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name)
return SDCARD_ERROR(result); return SDCARD_ERROR(result);
} }
strcpy_P(buf, PSTR(MODELS_PATH "/")); // TODO Not PSTR everywhere ... strcpy_P(buf, STR_MODELS_PATH);
buf[sizeof(MODELS_PATH)-1] = '/';
strcpy(&buf[sizeof(MODELS_PATH)], model_name); strcpy(&buf[sizeof(MODELS_PATH)], model_name);
strcpy_P(&buf[strlen(buf)], PSTR(".bin")); // TODO Not PSTR everywhere ... strcpy_P(&buf[strlen(buf)], STR_MODELS_EXT);
result = f_open(&restoreFile, buf, FA_OPEN_EXISTING | FA_READ); result = f_open(&restoreFile, buf, FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK) { if (result != FR_OK) {
+5 -5
View File
@@ -50,11 +50,11 @@ void initLogs()
if (g_oLogFile.fs) f_close(&g_oLogFile); if (g_oLogFile.fs) f_close(&g_oLogFile);
g_logState = 0; g_logState = 0;
strcpy_P(g_logFilename, PSTR(LOG_PATH "/M00_000.CSV")); strcpy_P(g_logFilename, PSTR(LOGS_PATH "/M00_000.CSV"));
// Set log file model number // Set log file model number
uint8_t num = g_eeGeneral.currModel + 1; uint8_t num = g_eeGeneral.currModel + 1;
char *n = &g_logFilename[sizeof(LOG_PATH) + 3]; char *n = &g_logFilename[sizeof(LOGS_PATH) + 3];
*n = (char)((num % 10) + '0'); *n = (char)((num % 10) + '0');
*(--n) = (char)((num / 10) + '0'); *(--n) = (char)((num / 10) + '0');
@@ -87,7 +87,7 @@ void initLogs()
f_close(&g_oLogFile); f_close(&g_oLogFile);
// bump log file counter (file extension) // bump log file counter (file extension)
n = &g_logFilename[sizeof(LOG_PATH) + 7]; n = &g_logFilename[sizeof(LOGS_PATH) + 7];
if (++*n > '9') if (++*n > '9')
{ {
*n='0'; *n='0';
@@ -110,10 +110,10 @@ void initLogs()
} }
else if (result == FR_NO_PATH) else if (result == FR_NO_PATH)
{ {
if (f_mkdir(LOG_PATH) != FR_OK) if (f_mkdir(LOGS_PATH) != FR_OK)
{ {
g_logState = -result; g_logState = -result;
g_logError = PSTR("Check " LOG_PATH " folder"); g_logError = PSTR("Check " LOGS_PATH " folder");
return; return;
} }
} }
@@ -31,12 +31,14 @@
* *
*/ */
#ifndef LOGS_H #ifndef sdcard_h
#define LOGS_H #define sdcard_h
#define LOG_PATH "/9XLOGS" // no trailing slash = important #define LOGS_PATH "/9XLOGS" // no trailing slash = important
#define MODELS_PATH "/9XMODELS" #define MODELS_PATH "/9XMODELS"
#define MODELS_EXT ".bin"
extern char g_logFilename[21]; // "/9XLOGS/M00_000.CSV\0" max required length = 21 extern char g_logFilename[21]; // "/9XLOGS/M00_000.CSV\0" max required length = 21
extern int8_t g_logState; // 0=closed, >0 = opened, <0 is error extern int8_t g_logState; // 0=closed, >0 = opened, <0 is error
extern FATFS g_FATFS_Obj; extern FATFS g_FATFS_Obj;
+2
View File
@@ -193,6 +193,8 @@ extern const char *s_menu[MENU_MAX_LINES];
extern char s_bss_menu[MENU_MAX_LINES*MENU_LINE_LENGTH]; extern char s_bss_menu[MENU_MAX_LINES*MENU_LINE_LENGTH];
extern uint8_t s_menu_count; extern uint8_t s_menu_count;
extern uint8_t s_menu_flags; extern uint8_t s_menu_flags;
extern uint8_t s_menu_offset;
extern bool s_menu_more;
const char * displayMenu(uint8_t event); const char * displayMenu(uint8_t event);
#endif #endif
+1 -1
View File
@@ -122,7 +122,7 @@ inline int8_t eeFindEmptyModel(uint8_t id, bool down)
return i; return i;
} }
#ifdef SDCARD #if defined(SDCARD)
// TODO to be elsewhere if common to many menus // TODO to be elsewhere if common to many menus
const pm_char * s_sdcard_error = NULL; const pm_char * s_sdcard_error = NULL;
+3
View File
@@ -314,6 +314,9 @@ const pm_char STR_DELETE_MODEL[] PROGMEM = TR_DELETE_MODEL;
const pm_char STR_RESTORE_MODEL[] PROGMEM = TR_RESTORE_MODEL; const pm_char STR_RESTORE_MODEL[] PROGMEM = TR_RESTORE_MODEL;
const pm_char STR_SDCARD_ERROR[] PROGMEM = TR_SDCARD_ERROR; const pm_char STR_SDCARD_ERROR[] PROGMEM = TR_SDCARD_ERROR;
const pm_char STR_NO_SDCARD[] PROGMEM = TR_NO_SDCARD; const pm_char STR_NO_SDCARD[] PROGMEM = TR_NO_SDCARD;
const pm_char STR_LOGS_PATH[] PROGMEM = LOGS_PATH;
const pm_char STR_MODELS_PATH[] PROGMEM = MODELS_PATH;
const pm_char STR_MODELS_EXT[] PROGMEM = MODELS_EXT;
#endif #endif
const pm_uchar font[] PROGMEM = { const pm_uchar font[] PROGMEM = {
+3
View File
@@ -380,6 +380,9 @@ extern const pm_char STR_DELETE_MODEL[];
extern const pm_char STR_RESTORE_MODEL[]; extern const pm_char STR_RESTORE_MODEL[];
extern const pm_char STR_SDCARD_ERROR[]; extern const pm_char STR_SDCARD_ERROR[];
extern const pm_char STR_NO_SDCARD[]; extern const pm_char STR_NO_SDCARD[];
extern const pm_char STR_LOGS_PATH[];
extern const pm_char STR_MODELS_PATH[];
extern const pm_char STR_MODELS_EXT[];
#define STR_UPDATE_LIST STR_DELAYDOWN #define STR_UPDATE_LIST STR_DELAYDOWN
#endif #endif
+1 -1
View File
@@ -830,7 +830,7 @@ extern uint16_t jeti_keys;
#endif #endif
#if defined(SDCARD) #if defined(SDCARD)
#include "logs.h" #include "sdcard.h"
#endif #endif
#if defined(SOMO) #if defined(SOMO)