Skip to content

Commit

Permalink
Substantial refactoring of base library code. (#228)
Browse files Browse the repository at this point in the history
* Added cycle flag to effects

* added cycle flag to custom effects

* initial code to separate segments and segment_runtimes

* added functions to manage active segments

* significant refactor of segment management

* fixed active_segment pointer usage

* fixed swap segment to allow completing the last frame

* increased number of custom effects from 4 to 8

* refactor ws2812fx_webinterface example sketch

* added setPixels() function.

Co-authored-by: Keith Lord <[email protected]>
  • Loading branch information
moose4lord and Keith Lord authored May 29, 2020
1 parent 0da073a commit fc571c4
Show file tree
Hide file tree
Showing 27 changed files with 1,113 additions and 761 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Download, Install and Example
You can **search for WS2812FX in the Arduino IDE Library Manager** or install the latest (or development) version manually:


* Install the famous [Adafruit NeoPixel library](https://github.com/adafruit/Adafruit_NeoPixel) (v1.1.4 or newer)
* Install the famous [Adafruit NeoPixel library](https://github.com/adafruit/Adafruit_NeoPixel) (v1.1.7 or newer)
* Download this repository.
* Extract to your Arduino libraries directory.
* Open Arduino IDE.
Expand Down
13 changes: 5 additions & 8 deletions examples/esp8266_webinterface/esp8266_webinterface.ino
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extern const char main_js[];
#define HTTP_PORT 80

#define DEFAULT_COLOR 0xFF5900
#define DEFAULT_BRIGHTNESS 255
#define DEFAULT_BRIGHTNESS 128
#define DEFAULT_SPEED 1000
#define DEFAULT_MODE FX_MODE_STATIC

Expand All @@ -82,9 +82,8 @@ ESP8266WebServer server(HTTP_PORT);

void setup(){
Serial.begin(115200);
Serial.println();
Serial.println();
Serial.println("Starting...");
delay(500);
Serial.println("\n\nStarting...");

modes.reserve(5000);
modes_setup();
Expand Down Expand Up @@ -192,9 +191,7 @@ void modes_setup() {
uint8_t num_modes = sizeof(myModes) > 0 ? sizeof(myModes) : ws2812fx.getModeCount();
for(uint8_t i=0; i < num_modes; i++) {
uint8_t m = sizeof(myModes) > 0 ? myModes[i] : i;
modes += "<li><a href='#' class='m' id='";
modes += m;
modes += "'>";
modes += "<li><a href='#'>";
modes += ws2812fx.getModeName(m);
modes += "</a></li>";
}
Expand Down Expand Up @@ -223,7 +220,7 @@ void srv_handle_modes() {
void srv_handle_set() {
for (uint8_t i=0; i < server.args(); i++){
if(server.argName(i) == "c") {
uint32_t tmp = (uint32_t) strtol(server.arg(i).c_str(), NULL, 16);
uint32_t tmp = (uint32_t) strtol(server.arg(i).c_str(), NULL, 10);
if(tmp >= 0x000000 && tmp <= 0xFFFFFF) {
ws2812fx.setColor(tmp);
}
Expand Down
181 changes: 99 additions & 82 deletions examples/esp8266_webinterface/index.html.cpp
Original file line number Diff line number Diff line change
@@ -1,97 +1,114 @@
#include <pgmspace.h>
char index_html[] PROGMEM = R"=====(
<!DOCTYPE html>
<html lang='en'>
<!doctype html>
<html lang='en' dir='ltr'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<meta name='viewport' content='width=device-width' />
<title>WS2812FX Ctrl</title>
<meta name='viewport' content='width=device-width, initial-scale=1.0' />
<title>WS2812FX Control</title>
<script type='text/javascript' src='main.js'></script>
<style>
* {
font-family:sans-serif;
margin:0;
padding:0;
}
body {
width:100%;
max-width:675px;
background-color:#202020;
}
h1 {
width:65%;
margin:25px 0 25px 25%;
color:#454545;
text-align:center;
}
#colorbar {
float:left;
}
#controls {
width:65%;
display:inline-block;
padding-left:5px;
}
ul {
text-align:center;
}
ul#mode li {
display:block;
}
ul#brightness li, ul#speed li, ul#auto li {
display:inline-block;
width:30%;
}
ul li a {
display:block;
margin:3px;
padding:10px 5px;
border:2px solid #454545;
border-radius:5px;
color:#454545;
font-weight:bold;
text-decoration:none;
}
ul li a.active {
border:2px solid #909090;
color:#909090;
}
body {
font-family:Arial,sans-serif;
margin:10px;
padding:0;
background-color:#202020;
color:#909090;
text-align:center;
}
.flex-row {
display:flex;
flex-direction:row;
}
.flex-row-wrap {
display:flex;
flex-direction:row;
flex-wrap:wrap;
}
.flex-col {
display:flex;
flex-direction:column;
align-items:center;
}
input[type='text'] {
background-color: #d0d0d0;
color:#404040;
}
ul {
list-style-type: none;
}
ul li a {
display:block;
margin:3px;
padding:10px;
border:2px solid #404040;
border-radius:5px;
color:#909090;
text-decoration:none;
}
ul#modes li a {
min-width:220px;
}
ul.control li a {
min-width:60px;
min-height:24px;
}
ul.control {
display:flex;
flex-direction:row;
justify-content: flex-end;
align-items: center;
padding: 0px;
}
ul li a.active {
border:2px solid #909090;
}
</style>
</head>
<body>
<h1>WS2812FX Control</h1>
<canvas id='colorbar' width='75' height='1080'></canvas>
<div id='controls'>
<ul id='mode'></ul>
<ul id='brightness'>
<li><a href='#' class='b' id='-'>&#9788;</a></li>
<li><a href='#' class='b' id='+'>&#9728;</a></li>
</ul>
<ul id='speed'>
<li><a href='#' class='s' id='-'>&#8722;</a></li>
<li><a href='#' class='s' id='+'>&#43;</a></li>
</ul>
<ul id='auto'>
<li><a href='#' class='a' id='-'>&#9632;</a></li>
<li><a href='#' class='a' id='+'>&#9658;</a></li>
</ul>
<div class='flex-row'>
<div class='flex-col'>
<div><canvas id='color-canvas' width='360' height='360'></canvas><br/></div>
<div><input type='text' id='color-value' oninput='onColor(event, this.value)'/></div>
<div>
<ul class='control'>
<li>Brightness:</li>
<li><a href='#' onclick="onBrightness(event, '-')">&#9788;</a></li>
<li><a href='#' onclick="onBrightness(event, '+')">&#9728;</a></li>
</ul>
<ul class='control'>
<li>Speed:</li>
<li><a href='#' onclick="onSpeed(event, '-')">&#8722;</a></li>
<li><a href='#' onclick="onSpeed(event, '+')">&#43;</a></li>
</ul>
<ul class='control'>
<li>Auto cycle:</li>
<li><a href='#' onclick="onAuto(event, '-')">&#9632;</a></li>
<li><a href='#' onclick="onAuto(event, '+')">&#9658;</a></li>
</ul>
</div>
</div>
<div>
<ul id='modes' class='flex-row-wrap'>
</div>
</div>
</body>
</html>
)=====";

Loading

0 comments on commit fc571c4

Please sign in to comment.