mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 02:09:06 +08:00
Fix SD File listing incomplete as still processing
Separate M20 command from file listing to give time to get the complete file list before sending the list Change SDK function system_get_time and wifi_get_opmode to use wrapper ones and avoid to include user_interface.h if not necessary
This commit is contained in:
parent
41d319bed8
commit
3d92f78eca
@ -22,9 +22,6 @@
|
||||
#include "config.h"
|
||||
#include "wifi.h"
|
||||
#include "webinterface.h"
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
|
||||
String COMMAND::buffer_serial;
|
||||
String COMMAND::buffer_tcp;
|
||||
@ -81,7 +78,7 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
||||
break;
|
||||
case 111: {
|
||||
String currentIP ;
|
||||
if (wifi_get_opmode()==WIFI_STA) {
|
||||
if (WiFi.getMode()==WIFI_STA) {
|
||||
currentIP=WiFi.localIP().toString();
|
||||
} else {
|
||||
currentIP=WiFi.softAPIP().toString();
|
||||
@ -141,7 +138,7 @@ void COMMAND::check_command(String buffer)
|
||||
//yes it is file list starting to be displayed
|
||||
if (filesstart>-1) {
|
||||
//init time out
|
||||
start_list=system_get_time();
|
||||
start_list = millis();
|
||||
//set file list started
|
||||
bfileslist=true;
|
||||
//clear current list
|
||||
@ -198,7 +195,7 @@ void COMMAND::check_command(String buffer)
|
||||
//if match mask T:xxx.xx /xxx.xx
|
||||
if(spacepos-Tpos < 17) {
|
||||
web_interface->answer4M105=buffer; //do not interprete just need when requested so store it
|
||||
web_interface->last_temp=system_get_time();
|
||||
web_interface->last_temp=millis();
|
||||
}
|
||||
}
|
||||
//Position of axis
|
||||
@ -248,18 +245,24 @@ void COMMAND::check_command(String buffer)
|
||||
}
|
||||
} else { //listing file is on going
|
||||
//check if we are too long
|
||||
if ((system_get_time()-start_list)>30000000) { //timeout in case of problem
|
||||
if ((millis()-start_list)>30000) { //timeout in case of problem
|
||||
bfileslist=false;
|
||||
(web_interface->blockserial) = false; //release serial
|
||||
LOG("Time out\n");
|
||||
} else {
|
||||
//check if this is the end
|
||||
if (buffer.indexOf("End file list")>-1) {
|
||||
bfileslist=false;
|
||||
(web_interface->blockserial) = false;
|
||||
LOG("End list\n");
|
||||
} else {
|
||||
//Serial.print(buffer);
|
||||
//add list to buffer
|
||||
web_interface->fileslist.add(buffer);
|
||||
LOG(String(web_interface->fileslist.size()));
|
||||
LOG(":");
|
||||
LOG(buffer);
|
||||
LOG('\n');
|
||||
}
|
||||
}
|
||||
|
||||
@ -315,7 +318,7 @@ void COMMAND::read_buffer_serial(uint8_t b)
|
||||
previous_was_char=false; //next call will reset the buffer
|
||||
}
|
||||
//this is not printable but end of command check if need to handle it
|
||||
if (b==13 ||b==10) {
|
||||
if (b==13) {
|
||||
//Minimum is something like M10 so 3 char
|
||||
if (buffer_serial.length()>3) {
|
||||
check_command(buffer_serial);
|
||||
|
@ -65,7 +65,7 @@ $INCLUDE[css2.inc]$
|
||||
<rect x="10" y="10" width="7" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" /> <rect x="23" y="10" width="7" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" /></svg></td>
|
||||
<td class="btnimg" onclick="Sendcommand('M50');"><svg width="40" height="40" viewBox="0 0 40 40"><circle cx="20" cy="20" r="18" stroke="black" stroke-width="2" fill="white" />
|
||||
<rect x="10" y="10" width="20" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" /></svg></td>
|
||||
<td class="btnimg" onclick="getSDfiles();"><svg width="40" height="40" viewBox="0 0 40 40"><rect x="5" y="10" width="30" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" />
|
||||
<td class="btnimg" onclick="refreshSDfiles();"><svg width="40" height="40" viewBox="0 0 40 40"><rect x="5" y="10" width="30" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" />
|
||||
<rect x="20" y="5" width="15" height="15" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" /><text x="10" y="25" font-family="Verdana" font-size="14" fill="white">SD</text></svg></td>
|
||||
<td> </td>
|
||||
<td id="SDLIST"></td></tr></table></td></tr>
|
||||
@ -351,13 +351,21 @@ Sendcommand("M23 " + filename);
|
||||
delay(100);
|
||||
Sendcommand("M24");}
|
||||
}
|
||||
|
||||
var retry = 0;
|
||||
function refreshfilelist(jsonresponse){
|
||||
|
||||
var list2display="<table><tr><td><select class=\"form-control\" id=\"sdfilelist\">";
|
||||
var content="";
|
||||
var i;
|
||||
for (i = 0; i < jsonresponse.length; i++){
|
||||
content =jsonresponse[i].entry;
|
||||
if (jsonresponse.status != "Ok"){
|
||||
delay(1000);
|
||||
retry = retry +1;
|
||||
if (retry < 6) getSDfiles();
|
||||
return;
|
||||
}
|
||||
retry = 0;
|
||||
for (i = 0; i < jsonresponse.file.length; i++){
|
||||
content =jsonresponse.file[i].entry;
|
||||
var tcontent=content.split(" ");
|
||||
if ((tcontent.length==2) || (tcontent.length==1 && tcontent[0].indexOf("/")==-1)){
|
||||
list2display+="<OPTION value=\"";
|
||||
@ -381,10 +389,15 @@ list2display+="</td></tr></table>";
|
||||
document.getElementById("SDLIST").innerHTML=list2display;
|
||||
}
|
||||
|
||||
function getSDfiles(){
|
||||
function refreshSDfiles(){
|
||||
document.getElementById("SDLIST").innerHTML="";
|
||||
Sendcommand("M20");
|
||||
delay(1000);
|
||||
retry = 0;
|
||||
getSDfiles();
|
||||
}
|
||||
|
||||
function getSDfiles(){
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
var url = "/SDFILES";
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
|
@ -555,7 +555,7 @@ void GetIpWeb(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList)
|
||||
String stmp;
|
||||
|
||||
KeysList.add(FPSTR(KEY_IP));
|
||||
if (wifi_get_opmode() == WIFI_STA ) {
|
||||
if (WiFi.getMode() == WIFI_STA ) {
|
||||
stmp = WiFi.localIP().toString();
|
||||
} else {
|
||||
stmp = WiFi.softAPIP().toString();
|
||||
@ -575,11 +575,11 @@ void GetIpWeb(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList)
|
||||
// -----------------------------------------------------------------------------
|
||||
void GetMode(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList)
|
||||
{
|
||||
if (wifi_get_opmode() == WIFI_STA ) {
|
||||
if (WiFi.getMode() == WIFI_STA ) {
|
||||
KeysList.add(FPSTR(KEY_MODE));
|
||||
ValuesList.add(FPSTR(VALUE_STA));
|
||||
} else {
|
||||
if (wifi_get_opmode() == WIFI_AP ) {
|
||||
if (WiFi.getMode() == WIFI_AP ) {
|
||||
KeysList.add(FPSTR(KEY_MODE));
|
||||
ValuesList.add(FPSTR(VALUE_AP));
|
||||
} else {
|
||||
@ -733,7 +733,7 @@ void handle_web_interface_home()
|
||||
GetIpWeb(KeysList, ValuesList);
|
||||
|
||||
//Hostname
|
||||
if (wifi_get_opmode()==WIFI_STA ) {
|
||||
if (WiFi.getMode()==WIFI_STA ) {
|
||||
KeysList.add(FPSTR(KEY_MODE));
|
||||
ValuesList.add(FPSTR(VALUE_STA));
|
||||
KeysList.add(FPSTR(KEY_HOSTNAME));
|
||||
@ -745,7 +745,7 @@ void handle_web_interface_home()
|
||||
ValuesList.add(FPSTR(KEY_NOT_APPLICABLE_4_AP));
|
||||
KeysList.add(FPSTR(KEY_HOSTNAME_VISIBLE));
|
||||
ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN));
|
||||
if (wifi_get_opmode()==WIFI_AP ) {
|
||||
if (WiFi.getMode()==WIFI_AP ) {
|
||||
KeysList.add(FPSTR(KEY_MODE));
|
||||
ValuesList.add(FPSTR(VALUE_AP));
|
||||
} else {
|
||||
@ -801,7 +801,7 @@ void handle_web_interface_home()
|
||||
|
||||
//Captive portal Feature
|
||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||
if (wifi_get_opmode()==WIFI_AP) {
|
||||
if (WiFi.getMode()==WIFI_AP) {
|
||||
KeysList.add(FPSTR(KEY_CAPTIVE_PORTAL_STATUS));
|
||||
ValuesList.add(FPSTR(VALUE_ENABLED));
|
||||
KeysList.add(FPSTR(KEY_CAPTIVE_PORTAL_VISIBLE));
|
||||
@ -847,7 +847,7 @@ void handle_web_interface_home()
|
||||
GetPorts(KeysList, ValuesList);
|
||||
|
||||
//AP part
|
||||
if (wifi_get_opmode()==WIFI_AP || wifi_get_opmode()==WIFI_AP_STA) {
|
||||
if (WiFi.getMode()==WIFI_AP || WiFi.getMode()==WIFI_AP_STA) {
|
||||
int client_counter=0;
|
||||
struct station_info * station;
|
||||
//AP is enabled
|
||||
@ -969,7 +969,7 @@ void handle_web_interface_home()
|
||||
ValuesList.add(FPSTR(VALUE_NO_IP));
|
||||
}
|
||||
//STA part
|
||||
if (wifi_get_opmode()==WIFI_STA || wifi_get_opmode()==WIFI_AP_STA) {
|
||||
if (WiFi.getMode()==WIFI_STA || WiFi.getMode()==WIFI_AP_STA) {
|
||||
//STA is enabled
|
||||
KeysList.add(FPSTR(KEY_STA_STATUS_ENABLED));
|
||||
ValuesList.add(FPSTR(VALUE_ENABLED));
|
||||
@ -1920,7 +1920,7 @@ void handle_web_interface_configSTA()
|
||||
//do we need to do a scan and display it ?
|
||||
if (!msg_alert_success) {
|
||||
//if in AP mode switch to mixed mode to be able to scan
|
||||
if (wifi_get_opmode()!=WIFI_STA ) {
|
||||
if (WiFi.getMode()!=WIFI_STA ) {
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
revertSTA=true;
|
||||
}
|
||||
@ -2224,13 +2224,13 @@ void handle_web_interface_status()
|
||||
//int temperature,target;
|
||||
|
||||
//request temperature only if no feedback
|
||||
if ((system_get_time()-web_interface->last_temp)>2000000) {
|
||||
if ((millis()-web_interface->last_temp)>120000) {
|
||||
Serial.println(F("M105"));
|
||||
}
|
||||
|
||||
if ((system_get_time()-web_interface->last_temp)<3200000) {
|
||||
if ((millis()-web_interface->last_temp)<180000) {
|
||||
value="Connected";
|
||||
} else if ((system_get_time()-web_interface->last_temp)<32000000) {
|
||||
} else if ((millis()-web_interface->last_temp)<200000) {
|
||||
value="Busy";
|
||||
} else {
|
||||
value="Offline";
|
||||
@ -2792,25 +2792,33 @@ void handleSDFileList()
|
||||
if (!web_interface->is_authenticated()) {
|
||||
return;
|
||||
}
|
||||
if(web_interface->WebServer.hasArg("action")) {
|
||||
if(web_interface->WebServer.arg("action")=="delete" && web_interface->WebServer.hasArg("filename")) {
|
||||
String filename;
|
||||
web_interface->urldecode(filename,web_interface->WebServer.arg("filename").c_str());
|
||||
filename = "M30 " + filename;
|
||||
//TODO:need a MACRO or helper for this test
|
||||
if((web_interface->blockserial) == false)Serial.println(filename);
|
||||
String jsonfile = "{\"status\":\"" ;
|
||||
//if action is processing do not build list
|
||||
if ((web_interface->blockserial)){
|
||||
LOG("Wait, blocking\n");
|
||||
jsonfile+="processing\"}";
|
||||
}
|
||||
}
|
||||
String jsonfile = "[";
|
||||
else{
|
||||
jsonfile+="Ok\",\"file\":[";
|
||||
LOG("No Blocking \n");
|
||||
LOG("JSON File\n");
|
||||
LOG(String(web_interface->fileslist.size()));
|
||||
LOG(" entries\n");
|
||||
for (int i=0; i<web_interface->fileslist.size(); i++) {
|
||||
if (i>0) {
|
||||
jsonfile+=",";
|
||||
}
|
||||
jsonfile+="{\"entry\":\"";
|
||||
jsonfile+=web_interface->fileslist.get(i);
|
||||
LOG(String(i+1));
|
||||
LOG(web_interface->fileslist.get(i));
|
||||
LOG("\n");
|
||||
jsonfile+="\"}";
|
||||
}
|
||||
jsonfile+="]";
|
||||
jsonfile+="]}";
|
||||
LOG("JSON done\n");
|
||||
}
|
||||
|
||||
web_interface->WebServer.sendHeader("Cache-Control", "no-cache");
|
||||
web_interface->WebServer.send(200, "application/json", jsonfile);
|
||||
web_interface->blockserial = false;
|
||||
@ -2862,7 +2870,7 @@ void handle_not_found()
|
||||
//if not template use default page
|
||||
contentType=FPSTR(PAGE_404);
|
||||
String stmp;
|
||||
if (wifi_get_opmode()==WIFI_STA ) {
|
||||
if (WiFi.getMode()==WIFI_STA ) {
|
||||
stmp=WiFi.localIP().toString();
|
||||
} else {
|
||||
stmp=WiFi.softAPIP().toString();
|
||||
@ -3152,7 +3160,7 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
|
||||
answer4M220="100";
|
||||
answer4M221="100";
|
||||
blockserial = false;
|
||||
last_temp=system_get_time();
|
||||
last_temp = millis();
|
||||
restartmodule=false;
|
||||
//rolling list of 4entries with a maximum of 50 char for each entry
|
||||
error_msg.setsize(4);
|
||||
@ -3161,7 +3169,7 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
|
||||
info_msg.setlength(50);
|
||||
status_msg.setsize(4);
|
||||
status_msg.setlength(50);
|
||||
fileslist.setlength(30);//12 for filename + space + size
|
||||
fileslist.setlength(100);//12 for filename + space + size
|
||||
fileslist.setsize(70); // 70 files to limite to 2K
|
||||
fsUploadFile=(fs::File)0;
|
||||
_head=NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user