move settings and configuration to namespaces
This commit is contained in:
parent
1352fdb735
commit
c4cccc97e1
|
@ -0,0 +1,171 @@
|
||||||
|
/*
|
||||||
|
configure.cpp
|
||||||
|
|
||||||
|
Copyright (c) 2020 Kevin Matz (kevin.matz@gmail.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "configure.h"
|
||||||
|
#include <Preferences.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace config {
|
||||||
|
|
||||||
|
/*
|
||||||
|
NVM preferances
|
||||||
|
*/
|
||||||
|
Preferences prefs_;
|
||||||
|
|
||||||
|
/*
|
||||||
|
settings struct
|
||||||
|
*/
|
||||||
|
settings_t settings_;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Load device configuration from NVM
|
||||||
|
*/
|
||||||
|
bool loadConfig() {
|
||||||
|
prefs_.begin("wiflash", false); // open RW;
|
||||||
|
|
||||||
|
Serial.print("Jump pin ");
|
||||||
|
Serial.print(reset_button);
|
||||||
|
Serial.println(" to GROUND to reset settings.");
|
||||||
|
|
||||||
|
pinMode(reset_button, INPUT_PULLUP);
|
||||||
|
if (prefs_.getBool("reset_on_reboot") ||
|
||||||
|
!digitalRead(reset_button)) {
|
||||||
|
prefs_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
settings_.ssid = prefs_.getString("ssid", "WiFlash");
|
||||||
|
settings_.pwd = prefs_.getString("pwd", "technologyismagic");
|
||||||
|
settings_.mode = (wifi_mode_t)prefs_.getUChar("wifi_mode", WIFI_AP);
|
||||||
|
settings_.hostname = prefs_.getString("hostname", "WiFlash");
|
||||||
|
|
||||||
|
settings_.dhcp = prefs_.getBool("dhcp", true);
|
||||||
|
settings_.ip = prefs_.getString("ip", "192.168.1.1");
|
||||||
|
settings_.subnet = prefs_.getString("subnet", "255.255.255.0");
|
||||||
|
settings_.gateway = prefs_.getString("gateway", "");
|
||||||
|
|
||||||
|
settings_.button_enable = prefs_.getBool("button_enable", true);
|
||||||
|
settings_.button_pin = prefs_.getUChar("butto_pin", A0); // A0, use 100nF to ground
|
||||||
|
|
||||||
|
settings_.osc_host = prefs_.getString("osc_host", "192.168.1.1");
|
||||||
|
settings_.osc_port = prefs_.getUShort("osc_port", 7001);
|
||||||
|
settings_.osc_pressed_addr = prefs_.getString("osc_pressed_addr", "/hog/playback/go/0");
|
||||||
|
settings_.osc_pressed_value = prefs_.getString("osc_pressed_value", "99.1");
|
||||||
|
settings_.osc_released_addr = prefs_.getString("osc_released_addr", "/hog/playback/go/0");
|
||||||
|
settings_.osc_released_value = prefs_.getString("osc_released_value", "99.2");
|
||||||
|
|
||||||
|
settings_.strobe_enable = prefs_.getBool("strobe_enable", true);
|
||||||
|
settings_.strobe_led_pin = prefs_.getUChar("strobe_led_pin", LED_BUILTIN); // IO13
|
||||||
|
settings_.strobe_universe = prefs_.getUShort("strobe_universe", 1);
|
||||||
|
settings_.strobe_address = prefs_.getUShort("strobe_address", 001);
|
||||||
|
|
||||||
|
settings_.strip_enable = prefs_.getBool("strip_enable", false);
|
||||||
|
settings_.strip_led_count = prefs_.getUShort("strip_led_count", 8); // not less than 4
|
||||||
|
settings_.strip_data_pin = prefs_.getUChar("strip_data_pin", 21);
|
||||||
|
settings_.strip_universe = prefs_.getUShort("strip_universe", 1);
|
||||||
|
settings_.strip_address = prefs_.getUShort("strip_address", 001);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
setting as a String
|
||||||
|
*/
|
||||||
|
String getString(const String& key) {
|
||||||
|
if (key == "CONFIG_WIFI_MODE") return String(settings_.mode);
|
||||||
|
if (key == "CONFIG_WIFI_SSID") return settings_.ssid;
|
||||||
|
if (key == "CONFIG_WIFI_PASSWORD") return settings_.pwd;
|
||||||
|
if (key == "CONFIG_NETWORK_HOSTNAME") return settings_.hostname;
|
||||||
|
if (key == "CONFIG_NETWORK_DHCP") return String(settings_.dhcp);
|
||||||
|
if (key == "CONFIG_NETWORK_IPV4") return settings_.ip;
|
||||||
|
if (key == "CONFIG_NETWORK_MASK") return settings_.subnet;
|
||||||
|
if (key == "CONFIG_NETWORK_GATEWAY") return settings_.gateway;
|
||||||
|
if (key == "CONFIG_BUTTON_ENABLE") return String(settings_.button_enable);
|
||||||
|
if (key == "CONFIG_BUTTON_PIN") return String(settings_.button_pin);
|
||||||
|
if (key == "CONFIG_BUTTON_OSC_HOST") return settings_.osc_host;
|
||||||
|
if (key == "CONFIG_BUTTON_OSC_PORT") return String(settings_.osc_port);
|
||||||
|
if (key == "CONFIG_BUTTON_OSC_PRESSED_ADDR") return settings_.osc_pressed_addr;
|
||||||
|
if (key == "CONFIG_BUTTON_OSC_PRESSED_VALUE") return settings_.osc_pressed_value;
|
||||||
|
if (key == "CONFIG_BUTTON_OSC_RELEASED_ADDR") return settings_.osc_released_addr;
|
||||||
|
if (key == "CONFIG_BUTTON_OSC_RELEASED_VALUE") return settings_.osc_released_value;
|
||||||
|
if (key == "CONFIG_STROBE_ENABLE") return String(settings_.strobe_enable);
|
||||||
|
if (key == "CONFIG_STROBE_PIN") return String(settings_.strobe_led_pin);
|
||||||
|
if (key == "CONFIG_STROBE_UNIVERSE") return String(settings_.strobe_universe);
|
||||||
|
if (key == "CONFIG_STROBE_ADDRESS") return String(settings_.strobe_address);
|
||||||
|
if (key == "CONFIG_STRIP_ENABLE") return String(settings_.strip_enable);
|
||||||
|
if (key == "CONFIG_STRIP_PIN") return String(settings_.strip_data_pin);
|
||||||
|
if (key == "CONFIG_STRIP_COUNT") return String(settings_.strip_led_count);
|
||||||
|
if (key == "CONFIG_STRIP_UNIVERSE") return String(settings_.strip_universe);
|
||||||
|
if (key == "CONFIG_STRIP_ADDRESS") return String(settings_.strip_address);
|
||||||
|
|
||||||
|
return String();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
change a setting in NVM
|
||||||
|
*/
|
||||||
|
size_t set (const String& key, const String& value) {
|
||||||
|
Serial.print("changing config: ");
|
||||||
|
Serial.print(key);
|
||||||
|
Serial.print(" = ");
|
||||||
|
Serial.println(value);
|
||||||
|
if (key == "CONFIG_WIFI_MODE") return prefs_.putUChar("mode", value.toInt());
|
||||||
|
if (key == "CONFIG_WIFI_SSID") return prefs_.putString("ssid", value);
|
||||||
|
if (key == "CONFIG_WIFI_PASSWORD") return prefs_.putString("pwd", value);
|
||||||
|
if (key == "CONFIG_NETWORK_HOSTNAME") return prefs_.putString("hostname", value);
|
||||||
|
if (key == "CONFIG_NETWORK_DHCP") return prefs_.putBool("dhcp", value == "1");
|
||||||
|
if (key == "CONFIG_NETWORK_IPV4") return prefs_.putString("ip", value);
|
||||||
|
if (key == "CONFIG_NETWORK_MASK") return prefs_.putString("subnet", value);
|
||||||
|
if (key == "CONFIG_NETWORK_GATEWAY") return prefs_.putString("gateway", value);
|
||||||
|
if (key == "CONFIG_BUTTON_ENABLE") return prefs_.putBool("button_enable", value == "1");
|
||||||
|
if (key == "CONFIG_BUTTON_PIN") return prefs_.putUChar("button_pin", value.toInt());
|
||||||
|
if (key == "CONFIG_BUTTON_OSC_HOST") return prefs_.putString("osc_host", value);
|
||||||
|
if (key == "CONFIG_BUTTON_OSC_PORT") return prefs_.putUShort("osc_port", value.toInt());
|
||||||
|
if (key == "CONFIG_BUTTON_OSC_PRESSED_ADDR") return prefs_.putString("osc_pressed_addr", value);
|
||||||
|
if (key == "CONFIG_BUTTON_OSC_PRESSED_VALUE") return prefs_.putString("osc_pressed_value", value);
|
||||||
|
if (key == "CONFIG_BUTTON_OSC_RELEASED_ADDR") return prefs_.putString("osc_released_addr", value);
|
||||||
|
if (key == "CONFIG_BUTTON_OSC_RELEASED_VALUE") return prefs_.putString("osc_released_value", value);
|
||||||
|
if (key == "CONFIG_STROBE_ENABLE") return prefs_.putBool("strobe_enable", value == "1");
|
||||||
|
if (key == "CONFIG_STROBE_PIN") return prefs_.putUChar("strobe_led_pin", value.toInt());
|
||||||
|
if (key == "CONFIG_STROBE_UNIVERSE") return prefs_.putUShort("strobe_universe", value.toInt());
|
||||||
|
if (key == "CONFIG_STROBE_ADDRESS") return prefs_.putUShort("strobe_address", value.toInt());
|
||||||
|
if (key == "CONFIG_STRIP_ENABLE") return prefs_.putBool("strip_enable", value == "1");
|
||||||
|
if (key == "CONFIG_STRIP_PIN") return prefs_.putUChar("strip_data_pin", value.toInt());
|
||||||
|
if (key == "CONFIG_STRIP_COUNT") return prefs_.putUShort("strip_led_count", value.toInt());
|
||||||
|
if (key == "CONFIG_STRIP_UNIVERSE") return prefs_.putUShort("strip_universe", value.toInt());
|
||||||
|
if (key == "CONFIG_STRIP_ADDRESS") return prefs_.putUShort("strip_address", value.toInt());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
access settings struct
|
||||||
|
*/
|
||||||
|
const settings_t settings() {
|
||||||
|
return settings_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace config
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
configure.h
|
||||||
|
|
||||||
|
Copyright (c) 2020 Kevin Matz (kevin.matz@gmail.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
#ifndef WIFLASH_CONFIGURE_H
|
||||||
|
#define WIFLASH_CONFIGURE_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
namespace config {
|
||||||
|
|
||||||
|
/*
|
||||||
|
If this pin is tied LOW at setup(), settings will be defaulted
|
||||||
|
*/
|
||||||
|
const uint8_t reset_button = A1; // tie A1 to ground to reset preferances
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
device configuration
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
String ssid;
|
||||||
|
String pwd;
|
||||||
|
wifi_mode_t mode;
|
||||||
|
|
||||||
|
bool dhcp;
|
||||||
|
String ip;
|
||||||
|
String subnet;
|
||||||
|
String gateway;
|
||||||
|
String hostname;
|
||||||
|
|
||||||
|
String osc_host;
|
||||||
|
uint16_t osc_port;
|
||||||
|
String osc_pressed_addr;
|
||||||
|
String osc_pressed_value;
|
||||||
|
String osc_released_addr;
|
||||||
|
String osc_released_value;
|
||||||
|
|
||||||
|
bool button_enable;
|
||||||
|
int button_pin;
|
||||||
|
|
||||||
|
bool strobe_enable;
|
||||||
|
int strobe_led_pin;
|
||||||
|
uint16_t strobe_universe;
|
||||||
|
uint16_t strobe_address;
|
||||||
|
|
||||||
|
bool strip_enable;
|
||||||
|
uint16_t strip_led_count;
|
||||||
|
uint8_t strip_data_pin;
|
||||||
|
uint16_t strip_universe;
|
||||||
|
uint16_t strip_address;
|
||||||
|
} settings_t;
|
||||||
|
|
||||||
|
|
||||||
|
bool loadConfig();
|
||||||
|
size_t set(const String& key, const String& value);
|
||||||
|
String getString(const String& key);
|
||||||
|
const settings_t settings();
|
||||||
|
|
||||||
|
} // namespace config
|
||||||
|
|
||||||
|
#endif // WIFLASH_CONFIGURE_H
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
status.cpp
|
||||||
|
|
||||||
|
Copyright (c) 2020 Kevin Matz (kevin.matz@gmail.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "status.h"
|
||||||
|
#include "configure.h"
|
||||||
|
|
||||||
|
#include <SPIFFS.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace status {
|
||||||
|
|
||||||
|
/*
|
||||||
|
Read the battery level
|
||||||
|
*/
|
||||||
|
float batteryVoltage() {
|
||||||
|
float v;
|
||||||
|
v = analogRead(battery_sense); // 12bit reading
|
||||||
|
v /= 4095.0f; // percent of range
|
||||||
|
v *= 2.0f; // doubled
|
||||||
|
v *= 3.3f; // percent of referance voltage
|
||||||
|
v *= 1.1f; // multiply by ADC resolution (V)
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Template keyiables
|
||||||
|
*/
|
||||||
|
String getString(const String& key) {
|
||||||
|
// status values
|
||||||
|
if (key == "STATUS_IRAM_TOTAL") return String(ESP.getHeapSize());
|
||||||
|
if (key == "STATUS_IRAM_FREE") return String(ESP.getFreeHeap());
|
||||||
|
if (key == "STATUS_IRAM_MAX") return String(ESP.getMinFreeHeap());
|
||||||
|
if (key == "STATUS_SPIFFS_TOTAL") return String(SPIFFS.totalBytes());
|
||||||
|
if (key == "STATUS_SPIFFS_FREE") return String(SPIFFS.totalBytes() - SPIFFS.usedBytes());
|
||||||
|
if (key == "STATUS_BATTERY_VOLTAGE") return String(batteryVoltage());
|
||||||
|
if (key == "STATUS_WIFI_MODE") return String(WiFi.getMode());
|
||||||
|
if (key == "STATUS_WIFI_POWER") return String(WiFi.getTxPower());
|
||||||
|
if (key == "STATUS_WIFI_SSID") return WiFi.SSID();
|
||||||
|
if (config::settings().mode == WIFI_AP) {
|
||||||
|
if (key == "STATUS_NETWORK_HOSTNAME") return String(WiFi.softAPgetHostname());
|
||||||
|
if (key == "STATUS_NETWORK_IPV4") return WiFi.softAPIP().toString();
|
||||||
|
if (key == "STATUS_NETWORK_IPV6") return WiFi.softAPIPv6().toString();
|
||||||
|
if (key == "STATUS_NETWORK_CIDR") return String(WiFi.softAPSubnetCIDR());
|
||||||
|
if (key == "STATUS_NETWORK_GATEWAY") return WiFi.gatewayIP().toString();
|
||||||
|
if (key == "STATUS_NETWORK_MAC") return WiFi.softAPmacAddress();
|
||||||
|
}
|
||||||
|
if (config::settings().mode == WIFI_STA) {
|
||||||
|
if (key == "STATUS_WIFI_STATUS") return String(WiFi.status());
|
||||||
|
if (key == "STATUS_WIFI_SLEEP") return String(WiFi.getSleep());
|
||||||
|
if (key == "STATUS_NETWORK_HOSTNAME") return String(WiFi.getHostname());
|
||||||
|
if (key == "STATUS_NETWORK_IPV4") return WiFi.localIP().toString();
|
||||||
|
if (key == "STATUS_NETWORK_IPV6") return WiFi.localIPv6().toString();
|
||||||
|
if (key == "STATUS_NETWORK_CIDR") return String(WiFi.subnetCIDR());
|
||||||
|
if (key == "STATUS_NETWORK_GATEWAY") return WiFi.gatewayIP().toString();
|
||||||
|
if (key == "STATUS_NETWORK_MAC") return WiFi.macAddress();
|
||||||
|
}
|
||||||
|
return String();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace status
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
status.h
|
||||||
|
|
||||||
|
Copyright (c) 2020 Kevin Matz (kevin.matz@gmail.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
#ifndef WIFLASH_STATUS_H
|
||||||
|
#define WIFLASH_STATUS_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
namespace status {
|
||||||
|
|
||||||
|
/*
|
||||||
|
Hazzah32 battery connected to A13
|
||||||
|
*/
|
||||||
|
const uint8_t battery_sense = A13;
|
||||||
|
|
||||||
|
String getString(const String& key);
|
||||||
|
float batteryVoltage();
|
||||||
|
|
||||||
|
} // namespace status
|
||||||
|
|
||||||
|
#endif // WIFLASH_STATUS.H
|
|
@ -33,241 +33,44 @@
|
||||||
#include <ArduinoOSC.h>
|
#include <ArduinoOSC.h>
|
||||||
#include <NeoPixelBus.h>
|
#include <NeoPixelBus.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <Preferences.h>
|
#include "configure.h"
|
||||||
|
#include "status.h"
|
||||||
#include "sacn.h"
|
#include "sacn.h"
|
||||||
#include "strobe_esp32.h"
|
#include "strobe_esp32.h"
|
||||||
#include "dmx_universe.h"
|
#include "dmx_universe.h"
|
||||||
|
|
||||||
/*
|
|
||||||
If this pin is tied LOW at setup(), settings will be defaulted
|
|
||||||
*/
|
|
||||||
const int reset_button = A1; // tie A1 to ground to reset preferances
|
|
||||||
|
|
||||||
/*
|
|
||||||
device configuration
|
|
||||||
*/
|
|
||||||
struct config_ {
|
|
||||||
String ssid;
|
|
||||||
String pwd;
|
|
||||||
wifi_mode_t mode;
|
|
||||||
|
|
||||||
bool dhcp;
|
|
||||||
String ip;
|
|
||||||
String subnet;
|
|
||||||
String gateway;
|
|
||||||
String hostname;
|
|
||||||
|
|
||||||
String osc_host;
|
|
||||||
uint16_t osc_port;
|
|
||||||
String osc_pressed_addr;
|
|
||||||
String osc_pressed_value;
|
|
||||||
String osc_released_addr;
|
|
||||||
String osc_released_value;
|
|
||||||
|
|
||||||
bool button_enable;
|
|
||||||
int button_pin;
|
|
||||||
|
|
||||||
bool strobe_enable;
|
|
||||||
int strobe_led_pin;
|
|
||||||
uint16_t strobe_universe;
|
|
||||||
uint16_t strobe_address;
|
|
||||||
|
|
||||||
bool strip_enable;
|
|
||||||
uint16_t strip_led_count;
|
|
||||||
uint8_t strip_data_pin;
|
|
||||||
uint16_t strip_universe;
|
|
||||||
uint16_t strip_address;
|
|
||||||
};
|
|
||||||
struct config_ config;
|
|
||||||
|
|
||||||
|
|
||||||
//// device objects
|
//// device objects
|
||||||
Strobe *strobe;
|
Strobe *strobe;
|
||||||
NeoPixelBus<NeoGrbwFeature, Neo800KbpsMethod> *strip;
|
NeoPixelBus<NeoGrbwFeature, Neo800KbpsMethod> *strip;
|
||||||
ESPAsyncE131 *e131 = new ESPAsyncE131();
|
ESPAsyncE131 *e131 = new ESPAsyncE131();
|
||||||
AsyncWebServer *httpd = new AsyncWebServer(80);
|
AsyncWebServer *httpd = new AsyncWebServer(80);
|
||||||
Preferences prefs;
|
|
||||||
|
|
||||||
//// static hardware
|
|
||||||
const uint8_t battery_sense = A13; //Hazzah32 battery connected to A13
|
|
||||||
|
|
||||||
//// Global button variables
|
//// Global button variables
|
||||||
bool pressed = false; // track button state
|
bool pressed = false; // track button state
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Template variables
|
|
||||||
*/
|
|
||||||
String templateProcessor(const String& var) {
|
|
||||||
// status values
|
|
||||||
if (var == "STATUS_IRAM_TOTAL") return String(ESP.getHeapSize());
|
|
||||||
if (var == "STATUS_IRAM_FREE") return String(ESP.getFreeHeap());
|
|
||||||
if (var == "STATUS_IRAM_MAX") return String(ESP.getMinFreeHeap());
|
|
||||||
if (var == "STATUS_SPIFFS_TOTAL") return String(SPIFFS.totalBytes());
|
|
||||||
if (var == "STATUS_SPIFFS_FREE") return String(SPIFFS.totalBytes() - SPIFFS.usedBytes());
|
|
||||||
if (var == "STATUS_BATTERY_VOLTAGE") return String(batteryVoltage());
|
|
||||||
if (var == "STATUS_WIFI_MODE") return String(WiFi.getMode());
|
|
||||||
if (var == "STATUS_WIFI_POWER") return String(WiFi.getTxPower());
|
|
||||||
if (var == "STATUS_WIFI_SSID") return WiFi.SSID();
|
|
||||||
if (config.mode == WIFI_AP) {
|
|
||||||
if (var == "STATUS_NETWORK_HOSTNAME") return String(WiFi.softAPgetHostname());
|
|
||||||
if (var == "STATUS_NETWORK_IPV4") return WiFi.softAPIP().toString();
|
|
||||||
if (var == "STATUS_NETWORK_IPV6") return WiFi.softAPIPv6().toString();
|
|
||||||
if (var == "STATUS_NETWORK_CIDR") return String(WiFi.softAPSubnetCIDR());
|
|
||||||
if (var == "STATUS_NETWORK_GATEWAY") return WiFi.gatewayIP().toString();
|
|
||||||
if (var == "STATUS_NETWORK_MAC") return WiFi.softAPmacAddress();
|
|
||||||
}
|
|
||||||
if (config.mode == WIFI_STA) {
|
|
||||||
if (var == "STATUS_WIFI_STATUS") return String(WiFi.status());
|
|
||||||
if (var == "STATUS_WIFI_SLEEP") return String(WiFi.getSleep());
|
|
||||||
if (var == "STATUS_NETWORK_HOSTNAME") return String(WiFi.getHostname());
|
|
||||||
if (var == "STATUS_NETWORK_IPV4") return WiFi.localIP().toString();
|
|
||||||
if (var == "STATUS_NETWORK_IPV6") return WiFi.localIPv6().toString();
|
|
||||||
if (var == "STATUS_NETWORK_CIDR") return String(WiFi.subnetCIDR());
|
|
||||||
if (var == "STATUS_NETWORK_GATEWAY") return WiFi.gatewayIP().toString();
|
|
||||||
if (var == "STATUS_NETWORK_MAC") return WiFi.macAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
// configuration values
|
|
||||||
if (var == "CONFIG_WIFI_MODE") return String(config.mode);
|
|
||||||
if (var == "CONFIG_WIFI_SSID") return config.ssid;
|
|
||||||
if (var == "CONFIG_WIFI_PASSWORD") return config.pwd;
|
|
||||||
if (var == "CONFIG_NETWORK_HOSTNAME") return config.hostname;
|
|
||||||
if (var == "CONFIG_NETWORK_DHCP") return String(config.dhcp);
|
|
||||||
if (var == "CONFIG_NETWORK_IPV4") return config.ip;
|
|
||||||
if (var == "CONFIG_NETWORK_MASK") return config.subnet;
|
|
||||||
if (var == "CONFIG_NETWORK_GATEWAY") return config.gateway;
|
|
||||||
if (var == "CONFIG_BUTTON_ENABLE") return String(config.button_enable);
|
|
||||||
if (var == "CONFIG_BUTTON_PIN") return String(config.button_pin);
|
|
||||||
if (var == "CONFIG_BUTTON_OSC_HOST") return config.osc_host;
|
|
||||||
if (var == "CONFIG_BUTTON_OSC_PORT") return String(config.osc_port);
|
|
||||||
if (var == "CONFIG_BUTTON_OSC_PRESSED_ADDR") return config.osc_pressed_addr;
|
|
||||||
if (var == "CONFIG_BUTTON_OSC_PRESSED_VALUE") return config.osc_pressed_value;
|
|
||||||
if (var == "CONFIG_BUTTON_OSC_RELEASED_ADDR") return config.osc_released_addr;
|
|
||||||
if (var == "CONFIG_BUTTON_OSC_RELEASED_VALUE") return config.osc_released_value;
|
|
||||||
if (var == "CONFIG_STROBE_ENABLE") return String(config.strobe_enable);
|
|
||||||
if (var == "CONFIG_STROBE_PIN") return String(config.strobe_led_pin);
|
|
||||||
if (var == "CONFIG_STROBE_UNIVERSE") return String(config.strobe_universe);
|
|
||||||
if (var == "CONFIG_STROBE_ADDRESS") return String(config.strobe_address);
|
|
||||||
if (var == "CONFIG_STRIP_ENABLE") return String(config.strip_enable);
|
|
||||||
if (var == "CONFIG_STRIP_PIN") return String(config.strip_data_pin);
|
|
||||||
if (var == "CONFIG_STRIP_COUNT") return String(config.strip_led_count);
|
|
||||||
if (var == "CONFIG_STRIP_UNIVERSE") return String(config.strip_universe);
|
|
||||||
if (var == "CONFIG_STRIP_ADDRESS") return String(config.strip_address);
|
|
||||||
|
|
||||||
return String();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Change a setting in NVM
|
|
||||||
*/
|
|
||||||
size_t changeSetting (const String& key, const String& value) {
|
|
||||||
Serial.print("changing config: ");
|
|
||||||
Serial.print(key);
|
|
||||||
Serial.print(" = ");
|
|
||||||
Serial.println(value);
|
|
||||||
if (key == "CONFIG_WIFI_MODE") return prefs.putUChar("mode", value.toInt());
|
|
||||||
if (key == "CONFIG_WIFI_SSID") return prefs.putString("ssid", value);
|
|
||||||
if (key == "CONFIG_WIFI_PASSWORD") return prefs.putString("pwd", value);
|
|
||||||
if (key == "CONFIG_NETWORK_HOSTNAME") return prefs.putString("hostname", value);
|
|
||||||
if (key == "CONFIG_NETWORK_DHCP") return prefs.putBool("dhcp", value == "1");
|
|
||||||
if (key == "CONFIG_NETWORK_IPV4") return prefs.putString("ip", value);
|
|
||||||
if (key == "CONFIG_NETWORK_MASK") return prefs.putString("subnet", value);
|
|
||||||
if (key == "CONFIG_NETWORK_GATEWAY") return prefs.putString("gateway", value);
|
|
||||||
if (key == "CONFIG_BUTTON_ENABLE") return prefs.putBool("button_enable", value == "1");
|
|
||||||
if (key == "CONFIG_BUTTON_PIN") return prefs.putUChar("button_pin", value.toInt());
|
|
||||||
if (key == "CONFIG_BUTTON_OSC_HOST") return prefs.putString("osc_host", value);
|
|
||||||
if (key == "CONFIG_BUTTON_OSC_PORT") return prefs.putUShort("osc_port", value.toInt());
|
|
||||||
if (key == "CONFIG_BUTTON_OSC_PRESSED_ADDR") return prefs.putString("osc_pressed_addr", value);
|
|
||||||
if (key == "CONFIG_BUTTON_OSC_PRESSED_VALUE") return prefs.putString("osc_pressed_value", value);
|
|
||||||
if (key == "CONFIG_BUTTON_OSC_RELEASED_ADDR") return prefs.putString("osc_released_addr", value);
|
|
||||||
if (key == "CONFIG_BUTTON_OSC_RELEASED_VALUE") return prefs.putString("osc_released_value", value);
|
|
||||||
if (key == "CONFIG_STROBE_ENABLE") return prefs.putBool("strobe_enable", value == "1");
|
|
||||||
if (key == "CONFIG_STROBE_PIN") return prefs.putUChar("strobe_led_pin", value.toInt());
|
|
||||||
if (key == "CONFIG_STROBE_UNIVERSE") return prefs.putUShort("strobe_universe", value.toInt());
|
|
||||||
if (key == "CONFIG_STROBE_ADDRESS") return prefs.putUShort("strobe_address", value.toInt());
|
|
||||||
if (key == "CONFIG_STRIP_ENABLE") return prefs.putBool("strip_enable", value == "1");
|
|
||||||
if (key == "CONFIG_STRIP_PIN") return prefs.putUChar("strip_data_pin", value.toInt());
|
|
||||||
if (key == "CONFIG_STRIP_COUNT") return prefs.putUShort("strip_led_count", value.toInt());
|
|
||||||
if (key == "CONFIG_STRIP_UNIVERSE") return prefs.putUShort("strip_universe", value.toInt());
|
|
||||||
if (key == "CONFIG_STRIP_ADDRESS") return prefs.putUShort("strip_address", value.toInt());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Load device configuration from NVM
|
|
||||||
*/
|
|
||||||
bool loadConfig() {
|
|
||||||
prefs.begin("wiflash", false); // open RW;
|
|
||||||
|
|
||||||
Serial.print("Jump pin ");
|
|
||||||
Serial.print(reset_button);
|
|
||||||
Serial.println(" to GROUND to reset settings.");
|
|
||||||
|
|
||||||
pinMode(reset_button, INPUT_PULLUP);
|
|
||||||
if (prefs.getBool("reset_on_reboot") ||
|
|
||||||
!digitalRead(reset_button)) {
|
|
||||||
prefs.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
config.ssid = prefs.getString("ssid", "WiFlash");
|
|
||||||
config.pwd = prefs.getString("pwd", "technologyismagic");
|
|
||||||
config.mode = (wifi_mode_t)prefs.getUChar("wifi_mode", WIFI_AP);
|
|
||||||
config.hostname = prefs.getString("hostname", "WiFlash");
|
|
||||||
|
|
||||||
config.dhcp = prefs.getBool("dhcp", true);
|
|
||||||
config.ip = prefs.getString("ip", "192.168.1.1");
|
|
||||||
config.subnet = prefs.getString("subnet", "255.255.255.0");
|
|
||||||
config.gateway = prefs.getString("gateway", "");
|
|
||||||
|
|
||||||
config.button_enable = prefs.getBool("button_enable", true);
|
|
||||||
config.button_pin = prefs.getUChar("butto_pin", A0); // A0, use 100nF to ground
|
|
||||||
|
|
||||||
config.osc_host = prefs.getString("osc_host", "192.168.1.1");
|
|
||||||
config.osc_port = prefs.getUShort("osc_port", 7001);
|
|
||||||
config.osc_pressed_addr = prefs.getString("osc_pressed_addr", "/hog/playback/go/0");
|
|
||||||
config.osc_pressed_value = prefs.getString("osc_pressed_value", "99.1");
|
|
||||||
config.osc_released_addr = prefs.getString("osc_released_addr", "/hog/playback/go/0");
|
|
||||||
config.osc_released_value = prefs.getString("osc_released_value", "99.2");
|
|
||||||
|
|
||||||
config.strobe_enable = prefs.getBool("strobe_enable", true);
|
|
||||||
config.strobe_led_pin = prefs.getUChar("strobe_led_pin", LED_BUILTIN); // IO13
|
|
||||||
config.strobe_universe = prefs.getUShort("strobe_universe", 1);
|
|
||||||
config.strobe_address = prefs.getUShort("strobe_address", 001);
|
|
||||||
|
|
||||||
config.strip_enable = prefs.getBool("strip_enable", false);
|
|
||||||
config.strip_led_count = prefs.getUShort("strip_led_count", 8); // not less than 4
|
|
||||||
config.strip_data_pin = prefs.getUChar("strip_data_pin", 21);
|
|
||||||
config.strip_universe = prefs.getUShort("strip_universe", 1);
|
|
||||||
config.strip_address = prefs.getUShort("strip_address", 001);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Start the async web server
|
Start the async web server
|
||||||
*/
|
*/
|
||||||
void startHTTPD() {
|
void startHTTPD() {
|
||||||
httpd->on("/api/config", HTTP_GET, [](AsyncWebServerRequest * request) {
|
httpd->on("/api/config", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||||
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/template/configuration.json", "application/json", false, templateProcessor);
|
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/template/configuration.json", "application/json", false, config::getString);
|
||||||
response->addHeader("Access-Control-Allow-Origin", "*");
|
response->addHeader("Access-Control-Allow-Origin", "*");
|
||||||
request->send(response);
|
request->send(response);
|
||||||
});
|
});
|
||||||
|
|
||||||
httpd->on("/api/status", HTTP_GET, [](AsyncWebServerRequest * request) {
|
httpd->on("/api/status", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||||
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/template/status.json", "application/json", false, templateProcessor);
|
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/template/status.json", "application/json", false, status::getString);
|
||||||
response->addHeader("Access-Control-Allow-Origin", "*");
|
response->addHeader("Access-Control-Allow-Origin", "*");
|
||||||
request->send(response);
|
request->send(response);
|
||||||
});
|
});
|
||||||
|
|
||||||
httpd->on("/api/reboot", HTTP_POST, [](AsyncWebServerRequest * request) {
|
httpd->on("/api/reboot", HTTP_POST, [](AsyncWebServerRequest * request) {
|
||||||
String url = "http://" + config.hostname + ".local";
|
String url = "http://" + config::settings().hostname + ".local";
|
||||||
request->redirect(url.c_str());
|
request->redirect(url.c_str());
|
||||||
httpd->end();
|
httpd->end();
|
||||||
prefs.end();
|
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -280,15 +83,15 @@ void startHTTPD() {
|
||||||
String key = request->getParam("key", true)->value();
|
String key = request->getParam("key", true)->value();
|
||||||
const String& val = request->getParam("value", true)->value();
|
const String& val = request->getParam("value", true)->value();
|
||||||
key.toUpperCase();
|
key.toUpperCase();
|
||||||
if (val == templateProcessor(key)) {
|
if (val == config::getString(key)) {
|
||||||
// already at value
|
// already at value
|
||||||
request->send(204);
|
request->send(204);
|
||||||
} else if (changeSetting(key, val) > 0) {
|
} else if (config::set(key, val) > 0) {
|
||||||
// change accepted OK
|
// change accepted OK
|
||||||
request->send(205);
|
request->send(205);
|
||||||
} else {
|
} else {
|
||||||
// change failed, return current value
|
// change failed, return current value
|
||||||
String json = "{\"" + key + "\": \"" + templateProcessor(key) + "\"}";
|
String json = "{\"" + key + "\": \"" + config::getString(key) + "\"}";
|
||||||
request->send(403, "application/json", json);
|
request->send(403, "application/json", json);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -303,30 +106,16 @@ void startHTTPD() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Read the battery level
|
|
||||||
*/
|
|
||||||
float batteryVoltage() {
|
|
||||||
float v;
|
|
||||||
v = analogRead(battery_sense); // 12bit reading
|
|
||||||
v /= 4095.0f; // percent of range
|
|
||||||
v *= 2.0f; // doubled
|
|
||||||
v *= 3.3f; // percent of referance voltage
|
|
||||||
v *= 1.1f; // multiply by ADC resolution (V)
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
change pixel strip colours on DMX change
|
change pixel strip colours on DMX change
|
||||||
*/
|
*/
|
||||||
void recvPixelData(Universe *universe) {
|
void recvPixelData(Universe *universe) {
|
||||||
for (int i = 0; i < config.strip_led_count; i++) {
|
for (int i = 0; i < config::settings().strip_led_count; i++) {
|
||||||
uint8_t r, g, b, w;
|
uint8_t r, g, b, w;
|
||||||
r = universe->data()->data[config.strip_address + (i * 4) + 0];
|
r = universe->data()->data[config::settings().strip_address + (i * 4) + 0];
|
||||||
g = universe->data()->data[config.strip_address + (i * 4) + 1];
|
g = universe->data()->data[config::settings().strip_address + (i * 4) + 1];
|
||||||
b = universe->data()->data[config.strip_address + (i * 4) + 2];
|
b = universe->data()->data[config::settings().strip_address + (i * 4) + 2];
|
||||||
w = universe->data()->data[config.strip_address + (i * 4) + 3];
|
w = universe->data()->data[config::settings().strip_address + (i * 4) + 3];
|
||||||
strip->SetPixelColor(i, RgbwColor(r, g, b, w));
|
strip->SetPixelColor(i, RgbwColor(r, g, b, w));
|
||||||
}
|
}
|
||||||
strip->Show();
|
strip->Show();
|
||||||
|
@ -342,36 +131,39 @@ void setup() {
|
||||||
Serial.println("Serial started!");
|
Serial.println("Serial started!");
|
||||||
|
|
||||||
Serial.println("Loading Prefferences from NVM.");
|
Serial.println("Loading Prefferences from NVM.");
|
||||||
loadConfig();
|
config::loadConfig();
|
||||||
|
|
||||||
//// start WiFi:
|
//// start WiFi:
|
||||||
// set IPv4
|
// set IPv4
|
||||||
Serial.println("Starting WiFi.");
|
Serial.println("Starting WiFi.");
|
||||||
WiFi.mode(config.mode);
|
WiFi.mode(config::settings().mode);
|
||||||
IPAddress ip_, gateway_, subnet_;
|
IPAddress ip_, gateway_, subnet_;
|
||||||
if (!config.dhcp) {
|
if (!config::settings().dhcp) {
|
||||||
ip_.fromString(config.ip);
|
ip_.fromString(config::settings().ip);
|
||||||
gateway_.fromString(config.gateway);
|
gateway_.fromString(config::settings().gateway);
|
||||||
subnet_.fromString(config.subnet);
|
subnet_.fromString(config::settings().subnet);
|
||||||
}
|
}
|
||||||
switch (config.mode) {
|
switch (config::settings().mode) {
|
||||||
case WIFI_AP: {
|
case WIFI_AP: {
|
||||||
WiFi.softAPsetHostname(config.hostname.c_str());
|
WiFi.softAPsetHostname(config::settings().hostname.c_str());
|
||||||
if (!config.dhcp) {
|
if (!config::settings().dhcp) {
|
||||||
WiFi.softAPConfig(ip_, gateway_, subnet_);
|
WiFi.softAPConfig(ip_, gateway_, subnet_);
|
||||||
}
|
}
|
||||||
WiFi.softAP(config.ssid.c_str(), config.pwd.c_str());
|
WiFi.softAP(config::settings().ssid.c_str(), config::settings().pwd.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WIFI_STA: {
|
case WIFI_STA: {
|
||||||
WiFi.setHostname(config.hostname.c_str());
|
WiFi.setHostname(config::settings().hostname.c_str());
|
||||||
if (!config.dhcp) {
|
if (!config::settings().dhcp) {
|
||||||
WiFi.config(ip_, gateway_, subnet_);
|
WiFi.config(ip_, gateway_, subnet_);
|
||||||
}
|
}
|
||||||
WiFi.begin(config.ssid.c_str(), config.pwd.c_str());
|
WiFi.begin(config::settings().ssid.c_str(), config::settings().pwd.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Serial.print("Access the configuration web page at http://");
|
||||||
|
Serial.print(config::settings().hostname.c_str());
|
||||||
|
Serial.println(".local");
|
||||||
|
|
||||||
Serial.println("Disabling Bluetooth.");
|
Serial.println("Disabling Bluetooth.");
|
||||||
btStop();
|
btStop();
|
||||||
|
@ -383,42 +175,42 @@ void setup() {
|
||||||
startHTTPD();
|
startHTTPD();
|
||||||
|
|
||||||
Serial.println("Starting mDNS responder.");
|
Serial.println("Starting mDNS responder.");
|
||||||
if (MDNS.begin(config.hostname.c_str())) {
|
if (MDNS.begin(config::settings().hostname.c_str())) {
|
||||||
MDNS.addService("http", "tcp", 80);
|
MDNS.addService("http", "tcp", 80);
|
||||||
}
|
}
|
||||||
|
|
||||||
//// start fixtures hardware:
|
//// start fixtures hardware:
|
||||||
// battery monitor
|
// battery monitor
|
||||||
pinMode(battery_sense, INPUT);
|
pinMode(status::battery_sense, INPUT);
|
||||||
|
|
||||||
// button
|
// button
|
||||||
if (config.button_enable) {
|
if (config::settings().button_enable) {
|
||||||
Serial.println("Initializing OSC button");
|
Serial.println("Initializing OSC button");
|
||||||
pinMode(config.button_pin, INPUT_PULLUP);
|
pinMode(config::settings().button_pin, INPUT_PULLUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
// strobe
|
// strobe
|
||||||
if (config.strobe_enable) {
|
if (config::settings().strobe_enable) {
|
||||||
strobe = new Strobe(config.strobe_address);
|
strobe = new Strobe(config::settings().strobe_address);
|
||||||
Serial.println("Initializing DMX Strobe");
|
Serial.println("Initializing DMX Strobe");
|
||||||
if (!strobe->begin(config.strobe_led_pin, 0)) {
|
if (!strobe->begin(config::settings().strobe_led_pin, 0)) {
|
||||||
Serial.println("Strobe failed to configure.");
|
Serial.println("Strobe failed to configure.");
|
||||||
}
|
}
|
||||||
if (e131->subscribe(config.strobe_universe)) {
|
if (e131->subscribe(config::settings().strobe_universe)) {
|
||||||
e131->universe(config.strobe_universe)->onData(std::bind(&Strobe::recvData,
|
e131->universe(config::settings().strobe_universe)->onData(std::bind(&Strobe::recvData,
|
||||||
strobe, std::placeholders::_1));
|
strobe, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pixels
|
// pixels
|
||||||
if (config.strip_enable) {
|
if (config::settings().strip_enable) {
|
||||||
Serial.println("Initializing Pixelmapped LEDs.");
|
Serial.println("Initializing Pixelmapped LEDs.");
|
||||||
|
|
||||||
strip = new NeoPixelBus<NeoGrbwFeature, Neo800KbpsMethod>(config.strip_led_count, config.strip_data_pin);
|
strip = new NeoPixelBus<NeoGrbwFeature, Neo800KbpsMethod>(config::settings().strip_led_count, config::settings().strip_data_pin);
|
||||||
strip->Begin();
|
strip->Begin();
|
||||||
strip->Show();
|
strip->Show();
|
||||||
if (e131->subscribe(config.strip_universe)) {
|
if (e131->subscribe(config::settings().strip_universe)) {
|
||||||
e131->universe(config.strip_universe)->onData(std::bind(&recvPixelData,
|
e131->universe(config::settings().strip_universe)->onData(std::bind(&recvPixelData,
|
||||||
std::placeholders::_1));
|
std::placeholders::_1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -431,7 +223,7 @@ void setup() {
|
||||||
Arduino process loop
|
Arduino process loop
|
||||||
*/
|
*/
|
||||||
void loop() {
|
void loop() {
|
||||||
if (config.mode == WIFI_STA &&
|
if (config::settings().mode == WIFI_STA &&
|
||||||
WiFi.status() != WL_CONNECTED) {
|
WiFi.status() != WL_CONNECTED) {
|
||||||
Serial.println("Waiting for WiFi...");
|
Serial.println("Waiting for WiFi...");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
@ -440,17 +232,17 @@ void loop() {
|
||||||
|
|
||||||
// Be a remote trigger
|
// Be a remote trigger
|
||||||
//
|
//
|
||||||
bool val = !digitalRead(config.button_pin);
|
bool val = !digitalRead(config::settings().button_pin);
|
||||||
if (val != pressed && config.button_enable) {
|
if (val != pressed && config::settings().button_enable) {
|
||||||
pressed = val;
|
pressed = val;
|
||||||
if (pressed) {
|
if (pressed) {
|
||||||
Serial.println("Pressed");
|
Serial.println("Pressed");
|
||||||
OscWiFi.send(config.osc_host, config.osc_port,
|
OscWiFi.send(config::settings().osc_host, config::settings().osc_port,
|
||||||
config.osc_pressed_addr, config.osc_pressed_value);
|
config::settings().osc_pressed_addr, config::settings().osc_pressed_value);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Released");
|
Serial.println("Released");
|
||||||
OscWiFi.send(config.osc_host, config.osc_port,
|
OscWiFi.send(config::settings().osc_host, config::settings().osc_port,
|
||||||
config.osc_released_addr, config.osc_released_value);
|
config::settings().osc_released_addr, config::settings().osc_released_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue