5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
31 #define MODELS_PATH ROOT_PATH "MODELS" // no trailing slash = important
32 #define RADIO_PATH ROOT_PATH "RADIO" // no trailing slash = important
33 #define LOGS_PATH ROOT_PATH "LOGS"
34 #define SCREENSHOTS_PATH ROOT_PATH "SCREENSHOTS"
35 #define SOUNDS_PATH ROOT_PATH "SOUNDS/en"
36 #define SOUNDS_PATH_LNG_OFS (sizeof(SOUNDS_PATH)-3)
37 #define SYSTEM_SUBDIR "SYSTEM"
38 #define BITMAPS_PATH ROOT_PATH "IMAGES"
39 #define FIRMWARES_PATH ROOT_PATH "FIRMWARE"
40 #define AUTOUPDATE_FILENAME FIRMWARES_PATH "/autoupdate.frsk"
41 #define EEPROMS_PATH ROOT_PATH "EEPROM"
42 #define SCRIPTS_PATH ROOT_PATH "SCRIPTS"
43 #define WIZARD_PATH SCRIPTS_PATH "/WIZARD"
44 #define THEMES_PATH ROOT_PATH "THEMES"
45 #define LAYOUTS_PATH ROOT_PATH "LAYOUTS"
46 #define WIDGETS_PATH ROOT_PATH "WIDGETS"
47 #define WIZARD_NAME "wizard.lua"
48 #define SCRIPTS_MIXES_PATH SCRIPTS_PATH "/MIXES"
49 #define SCRIPTS_FUNCS_PATH SCRIPTS_PATH "/FUNCTIONS"
50 #define SCRIPTS_TELEM_PATH SCRIPTS_PATH "/TELEMETRY"
51 #define SCRIPTS_TOOLS_PATH SCRIPTS_PATH "/TOOLS"
53 #define LEN_FILE_PATH_MAX (sizeof(SCRIPTS_TELEM_PATH)+1) // longest + "/"
56 const char RADIO_MODELSLIST_PATH
[] = RADIO_PATH
"/models.txt";
57 const char RADIO_SETTINGS_PATH
[] = RADIO_PATH
"/radio.bin";
58 #define SPLASH_FILE "splash.png"
61 #define MODELS_EXT ".bin"
62 #define LOGS_EXT ".csv"
63 #define SOUNDS_EXT ".wav"
64 #define BMP_EXT ".bmp"
65 #define PNG_EXT ".png"
66 #define JPG_EXT ".jpg"
67 #define SCRIPT_EXT ".lua"
68 #define SCRIPT_BIN_EXT ".luac"
69 #define TEXT_EXT ".txt"
70 #define FIRMWARE_EXT ".bin"
71 #define EEPROM_EXT ".bin"
72 #define SPORT_FIRMWARE_EXT ".frk"
73 #define FRSKY_FIRMWARE_EXT ".frsk"
74 #define MULTI_FIRMWARE_EXT ".bin"
76 #define LEN_FILE_EXTENSION_MAX 5 // longest used, including the dot, excluding null term.
79 #define BITMAPS_EXT BMP_EXT JPG_EXT PNG_EXT
80 #define LEN_BITMAPS_EXT 4
82 #define BITMAPS_EXT BMP_EXT
86 #define SCRIPTS_EXT SCRIPT_BIN_EXT SCRIPT_EXT
88 #define SCRIPTS_EXT SCRIPT_EXT
91 #define GET_FILENAME(filename, path, var, ext) \
92 char filename[sizeof(path) + sizeof(var) + sizeof(ext)]; \
93 memcpy(filename, path, sizeof(path) - 1); \
94 filename[sizeof(path) - 1] = '/'; \
95 memcpy(&filename[sizeof(path)], var, sizeof(var)); \
96 filename[sizeof(path)+sizeof(var)] = '\0'; \
97 strcat(&filename[sizeof(path)], ext)
99 extern FATFS g_FATFS_Obj
;
100 extern FIL g_oLogFile
;
102 extern uint8_t logDelay
;
108 uint32_t sdGetNoSectors();
109 uint32_t sdGetSize();
110 uint32_t sdGetFreeSectors();
111 const char * sdCheckAndCreateDirectory(const char * path
);
114 inline const char * SDCARD_ERROR(FRESULT result
)
116 if (result
== FR_NOT_READY
)
117 return STR_NO_SDCARD
;
119 return STR_SDCARD_ERROR
;
123 // NOTE: 'size' must = 0 or be a valid character position within 'filename' array -- it is NOT validated
124 const char * getFileExtension(const char * filename
, uint8_t size
=0, uint8_t extMaxLen
=0, uint8_t * fnlen
=nullptr, uint8_t * extlen
=nullptr);
125 const char * getBasename(const char * path
);
128 #define OTX_FOURCC 0x3478746F // otx for X12S
129 #elif defined(RADIO_T16)
130 #define OTX_FOURCC 0x3F78746F // otx for Jumper T16
131 #elif defined(PCBX10)
132 #define OTX_FOURCC 0x3778746F // otx for X10
133 #elif defined(PCBX9E)
134 #define OTX_FOURCC 0x3578746F // otx for Taranis X9E
135 #elif defined(PCBXLITES)
136 #define OTX_FOURCC 0x3B78746F // otx for Taranis X-Lite S
137 #elif defined(PCBXLITE)
138 #define OTX_FOURCC 0x3978746F // otx for Taranis X-Lite
139 #elif defined(RADIO_X7)
140 #define OTX_FOURCC 0x3678746F // otx for Taranis X7
141 #elif defined(PCBX9LITES)
142 #define OTX_FOURCC 0x3E78746F // otx for Taranis X9-Lite
143 #elif defined(PCBX9LITE)
144 #define OTX_FOURCC 0x3C78746F // otx for Taranis X9-Lite
145 #elif defined(PCBX9D) || defined(PCBX9DP)
146 #define OTX_FOURCC 0x3378746F // otx for Taranis X9D
147 #elif defined(PCBSKY9X)
148 #define OTX_FOURCC 0x3278746F // otx for sky9x
149 #elif defined(RADIO_T12)
150 #define OTX_FOURCC 0x3D78746F // otx for Jumper T12
153 bool isFileAvailable(const char * filename
, bool exclDir
= false);
154 int findNextFileIndex(char * filename
, uint8_t size
, const char * directory
);
155 bool isExtensionMatching(const char * extension
, const char * pattern
, char * match
= nullptr);
157 const char * sdCopyFile(const char * src
, const char * dest
);
158 const char * sdCopyFile(const char * srcFilename
, const char * srcDir
, const char * destFilename
, const char * destDir
);
160 #define LIST_NONE_SD_FILE 1
161 #define LIST_SD_FILE_EXT 2
162 bool sdListFiles(const char * path
, const char * extension
, const uint8_t maxlen
, const char * selection
, uint8_t flags
=0);
164 void sdReadTextFile(const char * filename
, char lines
[NUM_BODY_LINES
][LCD_COLS
+ 1], int & lines_count
);
167 FRESULT
sdReadDir(DIR * dir
, FILINFO
* fno
, bool & firstTime
);