Skip to content

Bug Fixes, More Patterns, and improovements #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The app is installed via the Arduino IDE which can be [downloaded here](https://
The app depends on the following libraries. They must either be downloaded from GitHub and placed in the Arduino 'libraries' folder, or installed as [described here](https://www.arduino.cc/en/Guide/Libraries) by using the Arduino library manager.

* [FastLED](https://github.com/FastLED/FastLED)
* [IRremoteESP8266](https://github.com/sebastienwarin/IRremoteESP8266)
* [IRremoteESP8266](https://github.com/crankyoldgit/IRremoteESP8266)
* [Arduino WebSockets](https://github.com/Links2004/arduinoWebSockets)
* [Arduino JSON](https://arduinojson.org)
* [lolrol LittleFS](https://github.com/lorol/LITTLEFS) -- (integrated into ESP32 core v2, which is not used here yet)
Expand Down
17 changes: 16 additions & 1 deletion esp8266-fastled-webserver/GradientPalettes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,22 @@ DEFINE_GRADIENT_PALETTE( Blue_Cyan_Yellow_gp ) {
255, 255,255, 0};


// Two copies of "Vapour" exist ... one explicitly as a "Gradient Palette",
// and one
DEFINE_GRADIENT_PALETTE( Vapour_gp ) {
0, 111, 234, 230,
64, 246, 163, 239,
128, 80, 216, 236,
192, 221, 109, 251,
255, 238, 205, 105
};


// Single array of defined cpt-city color palettes.
// This will let us programmatically choose one based on
// a number, rather than having to activate each explicitly
// by name every time.
//
// Since it is const, this array could also be moved
// into PROGMEM to save SRAM, but for simplicity of illustration
// we'll keep it in a regular SRAM array.
Expand Down Expand Up @@ -511,9 +523,12 @@ const TProgmemRGBGradientPalettePtr gGradientPalettes[] = {
BlacK_Blue_Magenta_White_gp,
BlacK_Magenta_Red_gp,
BlacK_Red_Magenta_Yellow_gp,
Blue_Cyan_Yellow_gp };
Blue_Cyan_Yellow_gp,
Vapour_gp,
};


// Count of how many cpt-city gradients are defined:
const uint8_t gGradientPaletteCount = ARRAY_SIZE2(gGradientPalettes);


9 changes: 7 additions & 2 deletions esp8266-fastled-webserver/Twinkles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void colortwinkles()
// Make each pixel brighter or darker, depending on
// its 'direction' flag.
brightenOrDarkenEachPixel( FADE_IN_SPEED, FADE_OUT_SPEED);

// Now consider adding a new random twinkle
if ( random8() < DENSITY ) {
int pos = random16(NUM_PIXELS);
Expand All @@ -90,6 +90,12 @@ void colortwinkles()
}
}

void currentPaletteTwinkles()
{
gCurrentPalette = palettes[currentPaletteIndex];
colortwinkles();
}

void cloudTwinkles()
{
gCurrentPalette = CloudColors_p; // Blues and whites!
Expand Down Expand Up @@ -117,4 +123,3 @@ void incandescentTwinkles()
gCurrentPalette = CRGBPalette16( l, l, l, l, l, l, l, l, l, l, l, l, l, l, l, l );
colortwinkles();
}

83 changes: 83 additions & 0 deletions esp8266-fastled-webserver/Websockets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
ESP8266 FastLED WebServer: https://github.com/jasoncoon/esp8266-fastled-webserver
Copyright (C) Jason Coon

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 <http://www.gnu.org/licenses/>.
*/

#if ENABLE_WEBSOCKETS

#include "common.h"

// #include <WebSockets.h>
#include <WebSocketsServer.h>


WebSocketsServer webSocketsServer = WebSocketsServer(81);

void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
switch (type) {
case WStype_DISCONNECTED:
Serial.printf("[%u] Disconnected!\n", num);
break;

case WStype_CONNECTED:
IPAddress ip = webSocketsServer.remoteIP(num);
Serial.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);

//send message to client
webSocketsServer.sendTXT(num, "Connected");
break;

case WStype_TEXT:
Serial.printf("[%u] get Text: %s\n", num, payload);

//send message to client
webSocketsServer.sendTXT(num, payload);

//send data to all connected clients
webSocketsServer.broadcastTXT(payload);

break;

case WStype_BIN:
Serial.printf("[%u] get binary length: %u\n", num, length);
hexdump(payload, length);

//send message to client
webSocketsServer.sendBIN(num, payload, length);
break;
}
}

void InitializeWebSocketServer(void) {
webSocketsServer.begin();
webSocketsServer.onEvent(webSocketEvent);
Serial.println("Web socket server started");
}
void handleWebSocketLoop(void) {
webSocketsServer.loop();
}
void broadcastInt(String name, uint8_t value) {
String json = "{\"name\":\"" + name + "\",\"value\":" + String(value) + "}";
webSocketsServer.broadcastTXT(json);
}
void broadcastString(String name, String value)
{
String json = "{\"name\":\"" + name + "\",\"value\":\"" + String(value) + "\"}";
webSocketsServer.broadcastTXT(json);
}


#endif // ENABLE_WEBSOCKETS
Loading