mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-05-19 10:32:56 +00:00
extracted default config values
This commit is contained in:
parent
003102fa90
commit
a6500cb8cc
3 changed files with 44 additions and 38 deletions
29
src/main.cpp
29
src/main.cpp
|
@ -101,7 +101,7 @@ void setup()
|
||||||
|
|
||||||
// LED
|
// LED
|
||||||
config.begin("dmx", true);
|
config.begin("dmx", true);
|
||||||
brightness_led = config.getUInt("led-brightness", 20);
|
brightness_led = config.getUInt("led-brightness", DEFAULT_LED_BRIGHTNESS);
|
||||||
config.end();
|
config.end();
|
||||||
analogWrite(PIN_LED, brightness_led);
|
analogWrite(PIN_LED, brightness_led);
|
||||||
// delay(5000);
|
// delay(5000);
|
||||||
|
@ -125,11 +125,11 @@ void setup()
|
||||||
|
|
||||||
config.begin("dmx", true);
|
config.begin("dmx", true);
|
||||||
|
|
||||||
universe1 = config.getUInt("universe-1", 1);
|
universe1 = config.getUInt("universe-1", DEFAULT_UNIVERSE1);
|
||||||
universe2 = config.getUInt("universe-2", 2);
|
universe2 = config.getUInt("universe-2", DEFAULT_UNIVERSE2);
|
||||||
|
|
||||||
direction1 = static_cast<Direction>(config.getUInt("direction-1", 0));
|
direction1 = static_cast<Direction>(config.getUInt("direction-1", DEFAULT_DIRECTION1));
|
||||||
direction2 = static_cast<Direction>(config.getUInt("direction-2", 1));
|
direction2 = static_cast<Direction>(config.getUInt("direction-2", DEFAULT_DIRECTION2));
|
||||||
|
|
||||||
Serial.print("Port A: Universe ");
|
Serial.print("Port A: Universe ");
|
||||||
Serial.print(universe1);
|
Serial.print(universe1);
|
||||||
|
@ -141,25 +141,22 @@ void setup()
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
Serial.println((direction2 == Input) ? "DMX -> Art-Net" : "Art-Net -> DMX");
|
Serial.println((direction2 == Input) ? "DMX -> Art-Net" : "Art-Net -> DMX");
|
||||||
|
|
||||||
Connection connection = static_cast<Connection>(config.getUInt("connection", WiFiAP));
|
Connection connection = static_cast<Connection>(config.getUInt("connection", DEFAULT_CONNECTION));
|
||||||
IpMethod ipMethod = static_cast<IpMethod>(config.getUInt("ip-method"), DHCP);
|
IpMethod ipMethod = static_cast<IpMethod>(config.getUInt("ip-method"), DEFAULT_IP_METHOD);
|
||||||
|
|
||||||
WiFi.macAddress(mac);
|
|
||||||
char hostname[30];
|
char hostname[30];
|
||||||
snprintf(hostname, sizeof(hostname), "ChaosDMX-%02X%02X", mac[4], mac[5]);
|
snprintf(hostname, sizeof(hostname), "ChaosDMX-%02X%02X", mac[4], mac[5]);
|
||||||
|
DEFAULT_SSID = hostname;
|
||||||
Serial.print("Hostname: ");
|
Serial.print("Hostname: ");
|
||||||
Serial.println(hostname);
|
Serial.println(hostname);
|
||||||
|
|
||||||
String ssid = config.getString("ssid", hostname);
|
String ssid = config.getString("ssid", DEFAULT_SSID);
|
||||||
String pwd = config.getString("password", "mbgmbgmbg");
|
String pwd = config.getString("password", DEFAULT_PASSWORD);
|
||||||
|
|
||||||
// Default IP as defined in standard https://art-net.org.uk/downloads/art-net.pdf, page 13
|
// 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", DEFAULT_IP);
|
||||||
IPAddress ip = config.getUInt("ip", defaultIp);
|
IPAddress subnet = config.getUInt("subnet", DEFAULT_SUBNET);
|
||||||
IPAddress defaultSubnet(255, 0, 0, 0);
|
IPAddress gateway = config.getUInt("gateway", DEFAULT_GATEWAY);
|
||||||
IPAddress subnet = config.getUInt("subnet", defaultSubnet);
|
|
||||||
IPAddress defaultGateway(2, 0, 0, 1);
|
|
||||||
IPAddress gateway = config.getUInt("gateway", defaultGateway);
|
|
||||||
|
|
||||||
config.end();
|
config.end();
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "WiFi.h"
|
#include "WiFi.h"
|
||||||
|
|
||||||
Preferences config;
|
Preferences config;
|
||||||
|
String DEFAULT_SSID = "";
|
||||||
|
|
||||||
#pragma region Utility
|
#pragma region Utility
|
||||||
|
|
||||||
|
@ -75,28 +76,23 @@ void onGetConfig(AsyncWebServerRequest *request)
|
||||||
{
|
{
|
||||||
config.begin("dmx", true);
|
config.begin("dmx", true);
|
||||||
|
|
||||||
IPAddress defaultIp(192, 168, 1, 201);
|
IPAddress ip = config.getUInt("ip", DEFAULT_IP);
|
||||||
IPAddress ip = config.getUInt("ip", defaultIp);
|
IPAddress subnet = config.getUInt("subnet", DEFAULT_SUBNET);
|
||||||
|
IPAddress gateway = config.getUInt("gateway", DEFAULT_GATEWAY);
|
||||||
IPAddress defaultSubnet(255, 255, 255, 0);
|
|
||||||
IPAddress subnet = config.getUInt("subnet", defaultSubnet);
|
|
||||||
|
|
||||||
IPAddress defaultGateway(192, 168, 1, 1);
|
|
||||||
IPAddress gateway = config.getUInt("gateway", defaultGateway);
|
|
||||||
|
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
doc["connection"] = config.getUInt("connection", WiFiSta);
|
doc["connection"] = config.getUInt("connection", DEFAULT_CONNECTION);
|
||||||
doc["ssid"] = config.getString("ssid", "artnet");
|
doc["ssid"] = config.getString("ssid", DEFAULT_SSID);
|
||||||
doc["password"] = config.getString("password", "mbgmbgmbg");
|
doc["password"] = config.getString("password", DEFAULT_PASSWORD);
|
||||||
doc["ip-method"] = config.getUInt("ip-method"), Static;
|
doc["ip-method"] = config.getUInt("ip-method", DEFAULT_IP_METHOD);
|
||||||
doc["ip"] = ip.toString();
|
doc["ip"] = ip.toString();
|
||||||
doc["subnet"] = subnet.toString();
|
doc["subnet"] = subnet.toString();
|
||||||
doc["gateway"] = gateway.toString();
|
doc["gateway"] = gateway.toString();
|
||||||
doc["universe-1"] = config.getUInt("universe-1", 1);
|
doc["universe-1"] = config.getUInt("universe-1", DEFAULT_UNIVERSE1);
|
||||||
doc["direction-1"] = config.getUInt("direction-1", Output);
|
doc["direction-1"] = config.getUInt("direction-1", DEFAULT_DIRECTION1);
|
||||||
doc["universe-2"] = config.getUInt("universe-2", 1);
|
doc["universe-2"] = config.getUInt("universe-2", DEFAULT_UNIVERSE2);
|
||||||
doc["direction-2"] = config.getUInt("direction-2", Input);
|
doc["direction-2"] = config.getUInt("direction-2", DEFAULT_DIRECTION2);
|
||||||
doc["led-brightness"] = config.getUInt("led-brightness", 25);
|
doc["led-brightness"] = config.getUInt("led-brightness", DEFAULT_LED_BRIGHTNESS);
|
||||||
|
|
||||||
config.end();
|
config.end();
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <AsyncWebServer_ESP32_W5500.h>
|
#include <AsyncWebServer_ESP32_W5500.h>
|
||||||
#include <ESPDMX.h>
|
#include <ESPDMX.h>
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
|
|
||||||
// #ifndef CONFIG_h
|
#ifndef CONFIG_h
|
||||||
// #define CONFIG_h
|
#define CONFIG_h
|
||||||
|
|
||||||
extern Preferences config;
|
extern Preferences config;
|
||||||
|
|
||||||
|
@ -31,10 +29,25 @@ enum Direction
|
||||||
};
|
};
|
||||||
const uint8_t DIRECTION_SIZE = 2;
|
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 onGetConfig(AsyncWebServerRequest *request);
|
||||||
|
|
||||||
void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total);
|
void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total);
|
||||||
|
|
||||||
void onGetNetworks(AsyncWebServerRequest *request);
|
void onGetNetworks(AsyncWebServerRequest *request);
|
||||||
|
|
||||||
// #endif
|
#endif
|
Loading…
Add table
Reference in a new issue