Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Commit 92b3aef

Browse files
committed
Merge branch 'develop'
2 parents e9cbc80 + f21548f commit 92b3aef

File tree

7 files changed

+215
-131
lines changed

7 files changed

+215
-131
lines changed

Config.cpp

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
ConfigStruct Config::_cfgStruct;
44
boolean Config::_cfgLoaded = false;
55

6-
void Config::saveConfig(ConfigStruct cfg) {
6+
void Config::saveConfig() {
77
EEPROM.begin(sizeof(ConfigStruct));
8-
EEPROM.put(CONFIG_START_ADDRESS, cfg);
9-
cfg.version = CONFIG_ACTIVE_VERSION;
10-
Log.info("Configuration saved at 0x%x with v%i", CONFIG_START_ADDRESS, cfg.version);
8+
EEPROM.put(CONFIG_START_ADDRESS, _cfgStruct);
9+
_cfgStruct.version = CONFIG_ACTIVE_VERSION;
10+
Log.info("Configuration saved at 0x%x with v%i", CONFIG_START_ADDRESS, _cfgStruct.version);
1111
//EEPROM.commit(); (done with end())
1212
EEPROM.end();
1313
_cfgLoaded = false;
@@ -28,16 +28,16 @@ void Config::initConfig(void) {
2828
_cfgStruct.ports.jsonServer = 19444;
2929
_cfgStruct.ports.udpLed = 19446;
3030
EEPROM.end();
31-
saveConfig(_cfgStruct);
31+
saveConfig();
3232
Log.info("Configuration at 0x%x with v%i (v%i expected), new configuration created", CONFIG_START_ADDRESS, version, CONFIG_ACTIVE_VERSION);
3333
}
3434
_cfgLoaded = true;
3535
}
3636
}
3737

38-
ConfigStruct Config::getConfig(void) {
38+
ConfigStruct *Config::getConfig(void) {
3939
initConfig();
40-
return _cfgStruct;
40+
return &_cfgStruct;
4141
}
4242

4343
void Config::loadStaticConfig(void) {
@@ -67,18 +67,44 @@ void Config::loadStaticConfig(void) {
6767
_cfgStruct.wifi.dns.c = 0;
6868
_cfgStruct.wifi.dns.d = 0;
6969
#endif
70-
//_cfgStruct.led.idleMode
70+
_cfgStruct.led.idleMode = CONFIG_LED_STANDARD_MODE;
7171

7272
_cfgStruct.ports.jsonServer = CONFIG_PORT_JSON_SERVER;
7373
_cfgStruct.ports.udpLed = CONFIG_PORT_UDP_LED;
7474

75-
saveConfig(_cfgStruct);
75+
saveConfig();
7676
Log.info("CFG=%s", "loadStaticConfig END");
7777
}
7878

79-
byte* Config::cfg2ip(ConfigIP ipStruct) {
79+
void Config::logConfig(void) {
80+
initConfig();
81+
Log.debug("CFG Show Config");
82+
83+
Log.debug("+WIFI+");
84+
Log.debug(" ssid=%s", _cfgStruct.wifi.ssid);
85+
Log.debug(" password=%s", _cfgStruct.wifi.password);
86+
Log.debug(" ip=%i.%i.%i.%i", _cfgStruct.wifi.ip.a, _cfgStruct.wifi.ip.b, _cfgStruct.wifi.ip.c, _cfgStruct.wifi.ip.d);
87+
Log.debug(" subnet=%i.%i.%i.%i", _cfgStruct.wifi.subnet.a, _cfgStruct.wifi.subnet.b, _cfgStruct.wifi.subnet.c, _cfgStruct.wifi.subnet.d);
88+
Log.debug(" dns=%i.%i.%i.%i", _cfgStruct.wifi.dns.a, _cfgStruct.wifi.dns.b, _cfgStruct.wifi.dns.c, _cfgStruct.wifi.dns.d);
89+
Log.debug(" hostname=%s", _cfgStruct.wifi.hostname);
90+
91+
Log.debug("+LED+");
92+
Log.debug(" idleMode=%i", _cfgStruct.led.idleMode);
93+
94+
Log.debug("+PORTS+");
95+
Log.debug(" jsonServer=%i", _cfgStruct.ports.jsonServer);
96+
Log.debug(" udpLed=%i", _cfgStruct.ports.udpLed);
97+
98+
}
99+
100+
byte *Config::cfg2ip(ConfigIP ipStruct) {
80101
Log.verbose("CFG=cfg2ip: %i.%i.%i.%i", ipStruct.a, ipStruct.b, ipStruct.c, ipStruct.d);
81-
byte ipByte[] = { ipStruct.a, ipStruct.b, ipStruct.c, ipStruct.d };
102+
byte *ipByte = new byte[4];
103+
ipByte[0] = ipStruct.a;
104+
ipByte[1] = ipStruct.b;
105+
ipByte[2] = ipStruct.c;
106+
ipByte[3] = ipStruct.d;
107+
//byte ipByte[] = { ipStruct.a, ipStruct.b, ipStruct.c, ipStruct.d };
82108
return ipByte;
83109
}
84110

Config.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111
class Config {
1212
public:
13-
static ConfigStruct getConfig(void);
14-
static void saveConfig(ConfigStruct cfg);
13+
static ConfigStruct *getConfig(void);
14+
static void saveConfig();
1515
static void loadStaticConfig(void);
16-
static byte* cfg2ip(ConfigIP ip);
16+
static byte *cfg2ip(ConfigIP ip);
1717
static ConfigIP ip2cfg(const byte ip[4]);
18+
static void logConfig(void);
1819
private:
1920
static void initConfig(void);
2021
static ConfigStruct _cfgStruct;

ConfigStructures.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,4 @@ typedef struct {
4646
ConfigPort ports;
4747
} ConfigStruct;
4848

49-
enum Chipset {
50-
SPI_LPD8806,
51-
SPI_WS2801,
52-
SPI_WS2803,
53-
SPI_SM16716,
54-
SPI_P9813,
55-
SPI_APA102,
56-
SPI_DOTSTAR
57-
};
58-
5949
#endif

HyperionRGB.ino

Lines changed: 71 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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

146161
void 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+
}

WrapperUdpLed.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ void WrapperUdpLed::handle(void) {
2626
Log.debug("UDP-Packet received, length: %i", bytes);
2727
if (bytes == _bufferSize) {
2828
_udp.readBytes(_udpBuffer, _bufferSize);
29-
Log.debug("Contents: %s", _udpBuffer);
29+
Log.verbose("Contents: %s", _udpBuffer);
3030
for (int i=0; i<_ledCount; i++) {
3131
updateLed(i, _udpBuffer[i*3+0], _udpBuffer[i*3+1], _udpBuffer[i*3+2]);
3232
}
3333
refreshLeds();
34+
} else {
35+
Log.debug("UDP-Packet size expected=%i, actual=%i", _bufferSize, bytes);
3436
}
3537
}
3638
}

0 commit comments

Comments
 (0)