diff --git a/src/main.cpp b/src/main.cpp index e6c57ed..e7dce89 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -102,7 +102,7 @@ void setup() // LED config.begin("dmx", true); - brightness_led = config.getUInt("led-brightness", 20); + brightness_led = config.getUInt("led-brightness", DEFAULT_LED_BRIGHTNESS); config.end(); analogWrite(PIN_LED, brightness_led); // delay(5000); @@ -127,11 +127,11 @@ void setup() config.begin("dmx", true); - universe1 = config.getUChar("universe-1", 1); - universe2 = config.getUChar("universe-2", 1); + universe1 = config.getUChar("universe-1", DEFAULT_UNIVERSE1); + universe2 = config.getUChar("universe-2", DEFAULT_UNIVERSE2); - direction1 = static_cast(config.getUInt("direction-1", 0)); - direction2 = static_cast(config.getUInt("direction-2", 1)); + direction1 = static_cast(config.getUInt("direction-1", DEFAULT_DIRECTION1)); + direction2 = static_cast(config.getUInt("direction-2", DEFAULT_DIRECTION2)); Serial.print("Port A: Universe "); Serial.print(universe1); @@ -143,25 +143,22 @@ void setup() Serial.print(" "); Serial.println((direction2 == Input) ? "DMX -> Art-Net" : "Art-Net -> DMX"); - Connection connection = static_cast(config.getUInt("connection", WiFiAP)); - IpMethod ipMethod = static_cast(config.getUInt("ip-method"), DHCP); + Connection connection = static_cast(config.getUInt("connection", DEFAULT_CONNECTION)); + IpMethod ipMethod = static_cast(config.getUInt("ip-method"), DEFAULT_IP_METHOD); - WiFi.macAddress(mac); char hostname[30]; snprintf(hostname, sizeof(hostname), "ChaosDMX-%02X%02X", mac[4], mac[5]); + DEFAULT_SSID = hostname; Serial.print("Hostname: "); Serial.println(hostname); - String ssid = config.getString("ssid", hostname); - String pwd = config.getString("password", "mbgmbgmbg"); + String ssid = config.getString("ssid", DEFAULT_SSID); + String pwd = config.getString("password", DEFAULT_PASSWORD); // Default IP as defined in standard https://art-net.org.uk/downloads/art-net.pdf, page 13 - IPAddress defaultIp(2, mac[3], mac[4], mac[5]); - IPAddress ip = config.getUInt("ip", defaultIp); - IPAddress defaultSubnet(255, 0, 0, 0); - IPAddress subnet = config.getUInt("subnet", defaultSubnet); - IPAddress defaultGateway(2, 0, 0, 1); - IPAddress gateway = config.getUInt("gateway", defaultGateway); + IPAddress ip = config.getUInt("ip", DEFAULT_IP); + IPAddress subnet = config.getUInt("subnet", DEFAULT_SUBNET); + IPAddress gateway = config.getUInt("gateway", DEFAULT_GATEWAY); config.end(); diff --git a/src/routes/config.cpp b/src/routes/config.cpp index 7450e5e..2f4e648 100644 --- a/src/routes/config.cpp +++ b/src/routes/config.cpp @@ -4,6 +4,7 @@ #include "WiFi.h" Preferences config; +String DEFAULT_SSID = ""; #pragma region Utility @@ -75,28 +76,23 @@ void onGetConfig(AsyncWebServerRequest *request) { config.begin("dmx", true); - IPAddress defaultIp(192, 168, 1, 201); - IPAddress ip = config.getUInt("ip", defaultIp); - - IPAddress defaultSubnet(255, 255, 255, 0); - IPAddress subnet = config.getUInt("subnet", defaultSubnet); - - IPAddress defaultGateway(192, 168, 1, 1); - IPAddress gateway = config.getUInt("gateway", defaultGateway); + IPAddress ip = config.getUInt("ip", DEFAULT_IP); + IPAddress subnet = config.getUInt("subnet", DEFAULT_SUBNET); + IPAddress gateway = config.getUInt("gateway", DEFAULT_GATEWAY); JsonDocument doc; - doc["connection"] = config.getUInt("connection", WiFiSta); - doc["ssid"] = config.getString("ssid", "artnet"); - doc["password"] = config.getString("password", "mbgmbgmbg"); - doc["ip-method"] = config.getUInt("ip-method"), Static; + doc["connection"] = config.getUInt("connection", DEFAULT_CONNECTION); + doc["ssid"] = config.getString("ssid", DEFAULT_SSID); + doc["password"] = config.getString("password", DEFAULT_PASSWORD); + doc["ip-method"] = config.getUInt("ip-method", DEFAULT_IP_METHOD); doc["ip"] = ip.toString(); doc["subnet"] = subnet.toString(); doc["gateway"] = gateway.toString(); - doc["universe-1"] = config.getUInt("universe-1", 1); - doc["direction-1"] = config.getUInt("direction-1", Output); - doc["universe-2"] = config.getUInt("universe-2", 1); - doc["direction-2"] = config.getUInt("direction-2", Input); - doc["led-brightness"] = config.getUInt("led-brightness", 25); + doc["universe-1"] = config.getUInt("universe-1", DEFAULT_UNIVERSE1); + doc["direction-1"] = config.getUInt("direction-1", DEFAULT_DIRECTION1); + doc["universe-2"] = config.getUInt("universe-2", DEFAULT_UNIVERSE2); + doc["direction-2"] = config.getUInt("direction-2", DEFAULT_DIRECTION2); + doc["led-brightness"] = config.getUInt("led-brightness", DEFAULT_LED_BRIGHTNESS); config.end(); diff --git a/src/routes/config.h b/src/routes/config.h index 54c1a03..948f0c3 100644 --- a/src/routes/config.h +++ b/src/routes/config.h @@ -1,11 +1,9 @@ -#pragma once - #include #include #include -// #ifndef CONFIG_h -// #define CONFIG_h +#ifndef CONFIG_h +#define CONFIG_h extern Preferences config; @@ -31,10 +29,25 @@ enum Direction }; const uint8_t DIRECTION_SIZE = 2; +const Connection DEFAULT_CONNECTION = WiFiAP; +const IpMethod DEFAULT_IP_METHOD = DHCP; +extern String DEFAULT_SSID; // initialized in setup because it depends on the mac address +const String DEFAULT_PASSWORD = "mbgmbgmbg"; +const IPAddress DEFAULT_IP(192, 168, 4, 1); +const IPAddress DEFAULT_SUBNET(255, 0, 0, 0); +const IPAddress DEFAULT_GATEWAY(2, 0, 0, 1); + +const Direction DEFAULT_DIRECTION1 = Output; +const Direction DEFAULT_DIRECTION2 = Input; +const uint8_t DEFAULT_UNIVERSE1 = 1; +const uint8_t DEFAULT_UNIVERSE2 = 2; + +const uint8_t DEFAULT_LED_BRIGHTNESS = 25; + void onGetConfig(AsyncWebServerRequest *request); void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total); void onGetNetworks(AsyncWebServerRequest *request); -// #endif \ No newline at end of file +#endif \ No newline at end of file