simple file editor
This commit is contained in:
parent
3339b6841c
commit
d6236b75d2
|
|
@ -538,6 +538,48 @@ const char *handleControlPost(AsyncWebServerRequest *request) {
|
|||
}
|
||||
}
|
||||
|
||||
// bad idea. prone to buffer overflow. use at your own risk...
|
||||
const char *createEditForm(String filename) {
|
||||
char *ptr = message;
|
||||
File file = SPIFFS.open("/" + filename, "r");
|
||||
if (!file) {
|
||||
Serial.println("There was an error opening the file '/config.txt' for reading");
|
||||
return "<html><head><title>File not found</title></head><body>File not found</body></html>";
|
||||
}
|
||||
|
||||
strcpy(ptr, "<html><head><title>Editor ");
|
||||
strcat(ptr, filename.c_str());
|
||||
strcat(ptr, "</title></head><body><form action=\"edit.html?file=");
|
||||
strcat(ptr, filename.c_str());
|
||||
strcat(ptr, "\" method=\"post\">");
|
||||
strcat(ptr, "<textarea name=\"text\" cols=\"80\" rows=\"40\">");
|
||||
while (file.available()) {
|
||||
String line = file.readStringUntil('\n');
|
||||
strcat(ptr, line.c_str()); strcat(ptr, "\n");
|
||||
}
|
||||
strcat(ptr, "</textarea><input type=\"submit\">Save</input></form></body></html>");
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
const char *handleEditPost(AsyncWebServerRequest *request) {
|
||||
Serial.println("Handling post request");
|
||||
AsyncWebParameter *filep = request->getParam("file");
|
||||
if(!filep) return NULL;
|
||||
String filename = filep->value();
|
||||
AsyncWebParameter *textp = request->getParam("text", true);
|
||||
if(!textp) return NULL;
|
||||
String content = textp->value();
|
||||
File file = SPIFFS.open("/" + filename, "w");
|
||||
if (!file) {
|
||||
Serial.println("There was an error opening the file '/" + filename + "'for writing");
|
||||
return "";
|
||||
}
|
||||
file.print(content);
|
||||
file.close();
|
||||
return "";
|
||||
}
|
||||
|
||||
const char *createUpdateForm(boolean run) {
|
||||
char *ptr = message;
|
||||
char tmp[4];
|
||||
|
|
@ -630,6 +672,14 @@ void SetupAsyncServer() {
|
|||
request->send(200, "text/html", createControlForm());
|
||||
});
|
||||
|
||||
server.on("/edit.html", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||
request->send(200, "text/html", createEditForm(request->getParam(0)->value()));
|
||||
});
|
||||
server.on("/edit.html", HTTP_POST, [](AsyncWebServerRequest * request) {
|
||||
handleEditPost(request);
|
||||
request->send(200, "text/html", createEditForm(request->getParam(0)->value()));
|
||||
});
|
||||
|
||||
// Route to load style.css file
|
||||
server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||
request->send(SPIFFS, "/style.css", "text/css");
|
||||
|
|
@ -694,11 +744,13 @@ void checkTouchStatus();
|
|||
void touchISR();
|
||||
|
||||
void initTouch() {
|
||||
#if 1
|
||||
timer = timerBegin(0, 80, true);
|
||||
timerAttachInterrupt(timer, checkTouchStatus, true);
|
||||
timerAlarmWrite(timer, 300000, true);
|
||||
timerAlarmEnable(timer);
|
||||
touchAttachInterrupt(T3, touchISR, 20);
|
||||
touchAttachInterrupt(T4, touchISR, 20);
|
||||
#endif
|
||||
}
|
||||
|
||||
void IRAM_ATTR touchISR() {
|
||||
|
|
@ -710,7 +762,7 @@ void IRAM_ATTR touchISR() {
|
|||
|
||||
void IRAM_ATTR checkTouchStatus() {
|
||||
if (isTouched) {
|
||||
if(touchRead(T3) > 60) {
|
||||
if (touchRead(T4) > 60) {
|
||||
isTouched = false;
|
||||
// simulate key press
|
||||
button1.pressed = KP_SHORT;
|
||||
|
|
@ -1551,8 +1603,8 @@ static int lastDisplay=1;
|
|||
void loop() {
|
||||
Serial.print("Running main loop. free heap:");
|
||||
Serial.println(ESP.getFreeHeap());
|
||||
Serial.println(touchRead(13));
|
||||
Serial.println(touchRead(4));
|
||||
//Serial.println(touchRead(13));
|
||||
//Serial.println(touchRead(4));
|
||||
switch (mainState) {
|
||||
case ST_DECODER: loopDecoder(); break;
|
||||
case ST_SCANNER: loopScanner(); break;
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
const char *version_name = "RDZ_TTGO_SONDE";
|
||||
const char *version_id = "devel20190522";
|
||||
const char *version_id = "devel20190522b";
|
||||
|
|
|
|||
Loading…
Reference in New Issue