mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-14 01:25:51 +08:00
Add Flash from SD FW and FS
Change configuration file name from espconf.ini to esp3dcnf.ini Bump version
This commit is contained in:
parent
e3545c8a5e
commit
9b4523fad0
@ -22,7 +22,7 @@
|
||||
#define _VERSION_ESP3D_H
|
||||
|
||||
//version and sources location
|
||||
#define FW_VERSION "3.0.0.a71"
|
||||
#define FW_VERSION "3.0.0.a72"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
||||
|
||||
#endif //_VERSION_ESP3D_H
|
||||
|
@ -41,10 +41,6 @@ ESP_ConfigFile::ESP_ConfigFile(const char * path, TProcessingFunction fn)
|
||||
bool ESP_ConfigFile::processFile()
|
||||
{
|
||||
bool res = true;
|
||||
if (ESP_SD::getState(true) != ESP_SDCARD_IDLE) {
|
||||
log_esp3d("No SD");
|
||||
return false;
|
||||
}
|
||||
if (!ESP_SD::exists(_filename)) {
|
||||
log_esp3d("No ini file");
|
||||
return false;
|
||||
|
@ -25,9 +25,23 @@
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/commands.h"
|
||||
#include "esp_config_file.h"
|
||||
#include "../filesystem/esp_sd.h"
|
||||
#include "../filesystem/esp_filesystem.h"
|
||||
#if defined (ARDUINO_ARCH_ESP32)
|
||||
#include <Update.h>
|
||||
#define U_FS U_SPIFFS
|
||||
#endif //ARDUINO_ARCH_ESP32
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
|
||||
#endif //ARDUINO_ARCH_ESP8266
|
||||
|
||||
|
||||
UpdateService update_service;
|
||||
#define CONFIG_FILE "/espconf.ini"
|
||||
|
||||
#define CONFIG_FILE "/esp3dcnf.ini"
|
||||
#define FW_FILE "/esp3dfw.bin"
|
||||
#define FS_FILE "/esp3dfs.bin"
|
||||
|
||||
const char * NetstringKeysVal[] = {"hostname",
|
||||
"STA_SSID",
|
||||
"STA_Password",
|
||||
@ -420,27 +434,101 @@ bool processingFileFunction (const char * section, const char * key, const char
|
||||
|
||||
UpdateService::UpdateService() {}
|
||||
UpdateService::~UpdateService() {}
|
||||
|
||||
bool UpdateService::flash(const char * filename, int type)
|
||||
{
|
||||
bool res = false;
|
||||
if (ESP_SD::exists (filename)) {
|
||||
log_esp3d("Update found");
|
||||
bool issucess = false;
|
||||
ESP_SDFile sdfile;
|
||||
String finalName = filename;
|
||||
sdfile = ESP_SD::open(filename);
|
||||
if(sdfile) {
|
||||
size_t s = sdfile.size();
|
||||
size_t rs = 0;
|
||||
uint8_t v[1] ;
|
||||
if(Update.begin(s, type)) {
|
||||
log_esp3d("Update started");
|
||||
while (sdfile.available() && (rs <= (s+1))) {
|
||||
rs++;
|
||||
v[0]=sdfile.read();
|
||||
Update.write(v,1);
|
||||
Hal::wait(0);
|
||||
}
|
||||
if (rs==s) {
|
||||
log_esp3d("Update done");
|
||||
if(Update.end(true)) {
|
||||
log_esp3d("Update success");
|
||||
issucess = true;
|
||||
}
|
||||
} else {
|
||||
Update.end();
|
||||
log_esp3d("Wrong size");
|
||||
}
|
||||
}
|
||||
sdfile.close();
|
||||
} else {
|
||||
log_esp3d("Cannot open file");
|
||||
}
|
||||
if(issucess) {
|
||||
res = true;
|
||||
finalName.replace(".bin", ".ok");
|
||||
} else {
|
||||
finalName.replace(".bin", ".bad");
|
||||
}
|
||||
if (ESP_SD::exists (finalName.c_str())) {
|
||||
String name = filename;
|
||||
uint8_t n = 1;
|
||||
log_esp3d("Final name already exists, backup existing");
|
||||
name.replace("bin", String(n).c_str());
|
||||
while(ESP_SD::exists (name.c_str())) {
|
||||
n++;
|
||||
name.replace("bin", String(n).c_str());
|
||||
}
|
||||
ESP_SD::rename(finalName.c_str(),name.c_str());
|
||||
}
|
||||
ESP_SD::rename(filename, finalName.c_str());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool UpdateService::begin()
|
||||
{
|
||||
bool res = false;
|
||||
if(Settings_ESP3D::read_byte(ESP_SD_CHECK_UPDATE_AT_BOOT)!=0) {
|
||||
bool isactive = ESP_SD::accessSD();
|
||||
log_esp3d("Update SD for update requestest");
|
||||
if(ESP_SD::getState(true) == ESP_SDCARD_IDLE) {
|
||||
ESP_ConfigFile updateConfig(CONFIG_FILE, processingFileFunction);
|
||||
if (updateConfig.processFile()) {
|
||||
log_esp3d("Processing ini file done");
|
||||
if(updateConfig.revokeFile()) {
|
||||
log_esp3d("Revoking ini file done");
|
||||
return true;
|
||||
res = true;
|
||||
} else {
|
||||
log_esp3d("Revoking ini file failed");
|
||||
}
|
||||
} else {
|
||||
log_esp3d("Processing ini file done");
|
||||
log_esp3d("Processing ini file failed");
|
||||
}
|
||||
log_esp3d("Update failed");
|
||||
return false;
|
||||
int command = U_FLASH;
|
||||
if (flash(FW_FILE,U_FLASH)) {
|
||||
res = true;
|
||||
} else {
|
||||
if (flash(FS_FILE,U_FS)) {
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isactive) {
|
||||
ESP_SD::releaseSD();
|
||||
}
|
||||
} else {
|
||||
log_esp3d("No need to check for update");
|
||||
return false;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
void UpdateService::end()
|
||||
{
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
void end();
|
||||
|
||||
private:
|
||||
bool flash(const char * filename, int type);
|
||||
};
|
||||
|
||||
extern UpdateService update_service;
|
||||
|
Loading…
x
Reference in New Issue
Block a user