mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-07-05 21:58:53 +00:00
analogWrite should also use ledc library; also added auto mac address for ethernet
This commit is contained in:
parent
c295017495
commit
ec624aba62
2 changed files with 54 additions and 35 deletions
|
@ -62,8 +62,8 @@ struct Config
|
||||||
uint16_t esta_man {0x0000}; // ESTA manufacturer code
|
uint16_t esta_man {0x0000}; // ESTA manufacturer code
|
||||||
uint8_t status1 {0x00}; // Unknown / Normal
|
uint8_t status1 {0x00}; // Unknown / Normal
|
||||||
uint8_t status2 {0x08}; // sACN capable
|
uint8_t status2 {0x08}; // sACN capable
|
||||||
String short_name {"ChaosArtNet"};
|
String short_name {"ChaosDMX"};
|
||||||
String long_name {"Chaos ArtNet Interface"};
|
String long_name {"ChaosDMX Interface"};
|
||||||
String node_report {""};
|
String node_report {""};
|
||||||
// Four universes from Device to Controller
|
// Four universes from Device to Controller
|
||||||
// NOTE: Only low 4 bits of the universes
|
// NOTE: Only low 4 bits of the universes
|
||||||
|
|
85
src/main.cpp
85
src/main.cpp
|
@ -26,23 +26,18 @@ DMXESPSerial dmx;
|
||||||
#define PIN_LED 7
|
#define PIN_LED 7
|
||||||
#define PIN_BUTTON 5
|
#define PIN_BUTTON 5
|
||||||
|
|
||||||
#ifdef ESP32
|
uint8_t brightness_led = 20;
|
||||||
#include "esp32-hal.h"
|
bool status_led;
|
||||||
#endif
|
|
||||||
|
|
||||||
hw_timer_t * timer = NULL; //H/W timer defining (Pointer to the Structure)
|
hw_timer_t * timer = NULL; //H/W timer defining (Pointer to the Structure)
|
||||||
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
|
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
|
||||||
|
|
||||||
bool status_led;
|
|
||||||
uint8_t brightness_led;
|
|
||||||
|
|
||||||
void IRAM_ATTR onTimer() { //Defining Inerrupt function with IRAM_ATTR for faster access
|
void IRAM_ATTR onTimer() { //Defining Inerrupt function with IRAM_ATTR for faster access
|
||||||
portENTER_CRITICAL_ISR(&timerMux);
|
portENTER_CRITICAL_ISR(&timerMux);
|
||||||
status_led = !status_led;
|
status_led = !status_led;
|
||||||
if (status_led) {
|
if (!status_led) {
|
||||||
ledcWrite(0, brightness_led);
|
analogWrite(PIN_LED, brightness_led);
|
||||||
} else {
|
} else {
|
||||||
ledcWrite(0, 0);
|
analogWrite(PIN_LED, 0);
|
||||||
}
|
}
|
||||||
portEXIT_CRITICAL_ISR(&timerMux);
|
portEXIT_CRITICAL_ISR(&timerMux);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +50,7 @@ void IRAM_ATTR onTimer() { //Defining Inerrupt function with IRAM_ATTR for
|
||||||
#define ETH_INT 38
|
#define ETH_INT 38
|
||||||
#define ETH_SPI_HOST SPI2_HOST
|
#define ETH_SPI_HOST SPI2_HOST
|
||||||
#define ETH_SPI_CLOCK_MHZ 25
|
#define ETH_SPI_CLOCK_MHZ 25
|
||||||
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
byte mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||||
|
|
||||||
enum ethTypes {TYP_AP = 1, TYP_STA = 2, TYP_ETH = 3}; // to be changed to Raffaels(TM) enum
|
enum ethTypes {TYP_AP = 1, TYP_STA = 2, TYP_ETH = 3}; // to be changed to Raffaels(TM) enum
|
||||||
ethTypes ethType;
|
ethTypes ethType;
|
||||||
|
@ -67,23 +62,33 @@ ArtnetWiFi artnet;
|
||||||
const uint16_t size = 512;
|
const uint16_t size = 512;
|
||||||
uint8_t data[size];
|
uint8_t data[size];
|
||||||
|
|
||||||
|
void ledBlink(int ms) {
|
||||||
|
if(timer == NULL) {
|
||||||
|
timer = timerBegin(0, 80, true); // timer 0, prescalar: 80, UP counting
|
||||||
|
timerAttachInterrupt(timer, &onTimer, true); // Attach interrupt
|
||||||
|
}
|
||||||
|
if(ms == 0) {
|
||||||
|
timerAlarmDisable(timer);
|
||||||
|
analogWrite(PIN_LED, 0);
|
||||||
|
} else if(ms == 1) {
|
||||||
|
timerAlarmDisable(timer);
|
||||||
|
analogWrite(PIN_LED, brightness_led);
|
||||||
|
} else {
|
||||||
|
ms = ms*1000;
|
||||||
|
timerAlarmWrite(timer, ms, true); // Match value= 1000000 for 1 sec. delay.
|
||||||
|
timerAlarmEnable(timer); // Enable Timer with interrupt (Alarm Enable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
// Get ETH mac
|
||||||
|
esp_read_mac(mac, ESP_MAC_ETH);
|
||||||
|
|
||||||
// LED
|
// LED
|
||||||
brightness_led = 20;
|
analogWrite(PIN_LED, brightness_led);
|
||||||
ledcAttachPin(PIN_LED, 0);
|
delay(5000);
|
||||||
ledcSetup(0, 20000, 8);
|
ledBlink(500);
|
||||||
//ledcFade();
|
|
||||||
//ledcRead(0);
|
|
||||||
//ledc_fade_func_install(0);
|
|
||||||
//ledc_set_fade_with_time( LEDC_HIGH_SPEED_MODE, (ledc_channel_t)0, ( 0x00000001 << LEDC_TIMER_15_BIT ) - 1, 86400 * 1000 );
|
|
||||||
//ledc_fade_start( LEDC_HIGH_SPEED_MODE, (ledc_channel_t)0, LEDC_FADE_NO_WAIT );
|
|
||||||
|
|
||||||
timer = timerBegin(0, 80, true); // timer 0, prescalar: 80, UP counting
|
|
||||||
timerAttachInterrupt(timer, &onTimer, true); // Attach interrupt
|
|
||||||
timerAlarmWrite(timer, 500000, true); // Match value= 1000000 for 1 sec. delay.
|
|
||||||
timerAlarmEnable(timer); // Enable Timer with interrupt (Alarm Enable)
|
|
||||||
|
|
||||||
|
|
||||||
// Serial console
|
// Serial console
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -95,17 +100,23 @@ void setup()
|
||||||
|
|
||||||
uint8_t universe = config.getUChar("universe", 1);
|
uint8_t universe = config.getUChar("universe", 1);
|
||||||
|
|
||||||
String ssid = config.getString("ssid", "artnet");
|
WiFi.macAddress(mac);
|
||||||
|
char hostname[30];
|
||||||
|
snprintf(hostname, sizeof(hostname), "ChaosDMX %02X%02X", mac[4], mac[5]);
|
||||||
|
Serial.print("Hostname: ");
|
||||||
|
Serial.println(hostname);
|
||||||
|
|
||||||
|
String ssid = config.getString("ssid", hostname);
|
||||||
String pwd = config.getString("pwd", "mbgmbgmbg");
|
String pwd = config.getString("pwd", "mbgmbgmbg");
|
||||||
|
|
||||||
IPAddress defaultIp(192, 168, 1, 201);
|
IPAddress defaultIp(2, mac[3], mac[4], mac[5]);
|
||||||
IPAddress ip = config.getUInt("ip", defaultIp);
|
IPAddress ip = config.getUInt("ip", defaultIp);
|
||||||
|
|
||||||
IPAddress cidr = config.getUChar("cidr", 24);
|
IPAddress cidr = config.getUChar("cidr", 24);
|
||||||
|
|
||||||
// TODO: \/ Herleiten \/ @psxde
|
// TODO: \/ Herleiten \/ @psxde
|
||||||
const IPAddress gateway(192, 168, 1, 1);
|
const IPAddress gateway(2, 0, 0, 1);
|
||||||
const IPAddress subnet(255, 255, 255, 0);
|
const IPAddress subnet(255, 0, 0, 0);
|
||||||
|
|
||||||
// TODO: Initialize Interface connection type - to be changed to Raffaels(TM) enum
|
// TODO: Initialize Interface connection type - to be changed to Raffaels(TM) enum
|
||||||
ethType = TYP_ETH;
|
ethType = TYP_ETH;
|
||||||
|
@ -114,8 +125,7 @@ void setup()
|
||||||
// Button
|
// Button
|
||||||
pinMode(PIN_BUTTON,INPUT_PULLUP);
|
pinMode(PIN_BUTTON,INPUT_PULLUP);
|
||||||
if(digitalRead(PIN_BUTTON) == LOW){
|
if(digitalRead(PIN_BUTTON) == LOW){
|
||||||
timerAlarmWrite(timer, 100000, true);
|
ledBlink(100);
|
||||||
timerAlarmEnable(timer);
|
|
||||||
delay(2000);
|
delay(2000);
|
||||||
Serial.println("Start AP-Mode");
|
Serial.println("Start AP-Mode");
|
||||||
ethType = TYP_AP;
|
ethType = TYP_AP;
|
||||||
|
@ -126,6 +136,7 @@ void setup()
|
||||||
case TYP_STA:
|
case TYP_STA:
|
||||||
Serial.println("Initialize as WiFi-STA");
|
Serial.println("Initialize as WiFi-STA");
|
||||||
WiFi.begin(ssid, pwd);
|
WiFi.begin(ssid, pwd);
|
||||||
|
WiFi.setHostname(hostname);
|
||||||
WiFi.config(ip, gateway, subnet);
|
WiFi.config(ip, gateway, subnet);
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
|
@ -133,11 +144,15 @@ void setup()
|
||||||
}
|
}
|
||||||
Serial.print("WiFi connected, IP = ");
|
Serial.print("WiFi connected, IP = ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
Serial.print("MAC address: ");
|
||||||
|
Serial.println(WiFi.macAddress());
|
||||||
break;
|
break;
|
||||||
case TYP_ETH:{
|
case TYP_ETH:{
|
||||||
Serial.println("Initialize as ETH");
|
Serial.println("Initialize as ETH");
|
||||||
ESP32_W5500_onEvent();
|
ESP32_W5500_onEvent();
|
||||||
|
|
||||||
|
ETH.setHostname(hostname);
|
||||||
|
|
||||||
if (ETH.begin( ETH_MISO, ETH_MOSI, ETH_SCK, ETH_SS, ETH_INT, ETH_SPI_CLOCK_MHZ, ETH_SPI_HOST, mac )) { // Dynamic IP setup
|
if (ETH.begin( ETH_MISO, ETH_MOSI, ETH_SCK, ETH_SS, ETH_INT, ETH_SPI_CLOCK_MHZ, ETH_SPI_HOST, mac )) { // Dynamic IP setup
|
||||||
Serial.println("ETH initialized");
|
Serial.println("ETH initialized");
|
||||||
}else{
|
}else{
|
||||||
|
@ -170,6 +185,8 @@ void setup()
|
||||||
Serial.println(ETH.gatewayIP());
|
Serial.println(ETH.gatewayIP());
|
||||||
Serial.print("DNS Server : ");
|
Serial.print("DNS Server : ");
|
||||||
Serial.println(ETH.dnsIP());
|
Serial.println(ETH.dnsIP());
|
||||||
|
Serial.print("MAC address : ");
|
||||||
|
Serial.println(ETH.macAddress());
|
||||||
|
|
||||||
Serial.println("Ethernet Successfully Initialized");
|
Serial.println("Ethernet Successfully Initialized");
|
||||||
break;
|
break;
|
||||||
|
@ -177,9 +194,12 @@ void setup()
|
||||||
default:
|
default:
|
||||||
Serial.println("Initialize as WiFi-AP");
|
Serial.println("Initialize as WiFi-AP");
|
||||||
WiFi.softAP(ssid, pwd);
|
WiFi.softAP(ssid, pwd);
|
||||||
|
WiFi.softAPsetHostname(hostname);
|
||||||
WiFi.softAPConfig(ip, gateway, subnet);
|
WiFi.softAPConfig(ip, gateway, subnet);
|
||||||
Serial.print("WiFi AP enabled, IP = ");
|
Serial.print("WiFi AP enabled, IP = ");
|
||||||
Serial.println(WiFi.softAPIP());
|
Serial.println(WiFi.softAPIP());
|
||||||
|
Serial.print("MAC address: ");
|
||||||
|
Serial.println(WiFi.softAPmacAddress());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,8 +264,7 @@ void setup()
|
||||||
server.begin();
|
server.begin();
|
||||||
Serial.println("Server started!");
|
Serial.println("Server started!");
|
||||||
|
|
||||||
timerAlarmDisable(timer);
|
ledBlink(1);
|
||||||
ledcWrite(0, 20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue