mirror of
https://github.com/opentx/opentx.git
synced 2025-07-24 16:55:20 +03:00
SD File Manager
This commit is contained in:
parent
ef141403bc
commit
fa667dbc78
7 changed files with 187 additions and 4 deletions
|
@ -110,7 +110,7 @@
|
|||
/ enable LFN feature and set _LFN_UNICODE to 1. */
|
||||
|
||||
|
||||
#define _FS_RPATH 0 /* 0 to 2 */
|
||||
#define _FS_RPATH 2 /* 0 to 2 */
|
||||
/* The _FS_RPATH option configures relative path feature.
|
||||
/
|
||||
/ 0: Disable relative path feature and remove related functions.
|
||||
|
|
|
@ -352,7 +352,8 @@ ifeq ($(PCB), V4)
|
|||
CPPSRC += stock/audio.cpp haptic.cpp
|
||||
|
||||
ifeq ($(SDCARD), YES)
|
||||
CPPSRC += gruvin9x/logs.cpp FatFs/fattime.c gruvin9x/rtc.cpp FatFs/ff.c FatFs/option/ccsbcs.c gruvin9x/diskio.cpp
|
||||
CPPSRC += gruvin9x/logs.cpp FatFs/fattime.c gruvin9x/rtc.cpp gruvin9x/diskio.cpp
|
||||
EXTRABOARDSRC += FatFs/ff.c FatFs/option/ccsbcs.c
|
||||
MODS:=${MODS}S
|
||||
endif
|
||||
|
||||
|
|
|
@ -70,4 +70,7 @@ uint16_t getCurrent();
|
|||
extern uint16_t Temperature ; // Raw temp reading
|
||||
extern uint16_t maxTemperature ; // Raw temp reading
|
||||
|
||||
#define strcpy_P strcpy
|
||||
#define strcat_P strcat
|
||||
|
||||
#endif
|
||||
|
|
|
@ -41,6 +41,9 @@ enum EnumTabDiag {
|
|||
e_Setup,
|
||||
#if defined(PCBV4) && defined(SDCARD)
|
||||
e_FrskyTime,
|
||||
#endif
|
||||
#if defined(SDCARD)
|
||||
e_Sd,
|
||||
#endif
|
||||
e_Trainer,
|
||||
e_Vers,
|
||||
|
@ -53,6 +56,9 @@ void menuProcSetup(uint8_t event);
|
|||
#if defined(PCBV4) && defined(SDCARD)
|
||||
void menuProcTime(uint8_t event);
|
||||
#endif
|
||||
#if defined(SDCARD)
|
||||
void menuProcSd(uint8_t event);
|
||||
#endif
|
||||
void menuProcTrainer(uint8_t event);
|
||||
void menuProcDiagVers(uint8_t event);
|
||||
void menuProcDiagKeys(uint8_t event);
|
||||
|
@ -63,6 +69,9 @@ const MenuFuncP_PROGMEM menuTabDiag[] PROGMEM = {
|
|||
menuProcSetup,
|
||||
#if defined(PCBV4) && defined(SDCARD)
|
||||
menuProcTime,
|
||||
#endif
|
||||
#if defined(SDCARD)
|
||||
menuProcSd,
|
||||
#endif
|
||||
menuProcTrainer,
|
||||
menuProcDiagVers,
|
||||
|
@ -504,6 +513,127 @@ void menuProcTime(uint8_t event)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(SDCARD)
|
||||
#if defined(PCBARM) && !defined(SIMU)
|
||||
// TODO rewrite this ...
|
||||
extern uint32_t Cmd_A41_resp;
|
||||
#define OCR_SD_CCS (1UL << 30)
|
||||
#else
|
||||
#define Cmd_A41_resp 0
|
||||
#define OCR_SD_CCS (0)
|
||||
#endif
|
||||
|
||||
const char STR_DELETE_FILE[] = "Delete";
|
||||
const char STR_COPY_FILE[] = "Copy";
|
||||
const char STR_RENAME_FILE[] = "Rename";
|
||||
|
||||
void menuProcSd(uint8_t event)
|
||||
{
|
||||
FILINFO fno;
|
||||
DIR dir;
|
||||
char *fn; /* This function is assuming non-Unicode cfg. */
|
||||
#if _USE_LFN
|
||||
TCHAR lfn[_MAX_LFN + 1];
|
||||
fno.lfname = lfn;
|
||||
fno.lfsize = sizeof(lfn);
|
||||
#endif
|
||||
|
||||
uint8_t _event = event;
|
||||
if (s_menu_count) {
|
||||
event = 0;
|
||||
}
|
||||
|
||||
SIMPLE_MENU(Cmd_A41_resp & OCR_SD_CCS ? PSTR("SD-HC Card") : PSTR("SD Card"), menuTabDiag, e_Sd, 1+reusableBuffer.sd.count);
|
||||
|
||||
s_editMode = 0;
|
||||
|
||||
switch(event) {
|
||||
case EVT_ENTRY:
|
||||
reusableBuffer.sd.offset = 255;
|
||||
break;
|
||||
case EVT_KEY_FIRST(KEY_RIGHT):
|
||||
case EVT_KEY_FIRST(KEY_MENU):
|
||||
{
|
||||
if (m_posVert > 0) {
|
||||
uint8_t index = m_posVert-1-s_pgOfs;
|
||||
if (reusableBuffer.sd.flags[index]) {
|
||||
killEvents(event);
|
||||
f_chdir(reusableBuffer.sd.lines[index]);
|
||||
s_pgOfs = 0;
|
||||
reusableBuffer.sd.offset = 255;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EVT_KEY_LONG(KEY_MENU):
|
||||
killEvents(event);
|
||||
s_menu[s_menu_count++] = STR_DELETE_FILE;
|
||||
s_menu[s_menu_count++] = STR_RENAME_FILE;
|
||||
s_menu[s_menu_count++] = STR_COPY_FILE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (reusableBuffer.sd.offset != s_pgOfs) {
|
||||
memset(reusableBuffer.sd.lines, 0, sizeof(reusableBuffer.sd.lines));
|
||||
reusableBuffer.sd.offset = s_pgOfs;
|
||||
reusableBuffer.sd.count = 0;
|
||||
uint16_t offset = 0;
|
||||
uint8_t count = 0;
|
||||
FRESULT res = f_opendir(&dir, "."); /* Open the directory */
|
||||
if (res == FR_OK) {
|
||||
for (;;) {
|
||||
res = f_readdir(&dir, &fno); /* Read a directory item */
|
||||
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
|
||||
if (fno.fname[0] == '.' && fno.fname[1] == '\0') continue; /* Ignore dot entry */
|
||||
#if _USE_LFN
|
||||
fn = *fno.lfname ? fno.lfname : fno.fname;
|
||||
#else
|
||||
fn = fno.fname;
|
||||
#endif
|
||||
reusableBuffer.sd.count++;
|
||||
if (offset < s_pgOfs) {
|
||||
offset++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (count < 7) {
|
||||
reusableBuffer.sd.flags[count] = (fno.fattrib & AM_DIR);
|
||||
char * line = reusableBuffer.sd.lines[count];
|
||||
memset(line, 0, SD_SCREEN_FILE_LENGTH);
|
||||
for (uint8_t i=0; i<SD_SCREEN_FILE_LENGTH-1 && fn[i]; i++) {
|
||||
line[i] = fn[i];
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i=0; i<7; i++) {
|
||||
uint8_t y = FH+i*FH;
|
||||
uint8_t x = 0;
|
||||
uint8_t attr = (m_posVert-1-s_pgOfs == i ? INVERS : 0);
|
||||
if (reusableBuffer.sd.flags[i]) { lcd_putcAtt(0, y, '[', attr); x += FW; }
|
||||
lcd_putsAtt(x, y, reusableBuffer.sd.lines[i], attr);
|
||||
if (reusableBuffer.sd.flags[i]) { lcd_putcAtt(lcdLastPos, y, ']', attr); }
|
||||
}
|
||||
|
||||
if (s_menu_count) {
|
||||
const char * result = displayMenu(_event);
|
||||
if (result) {
|
||||
uint8_t index = m_posVert-1-s_pgOfs;
|
||||
if (result == STR_DELETE_FILE) {
|
||||
f_unlink(reusableBuffer.sd.lines[index]);
|
||||
strcpy(statusLineMsg, reusableBuffer.sd.lines[index]);
|
||||
strcpy_P(statusLineMsg+min((uint8_t)strlen(statusLineMsg), (uint8_t)13), PSTR(" removed"));
|
||||
showStatusLine();
|
||||
reusableBuffer.sd.offset = s_pgOfs-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void menuProcTrainer(uint8_t event)
|
||||
{
|
||||
uint8_t y;
|
||||
|
|
16
src/open9x.h
16
src/open9x.h
|
@ -890,6 +890,7 @@ enum AUDIO_SOUNDS {
|
|||
#endif
|
||||
|
||||
#if defined(SDCARD)
|
||||
// TODO ailleurs
|
||||
#define FILENAME_MAXLEN 8
|
||||
#include "gruvin9x/sdcard.h"
|
||||
#endif
|
||||
|
@ -899,8 +900,11 @@ enum AUDIO_SOUNDS {
|
|||
#endif
|
||||
|
||||
// Re-useable byte array to save having multiple buffers
|
||||
#define SD_SCREEN_FILE_LENGTH 20
|
||||
union ReusableBuffer
|
||||
{
|
||||
/* 128 bytes on stock */
|
||||
|
||||
#if !defined(PCBARM)
|
||||
uint8_t eefs_buffer[BLOCKS]; // used by EeFsck
|
||||
#endif
|
||||
|
@ -919,6 +923,18 @@ union ReusableBuffer
|
|||
int16_t loVals[7];
|
||||
int16_t hiVals[7];
|
||||
} calib; // used by menuProcDiagCalib
|
||||
|
||||
#if defined(SDCARD)
|
||||
struct
|
||||
{
|
||||
char lines[7][SD_SCREEN_FILE_LENGTH];
|
||||
uint8_t flags[7];
|
||||
uint32_t available;
|
||||
uint8_t level;
|
||||
uint16_t offset;
|
||||
uint16_t count;
|
||||
} sd;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern union ReusableBuffer reusableBuffer;
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
namespace simu {
|
||||
#include <dirent.h>
|
||||
}
|
||||
|
||||
volatile uint8_t pinb=0xff, pinc=0xff, pind, pine=0xff, ping=0xff, pinh=0xff, pinj=0xff, pinl=0;
|
||||
uint8_t portb, portc, porth=0, dummyport;
|
||||
|
@ -306,13 +309,27 @@ FRESULT f_close (FIL*)
|
|||
return FR_OK;
|
||||
}
|
||||
|
||||
FRESULT f_opendir (DIR*, const TCHAR*)
|
||||
FRESULT f_chdir (const TCHAR *name)
|
||||
{
|
||||
chdir(name);
|
||||
return FR_OK;
|
||||
}
|
||||
|
||||
FRESULT f_readdir (DIR*, FILINFO*)
|
||||
FRESULT f_opendir (DIR * rep, const TCHAR * name)
|
||||
{
|
||||
rep->fs = (FATFS *)simu::opendir(name);
|
||||
return FR_OK;
|
||||
}
|
||||
|
||||
FRESULT f_readdir (DIR * rep, FILINFO * fil)
|
||||
{
|
||||
simu::dirent * ent = simu::readdir((simu::DIR *)rep->fs);
|
||||
if (!ent) return FR_NO_FILE;
|
||||
if(ent->d_type == simu::DT_DIR) fil->fattrib = AM_DIR; else fil->fattrib = 0;
|
||||
memset(fil->fname, 0, 13);
|
||||
memset(fil->lfname, 0, SD_SCREEN_FILE_LENGTH);
|
||||
strncpy(fil->fname, ent->d_name, 13-1);
|
||||
strcpy(fil->lfname, ent->d_name);
|
||||
return FR_OK;
|
||||
}
|
||||
|
||||
|
@ -321,5 +338,20 @@ FRESULT f_mkdir (const TCHAR*)
|
|||
return FR_OK;
|
||||
}
|
||||
|
||||
FRESULT f_unlink (const TCHAR*)
|
||||
{
|
||||
return FR_OK;
|
||||
}
|
||||
|
||||
int f_puts (const TCHAR*, FIL*)
|
||||
{
|
||||
return 0; /* Put a string to the file */
|
||||
}
|
||||
|
||||
int f_printf (FIL*, const TCHAR*, ...) /* Put a formatted string to the file */
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t Card_state = 8;
|
||||
#endif
|
||||
|
|
|
@ -142,6 +142,7 @@ extern void rxPdcUsart( void (*pChProcess)(uint8_t x) );
|
|||
#define cli()
|
||||
#define sei()
|
||||
#define strcpy_P strcpy
|
||||
#define strcat_P strcat
|
||||
#define memcpy_P memcpy
|
||||
|
||||
#define PORTA dummyport
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue