Skip to content

Commit ac366ca

Browse files
committed
Add support for ESP32
Closes #4
1 parent 56eda63 commit ac366ca

File tree

11 files changed

+120
-99
lines changed

11 files changed

+120
-99
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# FastLEDHub
22

3+
![ESP8266](https://img.shields.io/badge/ESP-8266-000000.svg?colorB=blue)
4+
![ESP32](https://img.shields.io/badge/ESP-32-000000.svg?colorB=blue)
35
[![arduino-library-badge](https://www.ardu-badge.com/badge/FastLEDHub.svg?)](https://www.ardu-badge.com/FastLEDHub)
46
[![LGPL-2.1 license](https://img.shields.io/github/license/stnkl/FastLEDHub)](https://github.com/stnkl/FastLEDHub/blob/master/LICENSE)
57

6-
FastLEDHub allows you to manage all of your [FastLED]([FastLED](https://github.com/FastLED/FastLED)) sketches on the ESP8266 with minimal changes to your existing code. It requires little knowledge about the ESP8266 platform making it an ideal playground for beginners getting started with FastLED animations.
8+
FastLEDHub allows you to manage all of your [FastLED]([FastLED](https://github.com/FastLED/FastLED)) sketches on the ESP8266 and ESP32 with minimal changes to your existing code. It requires little knowledge about the ESP8266/ESP32 platform making it an ideal playground for beginners getting started with FastLED animations.
79

810
## Features
911

@@ -65,6 +67,7 @@ Using FastLEDHub to manage your FastLED animations requires mainly three steps:
6567
- Creating the main sketch to initialize your lightstrip with FastLEDHub
6668
- Creating an animation or modifying an existing sketch to be compatible with FastLEDHub
6769
- Registering your animations in the main sketch
70+
- Upload the web interface files to SPIFFS storage
6871

6972
### Creating the main sketch
7073

@@ -147,6 +150,13 @@ FastLEDHub.registerAnimation(new ExampleAnimation("Example animation name"));
147150

148151
The animation name can be any unique string and will be used to identify animations in the web interface.
149152

153+
### Uploading web interface files
154+
155+
To be able to access the web interface, several files have to be uploaded to SPIFFS storage. They are located within the `data` folder inside FastLEDHub's library folder. To upload those files there are two easy options:
156+
157+
- Copy the whole `data` folder into your sketch directory and upload the files using the Arduino filesystem uploader ([ESP8266](https://github.com/esp8266/arduino-esp8266fs-plugin), [ESP32](https://github.com/me-no-dev/arduino-esp32fs-plugin)).
158+
- After the sketch has been flashed to the device upload each file within the `data` folder individually by accessing `http://<device-ip>/edit`.
159+
150160
## Additional features
151161

152162
### Custom color pickers
@@ -220,7 +230,7 @@ Most functions can be triggered via HTTP requests:
220230
- Restart animation: `http://<device-ip>/restart`
221231
- Trigger sunset: `http://<device-ip>/sunset`
222232
- Trigger alarm: `http://<device-ip>/alarm`
223-
- Reset ESP8266: `http://<device-ip>/reboot`
233+
- Reset device: `http://<device-ip>/reboot`
224234

225235
## License & Attribution
226236

library.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
{
22
"name": "FastLEDHub",
3-
"description": "Control multiple FastLED lightstrip animations on the ESP8266 without reuploading.",
3+
"description": "Control multiple FastLED lightstrip animations on the ESP8266/ESP32 without reuploading.",
44
"repository":
55
{
66
"type": "git",
77
"url": "https://github.com/stnkl/FastLEDHub.git"
88
},
99
"frameworks": "arduino",
10-
"platforms": "espressif8266",
10+
"platforms": [
11+
"espressif8266",
12+
"espressif32"
13+
],
1114
"authors":
1215
{
1316
"name": "Stephan Rumswinkel",
1417
"maintainer": true,
1518
"url": "https://github.com/stnkl"
1619
},
17-
"version": "1.0.0"
20+
"version": "2.0.0"
1821
}

library.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=FastLEDHub
2-
version=1.0.0
2+
version=2.0.0
33
author=Stephan Rumswinkel
44
maintainer=Stephan Rumswinkel
5-
sentence=Control multiple FastLED lightstrip animations on the ESP8266 without reuploading.
6-
paragraph=FastLEDHub allows you to manage all of your FastLED sketches on the ESP8266 with minimal changes to your existing code. It requires little knowledge about the ESP8266 platform making in an ideal playground for beginners getting started with FastLED animations.
5+
sentence=Control multiple FastLED lightstrip animations on the ESP8266 and ESP32 without reuploading.
6+
paragraph=FastLEDHub allows you to manage all of your FastLED sketches on the ESP8266 and ESP32 with minimal changes to your existing code. It requires little knowledge about the ESP8266/ESP32 platform making in an ideal playground for beginners getting started with FastLED animations.
77
url=https://github.com/stnkl/FastLEDHub.git
88
category=Display
9-
architectures=esp8266
9+
architectures=esp8266,esp32
1010
depends=WiFiManager,ESPEssentials,ArduinoJson,LinkedList,FastLED,WebSockets

src/Config.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
#include "SerialOut.h"
55
#include "FastLEDHub.h"
66

7-
#include <FS.h>
7+
#if defined(ESP32)
8+
#include <SPIFFS.h>
9+
#elif defined(ESP8266)
10+
#include <FS.h>
11+
#endif
812

913
bool ConfigClass::initialize()
1014
{

src/FWebserver.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "FWebserver.h"
2+
3+
#include "Animation.h"
4+
#include "Fade.h"
5+
#include "FastLEDHub.h"
6+
7+
#include <Arduino.h>
8+
#include <ESPEssentials.h>
9+
10+
namespace Webserver
11+
{
12+
13+
void initialize()
14+
{
15+
ESPEssentials::WebServer.on("/reboot", HTTP_GET, [&]()
16+
{ ESP.restart(); });
17+
ESPEssentials::WebServer.on("/sunset", HTTP_GET, [&]()
18+
{
19+
Fade::begin(Fade::FadeMode::SUNSET);
20+
ESPEssentials::WebServer.send(200, "text/plain", "Starting sunset.");
21+
});
22+
ESPEssentials::WebServer.on("/alarm", HTTP_GET, [&]()
23+
{
24+
Fade::begin(Fade::FadeMode::ALARM);
25+
ESPEssentials::WebServer.send(200, "text/plain", "Starting alarm.");
26+
});
27+
ESPEssentials::WebServer.on("/stop", HTTP_GET, [&]()
28+
{
29+
Fade::stop();
30+
FastLEDHub.stop();
31+
ESPEssentials::WebServer.send(200, "text/plain", "Animation stopped.");
32+
});
33+
ESPEssentials::WebServer.on("/pause", HTTP_GET, [&]()
34+
{
35+
FastLEDHub.pause();
36+
ESPEssentials::WebServer.send(200, "text/plain", "Animation paused.");
37+
});
38+
ESPEssentials::WebServer.on("/resume", HTTP_GET, [&]()
39+
{
40+
FastLEDHub.resume();
41+
ESPEssentials::WebServer.send(200, "text/plain", "Animation resumed.");
42+
});
43+
ESPEssentials::WebServer.on("/toggle", HTTP_GET, [&]()
44+
{
45+
FastLEDHub.toggle();
46+
ESPEssentials::WebServer.send(200, "text/plain", "Animation toggled.");
47+
});
48+
ESPEssentials::WebServer.on("/restart", HTTP_GET, [&]()
49+
{
50+
FastLEDHub.restart();
51+
ESPEssentials::WebServer.send(200, "text/plain", "Animation restarted.");
52+
});
53+
ESPEssentials::WebServer.on("/begin", HTTP_GET, [&]()
54+
{
55+
if (ESPEssentials::WebServer.hasArg("animation"))
56+
{
57+
String animationName = String(ESPEssentials::WebServer.arg("animation"));
58+
FastLEDHub.begin(FastLEDHub.getAnimation(animationName));
59+
ESPEssentials::WebServer.send(200, "text/plain", "Started '" + animationName + "'");
60+
}
61+
else
62+
{
63+
uint8_t animationIndex = ESPEssentials::WebServer.hasArg("index") ? ESPEssentials::WebServer.arg("index").toInt() : 0;
64+
FastLEDHub.begin(FastLEDHub.getAnimation(animationIndex));
65+
ESPEssentials::WebServer.send(200, "text/plain", "Started animation #" + String(animationIndex));
66+
}
67+
});
68+
}
69+
70+
} // namespace Webserver
File renamed without changes.

src/Fade.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
#include "FastLEDHub.h"
33
#include "SerialOut.h"
44

5+
#if defined(ESP32)
6+
#include <HTTPClient.h>
7+
#elif defined(ESP8266)
8+
#include <ESP8266HTTPClient.h>
9+
#endif
510
#include <ArduinoJson.h>
6-
#include <ESP8266HTTPClient.h>
711
#include <ESPEssentials.h>
812
#include <Ticker.h>
913
#include <time.h>
@@ -17,7 +21,8 @@ namespace Fade
1721
FadeMode m_mode = FadeMode::NONE;
1822
uint16_t m_targetBrightness = 0;
1923
Ticker m_fadeTicker;
20-
Ticker m_debounce;
24+
Ticker m_debounceTicker;
25+
bool m_debounce = false;
2126

2227
void tick()
2328
{
@@ -101,7 +106,7 @@ namespace Fade
101106

102107
void handle()
103108
{
104-
if (m_mode != FadeMode::NONE || m_debounce.active())
109+
if (m_mode != FadeMode::NONE || m_debounce)
105110
return;
106111

107112
int8_t hour, minute;
@@ -125,8 +130,8 @@ namespace Fade
125130
FastLEDHub.setBrightness(0);
126131
FastLEDHub.show();
127132

128-
m_debounce.once(61, [&]()
129-
{ m_debounce.detach(); });
133+
m_debounceTicker.once(61, [](){ m_debounce = false; });
134+
m_debounce = true;
130135

131136
if (fadeMode == FadeMode::ALARM)
132137
{

src/FastLEDHub.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
#include "FastLEDHub.h"
22

3-
#include "Animation.h"
4-
#include "ColorUtils.h"
5-
#include "Config.h"
63
#include "Fade.h"
74
#include "SerialOut.h"
8-
#include "Webserver.h"
5+
#include "FWebserver.h"
96
#include "WebSocket.h"
107

11-
#include <ESPEssentials.h>
12-
138
FastLEDHubClass::FastLEDHubClass() : m_cycleButtonPushed(false),
149
m_toggleButtonPushed(false),
1510
m_autostartHandled(false),
@@ -27,7 +22,7 @@ FastLEDHubClass::FastLEDHubClass() : m_cycleButtonPushed(false),
2722
void FastLEDHubClass::initialize(const String &projectName, bool enableGammaCorrection)
2823
{
2924
m_gammaCorrectionEnabled = enableGammaCorrection;
30-
initESPEssentials(projectName);
25+
ESPEssentials::init(projectName);
3126
Config.initialize();
3227
if (WiFi.status() == WL_CONNECTED)
3328
{
@@ -49,28 +44,28 @@ void FastLEDHubClass::initialize(const String &projectName, bool enableGammaCorr
4944

5045
void FastLEDHubClass::enableCycleButton(uint8_t pin)
5146
{
52-
m_inputTicker.attach_ms(FASTLEDHUB_INPUT_TICKER_INTERVAL, std::bind(&FastLEDHubClass::handleInput, this));
47+
m_inputTicker.attach_ms(FASTLEDHUB_INPUT_TICKER_INTERVAL, +[](FastLEDHubClass* t) { t->handleInput(); }, this);
5348
pinMode(pin, INPUT);
5449
m_cycleButtonPin = pin;
5550
}
5651

5752
void FastLEDHubClass::enableToggleButton(uint8_t pin)
5853
{
59-
m_inputTicker.attach_ms(FASTLEDHUB_INPUT_TICKER_INTERVAL, std::bind(&FastLEDHubClass::handleInput, this));
54+
m_inputTicker.attach_ms(FASTLEDHUB_INPUT_TICKER_INTERVAL, +[](FastLEDHubClass* t) { t->handleInput(); }, this);
6055
pinMode(pin, INPUT);
6156
m_cycleButtonPin = pin;
6257
}
6358

6459
void FastLEDHubClass::enablePotentiometer(uint8_t pin)
6560
{
66-
m_inputTicker.attach_ms(FASTLEDHUB_INPUT_TICKER_INTERVAL, std::bind(&FastLEDHubClass::handleInput, this));
61+
m_inputTicker.attach_ms(FASTLEDHUB_INPUT_TICKER_INTERVAL, +[](FastLEDHubClass* t) { t->handleInput(); }, this);
6762
pinMode(pin, INPUT);
6863
m_potentiometerPin = pin;
6964
}
7065

7166
void FastLEDHubClass::handle()
7267
{
73-
handleESPEssentials();
68+
ESPEssentials::handle();
7469

7570
if (!m_autostartHandled)
7671
autostart();
@@ -121,7 +116,7 @@ void FastLEDHubClass::delay(uint16_t ms)
121116
unsigned long start = micros();
122117
while (micros() - start < 1000.0 * ms * pow((m_speed - 255) / 128.0, 2))
123118
{
124-
handleESPEssentials();
119+
ESPEssentials::handle();
125120
Fade::handle();
126121
WebSocket::handle();
127122
}

src/FastLEDHub.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "Slider.h"
88

99
#include <Arduino.h>
10+
#include <ESPEssentials.h>
1011
#define FASTLED_INTERNAL
1112
#include <FastLED.h>
1213
#include <LinkedList.h>

src/WebSocket.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include "WebSocket.h"
22

33
#include <ArduinoJson.h>
4-
#include <ESP8266mDNS.h>
4+
#if defined(ESP32)
5+
#include <ESPmDNS.h>
6+
#elif defined(ESP8266)
7+
#include <ESP8266mDNS.h>
8+
#endif
59
#include <FastLED.h>
6-
#include <Hash.h>
710

811
#include "Animation.h"
912
#include "ColorUtils.h"

0 commit comments

Comments
 (0)