Skip to content

Commit 5322116

Browse files
committed
Merge branch 'main' into fibonacci512mini
2 parents 73f40cb + fb52db4 commit 5322116

File tree

6 files changed

+98
-57
lines changed

6 files changed

+98
-57
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ build/
44
buildcache/
55
arduino.json
66
c_cpp_properties.json
7+
.vscode

Fields.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ String getTwinkleDensity() {
133133
return String(twinkleDensity);
134134
}
135135

136+
String getCoolLikeIncandescent() {
137+
return String(coolLikeIncandescent);
138+
}
139+
136140
String getName() {
137141
return nameString;
138142
}
@@ -286,6 +290,15 @@ FieldList fields = {
286290
{"solidColorSection", "Solid Color", SectionFieldType},
287291
{"solidColor", "Color", ColorFieldType, 0, 255, getSolidColor},
288292

293+
{"fireSection", "Fire & Water", SectionFieldType},
294+
{"cooling", "Cooling", NumberFieldType, 0, 255, getCooling},
295+
{"sparking", "Sparking", NumberFieldType, 0, 255, getSparking},
296+
297+
{"twinklesSection", "Twinkles", SectionFieldType},
298+
{"twinkleSpeed", "Twinkle Speed", NumberFieldType, 0, 8, getTwinkleSpeed},
299+
{"twinkleDensity", "Twinkle Density", NumberFieldType, 0, 8, getTwinkleDensity},
300+
{"coolLikeIncandescent", "Incandescent Cool", BooleanFieldType, 0, 1, getCoolLikeIncandescent},
301+
289302
{"prideSection", "Pride & ColorWaves", SectionFieldType},
290303

291304
{"saturationBpm", "Saturation BPM", NumberFieldType, 0, 255, getSaturationBpm, NULL, setSaturationBpm},
@@ -311,15 +324,6 @@ FieldList fields = {
311324
{"sHueBpm", "S Hue BPM", NumberFieldType, 0, 255, getSHueBpm, NULL, setSHueBpm},
312325
{"sHueMin", "S Hue Min", NumberFieldType, 0, 255, getSHueMin, NULL, setSHueMin},
313326
{"sHueMax", "S Hue Max", NumberFieldType, 0, 255, getSHueMax, NULL, setSHueMax},
314-
315-
316-
{"fireSection", "Fire & Water", SectionFieldType},
317-
{"cooling", "Cooling", NumberFieldType, 0, 255, getCooling},
318-
{"sparking", "Sparking", NumberFieldType, 0, 255, getSparking},
319-
320-
{"twinklesSection", "Twinkles", SectionFieldType},
321-
{"twinkleSpeed", "Twinkle Speed", NumberFieldType, 0, 8, getTwinkleSpeed},
322-
{"twinkleDensity", "Twinkle Density", NumberFieldType, 0, 8, getTwinkleDensity}
323327
};
324328

325329
uint8_t fieldCount = ARRAY_SIZE(fields);

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ The web app needs to be uploaded to the ESP8266's SPIFFS. You can do this withi
7474

7575
With ESP8266FS installed upload the web app using `ESP8266 Sketch Data Upload` command in the Arduino Tools menu.
7676

77-
Then enter your wi-fi network SSID and password in the WiFi.h file, and upload the sketch using the Upload button.
78-
7977
Compression
8078
-----------
8179

TwinkleFOX.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ CRGB gBackgroundColor = CRGB::Black;
8585
// If COOL_LIKE_INCANDESCENT is set to 1, colors will
8686
// fade out slighted 'reddened', similar to how
8787
// incandescent bulbs change color as they get dim down.
88-
#define COOL_LIKE_INCANDESCENT 1
88+
uint8_t coolLikeIncandescent = 1;
8989

9090
CRGBPalette16 twinkleFoxPalette;
9191

@@ -112,7 +112,7 @@ uint8_t attackDecayWave8( uint8_t i)
112112
// This function takes a pixel, and if its in the 'fading down'
113113
// part of the cycle, it adjusts the color a little bit like the
114114
// way that incandescent bulbs fade toward 'red' as they dim.
115-
void coolLikeIncandescent( CRGB& c, uint8_t phase)
115+
void doCoolLikeIncandescent( CRGB& c, uint8_t phase)
116116
{
117117
if( phase < 128) return;
118118

@@ -148,8 +148,8 @@ CRGB computeOneTwinkle( uint32_t ms, uint8_t salt)
148148
CRGB c;
149149
if( bright > 0) {
150150
c = ColorFromPalette( twinkleFoxPalette, hue, bright, NOBLEND);
151-
if( COOL_LIKE_INCANDESCENT == 1 ) {
152-
coolLikeIncandescent( c, fastcycle8);
151+
if( coolLikeIncandescent == 1 ) {
152+
doCoolLikeIncandescent( c, fastcycle8);
153153
}
154154
} else {
155155
c = CRGB::Black;

deployfirmware.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
outputDir=build
2+
binFilename=tree-v2.ino.bin
3+
ip=${1:-"192.168.86.36"}
4+
url="http://$ip/update"
5+
6+
curl -v --form "file=@$outputDir/$binFilename;filename=$binFilename" $url

esp8266-fastled-webserver.ino

Lines changed: 74 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ CRGB leds[NUM_LEDS];
7979

8080
const uint8_t brightnessCount = 5;
8181
uint8_t brightnessMap[brightnessCount] = { 16, 32, 64, 128, 255 };
82-
uint8_t brightnessIndex = 0;
82+
uint8_t brightnessIndex = 3;
8383

8484
// ten seconds per color palette makes a good demo
8585
// 20-120 is better for deployment
@@ -300,7 +300,7 @@ void setup() {
300300
FastLED.show();
301301

302302
EEPROM.begin(512);
303-
loadSettings();
303+
readSettings();
304304

305305
FastLED.setBrightness(brightness);
306306

@@ -315,6 +315,7 @@ void setup() {
315315
Serial.print( F("Flash ID: ") ); Serial.println(spi_flash_get_id());
316316
Serial.print( F("Flash Size: ") ); Serial.println(ESP.getFlashChipRealSize());
317317
Serial.print( F("Vcc: ") ); Serial.println(ESP.getVcc());
318+
Serial.print( F("MAC Address: ") ); Serial.println(WiFi.macAddress());
318319
Serial.println();
319320

320321
SPIFFS.begin();
@@ -332,13 +333,20 @@ void setup() {
332333

333334
// Do a little work to get a unique-ish name. Get the
334335
// last two bytes of the MAC (HEX'd)":
336+
337+
// copy the mac address to a byte array
335338
uint8_t mac[WL_MAC_ADDR_LENGTH];
336339
WiFi.softAPmacAddress(mac);
337-
String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
338-
String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
339-
macID.toUpperCase();
340340

341-
nameString = "Fibonacci512-" + macID;
341+
// format the last two digits to hex character array, like 0A0B
342+
char macID[5];
343+
sprintf(macID, "%02X%02X", mac[WL_MAC_ADDR_LENGTH - 2], mac[WL_MAC_ADDR_LENGTH - 1]);
344+
345+
// convert the character array to a string
346+
String macIdString = macID;
347+
macIdString.toUpperCase();
348+
349+
nameString = "Fibonacci512-" + macIdString;
342350

343351
char nameChar[nameString.length() + 1];
344352
memset(nameChar, 0, nameString.length() + 1);
@@ -395,6 +403,7 @@ void setup() {
395403
webServer.on("/cooling", HTTP_POST, []() {
396404
String value = webServer.arg("value");
397405
cooling = value.toInt();
406+
writeAndCommitSettings();
398407
broadcastInt("cooling", cooling);
399408
webServer.sendHeader("Access-Control-Allow-Origin", "*");
400409
sendInt(cooling);
@@ -403,6 +412,7 @@ void setup() {
403412
webServer.on("/sparking", HTTP_POST, []() {
404413
String value = webServer.arg("value");
405414
sparking = value.toInt();
415+
writeAndCommitSettings();
406416
broadcastInt("sparking", sparking);
407417
webServer.sendHeader("Access-Control-Allow-Origin", "*");
408418
sendInt(sparking);
@@ -421,6 +431,7 @@ void setup() {
421431
twinkleSpeed = value.toInt();
422432
if (twinkleSpeed < 0) twinkleSpeed = 0;
423433
else if (twinkleSpeed > 8) twinkleSpeed = 8;
434+
writeAndCommitSettings();
424435
broadcastInt("twinkleSpeed", twinkleSpeed);
425436
webServer.sendHeader("Access-Control-Allow-Origin", "*");
426437
sendInt(twinkleSpeed);
@@ -431,11 +442,22 @@ void setup() {
431442
twinkleDensity = value.toInt();
432443
if (twinkleDensity < 0) twinkleDensity = 0;
433444
else if (twinkleDensity > 8) twinkleDensity = 8;
445+
writeAndCommitSettings();
434446
broadcastInt("twinkleDensity", twinkleDensity);
435447
webServer.sendHeader("Access-Control-Allow-Origin", "*");
436448
sendInt(twinkleDensity);
437449
});
438450

451+
webServer.on("/coolLikeIncandescent", HTTP_POST, []() {
452+
String value = webServer.arg("value");
453+
coolLikeIncandescent = value.toInt();
454+
if (coolLikeIncandescent < 0) coolLikeIncandescent = 0;
455+
else if (coolLikeIncandescent > 1) coolLikeIncandescent = 1;
456+
writeAndCommitSettings();
457+
broadcastInt("coolLikeIncandescent", coolLikeIncandescent);
458+
sendInt(coolLikeIncandescent);
459+
});
460+
439461
webServer.on("/solidColor", HTTP_POST, []() {
440462
String r = webServer.arg("r");
441463
String g = webServer.arg("g");
@@ -881,8 +903,15 @@ void loop() {
881903
// }
882904
//}
883905

884-
void loadSettings()
906+
void readSettings()
885907
{
908+
// check for "magic number" so we know settings have been written to EEPROM
909+
// and it's not just full of random bytes
910+
911+
if (EEPROM.read(511) != 55) {
912+
return;
913+
}
914+
886915
brightness = EEPROM.read(0);
887916

888917
currentPatternIndex = EEPROM.read(1);
@@ -914,37 +943,56 @@ void loadSettings()
914943
else if (currentPaletteIndex >= paletteCount)
915944
currentPaletteIndex = paletteCount - 1;
916945

917-
showClock = EEPROM.read(9);
918-
clockBackgroundFade = EEPROM.read(10);
946+
twinkleSpeed = EEPROM.read(9);
947+
twinkleDensity = EEPROM.read(10);
948+
949+
cooling = EEPROM.read(11);
950+
sparking = EEPROM.read(12);
951+
952+
coolLikeIncandescent = EEPROM.read(13);
953+
954+
showClock = EEPROM.read(14);
955+
clockBackgroundFade = EEPROM.read(15);
919956
}
920957

921-
void setPower(uint8_t value)
958+
void writeAndCommitSettings()
922959
{
923-
power = value == 0 ? 0 : 1;
924-
960+
EEPROM.write(0, brightness);
961+
EEPROM.write(1, currentPatternIndex);
962+
EEPROM.write(2, solidColor.r);
963+
EEPROM.write(3, solidColor.g);
964+
EEPROM.write(4, solidColor.b);
925965
EEPROM.write(5, power);
966+
EEPROM.write(6, autoplay);
967+
EEPROM.write(7, autoplayDuration);
968+
EEPROM.write(8, currentPaletteIndex);
969+
EEPROM.write(9, twinkleSpeed);
970+
EEPROM.write(10, twinkleDensity);
971+
EEPROM.write(11, cooling);
972+
EEPROM.write(12, sparking);
973+
974+
EEPROM.write(511, 55);
926975
EEPROM.commit();
976+
}
927977

978+
void setPower(uint8_t value)
979+
{
980+
power = value == 0 ? 0 : 1;
981+
writeAndCommitSettings();
928982
broadcastInt("power", power);
929983
}
930984

931985
void setAutoplay(uint8_t value)
932986
{
933987
autoplay = value == 0 ? 0 : 1;
934-
935-
EEPROM.write(6, autoplay);
936-
EEPROM.commit();
937-
988+
writeAndCommitSettings();
938989
broadcastInt("autoplay", autoplay);
939990
}
940991

941992
void setAutoplayDuration(uint8_t value)
942993
{
943994
autoplayDuration = value;
944-
945-
EEPROM.write(7, autoplayDuration);
946-
EEPROM.commit();
947-
995+
writeAndCommitSettings();
948996
autoPlayTimeout = millis() + (autoplayDuration * 1000);
949997

950998
broadcastInt("autoplayDuration", autoplayDuration);
@@ -958,12 +1006,7 @@ void setSolidColor(CRGB color)
9581006
void setSolidColor(uint8_t r, uint8_t g, uint8_t b)
9591007
{
9601008
solidColor = CRGB(r, g, b);
961-
962-
EEPROM.write(2, r);
963-
EEPROM.write(3, g);
964-
EEPROM.write(4, b);
965-
EEPROM.commit();
966-
1009+
writeAndCommitSettings();
9671010
setPattern(patternCount - 1);
9681011

9691012
broadcastString("color", String(solidColor.r) + "," + String(solidColor.g) + "," + String(solidColor.b));
@@ -984,8 +1027,7 @@ void adjustPattern(bool up)
9841027
currentPatternIndex = 0;
9851028

9861029
if (autoplay == 0) {
987-
EEPROM.write(1, currentPatternIndex);
988-
EEPROM.commit();
1030+
writeAndCommitSettings();
9891031
}
9901032

9911033
broadcastInt("pattern", currentPatternIndex);
@@ -999,8 +1041,7 @@ void setPattern(uint8_t value)
9991041
currentPatternIndex = value;
10001042

10011043
if (autoplay == 0) {
1002-
EEPROM.write(1, currentPatternIndex);
1003-
EEPROM.commit();
1044+
writeAndCommitSettings();
10041045
}
10051046

10061047
broadcastInt("pattern", currentPatternIndex);
@@ -1022,10 +1063,7 @@ void setPalette(uint8_t value)
10221063
value = paletteCount - 1;
10231064

10241065
currentPaletteIndex = value;
1025-
1026-
EEPROM.write(8, currentPaletteIndex);
1027-
EEPROM.commit();
1028-
1066+
writeAndCommitSettings();
10291067
broadcastInt("palette", currentPaletteIndex);
10301068
}
10311069

@@ -1049,10 +1087,7 @@ void adjustBrightness(bool up)
10491087
brightness = brightnessMap[brightnessIndex];
10501088

10511089
FastLED.setBrightness(brightness);
1052-
1053-
EEPROM.write(0, brightness);
1054-
EEPROM.commit();
1055-
1090+
writeAndCommitSettings();
10561091
broadcastInt("brightness", brightness);
10571092
}
10581093

@@ -1065,10 +1100,7 @@ void setBrightness(uint8_t value)
10651100
brightness = value;
10661101

10671102
FastLED.setBrightness(brightness);
1068-
1069-
EEPROM.write(0, brightness);
1070-
EEPROM.commit();
1071-
1103+
writeAndCommitSettings();
10721104
broadcastInt("brightness", brightness);
10731105
}
10741106

0 commit comments

Comments
 (0)