Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Local improvements #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.pio
/.vscode
/Pictures
/Renders
Expand Down
113 changes: 73 additions & 40 deletions Super_Simple_RGB_WiFi_Lamp/LEDs.ino
Original file line number Diff line number Diff line change
@@ -1,55 +1,76 @@
void ledStringInit() {
void ledStringInit()
{
// add the leds to fast led and clear them
FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(ledString, NUM_LEDS);
FastLED.clear ();
FastLED.clear();
FastLED.show();

// Set the maximum power draw
// FastLED.setMaxPowerInVoltsAndMilliamps(5,1000);

// Set initial mode
currentMode = "Colour"; // Automatically jump back to colour

// Debug
Serial.println("[handleMode] - LED string was set up correctly");
}

void handleMode() {
bool renderPass = true;
void handleMode()
{
// Adapt the leds to the current mode

auto modeIter = modes.find(currentMode);
if (modeIter == modes.end()) {
if (modeIter == modes.end())
{
// not found
Serial.println("[handleMode] - Mode \"" + Mode + "\" not found, resetting to default");
Mode = "Colour"; // Automatically jump back to colour
currentMode = "Colour"; // Automatically jump back to colour
Mode = "Colour"; // Automatically jump back to colour
currentMode = "Colour"; // Automatically jump back to colour
return;
}
else {
else
{
// Apply currentMode always?

// If mode is found run its render function
modeIter->second->render();

// Globally adjust the brightness
adjustBrightness();
if (renderPass)
{
// If mode is found run its render function
modeIter->second->render();

// Handle Fast LED
FastLED.show();
// FastLED.delay(1000 / FRAMES_PER_SECOND);
}
// Globally adjust the brightness
adjustBrightness();
}
else
{
// Handle Fast LED
FastLED.show();
// FastLED.delay(1000 / FRAMES_PER_SECOND);
}
// Let other code run before we do the update
renderPass = !renderPass;
}
}

void adjustBrightness() {
void adjustBrightness()
{
// Adjust the brightness depending on the mode
if (autoOnWithModeChange || State) {
if (Mode != currentMode) {
// Dim lights off first
if (modeChangeFadeAmount > 0) {
if (autoOnWithModeChange || State)
{
if (Mode != currentMode)
{
// Dim lights off first
if (modeChangeFadeAmount > 0)
{
// Set the dimming variables and apply
EVERY_N_MILLISECONDS(20) {
modeChangeFadeAmount -= (FadeTime > 0) ? (255 / ((float)FadeTime/20)) : 255;
EVERY_N_MILLISECONDS(20)
{
modeChangeFadeAmount -= (FadeTime > 0) ? (255 / ((float)FadeTime / 20)) : 255;
modeChangeFadeAmount = constrain(modeChangeFadeAmount, 0, 255);
};
}
else {
else
{
// Debug
Serial.println("[handleMode] - Mode changed to: " + Mode);

Expand All @@ -61,48 +82,60 @@ void adjustBrightness() {
modeChangeFadeAmount = 0;
}
}
else if (currentMode != previousMode) {
else if (currentMode != previousMode)
{
// On mode change dim lights up
if (modeChangeFadeAmount < 255) {
EVERY_N_MILLISECONDS(20) {
modeChangeFadeAmount += (FadeTime > 0) ? (255 / ((float)FadeTime/20)) : 255;
if (modeChangeFadeAmount < 255)
{
EVERY_N_MILLISECONDS(20)
{
modeChangeFadeAmount += (FadeTime > 0) ? (255 / ((float)FadeTime / 20)) : 255;
modeChangeFadeAmount = constrain(modeChangeFadeAmount, 0, 255);
};
}
else {
else
{
// Set the currentMode to Mode
previousMode = currentMode;
}
}
}

// Adjust the brightness depending on the state
if (!State && previousState) {
if (!State && previousState)
{
// Turn Lights off slowly
if (modeChangeFadeAmount > 0) {
EVERY_N_MILLISECONDS(20) {
modeChangeFadeAmount -= (FadeTime > 0) ? (255 / ((float)FadeTime/20)) : 255;
if (modeChangeFadeAmount > 0)
{
EVERY_N_MILLISECONDS(20)
{
modeChangeFadeAmount -= (FadeTime > 0) ? (255 / ((float)FadeTime / 20)) : 255;
modeChangeFadeAmount = constrain(modeChangeFadeAmount, 0, 255);
};
}
else {
else
{
// Debug
Serial.println("[handleMode] - LED's turned off");

// Set the previous state
previousState = false;
}
}
else if (State && !previousState) {
else if (State && !previousState)
{
// Turn on light slowly
if (modeChangeFadeAmount < 255) {
EVERY_N_MILLISECONDS(20) {
modeChangeFadeAmount += (FadeTime > 0) ? (255 / ((float)FadeTime/20)) : 255;
if (modeChangeFadeAmount < 255)
{
EVERY_N_MILLISECONDS(20)
{
modeChangeFadeAmount += (FadeTime > 0) ? (255 / ((float)FadeTime / 20)) : 255;
modeChangeFadeAmount = constrain(modeChangeFadeAmount, 0, 255);
};
}
else {
// Debug
else
{
// Debug
Serial.println("[handleMode] - LED's turned on");

// Set the previous values
Expand Down
17 changes: 16 additions & 1 deletion Super_Simple_RGB_WiFi_Lamp/Web_Page.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const char websiteSource[] PROGMEM =
" // console.log(\"Found Mode Message\")\n"
" handleModeMessage(jsonMessage.Mode)\n"
" }\n"
" if (\"Name\" in jsonMessage) {\n"
" // console.log(\"Found Name Message\")\n"
" handleNameMessage(jsonMessage.Name)\n"
" }\n"
" if (\"State\" in jsonMessage) {\n"
" // console.log(\"Found State Message\")\n"
" handleStateMessage(jsonMessage.State)\n"
Expand Down Expand Up @@ -110,6 +114,13 @@ const char websiteSource[] PROGMEM =
" }\n"
" }\n"
"\n"
" function handleNameMessage(jsonMessage) {\n"
" // console.log(jsonMessage)\n"
" if (typeof jsonMessage === \"string\") {\n"
" $(\"#NameInput\").val(jsonMessage)\n"
" }\n"
" }\n"
"\n"
" function handleStateMessage(jsonMessage) {\n"
" // console.log(jsonMessage)\n"
" if (typeof jsonMessage === \"boolean\") {\n"
Expand Down Expand Up @@ -1502,6 +1513,10 @@ const char websiteSource[] PROGMEM =
"\n"
" <div id=\"wifiConfigForm\">\n"
" <div class=\"form-group\">\n"
" <label for=\"NameInput\">Name</label>\n"
" <input id=\"NameInput\" class=\"form-control\" placeholder=\"Name\" type=\"text\">\n"
" </div>\n"
" <div class=\"form-group\">\n"
" <label for=\"SSIDInput\">SSID</label>\n"
" <input id=\"SSIDInput\" class=\"form-control\" placeholder=\"SSID\" type=\"text\">\n"
" </div>\n"
Expand Down Expand Up @@ -1537,6 +1552,7 @@ const char websiteSource[] PROGMEM =
"\n"
" function onSubmitWifiEvent() {\n"
" msg = {\n"
" \"Name\": $(\"#NameInput\").val(),\n"
" \"Wifi\": {\n"
" \"SSID\": $(\"#SSIDInput\").val(),\n"
" \"Password\": $(\"#PassInput\").val()\n"
Expand All @@ -1555,6 +1571,5 @@ const char websiteSource[] PROGMEM =
" </div>\n"
" </div>\n"
"</body>\n"
"\n"
"</html>\n"
;
19 changes: 17 additions & 2 deletions Website/Website.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
// console.log("Found Mode Message")
handleModeMessage(jsonMessage.Mode)
}
if ("Name" in jsonMessage) {
// console.log("Found Name Message")
handleNameMessage(jsonMessage.Name)
}
if ("State" in jsonMessage) {
// console.log("Found State Message")
handleStateMessage(jsonMessage.State)
Expand Down Expand Up @@ -108,6 +112,13 @@
}
}

function handleNameMessage(jsonMessage) {
// console.log(jsonMessage)
if (typeof jsonMessage === "string") {
$("#NameInput").val(jsonMessage)
}
}

function handleStateMessage(jsonMessage) {
// console.log(jsonMessage)
if (typeof jsonMessage === "boolean") {
Expand Down Expand Up @@ -1499,6 +1510,10 @@ <h2>Wifi Configuration</h2>
<button id="rescanButton" class="col mb-2 mx-2 btn btn-lg btn-outline-light">Rescan</button>

<div id="wifiConfigForm">
<div class="form-group">
<label for="NameInput">Name</label>
<input id="NameInput" class="form-control" placeholder="Name" type="text">
</div>
<div class="form-group">
<label for="SSIDInput">SSID</label>
<input id="SSIDInput" class="form-control" placeholder="SSID" type="text">
Expand Down Expand Up @@ -1535,6 +1550,7 @@ <h2>Wifi Configuration</h2>

function onSubmitWifiEvent() {
msg = {
"Name": $("#NameInput").val(),
"Wifi": {
"SSID": $("#SSIDInput").val(),
"Password": $("#PassInput").val()
Expand All @@ -1553,5 +1569,4 @@ <h2>Wifi Configuration</h2>
</div>
</div>
</body>

</html>
</html>
46 changes: 46 additions & 0 deletions lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
Loading