mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-09-14 14:13:12 +08:00
Add SHARED SD support
Note: need webUI 3.0.0.75+ Fix several warnings in code and libs
This commit is contained in:
parent
568fee6087
commit
71a4f25edf
@ -456,13 +456,6 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->print ("\"}");
|
||||
#endif //SENSOR_DEVICE
|
||||
#ifdef SD_DEVICE
|
||||
//Direct SD
|
||||
output->print(",{\"F\":\"device/sd\",\"P\":\"");
|
||||
output->print(ESP_SD_DEVICE_TYPE);
|
||||
output->print("\",\"T\":\"B\",\"V\":\"");
|
||||
output->print (Settings_ESP3D::read_byte(ESP_SD_DEVICE_TYPE));
|
||||
//hard coded for readibility but should use ESP_NO_SD / ESP_DIRECT_SD / ESP_SHARED_SD
|
||||
output->print("\",\"H\":\"type\",\"O\":[{\"none\":\"0\"},{\"direct\":\"1\"},{\"shared\":\"2\"}]}");
|
||||
//SPI SD Divider
|
||||
output->print(",{\"F\":\"device/sd\",\"P\":\"");
|
||||
output->print(ESP_SD_SPEED_DIV);
|
||||
|
@ -79,9 +79,6 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
|
||||
break;
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
#ifdef SD_DEVICE
|
||||
case ESP_SD_DEVICE_TYPE:
|
||||
Settings_ESP3D::GetSDDevice(true);
|
||||
break;
|
||||
case ESP_SD_SPEED_DIV:
|
||||
ESP_SD::setSPISpeedDivider(sval.toInt());
|
||||
break;
|
||||
|
@ -41,6 +41,7 @@ bool Commands::ESP715(const char* cmd_params, level_authenticate_type auth_type,
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
{
|
||||
if (parameter == "FORMATSD") {
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
output->printMSG("Start Formating");
|
||||
if (ESP_SD::format(output)) {
|
||||
output->printMSG("Format Done");
|
||||
@ -48,6 +49,9 @@ bool Commands::ESP715(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printERROR ("Format failed!");
|
||||
response = false;
|
||||
}
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
} else {
|
||||
output->printERROR ("Invalid parameter!");
|
||||
response = false;
|
||||
|
@ -56,6 +56,7 @@ bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printERROR ("Busy");
|
||||
return false;
|
||||
}
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
output->printf("Directory on SD : %s", parameter.c_str());
|
||||
output->printLN("");
|
||||
if (ESP_SD::exists(parameter.c_str())) {
|
||||
@ -112,6 +113,9 @@ bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printERROR ("Invalid directory!");
|
||||
response = false;
|
||||
}
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -53,45 +53,62 @@ bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type,
|
||||
}
|
||||
parameter = get_param (cmd_params, "mkdir=");
|
||||
if (parameter.length() != 0) {
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
if (ESP_SD::mkdir(parameter.c_str())) {
|
||||
output->printMSG ("ok");
|
||||
} else {
|
||||
output->printERROR ("failed!");
|
||||
response = false;
|
||||
}
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
parameter = get_param (cmd_params, "rmdir=");
|
||||
if (parameter.length() != 0) {
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
if (ESP_SD::rmdir(parameter.c_str())) {
|
||||
output->printMSG ("ok");
|
||||
} else {
|
||||
output->printERROR ("failed!");
|
||||
response = false;
|
||||
}
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
parameter = get_param (cmd_params, "remove=");
|
||||
if (parameter.length() != 0) {
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
if (ESP_SD::remove(parameter.c_str())) {
|
||||
output->printMSG ("ok");
|
||||
} else {
|
||||
output->printERROR ("failed!");
|
||||
response = false;
|
||||
}
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
parameter = get_param (cmd_params, "exists=");
|
||||
if (parameter.length() != 0) {
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
if (ESP_SD::exists(parameter.c_str())) {
|
||||
output->printMSG ("yes");
|
||||
} else {
|
||||
output->printMSG ("no");
|
||||
}
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
parameter = get_param (cmd_params, "create=");
|
||||
if (parameter.length() != 0) {
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
ESP_SDFile f = ESP_SD::open(parameter.c_str(), ESP_FILE_WRITE);
|
||||
if (f.isOpen()) {
|
||||
f.close();
|
||||
@ -100,6 +117,9 @@ bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printERROR ("failed!");
|
||||
response = false;
|
||||
}
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
output->printERROR ("Incorrect command!");
|
||||
|
@ -174,7 +174,6 @@ const uint8_t DEFAULT_ADDRESS_VALUE[] = {0, 0, 0, 0};
|
||||
#endif //WIFI_FEATURE || ETH_FEATURE
|
||||
|
||||
uint8_t Settings_ESP3D::_FirmwareTarget = UNKNOWN_FW;
|
||||
bool Settings_ESP3D::_SDdevice = ESP_NO_SD;
|
||||
|
||||
bool Settings_ESP3D::begin()
|
||||
{
|
||||
@ -183,8 +182,6 @@ bool Settings_ESP3D::begin()
|
||||
}
|
||||
//get target FW
|
||||
Settings_ESP3D::GetFirmwareTarget(true);
|
||||
//get SD device if any
|
||||
Settings_ESP3D::GetSDDevice(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -196,16 +193,13 @@ uint8_t Settings_ESP3D::GetFirmwareTarget(bool fromsettings)
|
||||
return _FirmwareTarget;
|
||||
}
|
||||
|
||||
uint8_t Settings_ESP3D::GetSDDevice(bool fromsettings)
|
||||
uint8_t Settings_ESP3D::GetSDDevice()
|
||||
{
|
||||
if(fromsettings) {
|
||||
#ifdef SD_DEVICE
|
||||
_SDdevice = read_byte (ESP_SD_DEVICE_TYPE);
|
||||
return SD_DEVICE_CONNECTION;
|
||||
#else // !SD_DEVICE
|
||||
_SDdevice = ESP_NO_SD;
|
||||
return ESP_NO_SD;
|
||||
#endif //SD_DEVICE
|
||||
}
|
||||
return _SDdevice;
|
||||
}
|
||||
|
||||
const char* Settings_ESP3D::GetFirmwareTargetShortName()
|
||||
|
@ -127,7 +127,7 @@ public:
|
||||
static bool reset();
|
||||
static int8_t GetSettingsVersion();
|
||||
static uint8_t GetFirmwareTarget(bool fromsettings = false);
|
||||
static uint8_t GetSDDevice(bool fromsettings = false);
|
||||
static uint8_t GetSDDevice();
|
||||
static const char* GetFirmwareTargetShortName();
|
||||
static String IPtoString(uint32_t ip_int);
|
||||
static uint32_t StringtoIP(const char *s);
|
||||
@ -136,7 +136,6 @@ public:
|
||||
private:
|
||||
static bool is_string(const char * s, uint len);
|
||||
static uint8_t _FirmwareTarget;
|
||||
static bool _SDdevice;
|
||||
};
|
||||
|
||||
|
||||
|
@ -51,9 +51,19 @@
|
||||
#define UI_MONOCHROME 2
|
||||
|
||||
//SD connection
|
||||
#define ESP_NO_SD 0
|
||||
#define ESP_DIRECT_SD 1
|
||||
#define ESP_SHARED_SD 2
|
||||
#define ESP_NO_SD 0
|
||||
#define ESP_DIRECT_SD 1
|
||||
#define ESP_SHARED_SD 2
|
||||
|
||||
//Upload type
|
||||
#define ESP_UPLOAD_DIRECT_SD 1
|
||||
#define ESP_UPLOAD_SHARED_SD 2
|
||||
#define ESP_UPLOAD_SERIAL_SD 3
|
||||
#define ESP_UPLOAD_FAST_SERIAL_SD 4
|
||||
#define ESP_UPLOAD_FAST_SERIAL_USB 5
|
||||
#define ESP_UPLOAD_DIRECT_USB 6
|
||||
|
||||
|
||||
|
||||
//SD mount point
|
||||
#define ESP_SD_ROOT 1
|
||||
|
@ -202,14 +202,21 @@
|
||||
#define ESP_SD_SCK_PIN -1
|
||||
#endif //ESP_SD_SCK_PIN
|
||||
|
||||
// For SDIO Connect the SD card to the following pins:
|
||||
//SD Card | ESP32
|
||||
// D2 12
|
||||
// D3 13
|
||||
// CMD 15
|
||||
// VSS GND
|
||||
// VDD 3.3V
|
||||
// CLK 14
|
||||
// VSS GND
|
||||
// D0 2 (add 1K pull up after flashing)
|
||||
// D1 4
|
||||
#ifndef ESP_SD_DETECT_PIN
|
||||
#define ESP_SD_DETECT_PIN -1
|
||||
#endif //ESP_SD_DETECT_PIN
|
||||
|
||||
#if defined (PIN_RESET_FEATURE) && !defined(ESP3D_RESET_PIN)
|
||||
#define ESP3D_RESET_PIN 0
|
||||
#endif //PIN_RESET_FEATURE
|
||||
|
||||
#ifdef SD_DEVICE_CONNECTION
|
||||
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||
#ifndef ESP_FLAG_SHARED_SD_PIN
|
||||
#define ESP_FLAG_SHARED_SD_PIN 0
|
||||
#endif //ESP_PIN_SHARED_SD
|
||||
#ifndef ESP_FLAG_SHARED_SD_VALUE
|
||||
#define ESP_FLAG_SHARED_SD_VALUE 0
|
||||
#endif //ESP_FLAG_SHARED_SD_VALUE
|
||||
#endif //SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||
#endif //SD_DEVICE_CONNECTION
|
||||
|
@ -113,7 +113,7 @@
|
||||
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD && ESP_FLAG_SHARED_SD_PIN == ESP3D_RESET_PIN
|
||||
#error ESP_FLAG_SHARED_SD_PIN and ESP3D_RESET_PIN are same, it is not allowed.
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**************************
|
||||
* FTP
|
||||
|
@ -22,7 +22,7 @@
|
||||
#define _VERSION_ESP3D_H
|
||||
|
||||
//version and sources location
|
||||
#define FW_VERSION "3.0.0.a69"
|
||||
#define FW_VERSION "3.0.0.a70"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
||||
|
||||
#endif //_VERSION_ESP3D_H
|
||||
|
@ -69,7 +69,13 @@ uint64_t ESP_GBFS::totalBytes(uint8_t FS)
|
||||
#endif //FILESYSTEM_FEATURE
|
||||
#ifdef SD_DEVICE
|
||||
if(FS == FS_SD) {
|
||||
return ESP_SD::totalBytes();
|
||||
uint64_t size = 0;
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
size =ESP_SD::totalBytes();
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
#endif //SD_DEVICE
|
||||
return 0;
|
||||
@ -84,7 +90,13 @@ uint64_t ESP_GBFS::usedBytes(uint8_t FS)
|
||||
#endif //FILESYSTEM_FEATURE
|
||||
#ifdef SD_DEVICE
|
||||
if(FS == FS_SD) {
|
||||
return ESP_SD::usedBytes();
|
||||
uint64_t size = 0;
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
size = ESP_SD::usedBytes();
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
#endif //SD_DEVICE
|
||||
return 0;
|
||||
@ -99,7 +111,13 @@ uint64_t ESP_GBFS::freeBytes(uint8_t FS)
|
||||
#endif //FILESYSTEM_FEATURE
|
||||
#ifdef SD_DEVICE
|
||||
if(FS == FS_SD) {
|
||||
return ESP_SD::freeBytes();
|
||||
uint64_t size = 0;
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
size = ESP_SD::freeBytes();
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
#endif //SD_DEVICE
|
||||
return 0;
|
||||
@ -115,7 +133,13 @@ bool format(uint8_t FS, ESP3DOutput * output = nullptr)
|
||||
#endif //FILESYSTEM_FEATURE
|
||||
#ifdef SD_DEVICE
|
||||
if(FS == FS_SD) {
|
||||
return ESP_SD::format(output);
|
||||
bool res = false;
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
res = ESP_SD::format(output);
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif //SD_DEVICE
|
||||
output->printERROR("Not available");
|
||||
@ -189,7 +213,13 @@ bool ESP_GBFS::exists(const char* path)
|
||||
#endif //FILESYSTEM_FEATURE
|
||||
#if defined (SD_DEVICE)
|
||||
if (t == FS_SD) {
|
||||
return ESP_SD::exists(getRealPath(path));
|
||||
bool res = false;
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
res = ESP_SD::exists(getRealPath(path));
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif //SD_DEVICE
|
||||
#endif // FILESYSTEM_FEATURE || SD_DEVICE
|
||||
@ -210,7 +240,13 @@ bool ESP_GBFS::remove(const char *path)
|
||||
#endif //FILESYSTEM_FEATURE
|
||||
#if defined (SD_DEVICE)
|
||||
if (t == FS_SD) {
|
||||
return ESP_SD::remove(getRealPath(path));
|
||||
bool res = false;
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
res = ESP_SD::remove(getRealPath(path));
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif //SD_DEVICE
|
||||
#endif // FILESYSTEM_FEATURE || SD_DEVICE
|
||||
@ -231,7 +267,13 @@ bool ESP_GBFS::rename(const char *oldpath, const char *newpath)
|
||||
#endif //FILESYSTEM_FEATURE
|
||||
#if defined (SD_DEVICE)
|
||||
if (t == FS_SD) {
|
||||
return ESP_SD::rename(getRealPath(oldpath), getRealPath(newpath));
|
||||
bool res = false;
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
res = ESP_SD::rename(getRealPath(oldpath), getRealPath(newpath));
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif //SD_DEVICE
|
||||
#endif // FILESYSTEM_FEATURE || SD_DEVICE
|
||||
@ -247,12 +289,18 @@ bool ESP_GBFS::mkdir(const char *path)
|
||||
}
|
||||
#if defined (FILESYSTEM_FEATURE)
|
||||
if (t == FS_FLASH) {
|
||||
return ESP_FileSystem::mkdir(getRealPath(path));
|
||||
return ESP_FileSystem::mkdir(getRealPath(path));;
|
||||
}
|
||||
#endif //FILESYSTEM_FEATURE
|
||||
#if defined (SD_DEVICE)
|
||||
if (t == FS_SD) {
|
||||
return ESP_SD::mkdir(getRealPath(path));
|
||||
bool res = false;
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
res = ESP_SD::mkdir(getRealPath(path));
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif //SD_DEVICE
|
||||
#endif // FILESYSTEM_FEATURE || SD_DEVICE
|
||||
@ -273,7 +321,13 @@ bool ESP_GBFS::rmdir(const char *path)
|
||||
#endif //FILESYSTEM_FEATURE
|
||||
#if defined (SD_DEVICE)
|
||||
if (t == FS_SD) {
|
||||
return ESP_SD::rmdir(getRealPath(path));
|
||||
bool res = false;
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
res = ESP_SD::rmdir(getRealPath(path));
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif //SD_DEVICE
|
||||
#endif // FILESYSTEM_FEATURE || SD_DEVICE
|
||||
|
@ -48,6 +48,25 @@ uint8_t ESP_SD::setState(uint8_t flag)
|
||||
return _state;
|
||||
}
|
||||
|
||||
bool ESP_SD::accessSD()
|
||||
{
|
||||
bool res = false;
|
||||
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||
//need to send the current state to avoid
|
||||
res = (digitalRead(ESP_FLAG_SHARED_SD_PIN) == ESP_FLAG_SHARED_SD_VALUE);
|
||||
if (!res) {
|
||||
digitalWrite(ESP_FLAG_SHARED_SD_PIN, ESP_FLAG_SHARED_SD_VALUE);
|
||||
}
|
||||
#endif //SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||
return res;
|
||||
}
|
||||
void ESP_SD::releaseSD()
|
||||
{
|
||||
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||
digitalWrite(ESP_FLAG_SHARED_SD_PIN, !ESP_FLAG_SHARED_SD_VALUE);
|
||||
#endif //SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||
}
|
||||
|
||||
|
||||
void ESP_SD::handle()
|
||||
{
|
||||
|
@ -67,6 +67,8 @@ class ESP_SD
|
||||
public:
|
||||
static String & formatBytes (uint64_t bytes);
|
||||
static bool begin();
|
||||
static bool accessSD();
|
||||
static void releaseSD();
|
||||
static void handle();
|
||||
static void end();
|
||||
static uint8_t getState(bool refresh);
|
||||
|
@ -52,6 +52,7 @@ uint8_t ESP_SD::getState(bool refresh)
|
||||
|
||||
SD.end();
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
bool isactive = accessSD();
|
||||
//using default value for speed ? should be parameter
|
||||
//refresh content if card was removed
|
||||
log_esp3d("Spi : CS: %d, Miso: %d, Mosi: %d, SCK: %d",ESP_SD_CS_PIN!=-1?ESP_SD_CS_PIN:SS, ESP_SD_MISO_PIN!=-1?ESP_SD_MISO_PIN:MISO, ESP_SD_MOSI_PIN!=-1?ESP_SD_MOSI_PIN:MOSI, ESP_SD_SCK_PIN!=-1?ESP_SD_SCK_PIN:SCK);
|
||||
@ -60,6 +61,9 @@ uint8_t ESP_SD::getState(bool refresh)
|
||||
_state = ESP_SDCARD_IDLE;
|
||||
}
|
||||
}
|
||||
if (!isactive) {
|
||||
releaseSD();
|
||||
}
|
||||
return _state;
|
||||
}
|
||||
|
||||
@ -76,6 +80,16 @@ bool ESP_SD::begin()
|
||||
if (_spi_speed_divider <= 0) {
|
||||
_spi_speed_divider = 1;
|
||||
}
|
||||
//Setup pins
|
||||
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
||||
pinMode (ESP_SD_DETECT_PIN, INPUT);
|
||||
#endif //ESP_SD_DETECT_PIN
|
||||
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||
#if defined(ESP_FLAG_SHARED_SD_PIN) && ESP_FLAG_SHARED_SD_PIN != -1
|
||||
pinMode (ESP_FLAG_SHARED_SD_PIN, OUTPUT);
|
||||
digitalWrite(ESP_FLAG_SHARED_SD_PIN, !ESP_FLAG_SHARED_SD_VALUE);
|
||||
#endif //ESP_FLAG_SHARED_SD_PIN
|
||||
#endif //SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||
return _started;
|
||||
}
|
||||
|
||||
|
@ -73,24 +73,40 @@ uint8_t ESP_SD::getState(bool refresh)
|
||||
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
||||
//no need to go further if SD detect is not correct
|
||||
if (!((digitalRead (ESP_SD_DETECT_PIN) == ESP_SD_DETECT_VALUE) ? true : false)) {
|
||||
log_esp3d("No SD State %d vs %d", digitalRead (ESP_SD_DETECT_PIN), ESP_SD_DETECT_VALUE);
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
return _state;
|
||||
} else {
|
||||
log_esp3d("SD Detect Pin ok");
|
||||
}
|
||||
#endif //ESP_SD_DETECT_PIN
|
||||
//if busy doing something return state
|
||||
if (!((_state == ESP_SDCARD_NOT_PRESENT) || _state == ESP_SDCARD_IDLE)) {
|
||||
log_esp3d("Busy SD State");
|
||||
return _state;
|
||||
}
|
||||
if (!refresh) {
|
||||
log_esp3d("SD State cache is %d", _state);
|
||||
return _state; //to avoid refresh=true + busy to reset SD and waste time
|
||||
}
|
||||
//SD is idle or not detected, let see if still the case
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
bool isactive = accessSD();
|
||||
//refresh content if card was removed
|
||||
if (SD.begin((ESP_SD_CS_PIN == -1)?SS:ESP_SD_CS_PIN, SD_SCK_HZ(F_CPU/_spi_speed_divider))) {
|
||||
log_esp3d("Init SD State ok");
|
||||
if (SD.card()->cardSize() > 0 ) {
|
||||
log_esp3d("SD available");
|
||||
_state = ESP_SDCARD_IDLE;
|
||||
} else {
|
||||
log_esp3d("Cannot get card size");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("Init SD State failed");
|
||||
}
|
||||
log_esp3d("SD State is %d", _state);
|
||||
if (!isactive) {
|
||||
releaseSD();
|
||||
}
|
||||
return _state;
|
||||
}
|
||||
@ -108,9 +124,16 @@ bool ESP_SD::begin()
|
||||
//set callback to get time on files on SD
|
||||
SdFile::dateTimeCallback (dateTime);
|
||||
#endif //SD_TIMESTAMP_FEATURE
|
||||
if (getState(true) == ESP_SDCARD_IDLE) {
|
||||
freeBytes();
|
||||
}
|
||||
//Setup pins
|
||||
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
||||
pinMode (ESP_SD_DETECT_PIN, INPUT);
|
||||
#endif //ESP_SD_DETECT_PIN
|
||||
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||
#if defined(ESP_FLAG_SHARED_SD_PIN) && ESP_FLAG_SHARED_SD_PIN != -1
|
||||
pinMode (ESP_FLAG_SHARED_SD_PIN, OUTPUT);
|
||||
digitalWrite(ESP_FLAG_SHARED_SD_PIN, !ESP_FLAG_SHARED_SD_VALUE);
|
||||
#endif //ESP_FLAG_SHARED_SD_PIN
|
||||
#endif //SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||
return _started;
|
||||
}
|
||||
|
||||
@ -155,7 +178,7 @@ bool ESP_SD::rename(const char *oldpath, const char *newpath)
|
||||
// constants for file system structure
|
||||
#define BU16 128
|
||||
#define BU32 8192
|
||||
#define ERASE_SIZE 262144L;
|
||||
#define ERASE_SIZE 262144L
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// write cached block to the card
|
||||
@ -309,7 +332,7 @@ uint32_t volSerialNumber(uint32_t cardSizeBlocks)
|
||||
}
|
||||
|
||||
// format the SD as FAT16
|
||||
bool makeFat16(uint32_t & dataStart, Sd2Card & card, cache_t & cache, uint8_t numberOfHeads, uint8_t sectorsPerTrack, uint32_t cardSizeBlocks, uint8_t sectorsPerCluster, uint32_t &relSector, uint32_t partSize, uint8_t & partType, uint32_t &fatSize, uint32_t &fatStart, uint16_t reservedSectors, ESP3DOutput * output)
|
||||
bool makeFat16(uint32_t & dataStart, Sd2Card & card, cache_t & cache, uint8_t numberOfHeads, uint8_t sectorsPerTrack, uint32_t cardSizeBlocks, uint8_t sectorsPerCluster, uint32_t &relSector, uint8_t & partType, uint32_t &fatSize, uint32_t &fatStart, ESP3DOutput * output)
|
||||
{
|
||||
uint32_t nc;
|
||||
for (dataStart = 2 * BU16;; dataStart += BU16) {
|
||||
@ -326,9 +349,9 @@ bool makeFat16(uint32_t & dataStart, Sd2Card & card, cache_t & cache, uint8_t nu
|
||||
if (nc < 4085 || nc >= 65525) {
|
||||
return false;
|
||||
}
|
||||
reservedSectors = 1;
|
||||
uint16_t reservedSectors = 1;
|
||||
fatStart = relSector + reservedSectors;
|
||||
partSize = nc * sectorsPerCluster + 2 * fatSize + reservedSectors + 32;
|
||||
uint32_t partSize = nc * sectorsPerCluster + 2 * fatSize + reservedSectors + 32;
|
||||
if (partSize < 32680) {
|
||||
partType = 0X01;
|
||||
} else if (partSize < 65536) {
|
||||
@ -382,7 +405,7 @@ bool makeFat16(uint32_t & dataStart, Sd2Card & card, cache_t & cache, uint8_t nu
|
||||
}
|
||||
|
||||
// format the SD as FAT32
|
||||
bool makeFat32(uint32_t & dataStart, Sd2Card & card, cache_t & cache, uint8_t numberOfHeads, uint8_t sectorsPerTrack, uint32_t cardSizeBlocks, uint8_t sectorsPerCluster, uint32_t &relSector, uint32_t partSize, uint8_t & partType, uint32_t &fatSize, uint32_t &fatStart, uint16_t reservedSectors, ESP3DOutput * output)
|
||||
bool makeFat32(uint32_t & dataStart, Sd2Card & card, cache_t & cache, uint8_t numberOfHeads, uint8_t sectorsPerTrack, uint32_t cardSizeBlocks, uint8_t sectorsPerCluster, uint32_t &relSector, uint8_t & partType, uint32_t &fatSize, uint32_t &fatStart, ESP3DOutput * output)
|
||||
{
|
||||
uint32_t nc;
|
||||
relSector = BU32;
|
||||
@ -398,9 +421,9 @@ bool makeFat32(uint32_t & dataStart, Sd2Card & card, cache_t & cache, uint8_t nu
|
||||
if (nc < 65525) {
|
||||
return false;
|
||||
}
|
||||
reservedSectors = dataStart - relSector - 2 * fatSize;
|
||||
uint16_t reservedSectors = dataStart - relSector - 2 * fatSize;
|
||||
fatStart = relSector + reservedSectors;
|
||||
partSize = nc * sectorsPerCluster + dataStart - relSector;
|
||||
uint32_t partSize = nc * sectorsPerCluster + dataStart - relSector;
|
||||
// type depends on address of end sector
|
||||
// max CHS has lbn = 16450560 = 1024*255*63
|
||||
if ((relSector + partSize) <= 16450560) {
|
||||
@ -478,7 +501,6 @@ bool eraseCard(Sd2Card & card, cache_t & cache, uint32_t cardSizeBlocks, ESP3DOu
|
||||
{
|
||||
uint32_t firstBlock = 0;
|
||||
uint32_t lastBlock;
|
||||
uint16_t n = 0;
|
||||
if (output) {
|
||||
output->printMSG("Erasing ", false);
|
||||
}
|
||||
@ -506,26 +528,31 @@ bool eraseCard(Sd2Card & card, cache_t & cache, uint32_t cardSizeBlocks, ESP3DOu
|
||||
}
|
||||
|
||||
bool formatCard(uint32_t & dataStart, Sd2Card & card,
|
||||
cache_t & cache, uint8_t numberOfHeads,
|
||||
uint8_t sectorsPerTrack, uint32_t cardSizeBlocks,
|
||||
uint8_t sectorsPerCluster, uint32_t &relSector,
|
||||
uint32_t partSize, uint8_t & partType,
|
||||
cache_t & cache, uint32_t cardSizeBlocks,
|
||||
uint32_t &relSector,
|
||||
uint8_t & partType,
|
||||
uint32_t &fatSize, uint32_t &fatStart,
|
||||
uint32_t cardCapacityMB, uint16_t reservedSectors, ESP3DOutput * output)
|
||||
uint32_t cardCapacityMB, ESP3DOutput * output)
|
||||
{
|
||||
// Fake disk geometry
|
||||
uint8_t numberOfHeads;
|
||||
uint8_t sectorsPerTrack;
|
||||
// FAT parameters
|
||||
uint8_t sectorsPerCluster;
|
||||
|
||||
initSizes(cardCapacityMB, sectorsPerCluster, numberOfHeads, sectorsPerTrack);
|
||||
if (card.type() != SD_CARD_TYPE_SDHC) {
|
||||
if (output) {
|
||||
output->printMSG("Formating FAT16 ");
|
||||
}
|
||||
if(!makeFat16(dataStart, card, cache, numberOfHeads, sectorsPerTrack, cardSizeBlocks, sectorsPerCluster, relSector, partSize, partType, fatSize, fatStart, reservedSectors, output)) {
|
||||
if(!makeFat16(dataStart, card, cache, numberOfHeads, sectorsPerTrack, cardSizeBlocks, sectorsPerCluster, relSector, partType, fatSize, fatStart, output)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (output) {
|
||||
output->printMSG("Formating FAT32 ", false);
|
||||
}
|
||||
if(!makeFat32(dataStart, card, cache, numberOfHeads, sectorsPerTrack, cardSizeBlocks, sectorsPerCluster, relSector, partSize, partType, fatSize, fatStart, reservedSectors, output)) {
|
||||
if(!makeFat32(dataStart, card, cache, numberOfHeads, sectorsPerTrack, cardSizeBlocks, sectorsPerCluster, relSector, partType, fatSize, fatStart, output)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -547,15 +574,8 @@ bool ESP_SD::format(ESP3DOutput * output)
|
||||
// MBR information
|
||||
uint8_t partType;
|
||||
uint32_t relSector;
|
||||
uint32_t partSize;
|
||||
|
||||
// Fake disk geometry
|
||||
uint8_t numberOfHeads;
|
||||
uint8_t sectorsPerTrack;
|
||||
|
||||
// FAT parameters
|
||||
uint16_t reservedSectors;
|
||||
uint8_t sectorsPerCluster;
|
||||
uint32_t fatStart;
|
||||
uint32_t fatSize;
|
||||
uint32_t dataStart;
|
||||
@ -575,10 +595,9 @@ bool ESP_SD::format(ESP3DOutput * output)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!formatCard(dataStart, card, cache, numberOfHeads,
|
||||
sectorsPerTrack, cardSizeBlocks,
|
||||
sectorsPerCluster, relSector, partSize, partType,
|
||||
fatSize, fatStart, cardCapacityMB, reservedSectors,output)) {
|
||||
if (!formatCard(dataStart, card, cache, cardSizeBlocks,
|
||||
relSector, partType,
|
||||
fatSize, fatStart, cardCapacityMB,output)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -86,6 +86,7 @@ uint8_t ESP_SD::getState(bool refresh)
|
||||
}
|
||||
//SD is idle or not detected, let see if still the case
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
bool isactive = accessSD();
|
||||
log_esp3d("Spi : CS: %d, Miso: %d, Mosi: %d, SCK: %d",ESP_SD_CS_PIN!=-1?ESP_SD_CS_PIN:SS, ESP_SD_MISO_PIN!=-1?ESP_SD_MISO_PIN:MISO, ESP_SD_MOSI_PIN!=-1?ESP_SD_MOSI_PIN:MOSI, ESP_SD_SCK_PIN!=-1?ESP_SD_SCK_PIN:SCK);
|
||||
//refresh content if card was removed
|
||||
if (SD.begin((ESP_SD_CS_PIN == -1)?SS:ESP_SD_CS_PIN, SD_SCK_MHZ(FREQMZ/_spi_speed_divider))) {
|
||||
@ -93,6 +94,9 @@ uint8_t ESP_SD::getState(bool refresh)
|
||||
_state = ESP_SDCARD_IDLE;
|
||||
}
|
||||
}
|
||||
if (!isactive) {
|
||||
releaseSD();
|
||||
}
|
||||
return _state;
|
||||
}
|
||||
|
||||
@ -112,9 +116,16 @@ bool ESP_SD::begin()
|
||||
//set callback to get time on files on SD
|
||||
SdFile::dateTimeCallback (dateTime);
|
||||
#endif //SD_TIMESTAMP_FEATURE
|
||||
if (getState(true) == ESP_SDCARD_IDLE) {
|
||||
freeBytes();
|
||||
}
|
||||
//Setup pins
|
||||
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
||||
pinMode (ESP_SD_DETECT_PIN, INPUT);
|
||||
#endif //ESP_SD_DETECT_PIN
|
||||
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||
#if defined(ESP_FLAG_SHARED_SD_PIN) && ESP_FLAG_SHARED_SD_PIN != -1
|
||||
pinMode (ESP_FLAG_SHARED_SD_PIN, OUTPUT);
|
||||
digitalWrite(ESP_FLAG_SHARED_SD_PIN, !ESP_FLAG_SHARED_SD_VALUE);
|
||||
#endif //ESP_FLAG_SHARED_SD_PIN
|
||||
#endif //SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||
return _started;
|
||||
}
|
||||
|
||||
|
@ -1303,7 +1303,8 @@ bool FtpServer::getFileModTime(const char * path, time_t & t)
|
||||
}
|
||||
//TODO
|
||||
bool FtpServer::timeStamp( const char * path, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second )
|
||||
{ //TODO
|
||||
{
|
||||
//TODO
|
||||
//Not available yet
|
||||
(void)path;
|
||||
(void ) year;
|
||||
|
@ -48,6 +48,7 @@ void HTTP_Server::handleSDFileList ()
|
||||
_webserver->send (200, "text/plain", "{\"status\":\"no SD card\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_webserver->hasArg ("quiet")) {
|
||||
if(_webserver->arg ("quiet") == "yes") {
|
||||
Serial.println("quiet");
|
||||
@ -55,7 +56,7 @@ void HTTP_Server::handleSDFileList ()
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
//get current path
|
||||
if (_webserver->hasArg ("path") ) {
|
||||
path += _webserver->arg ("path") ;
|
||||
@ -214,6 +215,9 @@ void HTTP_Server::handleSDFileList ()
|
||||
_webserver->sendContent_P(buffer2send.c_str(),buffer2send.length());
|
||||
_webserver->sendContent("");
|
||||
_upload_status = UPLOAD_STATUS_NONE;
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
}
|
||||
|
||||
#endif //HTTP_FEATURE && SD_DEVICE
|
||||
|
@ -44,9 +44,11 @@ void HTTP_Server:: handle_not_found()
|
||||
String pathWithGz = path + ".gz";
|
||||
#if defined (FILESYSTEM_FEATURE)
|
||||
if(ESP_FileSystem::exists(pathWithGz.c_str()) || ESP_FileSystem::exists(path.c_str())) {
|
||||
log_esp3d("Path found `%s`", path.c_str());
|
||||
if(ESP_FileSystem::exists(pathWithGz.c_str())) {
|
||||
_webserver->sendHeader("Content-Encoding", "gzip");
|
||||
path = pathWithGz;
|
||||
log_esp3d("Path is gz `%s`", path.c_str());
|
||||
}
|
||||
if(!StreamFSFile(path.c_str(),contentType.c_str())) {
|
||||
log_esp3d("Stream `%s` failed", path.c_str());
|
||||
@ -59,6 +61,7 @@ void HTTP_Server:: handle_not_found()
|
||||
if (path.startsWith("/sd/")) {
|
||||
path = path.substring(3);
|
||||
pathWithGz = path + ".gz";
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
if(ESP_SD::exists(pathWithGz.c_str()) || ESP_SD::exists(path.c_str())) {
|
||||
if(ESP_SD::exists(pathWithGz.c_str())) {
|
||||
_webserver->sendHeader("Content-Encoding", "gzip");
|
||||
@ -67,8 +70,14 @@ void HTTP_Server:: handle_not_found()
|
||||
if(!StreamSDFile(path.c_str(),contentType.c_str())) {
|
||||
log_esp3d("Stream `%s` failed", path.c_str());
|
||||
}
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
}
|
||||
#endif //#if defined (SD_DEVICE)
|
||||
|
||||
|
@ -37,9 +37,11 @@ void HTTP_Server::handle_root()
|
||||
String pathWithGz = path + ".gz";
|
||||
//if have a index.html or gzip version this is default root page
|
||||
if((ESP_FileSystem::exists(pathWithGz.c_str()) || ESP_FileSystem::exists(path.c_str())) && !_webserver->hasArg("forcefallback") && _webserver->arg("forcefallback")!="yes") {
|
||||
log_esp3d("Path found `%s`", path.c_str());
|
||||
if(ESP_FileSystem::exists(pathWithGz.c_str())) {
|
||||
_webserver->sendHeader("Content-Encoding", "gzip");
|
||||
path = pathWithGz;
|
||||
log_esp3d("Path is gz `%s`", path.c_str());
|
||||
}
|
||||
if(!StreamFSFile(path.c_str(),contentType.c_str())) {
|
||||
log_esp3d("Stream `%s` failed", path.c_str());
|
||||
|
@ -47,6 +47,7 @@ void HTTP_Server::SDFileupload ()
|
||||
//Upload start
|
||||
if (upload.status == UPLOAD_FILE_START) {
|
||||
_upload_status = UPLOAD_STATUS_ONGOING;
|
||||
ESP_SD::accessSD();
|
||||
if (upload_filename[0] != '/') {
|
||||
filename = "/" + upload_filename;
|
||||
} else {
|
||||
@ -129,10 +130,12 @@ void HTTP_Server::SDFileupload ()
|
||||
_upload_status=UPLOAD_STATUS_FAILED;
|
||||
pushError(ESP_ERROR_FILE_CLOSE, "File close failed");
|
||||
}
|
||||
ESP_SD::releaseSD();
|
||||
//Upload cancelled
|
||||
} else {
|
||||
if (_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||
_upload_status = UPLOAD_STATUS_FAILED;
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -148,6 +151,7 @@ void HTTP_Server::SDFileupload ()
|
||||
ESP_SD::remove (filename.c_str());
|
||||
}
|
||||
}
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
}
|
||||
#endif //HTTP_FEATURE && SD_DEVICE
|
||||
|
@ -86,7 +86,7 @@ void HTTP_Server::WebUpdateUpload ()
|
||||
}
|
||||
String s = "Update ";
|
||||
s+= String(last_upload_update);
|
||||
s+="%";
|
||||
s+="/100";
|
||||
output.printMSG(s.c_str());
|
||||
}
|
||||
}
|
||||
|
@ -253,8 +253,11 @@ const char * HTTP_Server::get_Splited_Value(String data, char separator, int ind
|
||||
strIndex[1] = (i == maxIndex) ? i+1 : i;
|
||||
}
|
||||
}
|
||||
if (found>index) s = data.substring(strIndex[0], strIndex[1]).c_str();
|
||||
else s = "";
|
||||
if (found>index) {
|
||||
s = data.substring(strIndex[0], strIndex[1]).c_str();
|
||||
} else {
|
||||
s = "";
|
||||
}
|
||||
return s.c_str();
|
||||
}
|
||||
|
||||
|
@ -213,7 +213,7 @@ void Telnet_Server::push2buffer(uint8_t * sbuf, size_t len)
|
||||
}
|
||||
flushbuffer();
|
||||
} else if (isPrintable (char(sbuf[i]) )) {
|
||||
if (_buffer_size < ESP3D_TELNET_BUFFER_SIZE) {
|
||||
if (_buffer_size < ESP3D_TELNET_BUFFER_SIZE) {
|
||||
_buffer[_buffer_size] = sbuf[i];
|
||||
_buffer_size++;
|
||||
} else {
|
||||
|
@ -551,6 +551,8 @@ static int handle_luainit (lua_State *L) {
|
||||
** Main body of stand-alone interpreter (to be called in protected mode).
|
||||
** Reads the options and handles them all.
|
||||
*/
|
||||
static int pmain (lua_State *L) __attribute__ ((unused));
|
||||
|
||||
static int pmain (lua_State *L) {
|
||||
int argc = (int)lua_tointeger(L, 1);
|
||||
char **argv = (char **)lua_touserdata(L, 2);
|
||||
@ -591,8 +593,6 @@ static int pmain (lua_State *L) {
|
||||
lua_pushboolean(L, 1); /* signal no errors */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
//int main (int argc, char **argv) {
|
||||
// int status, result;
|
||||
// lua_State *L = luaL_newstate(); /* create state */
|
||||
|
@ -84,9 +84,10 @@ void TFT_eSPI::loadFont(String fontName, bool flash)
|
||||
*/
|
||||
|
||||
spiffs = flash;
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
if(spiffs) fontFS = SPIFFS;
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
unloadFont();
|
||||
|
||||
// Avoid a crash on the ESP32 if the file does not exist
|
||||
|
@ -45,6 +45,8 @@ fontMetrics gFont = { 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
void loadMetrics(uint16_t gCount);
|
||||
uint32_t readInt32(void);
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
fs::FS &fontFS = SPIFFS;
|
||||
#pragma GCC diagnostic pop
|
||||
bool spiffs = true;
|
@ -142,7 +142,7 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_st
|
||||
cmd_state_t cmd_state = CMD_STATE_WAIT;
|
||||
uint32_t i;
|
||||
uint16_t par_start = 0;
|
||||
lv_color_t recolor;
|
||||
lv_color_t recolor = lv_color_make(0, 0, 0);
|
||||
lv_coord_t letter_w;
|
||||
lv_style_t sel_style;
|
||||
lv_style_copy(&sel_style, &lv_style_plain_color);
|
||||
|
Loading…
x
Reference in New Issue
Block a user