first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
/*
millisArray.ino
Copyright (c) 2020 Dale Giancono. All rights reserved..
This file is a an application to demonstrte the abilities of the
ESPFlash Library. It uses an ESPFlash<uint32_t> instance to store
10 millis values in an array.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ESPFlash.h"
#define ARRAY_FILEPATH "/millisArray"
ESPFlash<uint32_t> millisArray(ARRAY_FILEPATH);
void setup()
{
Serial.begin(115200);
Serial.println("Begining millisArray example...");
/* Have to initialise before performing any SPIFFS operations*/
SPIFFS.begin();
for(int ii = 0; ii < 10; ii++)
{
millisArray.append(millis());
for(int jj = 0; jj < millisArray.length(); jj++)
{
Serial.printf("%d ", millisArray.getElementAt(jj));
}
Serial.println();
}
Serial.println("Example finished...");
}
void loop()
{
}

View File

@@ -0,0 +1,45 @@
/*
powerCycleCounter.ino
Copyright (c) 2020 Dale Giancono. All rights reserved..
This file is a an application to demonstrte the abilities of the
ESPFlash Library. It uses an ESPFlashCounter instance to count
the number of times the ESP chip has had a power cycle/software reset.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ESPFlashCounter.h"
void setup()
{
Serial.begin(115200);
Serial.println("Starting");
/* Have to initialise before performing any SPIFFS operations*/
SPIFFS.begin();
ESPFlashCounter flashCounter("/counter");
flashCounter.increment();
Serial.print("Power Cycle ESPFlashCounter: ");
Serial.print(flashCounter.get());
Serial.println();
delay(3000);
ESP.reset();
}
void loop()
{
}

View File

@@ -0,0 +1,78 @@
/*
ssidStorage.ino
Copyright (c) 2020 Dale Giancono. All rights reserved..
This file is a an application to demonstrte the abilities of the
ESPFlash Library. It uses an ESPFlashString instance to store
the value of an SSID. An AsyncWebServer provides a way to change the
ssid value with a browser.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ESP8266WiFi.h"
#include "ESPAsyncTCP.h"
#include <ESPAsyncWebServer.h>
#include "ESPFlashString.h"
#define DEFAULT_SSID "ESPFlashString Test"
#define SSID_FILEPATH "/ssid"
static const char _SSIDEDIT[] = "<html><body><form action=\"/ssidedit\">New SSID: <input type=\"text\" value=\"\" name=\"SSID\"><input type=\"submit\" name=\"submit\"></form></html></body>";
/* Create webserver instance for serving the StringTemplate example. */
AsyncWebServer server(80);
void setup()
{
/* Have to initialise before performing any SPIFFS operations*/
SPIFFS.begin();
ESPFlashString ssid(SSID_FILEPATH, DEFAULT_SSID);
Serial.begin(115200);
/* Configure access point with static IP address */
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(
IPAddress(192, 168, 4, 1),
IPAddress(192, 168, 4, 1),
IPAddress(255, 255, 255, 0));
WiFi.softAP(ssid.get());
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
{
request->send(200, "text/html", _SSIDEDIT);
});
server.on("/ssidedit", HTTP_GET, [](AsyncWebServerRequest *request)
{
AsyncWebParameter* p = request->getParam("SSID");
if(p->value() != "")
{
ESPFlashString ssid(SSID_FILEPATH);
ssid.set(p->value());
WiFi.softAPdisconnect(true);
WiFi.softAP(ssid.get());
}
else
{
request->redirect("/");
}
});
server.begin();
}
void loop()
{
}

View File

@@ -0,0 +1,154 @@
#include "ESPFlash.h"
#include <limits>
void setup()
{
Serial.begin(115200);
delay(500);
Serial.println("Starting!");
Serial.println();
SPIFFS.begin();
Serial.println("Formatting SPIFFS. Will take a while...");
SPIFFS.format();
unitTest<bool>("bool");
unitTest<char>("char");
unitTest<signed char>("signed char");
unitTest<unsigned char>("unsigned char");
unitTest<wchar_t>("wchar_t");
unitTest<int8_t>("int8_t");
unitTest<char16_t>("char16_t");
unitTest<char32_t>("char32_t");
unitTest<short>("short");
unitTest<unsigned short>("unsigned short");
unitTest<int>("int");
unitTest<unsigned int>("unsigned int");
unitTest<long>("long");
unitTest<unsigned long>("unsigned long");
unitTest<int16_t>("int16_t");
unitTest<int32_t>("int32_t");
unitTest<uint8_t>("uint8_t");
unitTest<uint16_t>("uint16_t");
unitTest<uint32_t>("uint32_t");
unitTest<float>("float");
unitTest<double>("double");
Serial.println("Done!");
}
void loop()
{
}
template<typename T> void unitTest(const char* testName)
{
Serial.print(testName);
Serial.println(" unit test... ");
String filename = "/";
filename += testName;
ESPFlash<T> test(filename.c_str());
T testData[10];
T checkGet;
T checkGetFront[5];
T checkGetBack[5];
/* Prepare test data */
for(int ii = 0; ii < 10; ii++)
{
testData[ii] = std::numeric_limits<T>::max()/(ii+1);
test.append(testData[ii]);
}
Serial.println("get TEST ");
checkGet = testData[0];
if(test.get() == checkGet)
{
Serial.println("SUCCESS!!!");
}
else
{
Serial.println("FAILED...");
Serial.print("test.getElementAt(ii) ");
Serial.println(test.get());
Serial.print("checkGet ");
Serial.println(checkGet);
}
Serial.println("getFrontElements TEST ");
if(!test.getFrontElements(checkGetFront, 5))
{
Serial.println("getFrontElements ERROR ");
}
for(int ii = 0; ii < 5; ii++)
{
if(checkGetFront[ii] == testData[ii])
{
Serial.println("SUCCESS!!!");
}
else
{
Serial.println("FAILED...");
Serial.print("checkGetFront[");
Serial.print(ii);
Serial.print("] ");
Serial.println(checkGetFront[ii]);
Serial.print("testData[");
Serial.print(ii);
Serial.print("] ");
Serial.println(testData[ii]);
}
}
Serial.println("getBackElements TEST ");
if(!test.getBackElements(checkGetBack, 5))
{
Serial.println("checkGetBack ERROR ");
}
for(int ii = 0; ii < 5; ii++)
{
if(checkGetBack[ii] == testData[ii+5])
{
Serial.println("SUCCESS!!!");
}
else
{
Serial.println("FAILED...");
Serial.println(checkGetBack[ii]);
Serial.print("checkGetBack[");
Serial.print(ii);
Serial.print("] ");
Serial.print("testData[");
Serial.print(ii+5);
Serial.print("] ");
Serial.println(testData[ii+5]);
}
}
Serial.println("getElementAt TEST ");
for(int ii = 0; ii < test.length(); ii++)
{
if(test.getElementAt(ii) == testData[ii])
{
Serial.println("SUCCESS!!!");
}
else
{
Serial.println("FAILED...");
Serial.print("test.getElementAt(");
Serial.print(ii);
Serial.print(") ");
Serial.println(test.getElementAt(ii));
Serial.print("testData[ii");
Serial.print(ii);
Serial.print("] ");
Serial.println(testData[ii]);
}
}
Serial.println();
}

View File

@@ -0,0 +1,85 @@
#include "ESPFlash.h"
#include <limits>
void setup()
{
Serial.begin(115200);
delay(500);
Serial.println("Starting!");
Serial.println();
SPIFFS.begin();
Serial.println("Formatting SPIFFS. Will take a while...");
SPIFFS.format();
unitTest<bool>("bool");
unitTest<char>("char");
unitTest<signed char>("signed char");
unitTest<unsigned char>("unsigned char");
unitTest<wchar_t>("wchar_t");
unitTest<int8_t>("int8_t");
unitTest<char16_t>("char16_t");
unitTest<char32_t>("char32_t");
unitTest<short>("short");
unitTest<unsigned short>("unsigned short");
unitTest<int>("int");
unitTest<unsigned int>("unsigned int");
unitTest<long>("long");
unitTest<unsigned long>("unsigned long");
unitTest<int16_t>("int16_t");
unitTest<int32_t>("int32_t");
unitTest<uint8_t>("uint8_t");
unitTest<uint16_t>("uint16_t");
unitTest<uint32_t>("uint32_t");
unitTest<float>("float");
unitTest<double>("double");
Serial.println("Done!");
}
void loop()
{
}
template<typename T> void unitTest(const char* testName)
{
Serial.print(testName);
Serial.println(" unit test... ");
String filename = "/";
filename += testName;
ESPFlash<T> test(filename.c_str());
test.set(std::numeric_limits<T>::min());
Serial.print("MIN TEST ");
if(test.get() == std::numeric_limits<T>::min())
{
Serial.println("SUCCESS!!!");
}
else
{
Serial.println("FAILED...");
Serial.print("test.get() ");
Serial.println(test.get());
Serial.print("std::numeric_limits<T>::min() ");
Serial.println(std::numeric_limits<T>::min());
}
test.set(std::numeric_limits<T>::max());
Serial.print("MAX TEST ");
if(test.get() == std::numeric_limits<T>::max())
{
Serial.println("SUCCESS!!!");
}
else
{
Serial.println("FAILED...");
Serial.println(test.get());
Serial.print("std::numeric_limits<T>::max() ");
Serial.println(std::numeric_limits<T>::max());
}
}