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

Commit

Permalink
Merge pull request #31 from LarsMichelsen/different-fixes
Browse files Browse the repository at this point in the history
Different fixes
  • Loading branch information
thebigpotatoe authored Dec 31, 2019
2 parents c482d6c + eea3c50 commit d0db7fe
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
41 changes: 23 additions & 18 deletions Super_Simple_RGB_WiFi_Lamp/LEDs.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,37 @@ void ledStringInit() {
}

void handleMode() {
// Adapt the leds to the current mode
// Adapt the leds to the current mode. Please note the differences between Mode and currentMode.
//
// Mode: Is set by the config or the web interface to tell the lamp that a specific mode should
// be shown. The lamp will then change to that mode slowly (see adjustBrightnessAndSwitchMode())
// currentMode: In case this is set to a mode name, the lamp came to the point where a mode should be
// asked to render it's pattern.
// During startup this is set to "". In this situation the mode should not be rendered, but
// adjustBrightnessAndSwitchMode() should be called to introduce Mode.

auto modeIter = modes.find(currentMode);
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
return;
}
else {
// Apply currentMode always?
if (currentMode != "") {
auto modeIter = modes.find(currentMode);
if (modeIter == modes.end()) {
// Should only be reached when a user has configured a mode that does not exist (anymore)
Serial.println("[handleMode] - Mode \"" + currentMode + "\" not found, resetting to default");
Mode = "Colour"; // Automatically jump back to colour
return;
}

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

// Globally adjust the brightness
adjustBrightness();
// Globally adjust the brightness
adjustBrightnessAndSwitchMode();

// Handle Fast LED
FastLED.show();
// FastLED.delay(1000 / FRAMES_PER_SECOND);
}
// Handle Fast LED
FastLED.show();
// FastLED.delay(1000 / FRAMES_PER_SECOND);
}

void adjustBrightness() {
void adjustBrightnessAndSwitchMode() {
// Adjust the brightness depending on the mode
if (autoOnWithModeChange || State) {
if (Mode != currentMode) {
Expand Down
3 changes: 0 additions & 3 deletions Super_Simple_RGB_WiFi_Lamp/ModeCircle.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public:
if (circleActiveLedNumber == NUM_LEDS)
circleActiveLedNumber = 0;

Serial.print("Active number: ");
Serial.println(circleActiveLedNumber);

// Darken all LEDs to slightly dim the previous active LEDs
fadeToBlackBy(ledString, NUM_LEDS, 80);
};
Expand Down
4 changes: 2 additions & 2 deletions Super_Simple_RGB_WiFi_Lamp/Super_Simple_RGB_WiFi_Lamp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void parseConfig(JsonDocument& jsonMessage, bool sendViaWebsockets);
void ledStringInit();
void ledModeInit();
void handleMode();
void adjustBrightness();
void adjustBrightnessAndSwitchMode();
// NTP.ino
void handleNTP();
bool getNTPServerIP(const char *_ntpServerName, IPAddress &_ntpServerIp);
Expand Down Expand Up @@ -195,7 +195,7 @@ void loop() {
// Handle mDNS
MDNS.update();

// // Handle the webserver
// Handle the webserver
restServer.handleClient();

// Handle Websockets
Expand Down
11 changes: 11 additions & 0 deletions Super_Simple_RGB_WiFi_Lamp/Web_Page.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const char websiteSource[] PROGMEM =
" // console.log(\"Found State Message\")\n"
" handleStateMessage(jsonMessage.State)\n"
" }\n"
" if (\"Name\" in jsonMessage) {\n"
" // console.log(\"Found Name Message\")\n"
" handleNameMessage(jsonMessage.Name)\n"
" }\n"
" if (\"Fade Time\" in jsonMessage) {\n"
" // console.log(\"Found Fade Time Message\")\n"
" handleFadeTimeMessage(jsonMessage[\"Fade Time\"])\n"
Expand Down Expand Up @@ -124,6 +128,13 @@ const char websiteSource[] PROGMEM =
" }\n"
" }\n"
"\n"
" function handleNameMessage(name) {\n"
" if (typeof name === \"string\") {\n"
" $(document).attr(\"title\", name);\n"
" $(\"#HomeButton\").text(name);\n"
" }\n"
" }\n"
"\n"
" function handleFadeTimeMessage(jsonMessage) {\n"
" if (typeof jsonMessage === \"number\") {\n"
" $(\"#fadeTime\").val(jsonMessage)\n"
Expand Down
13 changes: 12 additions & 1 deletion Website/Website.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
// console.log("Found State Message")
handleStateMessage(jsonMessage.State)
}
if ("Name" in jsonMessage) {
// console.log("Found Name Message")
handleNameMessage(jsonMessage.Name)
}
if ("Fade Time" in jsonMessage) {
// console.log("Found Fade Time Message")
handleFadeTimeMessage(jsonMessage["Fade Time"])
Expand Down Expand Up @@ -122,6 +126,13 @@
}
}

function handleNameMessage(name) {
if (typeof name === "string") {
$(document).attr("title", name);
$("#HomeButton").text(name);
}
}

function handleFadeTimeMessage(jsonMessage) {
if (typeof jsonMessage === "number") {
$("#fadeTime").val(jsonMessage)
Expand Down Expand Up @@ -1554,4 +1565,4 @@ <h2>Wifi Configuration</h2>
</div>
</body>

</html>
</html>

0 comments on commit d0db7fe

Please sign in to comment.