1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-23 10:50:54 +00:00

Added code to create a file display dynamic test / demo.

This commit is contained in:
Martin 2024-02-10 13:54:58 -05:00
parent 6e281e302a
commit 6a18c59f31

View File

@ -16,10 +16,12 @@ const char* password = "martinshomenetwork";
const char* hostname = "espui"; const char* hostname = "espui";
int statusLabelId; String DisplayTestFileName = "/FileName.txt";
int graphId; int statusLabelId = Control::noParent;
int millisLabelId; int graphId = Control::noParent;
int testSwitchId; int millisLabelId = Control::noParent;
int testSwitchId = Control::noParent;
int fileDisplayId = Control::noParent;
void numberCall(Control* sender, int type) void numberCall(Control* sender, int type)
{ {
@ -238,7 +240,7 @@ void setup(void)
ESPUI.slider("Slider two", &slider, ControlColor::None, 100); ESPUI.slider("Slider two", &slider, ControlColor::None, 100);
ESPUI.text("Text Test:", &textCall, ControlColor::Alizarin, "a Text Field"); ESPUI.text("Text Test:", &textCall, ControlColor::Alizarin, "a Text Field");
ESPUI.number("Numbertest", &numberCall, ControlColor::Alizarin, 5, 0, 10); ESPUI.number("Numbertest", &numberCall, ControlColor::Alizarin, 5, 0, 10);
ESPUI.fileDisplay("Filetest", ControlColor::Turquoise, "DisplayFile.txt"); fileDisplayId = ESPUI.fileDisplay("Filetest", ControlColor::Turquoise, DisplayTestFileName);
graphId = ESPUI.graph("Graph Test", ControlColor::Wetasphalt); graphId = ESPUI.graph("Graph Test", ControlColor::Wetasphalt);
@ -259,20 +261,20 @@ void setup(void)
* password, for example begin("ESPUI Control", "username", "password") * password, for example begin("ESPUI Control", "username", "password")
*/ */
ESPUI.sliderContinuous = true; ESPUI.sliderContinuous = true;
ESPUI.prepareFileSystem();
ESPUI.beginLITTLEFS("ESPUI Control"); ESPUI.beginLITTLEFS("ESPUI Control");
// create a text file // create a text file
ESPUI.prepareFileSystem();
#if defined(ESP32) #if defined(ESP32)
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
File testFile = LittleFS.open("/DisplayFile.txt", "w"); File testFile = LittleFS.open(String("/") + DisplayTestFileName, "w");
#else #else
File testFile = LITTLEFS.open("/DisplayFile.txt", "w"); File testFile = LITTLEFS.open(String("/") + DisplayTestFileName, "w");
#endif #endif
#else #else
File testFile = LittleFS.open("/DisplayFile.txt", "w"); File testFile = LittleFS.open(String("/") + DisplayTestFileName, "w");
#endif #endif
String TestLine = "Test Line\n"; String TestLine = String("Current Time = ") + String(millis()) + "\n";
testFile.write((const uint8_t*)TestLine.c_str(), TestLine.length()); testFile.write((const uint8_t*)TestLine.c_str(), TestLine.length());
testFile.close(); testFile.close();
} }
@ -284,7 +286,6 @@ void loop(void)
static long oldTime = 0; static long oldTime = 0;
static bool testSwitchState = false; static bool testSwitchState = false;
delay(10); delay(10);
return;
if (millis() - oldTime > 5000) if (millis() - oldTime > 5000)
{ {
@ -295,6 +296,29 @@ void loop(void)
testSwitchState = !testSwitchState; testSwitchState = !testSwitchState;
ESPUI.updateSwitcher(testSwitchId, testSwitchState); ESPUI.updateSwitcher(testSwitchId, testSwitchState);
#if defined(ESP32)
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4
File testFile = LittleFS.open(String("/") + DisplayTestFileName, "a");
uint32_t filesize = testFile.size();
#else
File testFile = LITTLEFS.open(String("/") + DisplayTestFileName, "a");
uint32_t filesize = testFile.size();
#endif
#else
File testFile = LittleFS.open(String("/") + DisplayTestFileName, "a");
uint32_t filesize = testFile.fileSize();
#endif
String TestLine = String("Current Time = ") + String(millis()) + "\n";
if(filesize < 1000)
{
testFile.write((const uint8_t*)TestLine.c_str(), TestLine.length());
ESPUI.updateControl(fileDisplayId);
TestLine += String("filesize: ") + String(filesize);
// Serial.println(TestLine);
}
testFile.close();
oldTime = millis(); oldTime = millis();
} }
} }