@@ -64,31 +64,15 @@ void changeMode(Mode newMode) {
6464  if  (newMode != activeMode) {
6565    Log.info (" Mode changed to %i"  , newMode);
6666    activeMode = newMode;
67-   }
68- }
6967
70- void  handleEvents (void ) {
71-   ota.handle ();
72-   udpLed.handle ();
73-   jsonServer.handle ();
74-   #ifdef  CONFIG_TYPE_WEBCONFIG
75-     webServer.handle ();
76-   #endif 
77- 
78-   threadController.run ();
79- }
80- 
81- void  loop (void ) {
82-   handleEvents ();
83-   switch  (activeMode) {
84-     case  RAINBOW:
85-     case  FIRE2012:
86-       animationThread.runIfNeeded ();
87-       break ;
88-     case  STATIC_COLOR:
89-       break ;
90-     case  AMBILIGHT:
91-       break ;
68+     switch  (activeMode) {
69+       case  RAINBOW:
70+         animationThread.setInterval (500 );
71+         break ;
72+       case  FIRE2012:
73+         animationThread.setInterval (16 );
74+         break ;
75+     }
9276  }
9377}
9478
@@ -119,28 +103,59 @@ void initConfig(void) {
119103    Config::loadStaticConfig ();
120104  #endif 
121105
106+   const  char * ssid;
107+   const  char * password;
108+   const  byte* ip;
109+   const  byte* subnet;
110+   const  byte* dns;
111+   uint16_t  jsonServerPort;
112+   uint16_t  udpLedPort;
113+ 
122114  #ifdef  CONFIG_ENABLE_WEBCONFIG
123-     // Load WiFi Config from EEPROM
124115    // TODO Fallback
125-     const  byte* ip = Config::cfg2ip (Config::getConfig ().wifi .ip );
126-     const  byte* subnet = Config::cfg2ip (Config::getConfig ().wifi .subnet );
127-     const  byte* dns = Config::cfg2ip (Config::getConfig ().wifi .dns );
116+     ConfigStruct* cfg = Config::getConfig ();
117+     
118+     ssid = cfg->wifi .ssid ;
119+     password = cfg->wifi .password ;
120+     ip = Config::cfg2ip (cfg->wifi .ip );
121+     subnet = Config::cfg2ip (cfg->wifi .subnet );
122+     dns = Config::cfg2ip (cfg->wifi .dns );
123+     jsonServerPort = cfg->ports .jsonServer ;
124+     udpLedPort = cfg->ports .udpLed ;
128125
129-     wifi = WrapperWiFi (Config::getConfig ().wifi .ssid , Config::getConfig ().wifi .password , ip, subnet, dns);
130-     udpLed = WrapperUdpLed (CONFIG_LED_COUNT, Config::getConfig ().ports .udpLed );
131-     jsonServer = WrapperJsonServer (CONFIG_LED_COUNT, Config::getConfig ().ports .jsonServer );
132126    Log.info (" CFG=%s"  , " EEPROM config loaded"  );
127+     Config::logConfig ();
133128  #else 
134-     // Load WiFi Config from ConfigStatic.h
129+     ssid = CONFIG_WIFI_SSID;
130+     password = CONFIG_WIFI_PASSWORD;
135131    #ifdef  CONFIG_WIFI_STATIC_IP
136-       wifi = WrapperWiFi (CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD, CONFIG_WIFI_IP, CONFIG_WIFI_SUBNET, CONFIG_WIFI_DNS);
132+       ip = CONFIG_WIFI_IP;
133+       subnet = CONFIG_WIFI_SUBNET;
134+       dns = CONFIG_WIFI_DNS;
137135    #else 
138-       wifi = WrapperWiFi (CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD);
136+       const  byte empty[4 ] = {0 };
137+       ip = empty;
139138    #endif 
140-     udpLed = WrapperUdpLed (CONFIG_LED_COUNT, CONFIG_PORT_UDP_LED);
141-     jsonServer = WrapperJsonServer (CONFIG_LED_COUNT, CONFIG_PORT_JSON_SERVER);
139+     jsonServerPort = CONFIG_PORT_JSON_SERVER;
140+     udpLedPort = CONFIG_PORT_UDP_LED;
141+     
142142    Log.info (" CFG=%s"  , " Static config loaded"  );
143143  #endif 
144+   
145+   wifi = WrapperWiFi (ssid, password, ip, subnet, dns);
146+   udpLed = WrapperUdpLed (CONFIG_LED_COUNT, udpLedPort);
147+   jsonServer = WrapperJsonServer (CONFIG_LED_COUNT, jsonServerPort);
148+ }
149+ 
150+ void  handleEvents (void ) {
151+   ota.handle ();
152+   udpLed.handle ();
153+   jsonServer.handle ();
154+   #ifdef  CONFIG_ENABLE_WEBCONFIG
155+     webServer.handle ();
156+   #endif 
157+ 
158+   threadController.run ();
144159}
145160
146161void  setup (void ) {
@@ -149,32 +164,33 @@ void setup(void) {
149164  initConfig ();
150165  ota = WrapperOTA ();
151166  ledStrip = WrapperFastLed ();
152-   resetMode ();
153-   ledStrip.begin ();
154167
155168  statusThread.onRun (statusInfo);
156169  statusThread.setInterval (5000 );
157170  threadController.add (&statusThread);
158171
159172  animationThread.onRun (animationStep);
160173  animationThread.setInterval (500 );
161- 
174+    
162175  resetThread.onRun (resetMode);
163176  resetThread.setInterval (5000 );
164177  resetThread.enabled  = false ;
165178  threadController.add (&resetThread);
179+   
180+   ledStrip.begin ();
181+   resetMode ();
182+   animationStep ();
166183
167184  wifi.begin ();
168185
169186  #ifdef  CONFIG_ENABLE_WEBCONFIG
170187    webServer = WrapperWebconfig ();
171188    webServer.begin ();
172-     ota.begin (Config::getConfig (). wifi .hostname );
189+     ota.begin (Config::getConfig ()-> wifi .hostname );
173190  #else 
174191    ota.begin (CONFIG_WIFI_HOSTNAME); 
175192  #endif 
176193
177- 
178194  udpLed.begin ();
179195  udpLed.onUpdateLed (updateLed);
180196  udpLed.onRefreshLeds (refreshLeds);
@@ -187,3 +203,17 @@ void setup(void) {
187203  pinMode (LED, OUTPUT);   //  LED pin as output.
188204  Log.info (" HEAP=%i"  , ESP.getFreeHeap ());
189205}
206+ 
207+ void  loop (void ) {
208+   handleEvents ();
209+   switch  (activeMode) {
210+     case  RAINBOW:
211+     case  FIRE2012:
212+       animationThread.runIfNeeded ();
213+       break ;
214+     case  STATIC_COLOR:
215+       break ;
216+     case  AMBILIGHT:
217+       break ;
218+   }
219+ }
0 commit comments