Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #372 from dale3h/d1_nodemcu_fix
Browse files Browse the repository at this point in the history
Fix D1 and NodeMCU (#368)
  • Loading branch information
debsahu authored Apr 5, 2019
2 parents b459b24 + 627102d commit d0c399e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
34 changes: 17 additions & 17 deletions Arduino/McLighting/McLighting.ino
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,11 @@ void setup() {
WiFiManagerParameter custom_mqtt_pass("pass", "MQTT pass", mqtt_pass, 32, " maxlength=31 type='password'");
#endif

// sprintf(strip_size, "%d", WS2812FXStripSettings.stripSize);
// sprintf(led_pin, "%d", WS2812FXStripSettings.pin);
sprintf(strip_size, "%d", WS2812FXStripSettings.stripSize);
sprintf(led_pin, "%d", WS2812FXStripSettings.pin);

// WiFiManagerParameter custom_strip_size("strip_size", "Number of LEDs", strip_size, 3);
// WiFiManagerParameter custom_led_pin("led_pin", "LED GPIO", led_pin, 2);
WiFiManagerParameter custom_strip_size("strip_size", "Number of LEDs", strip_size, 3);
WiFiManagerParameter custom_led_pin("led_pin", "LED GPIO", led_pin, 2);

//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
Expand All @@ -392,19 +392,19 @@ void setup() {
//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
wifiManager.setAPCallback(configModeCallback);

#if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT)
//set config save notify callback
wifiManager.setSaveConfigCallback(saveConfigCallback);
//set config save notify callback
wifiManager.setSaveConfigCallback(saveConfigCallback);

#if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT)
//add all your parameters here
wifiManager.addParameter(&custom_mqtt_host);
wifiManager.addParameter(&custom_mqtt_port);
wifiManager.addParameter(&custom_mqtt_user);
wifiManager.addParameter(&custom_mqtt_pass);
#endif

// wifiManager.addParameter(&custom_strip_size);
// wifiManager.addParameter(&custom_led_pin);
wifiManager.addParameter(&custom_strip_size);
wifiManager.addParameter(&custom_led_pin);

WiFi.setSleepMode(WIFI_NONE_SLEEP);

Expand Down Expand Up @@ -460,15 +460,15 @@ void setup() {
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
#endif

// strcpy(strip_size, custom_strip_size.getValue());
// strcpy(led_pin, custom_led_pin.getValue());
strcpy(strip_size, custom_strip_size.getValue());
strcpy(led_pin, custom_led_pin.getValue());

// if(atoi(strip_size) != WS2812FXStripSettings.stripSize)
// WS2812FXStripSettings.stripSize = atoi(strip_size);
// uint8_t pin = atoi(led_pin);
// if ((pin == 16 or pin == 5 or pin == 4 or pin == 0 or pin == 2 or pin == 14 or pin == 12 or pin == 13 or pin == 15 or pin == 3 or pin == 1) and (pin != WS2812FXStripSettings.pin) )
// WS2812FXStripSettings.pin = pin;
// initStrip();
if(atoi(strip_size) != WS2812FXStripSettings.stripSize)
WS2812FXStripSettings.stripSize = atoi(strip_size);
uint8_t pin = atoi(led_pin);
if ((pin == 16 or pin == 5 or pin == 4 or pin == 0 or pin == 2 or pin == 14 or pin == 12 or pin == 13 or pin == 15 or pin == 3 or pin == 1) and (pin != WS2812FXStripSettings.pin) )
WS2812FXStripSettings.pin = pin;
initStrip();

//if you get here you have connected to the WiFi
DBG_OUTPUT_PORT.println("connected...yeey :)");
Expand Down
24 changes: 12 additions & 12 deletions Arduino/McLighting/request_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1415,13 +1415,13 @@ bool readStateFS() {
if (!error) {
JsonObject json = jsonBuffer.as<JsonObject>();
serializeJson(json, DBG_OUTPUT_PORT);
mode = static_cast<MODE>((int) json["mode"]);
ws2812fx_mode = json["strip_mode"];
brightness = json["brightness"];
ws2812fx_speed = json["speed"];
main_color.red = json["red"];
main_color.green = json["green"];
main_color.blue = json["blue"];
mode = static_cast<MODE>(json["mode"].as<int>());
ws2812fx_mode = json["strip_mode"].as<int>();
brightness = json["brightness"].as<int>();
ws2812fx_speed = json["speed"].as<int>();
main_color.red = json["red"].as<int>();
main_color.green = json["green"].as<int>();
main_color.blue = json["blue"].as<int>();

#ifdef ENABLE_HOMEASSISTANT
if(mode != OFF) stateOn = true;
Expand Down Expand Up @@ -1455,7 +1455,7 @@ bool readStateFS() {
#endif

//Strip Config
// char strip_size[3], led_pin[2]; //needed for WiFiManager Settings
char strip_size[4], led_pin[3]; //needed for WiFiManager Settings

struct
{
Expand Down Expand Up @@ -1497,9 +1497,9 @@ bool readStripConfigFS(void) {
DBG_OUTPUT_PORT.println(" Parsed!");
JsonObject json = jsonBuffer.as<JsonObject>();
serializeJson(json, DBG_OUTPUT_PORT);
WS2812FXStripSettings.stripSize = json["pixel_pount"];
WS2812FXStripSettings.RGBOrder = json["rgb_order"];
WS2812FXStripSettings.pin = json["pin"];
WS2812FXStripSettings.stripSize = (json["pixel_count"].as<int>()) ? json["pixel_count"].as<int>() : NUMLEDS;
WS2812FXStripSettings.RGBOrder = json["rgb_order"].as<int>();
WS2812FXStripSettings.pin = json["pin"].as<int>();
updateFS = false;
return true;
} else {
Expand All @@ -1523,7 +1523,7 @@ void writeStripConfigFS(void){
DBG_OUTPUT_PORT.print("Saving Strip cfg: ");
DynamicJsonDocument jsonBuffer(JSON_OBJECT_SIZE(4)+300);
JsonObject json = jsonBuffer.to<JsonObject>();
json["pixel_pount"] = WS2812FXStripSettings.stripSize;
json["pixel_count"] = WS2812FXStripSettings.stripSize;
json["rgb_order"] = WS2812FXStripSettings.RGBOrder;
json["pin"] = WS2812FXStripSettings.pin;

Expand Down

0 comments on commit d0c399e

Please sign in to comment.