mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-06-06 02:36:49 +08:00
basic esp commands for SD
This commit is contained in:
parent
3694e3ca4b
commit
14a15bf815
@ -72,6 +72,9 @@ Note:
|
||||
label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling/colorbar/awb/agc/aec/hmirror/vflip/awb_gain/agc_gain/aec_value/aec2/cw/bpc/wpc/raw_gma/lenc/special_effect/wb_mode/ae_level
|
||||
[ESP172]<plain><label=value> pwd=<admin password>
|
||||
|
||||
* Get SD Card Status
|
||||
[ESP200] pwd=<user/admin password>
|
||||
|
||||
*Get/Set pin value
|
||||
[ESP201]P<pin> V<value> [PULLUP=YES RAW=YES]pwd=<admin password>
|
||||
if no V<value> get P<pin> value
|
||||
@ -191,6 +194,13 @@ Get will give type and settings only, not the protected T1/T2
|
||||
rmdir / remove / mkdir / exists
|
||||
[ESP730]<Action>=<path> pwd=<admin password>
|
||||
|
||||
* List SD Filesystem
|
||||
[ESP740]<Root> pwd=<admin password>
|
||||
|
||||
* Action on SD Filesystem
|
||||
rmdir / remove / mkdir / exists
|
||||
[ESP750]<Action>=<path> pwd=<admin password>
|
||||
|
||||
* FW Informations
|
||||
[ESP800]<plain> pwd=<admin password>
|
||||
|
||||
|
@ -397,6 +397,13 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
||||
response = ESP172(cmd_params, auth_type, output);
|
||||
break;
|
||||
#endif //CAMERA_DEVICE
|
||||
#if defined (SD_DEVICE)
|
||||
//Get SD Card Status
|
||||
//[ESP200] pwd=<user/admin password>
|
||||
case 200:
|
||||
response = ESP200(cmd_params, auth_type, output);
|
||||
break;
|
||||
#endif //SD_DEVICE
|
||||
#ifdef DIRECT_PIN_FEATURE
|
||||
//Get/Set pin value
|
||||
//[ESP201]P<pin> V<value> [PULLUP=YES RAW=YES]pwd=<admin password>
|
||||
@ -525,7 +532,19 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
||||
response = ESP730(cmd_params, auth_type, output);
|
||||
break;
|
||||
#endif //FILESYSTEM_FEATURE
|
||||
|
||||
#if defined (SD_DEVICE)
|
||||
//List SD Filesystem
|
||||
//[ESP740]<Root> pwd=<admin password>
|
||||
case 740:
|
||||
response = ESP740(cmd_params, auth_type, output);
|
||||
break;
|
||||
//Action on SD Filesystem
|
||||
//rmdir / remove / mkdir / exists
|
||||
//[ESP750]<Action>=<path> pwd=<admin password>
|
||||
case 750:
|
||||
response = ESP750(cmd_params, auth_type, output);
|
||||
break;
|
||||
#endif //SD_DEVICE
|
||||
//Get fw version firmare target and fw version
|
||||
//eventually set time with pc time
|
||||
//output is JSON or plain text according parameter
|
||||
|
@ -81,6 +81,9 @@ public:
|
||||
bool ESP171(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
bool ESP172(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //CAMERA_DEVICE
|
||||
#if defined (SD_DEVICE)
|
||||
bool ESP200(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //SD_DEVICE
|
||||
#ifdef DIRECT_PIN_FEATURE
|
||||
bool ESP201(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //DIRECT_PIN_FEATURE
|
||||
@ -120,6 +123,10 @@ public:
|
||||
bool ESP720(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
bool ESP730(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //FILESYSTEM_FEATURE
|
||||
#if defined (SD_DEVICE)
|
||||
bool ESP750(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
bool ESP740(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //SD_DEVICE
|
||||
bool ESP800(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
bool ESP900(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#ifdef BUZZER_DEVICE
|
||||
|
52
esp3d/src/core/espcmd/ESP200.cpp
Normal file
52
esp3d/src/core/espcmd/ESP200.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
ESP200.cpp - ESP3D command class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined (SD_DEVICE)
|
||||
#include "../commands.h"
|
||||
#include "../esp3doutput.h"
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/filesystem/esp_sd.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
//Get SD Card Status
|
||||
//[ESP200] pwd=<user/admin password>
|
||||
bool Commands::ESP200(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
{
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (auth_type == LEVEL_GUEST) {
|
||||
output->printERROR("Wrong authentication!", 401);
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
(void)auth_type;
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
String resp = "No SD card";
|
||||
int8_t state = ESP_SD::getState(true);
|
||||
if (state == ESP_SDCARD_IDLE) {
|
||||
resp="SD card detected";
|
||||
} else if (state == ESP_SDCARD_NOT_PRESENT) {
|
||||
resp="No SD card";
|
||||
} else {
|
||||
resp="Busy";
|
||||
}
|
||||
output->printMSG (resp.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif //SD_DEVICE
|
@ -42,7 +42,7 @@ bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type,
|
||||
if (parameter.length() == 0) {
|
||||
parameter = "/";
|
||||
}
|
||||
output->printf("Directory : %s", parameter.c_str());
|
||||
output->printf("Directory on FS : %s", parameter.c_str());
|
||||
output->printLN("");
|
||||
if (ESP_FileSystem::exists(parameter.c_str())) {
|
||||
ESP_File f = ESP_FileSystem::open(parameter.c_str(), ESP_FILE_READ);
|
||||
|
117
esp3d/src/core/espcmd/ESP740.cpp
Normal file
117
esp3d/src/core/espcmd/ESP740.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
ESP740.cpp - ESP3D command class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined (SD_DEVICE)
|
||||
#include "../commands.h"
|
||||
#include "../esp3doutput.h"
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
#include "../../modules/filesystem/esp_sd.h"
|
||||
//List SD Filesystem
|
||||
//[ESP740]<Root> pwd=<admin password>
|
||||
bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
{
|
||||
bool response = true;
|
||||
String parameter;
|
||||
parameter = get_param (cmd_params, "");
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (auth_type != LEVEL_ADMIN) {
|
||||
output->printERROR("Wrong authentication!", 401);
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
(void)auth_type;
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
if (parameter.length() == 0) {
|
||||
parameter = "/";
|
||||
}
|
||||
int8_t state = ESP_SD::getState(false);
|
||||
if (state != ESP_SDCARD_IDLE){
|
||||
state = ESP_SD::getState(true);
|
||||
}
|
||||
if (state == ESP_SDCARD_NOT_PRESENT) {
|
||||
output->printERROR ("No SD card");
|
||||
return false;
|
||||
} else if (state != ESP_SDCARD_IDLE) {
|
||||
output->printERROR ("Busy");
|
||||
return false;
|
||||
}
|
||||
output->printf("Directory on SD : %s", parameter.c_str());
|
||||
output->printLN("");
|
||||
if (ESP_SD::exists(parameter.c_str())) {
|
||||
ESP_SDFile f = ESP_SD::open(parameter.c_str(), ESP_SD_FILE_READ);
|
||||
uint countf = 0;
|
||||
uint countd = 0;
|
||||
if (f) {
|
||||
//Check directories
|
||||
ESP_SDFile sub = f.openNextFile();
|
||||
while (sub) {
|
||||
if (sub.isDirectory()) {
|
||||
countd++;
|
||||
output->print("<DIR> \t");
|
||||
output->print(sub.name());
|
||||
output->print(" \t");
|
||||
output->printLN("");
|
||||
}
|
||||
sub.close();
|
||||
sub = f.openNextFile();
|
||||
}
|
||||
f.close();
|
||||
f = ESP_SD::open(parameter.c_str(), ESP_SD_FILE_READ);
|
||||
//Check files
|
||||
sub = f.openNextFile();
|
||||
while (sub) {
|
||||
if (!sub.isDirectory()) {
|
||||
countf++;
|
||||
output->print(" \t");
|
||||
output->print(sub.name());
|
||||
output->print(" \t");
|
||||
output->print(ESP_SD::formatBytes(sub.size()).c_str());
|
||||
output->print(" \t");
|
||||
#ifdef SD_TIMESTAMP_FEATURE
|
||||
time_t t = sub.getLastWrite();
|
||||
struct tm * tmstruct = localtime(&t);
|
||||
output->printf("%d-%02d-%02d %02d:%02d:%02d",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
|
||||
output->print(" \t");
|
||||
#endif //SD_TIMESTAMP_FEATURE
|
||||
output->printLN("");
|
||||
}
|
||||
sub.close();
|
||||
sub = f.openNextFile();
|
||||
}
|
||||
f.close();
|
||||
output->printf("%d file%s, %d dir%s", countf, (countf > 1)?"(s)":"", countd, (countd > 1)?"(s)":"");
|
||||
output->printLN("");
|
||||
String t = ESP_SD::formatBytes(ESP_SD::totalBytes());
|
||||
String u = ESP_SD::formatBytes(ESP_SD::usedBytes());
|
||||
String f = ESP_SD::formatBytes(ESP_SD::freeBytes());
|
||||
output->printf("Total %s, Used %s, Available: %s", t.c_str(), u.c_str(),f.c_str());
|
||||
output->printLN("");
|
||||
} else {
|
||||
output->printERROR ("Invalid directory!");
|
||||
}
|
||||
} else {
|
||||
output->printERROR ("Invalid directory!");
|
||||
response = false;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
#endif //SD_DEVICE
|
97
esp3d/src/core/espcmd/ESP750.cpp
Normal file
97
esp3d/src/core/espcmd/ESP750.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
ESP750.cpp - ESP3D command class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined (SD_DEVICE)
|
||||
#include "../commands.h"
|
||||
#include "../esp3doutput.h"
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
#include "../../modules/filesystem/esp_sd.h"
|
||||
// Action on SD Filesystem
|
||||
//rmdir / remove / mkdir / exists
|
||||
//[ESP750]<Action>=<path> pwd=<admin password>
|
||||
bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
{
|
||||
bool response = true;
|
||||
String parameter;
|
||||
parameter = get_param (cmd_params, "");
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (auth_type != LEVEL_ADMIN) {
|
||||
output->printERROR("Wrong authentication!", 401);
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
(void)auth_type;
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
int8_t state = ESP_SD::getState(false);
|
||||
if (state != ESP_SDCARD_IDLE){
|
||||
state = ESP_SD::getState(true);
|
||||
}
|
||||
if (state == ESP_SDCARD_NOT_PRESENT) {
|
||||
output->printERROR ("No SD card");
|
||||
return false;
|
||||
} else if (state != ESP_SDCARD_IDLE) {
|
||||
output->printERROR ("Busy");
|
||||
return false;
|
||||
}
|
||||
parameter = get_param (cmd_params, "mkdir=");
|
||||
if (parameter.length() != 0) {
|
||||
if (ESP_SD::mkdir(parameter.c_str())) {
|
||||
output->printMSG ("ok");
|
||||
} else {
|
||||
output->printERROR ("failed!");
|
||||
response = false;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
parameter = get_param (cmd_params, "rmdir=");
|
||||
if (parameter.length() != 0) {
|
||||
if (ESP_SD::rmdir(parameter.c_str())) {
|
||||
output->printMSG ("ok");
|
||||
} else {
|
||||
output->printERROR ("failed!");
|
||||
response = false;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
parameter = get_param (cmd_params, "remove=");
|
||||
if (parameter.length() != 0) {
|
||||
if (ESP_SD::remove(parameter.c_str())) {
|
||||
output->printMSG ("ok");
|
||||
} else {
|
||||
output->printERROR ("failed!");
|
||||
response = false;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
parameter = get_param (cmd_params, "exists=");
|
||||
if (parameter.length() != 0) {
|
||||
if (ESP_SD::exists(parameter.c_str())) {
|
||||
output->printMSG ("yes");
|
||||
} else {
|
||||
output->printMSG ("no");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
output->printERROR ("Incorrect command!");
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif //SD_DEVICE
|
@ -22,7 +22,7 @@
|
||||
#define _VERSION_ESP3D_H
|
||||
|
||||
//version and sources location
|
||||
#define FW_VERSION "3.0.0.a21"
|
||||
#define FW_VERSION "3.0.0.a22"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
||||
|
||||
#endif //_VERSION_ESP3D_H
|
||||
|
@ -31,7 +31,7 @@
|
||||
File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||
|
||||
bool ESP_SD::_started = false;
|
||||
uint8_t ESP_SD::_state = ESP_SDCARD_IDLE;
|
||||
uint8_t ESP_SD::_state = ESP_SDCARD_NOT_PRESENT;
|
||||
|
||||
uint8_t ESP_SD::setState(uint8_t flag)
|
||||
{
|
||||
|
@ -68,14 +68,14 @@ bool ESP_SD::begin()
|
||||
SPI.begin(ESP_SD_SCK_PIN, ESP_SD_MISO_PIN, ESP_SD_MOSI_PIN, ESP_SD_CS_PIN);
|
||||
#endif
|
||||
_started = true;
|
||||
_state = ESP_SDCARD_IDLE;
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
return _started;
|
||||
}
|
||||
|
||||
void ESP_SD::end()
|
||||
{
|
||||
SD.end();
|
||||
_state = ESP_SDCARD_IDLE;
|
||||
_state = ESP_SDCARD_NOT_PRESENT;
|
||||
_started = false;
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ uint64_t ESP_SD::usedBytes()
|
||||
return SD.usedBytes();
|
||||
}
|
||||
|
||||
uint64_t freeBytes()
|
||||
uint64_t ESP_SD::freeBytes()
|
||||
{
|
||||
return (SD.totalBytes() - SD.usedBytes());
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user