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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Nov 1, 2016
2 parents e9cbc80 + f21548f commit 92b3aef
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 131 deletions.
48 changes: 37 additions & 11 deletions Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
ConfigStruct Config::_cfgStruct;
boolean Config::_cfgLoaded = false;

void Config::saveConfig(ConfigStruct cfg) {
void Config::saveConfig() {
EEPROM.begin(sizeof(ConfigStruct));
EEPROM.put(CONFIG_START_ADDRESS, cfg);
cfg.version = CONFIG_ACTIVE_VERSION;
Log.info("Configuration saved at 0x%x with v%i", CONFIG_START_ADDRESS, cfg.version);
EEPROM.put(CONFIG_START_ADDRESS, _cfgStruct);
_cfgStruct.version = CONFIG_ACTIVE_VERSION;
Log.info("Configuration saved at 0x%x with v%i", CONFIG_START_ADDRESS, _cfgStruct.version);
//EEPROM.commit(); (done with end())
EEPROM.end();
_cfgLoaded = false;
Expand All @@ -28,16 +28,16 @@ void Config::initConfig(void) {
_cfgStruct.ports.jsonServer = 19444;
_cfgStruct.ports.udpLed = 19446;
EEPROM.end();
saveConfig(_cfgStruct);
saveConfig();
Log.info("Configuration at 0x%x with v%i (v%i expected), new configuration created", CONFIG_START_ADDRESS, version, CONFIG_ACTIVE_VERSION);
}
_cfgLoaded = true;
}
}

ConfigStruct Config::getConfig(void) {
ConfigStruct *Config::getConfig(void) {
initConfig();
return _cfgStruct;
return &_cfgStruct;
}

void Config::loadStaticConfig(void) {
Expand Down Expand Up @@ -67,18 +67,44 @@ void Config::loadStaticConfig(void) {
_cfgStruct.wifi.dns.c = 0;
_cfgStruct.wifi.dns.d = 0;
#endif
//_cfgStruct.led.idleMode
_cfgStruct.led.idleMode = CONFIG_LED_STANDARD_MODE;

_cfgStruct.ports.jsonServer = CONFIG_PORT_JSON_SERVER;
_cfgStruct.ports.udpLed = CONFIG_PORT_UDP_LED;

saveConfig(_cfgStruct);
saveConfig();
Log.info("CFG=%s", "loadStaticConfig END");
}

byte* Config::cfg2ip(ConfigIP ipStruct) {
void Config::logConfig(void) {
initConfig();
Log.debug("CFG Show Config");

Log.debug("+WIFI+");
Log.debug(" ssid=%s", _cfgStruct.wifi.ssid);
Log.debug(" password=%s", _cfgStruct.wifi.password);
Log.debug(" ip=%i.%i.%i.%i", _cfgStruct.wifi.ip.a, _cfgStruct.wifi.ip.b, _cfgStruct.wifi.ip.c, _cfgStruct.wifi.ip.d);
Log.debug(" subnet=%i.%i.%i.%i", _cfgStruct.wifi.subnet.a, _cfgStruct.wifi.subnet.b, _cfgStruct.wifi.subnet.c, _cfgStruct.wifi.subnet.d);
Log.debug(" dns=%i.%i.%i.%i", _cfgStruct.wifi.dns.a, _cfgStruct.wifi.dns.b, _cfgStruct.wifi.dns.c, _cfgStruct.wifi.dns.d);
Log.debug(" hostname=%s", _cfgStruct.wifi.hostname);

Log.debug("+LED+");
Log.debug(" idleMode=%i", _cfgStruct.led.idleMode);

Log.debug("+PORTS+");
Log.debug(" jsonServer=%i", _cfgStruct.ports.jsonServer);
Log.debug(" udpLed=%i", _cfgStruct.ports.udpLed);

}

byte *Config::cfg2ip(ConfigIP ipStruct) {
Log.verbose("CFG=cfg2ip: %i.%i.%i.%i", ipStruct.a, ipStruct.b, ipStruct.c, ipStruct.d);
byte ipByte[] = { ipStruct.a, ipStruct.b, ipStruct.c, ipStruct.d };
byte *ipByte = new byte[4];
ipByte[0] = ipStruct.a;
ipByte[1] = ipStruct.b;
ipByte[2] = ipStruct.c;
ipByte[3] = ipStruct.d;
//byte ipByte[] = { ipStruct.a, ipStruct.b, ipStruct.c, ipStruct.d };
return ipByte;
}

Expand Down
7 changes: 4 additions & 3 deletions Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

class Config {
public:
static ConfigStruct getConfig(void);
static void saveConfig(ConfigStruct cfg);
static ConfigStruct *getConfig(void);
static void saveConfig();
static void loadStaticConfig(void);
static byte* cfg2ip(ConfigIP ip);
static byte *cfg2ip(ConfigIP ip);
static ConfigIP ip2cfg(const byte ip[4]);
static void logConfig(void);
private:
static void initConfig(void);
static ConfigStruct _cfgStruct;
Expand Down
10 changes: 0 additions & 10 deletions ConfigStructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,4 @@ typedef struct {
ConfigPort ports;
} ConfigStruct;

enum Chipset {
SPI_LPD8806,
SPI_WS2801,
SPI_WS2803,
SPI_SM16716,
SPI_P9813,
SPI_APA102,
SPI_DOTSTAR
};

#endif
112 changes: 71 additions & 41 deletions HyperionRGB.ino
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,15 @@ void changeMode(Mode newMode) {
if (newMode != activeMode) {
Log.info("Mode changed to %i", newMode);
activeMode = newMode;
}
}

void handleEvents(void) {
ota.handle();
udpLed.handle();
jsonServer.handle();
#ifdef CONFIG_TYPE_WEBCONFIG
webServer.handle();
#endif

threadController.run();
}

void loop(void) {
handleEvents();
switch (activeMode) {
case RAINBOW:
case FIRE2012:
animationThread.runIfNeeded();
break;
case STATIC_COLOR:
break;
case AMBILIGHT:
break;
switch (activeMode) {
case RAINBOW:
animationThread.setInterval(500);
break;
case FIRE2012:
animationThread.setInterval(16);
break;
}
}
}

Expand Down Expand Up @@ -119,28 +103,59 @@ void initConfig(void) {
Config::loadStaticConfig();
#endif

const char* ssid;
const char* password;
const byte* ip;
const byte* subnet;
const byte* dns;
uint16_t jsonServerPort;
uint16_t udpLedPort;

#ifdef CONFIG_ENABLE_WEBCONFIG
//Load WiFi Config from EEPROM
//TODO Fallback
const byte* ip = Config::cfg2ip(Config::getConfig().wifi.ip);
const byte* subnet = Config::cfg2ip(Config::getConfig().wifi.subnet);
const byte* dns = Config::cfg2ip(Config::getConfig().wifi.dns);
ConfigStruct* cfg = Config::getConfig();

ssid = cfg->wifi.ssid;
password = cfg->wifi.password;
ip = Config::cfg2ip(cfg->wifi.ip);
subnet = Config::cfg2ip(cfg->wifi.subnet);
dns = Config::cfg2ip(cfg->wifi.dns);
jsonServerPort = cfg->ports.jsonServer;
udpLedPort = cfg->ports.udpLed;

wifi = WrapperWiFi(Config::getConfig().wifi.ssid, Config::getConfig().wifi.password, ip, subnet, dns);
udpLed = WrapperUdpLed(CONFIG_LED_COUNT, Config::getConfig().ports.udpLed);
jsonServer = WrapperJsonServer(CONFIG_LED_COUNT, Config::getConfig().ports.jsonServer);
Log.info("CFG=%s", "EEPROM config loaded");
Config::logConfig();
#else
//Load WiFi Config from ConfigStatic.h
ssid = CONFIG_WIFI_SSID;
password = CONFIG_WIFI_PASSWORD;
#ifdef CONFIG_WIFI_STATIC_IP
wifi = WrapperWiFi(CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD, CONFIG_WIFI_IP, CONFIG_WIFI_SUBNET, CONFIG_WIFI_DNS);
ip = CONFIG_WIFI_IP;
subnet = CONFIG_WIFI_SUBNET;
dns = CONFIG_WIFI_DNS;
#else
wifi = WrapperWiFi(CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD);
const byte empty[4] = {0};
ip = empty;
#endif
udpLed = WrapperUdpLed(CONFIG_LED_COUNT, CONFIG_PORT_UDP_LED);
jsonServer = WrapperJsonServer(CONFIG_LED_COUNT, CONFIG_PORT_JSON_SERVER);
jsonServerPort = CONFIG_PORT_JSON_SERVER;
udpLedPort = CONFIG_PORT_UDP_LED;

Log.info("CFG=%s", "Static config loaded");
#endif

wifi = WrapperWiFi(ssid, password, ip, subnet, dns);
udpLed = WrapperUdpLed(CONFIG_LED_COUNT, udpLedPort);
jsonServer = WrapperJsonServer(CONFIG_LED_COUNT, jsonServerPort);
}

void handleEvents(void) {
ota.handle();
udpLed.handle();
jsonServer.handle();
#ifdef CONFIG_ENABLE_WEBCONFIG
webServer.handle();
#endif

threadController.run();
}

void setup(void) {
Expand All @@ -149,32 +164,33 @@ void setup(void) {
initConfig();
ota = WrapperOTA();
ledStrip = WrapperFastLed();
resetMode();
ledStrip.begin();

statusThread.onRun(statusInfo);
statusThread.setInterval(5000);
threadController.add(&statusThread);

animationThread.onRun(animationStep);
animationThread.setInterval(500);

resetThread.onRun(resetMode);
resetThread.setInterval(5000);
resetThread.enabled = false;
threadController.add(&resetThread);

ledStrip.begin();
resetMode();
animationStep();

wifi.begin();

#ifdef CONFIG_ENABLE_WEBCONFIG
webServer = WrapperWebconfig();
webServer.begin();
ota.begin(Config::getConfig().wifi.hostname);
ota.begin(Config::getConfig()->wifi.hostname);
#else
ota.begin(CONFIG_WIFI_HOSTNAME);
#endif


udpLed.begin();
udpLed.onUpdateLed(updateLed);
udpLed.onRefreshLeds(refreshLeds);
Expand All @@ -187,3 +203,17 @@ void setup(void) {
pinMode(LED, OUTPUT); // LED pin as output.
Log.info("HEAP=%i", ESP.getFreeHeap());
}

void loop(void) {
handleEvents();
switch (activeMode) {
case RAINBOW:
case FIRE2012:
animationThread.runIfNeeded();
break;
case STATIC_COLOR:
break;
case AMBILIGHT:
break;
}
}
4 changes: 3 additions & 1 deletion WrapperUdpLed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ void WrapperUdpLed::handle(void) {
Log.debug("UDP-Packet received, length: %i", bytes);
if (bytes == _bufferSize) {
_udp.readBytes(_udpBuffer, _bufferSize);
Log.debug("Contents: %s", _udpBuffer);
Log.verbose("Contents: %s", _udpBuffer);
for (int i=0; i<_ledCount; i++) {
updateLed(i, _udpBuffer[i*3+0], _udpBuffer[i*3+1], _udpBuffer[i*3+2]);
}
refreshLeds();
} else {
Log.debug("UDP-Packet size expected=%i, actual=%i", _bufferSize, bytes);
}
}
}
Expand Down
Loading

0 comments on commit 92b3aef

Please sign in to comment.