Skip to content

Commit cc944c4

Browse files
committed
#89, LittleFS supoort, #90
- Renamed all SPIFFS to FILESYSTEM - Users can now choose to use SPIFFS or LittleFS - Fix #89 added a restart button when in WiFi mode - Fix #90 Allow for multiple files uploads Note! Because changes are made to the data folder, this version requires you to also upload the data folder again.
1 parent b0f2962 commit cc944c4

7 files changed

+113
-29
lines changed

ConfigHelper.h

+5
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ void configmode()
150150
tft.println("Then go to http://freetouchdeck.local");
151151
tft.print("The IP is: ");
152152
tft.println(WiFi.softAPIP());
153+
drawSingleButton(140, 180, 200, 80, generalconfig.menuButtonColour, TFT_WHITE, "Restart");
153154
return;
154155
}
155156

@@ -163,6 +164,7 @@ void configmode()
163164
tft.println("Then go to http://freetouchdeck.local");
164165
tft.print("The IP is: ");
165166
tft.println(WiFi.softAPIP());
167+
drawSingleButton(140, 180, 200, 80, generalconfig.menuButtonColour, TFT_WHITE, "Restart");
166168
return;
167169
}
168170

@@ -176,6 +178,7 @@ void configmode()
176178
tft.println("Then go to http://freetouchdeck.local");
177179
tft.print("The IP is: ");
178180
tft.println(WiFi.softAPIP());
181+
drawSingleButton(140, 180, 200, 80, generalconfig.menuButtonColour, TFT_WHITE, "Restart");
179182
}
180183
else
181184
{
@@ -184,6 +187,7 @@ void configmode()
184187
tft.println("http://freetouchdeck.local");
185188
tft.print("The IP is: ");
186189
tft.println(WiFi.localIP());
190+
drawSingleButton(140, 180, 200, 80, generalconfig.menuButtonColour, TFT_WHITE, "Restart");
187191
}
188192

189193
}
@@ -195,6 +199,7 @@ void configmode()
195199
tft.println("http://freetouchdeck.local");
196200
tft.print("The IP is: ");
197201
tft.println(WiFi.softAPIP());
202+
drawSingleButton(140, 180, 200, 80, generalconfig.menuButtonColour, TFT_WHITE, "Restart");
198203
}
199204
}
200205

DrawHelper.h

+41-1
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ void printinfo()
15811581
#endif
15821582

15831583
tft.print("Free Storage: ");
1584-
float freemem = SPIFFS.totalBytes() - SPIFFS.usedBytes();
1584+
float freemem = FILESYSTEM.totalBytes() - FILESYSTEM.usedBytes();
15851585
tft.print(freemem / 1000);
15861586
tft.println(" kB");
15871587
#if defined(USEUSBHID)
@@ -1600,3 +1600,43 @@ void printinfo()
16001600

16011601
displayinginfo = true;
16021602
}
1603+
1604+
/**
1605+
* @brief This function allow for drawing a single button which is not part of the
1606+
button class. It should be manually checked for touched.
1607+
*
1608+
* @param int32_t x
1609+
int32_t y
1610+
int32_t w
1611+
int32_t h
1612+
int32_t r
1613+
uint32_t color
1614+
uint32_t outline
1615+
char *label
1616+
*
1617+
* @return none
1618+
*
1619+
* @note Use the X and Y coordinates and check in the loop if it was pressed.
1620+
*/
1621+
1622+
void drawSingleButton(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color, uint32_t outline, String label)
1623+
{
1624+
1625+
//Draw the button
1626+
uint8_t r = min(w, h) / 4; // Corner radius
1627+
tft.fillRoundRect(x, y, w, h, r, color);
1628+
tft.drawRoundRect(x, y, w, h, r, outline);
1629+
1630+
//Print the label
1631+
tft.setTextColor(TFT_WHITE,color);
1632+
tft.setTextSize(2);
1633+
uint8_t tempdatum = tft.getTextDatum();
1634+
tft.setTextDatum(MC_DATUM);
1635+
uint16_t tempPadding = tft.getTextPadding();
1636+
tft.setTextPadding(0);
1637+
1638+
tft.drawString(label, x + (w/2), y + (h/2));
1639+
tft.setTextDatum(tempdatum);
1640+
tft.setTextPadding(tempPadding);
1641+
1642+
}

FreeTouchDeck.ino

+53-10
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,25 @@
6161
// and if you are using the original ESP32-BLE-Keyboard library by T-VK -------
6262
//#define USE_NIMBLE
6363

64+
// Define the filesystem to be used. For now just SPIFFS.
65+
#define FILESYSTEM SPIFFS
66+
67+
#include <SPIFFS.h> // Filesystem support header
68+
//#include <LittleFS.h> // Filesystem support header
69+
6470
const char *versionnumber = "0.9.18a";
6571

6672
/* Version 0.9.18a.
6773
*
6874
* Adding ESP32-S3 support
75+
* Trying to add LitteFS Support
76+
* Fix #89
77+
* Fix #90
6978
*/
7079

7180
#include <pgmspace.h> // PROGMEM support header
7281
#include <FS.h> // Filesystem support header
73-
#include <SPIFFS.h> // Filesystem support header
82+
7483
#include <Preferences.h> // Used to store states before sleep/reboot
7584

7685
#include <TFT_eSPI.h> // The TFT_eSPI library
@@ -134,9 +143,6 @@ TFT_eSPI tft = TFT_eSPI();
134143

135144
Preferences savedStates;
136145

137-
// Define the storage to be used. For now just SPIFFS.
138-
#define FILESYSTEM SPIFFS
139-
140146
// This is the file name used to store the calibration data
141147
// You can change this to create new calibration files.
142148
// The FILESYSTEM file name must start with "/".
@@ -375,17 +381,17 @@ void setup()
375381

376382
if (!FILESYSTEM.begin())
377383
{
378-
Serial.println("[ERROR]: SPIFFS initialisation failed!");
379-
drawErrorMessage("Failed to init SPIFFS! Did you upload the data folder?");
384+
Serial.println("[ERROR]: FILESYSTEM initialisation failed!");
385+
drawErrorMessage("Failed to init FILESYSTEM! Did you upload the data folder?");
380386
while (1)
381387
yield(); // We stop here
382388
}
383-
Serial.println("[INFO]: SPIFFS initialised.");
389+
Serial.println("[INFO]: FILESYSTEM initialised.");
384390

385391
// Check for free space
386392

387393
Serial.print("[INFO]: Free Space: ");
388-
Serial.println(SPIFFS.totalBytes() - SPIFFS.usedBytes());
394+
Serial.println(FILESYSTEM.totalBytes() - FILESYSTEM.usedBytes());
389395

390396
//------------------ Load Wifi Config ----------------------------------------------
391397

@@ -722,9 +728,46 @@ void loop(void)
722728

723729
if (pageNum == 7)
724730
{
731+
uint16_t t_x = 0, t_y = 0;
732+
boolean pressed = false;
733+
734+
// If pageNum = 7, we are in STA or AP mode.
735+
// We no check if the button is pressed, and if so restart.
736+
#ifdef USECAPTOUCH
737+
if (ts.touched())
738+
{
739+
740+
// Retrieve a point
741+
TS_Point p = ts.getPoint();
742+
743+
//Flip things around so it matches our screen rotation
744+
p.x = map(p.x, 0, 320, 320, 0);
745+
t_y = p.x;
746+
t_x = p.y;
747+
748+
pressed = true;
749+
}
750+
751+
#else
752+
753+
pressed = tft.getTouch(&t_x, &t_y);
754+
755+
#endif // defined(USECAPTOUCH)
756+
757+
if (pressed)
758+
{
759+
// If pressed check if the touch falls within the restart button
760+
// drawSingleButton(140, 180, 200, 80, generalconfig.menuButtonColour, TFT_WHITE, "Restart");
761+
if (t_x > 140 && t_x < 340){
762+
if (t_y > 180 && t_y < 260){
763+
// Touch falls within the boundaries of our button so we restart
764+
Serial.println("[WARNING]: Restarting");
765+
ESP.restart();
766+
}
767+
}
768+
769+
}
725770

726-
// If the pageNum is set to 7, do not draw anything on screen or check for touch
727-
// and start handeling incomming web requests.
728771
}
729772
else if (pageNum == 8)
730773
{

README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@ For interfacing with Windows/macOS/Linux using an ESP32, a touchscreen and BLE.
1414

1515
# Install Using The Web Installer (recommended!)
1616

17-
Easy installation without the need for the Arduino IDE, and downloading and editing libraries is now available using ESP Web Tools. Visit this url to install FreeTouchDeck to your board via your browser: ***https://install.freetouchdeck.com/*** Chrome, Edge, and Opera only at the moment.
17+
Easy installation without the need for the Arduino IDE, and downloading and editing libraries is now available using ESP Web Tools. Visit this url to install FreeTouchDeck to your board via your browser: (https://install.freetouchdeck.com/) Chrome, Edge, and Opera only at the moment.
1818

1919
# User Guide
20-
The User Guide will help you with installing and configuring if you want to build the project yourself:
21-
### [User guide](https://github.com/DustinWatts/FreeTouchDeck/wiki)
22-
23-
Another great source is the Instructables that will guide your step by step:
24-
### [Instructable](https://www.instructables.com/A-Bluetooth-ESP32-TFT-Touch-Macro-Keypad/)
20+
The User Guide will help you with installing and configuring if you want to build the project yourself: ### [User guide](https://github.com/DustinWatts/FreeTouchDeck/wiki)
2521

2622
# ESP32 TouchDown users
2723

ScreenHelper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ uint16_t getBMPColor(const char *filename)
273273

274274
// Open File
275275
File bmpImage;
276-
bmpImage = SPIFFS.open(filename, FILE_READ);
276+
bmpImage = FILESYSTEM.open(filename, FILE_READ);
277277

278278
int32_t dataStartingOffset = readNbytesInt(&bmpImage, 0x0A, 4);
279279
int16_t pixelsize = readNbytesInt(&bmpImage, 0x1C, 2);

Webserver.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ String handleAPISList()
107107
String handleInfo()
108108
{
109109

110-
float freemem = SPIFFS.totalBytes() - SPIFFS.usedBytes();
110+
float freemem = FILESYSTEM.totalBytes() - FILESYSTEM.usedBytes();
111111

112112
String output = "[";
113113

@@ -254,7 +254,7 @@ void handleJSONUpload(AsyncWebServerRequest *request, String filename, size_t in
254254
filename = "/config/" + filename; // TODO: Does the config directory need to be hardcoded?
255255

256256
// Open the file on first call and store the file handle in the request object
257-
request->_tempFile = SPIFFS.open(filename, "w");
257+
request->_tempFile = FILESYSTEM.open(filename, "w");
258258
}
259259
if (len)
260260
{
@@ -292,7 +292,7 @@ void handleAPIUpload(AsyncWebServerRequest *request, String filename, size_t ind
292292
filename = "/uploads/" + filename; // TODO: Does the uploads directory need to be hardcoded?
293293

294294
// Open the file on first call and store the file handle in the request object
295-
request->_tempFile = SPIFFS.open(filename, "w");
295+
request->_tempFile = FILESYSTEM.open(filename, "w");
296296
}
297297
if (len)
298298
{
@@ -308,17 +308,17 @@ void handleAPIUpload(AsyncWebServerRequest *request, String filename, size_t ind
308308
}
309309
}
310310

311-
/* --------------- Checking for free space on SPIFFS ----------------
312-
Purpose: This checks if the free memory on the SPIFFS is bigger then a set threshold
311+
/* --------------- Checking for free space on FILESYSTEM ----------------
312+
Purpose: This checks if the free memory on the FILESYSTEM is bigger then a set threshold
313313
Input : none
314314
Output : boolean
315315
Note : none
316316
*/
317317

318318
bool spaceLeft()
319319
{
320-
float minmem = 100000.00; // Always leave 100 kB free pace on SPIFFS
321-
float freeMemory = SPIFFS.totalBytes() - SPIFFS.usedBytes();
320+
float minmem = 100000.00; // Always leave 100 kB free pace on FILESYSTEM
321+
float freeMemory = FILESYSTEM.totalBytes() - FILESYSTEM.usedBytes();
322322
Serial.printf("[INFO]: Free memory left: %f bytes\n", freeMemory);
323323
if (freeMemory < minmem)
324324
{
@@ -350,7 +350,7 @@ void handleUpload(AsyncWebServerRequest *request, String filename, size_t index,
350350
Serial.printf("[INFO]: File Upload Start: %s\n", filename.c_str());
351351
filename = "/logos/" + filename;
352352
// Open the file on first call and store the file handle in the request object
353-
request->_tempFile = SPIFFS.open(filename, "w");
353+
request->_tempFile = FILESYSTEM.open(filename, "w");
354354
}
355355
if (len)
356356
{
@@ -1863,9 +1863,9 @@ void handlerSetup()
18631863
Serial.printf("[INFO]: Deleting file: %s\n", p->value().c_str());
18641864
String filename = "/logos/";
18651865
filename += p->value().c_str();
1866-
if (SPIFFS.exists(filename))
1866+
if (FILESYSTEM.exists(filename))
18671867
{
1868-
SPIFFS.remove(filename);
1868+
FILESYSTEM.remove(filename);
18691869
}
18701870

18711871
resultFiles += p->value().c_str();

data/index.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ <h3>Upload a new logo</h3>
926926
</div>
927927
<p>
928928
<div class="form" style="width: 10%; text-align: : center; margin: auto;">
929-
<input form="uploadfile" type="file" name="name" accept=".bmp"><br /><br />
929+
<input form="uploadfile" type="file" name="name" accept=".bmp" multiple><br /><br />
930930
<button style='cursor: pointer;' form="uploadfile" type="save">Upload</button>
931931
</div>
932932
</p>

0 commit comments

Comments
 (0)