mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
Smooth DMX fadind for DUE
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
-DWiz5500
|
-DWiz5500
|
||||||
-DARTNET_ENABLE
|
-DARTNET_ENABLE
|
||||||
|
-DDMX_SMOOTH
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
-DWiz5500
|
-DWiz5500
|
||||||
-DW5500_CS_PIN=53
|
-DW5500_CS_PIN=53
|
||||||
-DARTNET_ENABLE
|
-DARTNET_ENABLE
|
||||||
|
-DDMX_SMOOTH
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ e-mail anklimov@gmail.com
|
|||||||
//#include <DmxSimple.h>
|
//#include <DmxSimple.h>
|
||||||
//#include <DMXSerial.h>
|
//#include <DMXSerial.h>
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
#include "item.h"
|
||||||
|
|
||||||
#ifdef _dmxin
|
#ifdef _dmxin
|
||||||
#if defined(ARDUINO_ARCH_AVR)
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
@@ -35,6 +36,13 @@ DMXESPSerial dmxout;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t * DMXin = NULL;
|
uint8_t * DMXin = NULL;
|
||||||
|
|
||||||
|
#ifdef DMX_SMOOTH
|
||||||
|
uint8_t * DMXinterimBuf = NULL;
|
||||||
|
uint16_t DMXOUT_Channels=0;
|
||||||
|
uint32_t checkTimestamp=0L;
|
||||||
|
#endif
|
||||||
|
|
||||||
int D_State=0;
|
int D_State=0;
|
||||||
|
|
||||||
unsigned long D_checkT=0;
|
unsigned long D_checkT=0;
|
||||||
@@ -61,16 +69,16 @@ int itemCtrl2(char* name,int r,int g, int b, int w)
|
|||||||
short itemaddr = aJson.getArrayItem(itemArr,1)->valueint;
|
short itemaddr = aJson.getArrayItem(itemArr,1)->valueint;
|
||||||
switch (itemtype){
|
switch (itemtype){
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
case 0: //Dimmed light
|
case CH_DIMMER: //Dimmed light
|
||||||
|
|
||||||
DmxWrite(itemaddr, w);
|
DmxWrite(itemaddr, w);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case 1: //Colour RGBW
|
case CH_RGBW: //Colour RGBW
|
||||||
DmxWrite(itemaddr+3, w);
|
DmxWrite(itemaddr+3, w);
|
||||||
|
|
||||||
case 2: // RGB
|
case CH_RGB: // RGB
|
||||||
{
|
{
|
||||||
|
|
||||||
DmxWrite(itemaddr, r);
|
DmxWrite(itemaddr, r);
|
||||||
@@ -79,7 +87,7 @@ int itemCtrl2(char* name,int r,int g, int b, int w)
|
|||||||
|
|
||||||
break; }
|
break; }
|
||||||
#endif
|
#endif
|
||||||
case 7: //Group
|
case CH_GROUP: //Group
|
||||||
aJsonObject *groupArr= aJson.getArrayItem(itemArr, 1);
|
aJsonObject *groupArr= aJson.getArrayItem(itemArr, 1);
|
||||||
if (groupArr && (groupArr->type==aJson_Array))
|
if (groupArr && (groupArr->type==aJson_Array))
|
||||||
{ aJsonObject *i =groupArr->child;
|
{ aJsonObject *i =groupArr->child;
|
||||||
@@ -162,6 +170,7 @@ for (short tch=0; tch<=3 ; tch++)
|
|||||||
{
|
{
|
||||||
// CHSV hsv;
|
// CHSV hsv;
|
||||||
// CRGB rgb;
|
// CRGB rgb;
|
||||||
|
DMXOUT_propagate();
|
||||||
#if defined(_dmxin)
|
#if defined(_dmxin)
|
||||||
|
|
||||||
short t,tch;
|
short t,tch;
|
||||||
@@ -251,8 +260,42 @@ dmxout.setTxMaxChannels(channels);
|
|||||||
#ifndef DMX_DISABLE
|
#ifndef DMX_DISABLE
|
||||||
for (int i=1;i<=channels;i++) DmxWrite(i,0);
|
for (int i=1;i<=channels;i++) DmxWrite(i,0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DMX_SMOOTH
|
||||||
|
if (DMXinterimBuf) delete DMXinterimBuf;
|
||||||
|
DMXinterimBuf = new uint8_t [channels];
|
||||||
|
DMXOUT_Channels=channels;
|
||||||
|
for (int i=1;i<=channels;i++) DMXinterimBuf[i]=0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DMXOUT_propagate()
|
||||||
|
{
|
||||||
|
#ifdef DMX_SMOOTH
|
||||||
|
uint32_t now = millis();
|
||||||
|
if (now<checkTimestamp) return;
|
||||||
|
|
||||||
|
for(int i=1;i<=DMXOUT_Channels;i++)
|
||||||
|
{
|
||||||
|
uint8_t currLevel=dmxout.getTx(i);
|
||||||
|
uint16_t delta = currLevel-DMXinterimBuf[i-1];
|
||||||
|
if (delta)
|
||||||
|
{
|
||||||
|
uint16_t step = abs(delta) >> 4;
|
||||||
|
if (!step) step=1;
|
||||||
|
|
||||||
|
if (delta<0)
|
||||||
|
DmxWrite2(i,currLevel+step);
|
||||||
|
|
||||||
|
if (delta>0)
|
||||||
|
DmxWrite2(i,currLevel-step);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkTimestamp=now+DMX_SMOOTH_DELAY;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ArtnetSetup()
|
void ArtnetSetup()
|
||||||
{
|
{
|
||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
@@ -261,3 +304,12 @@ void ArtnetSetup()
|
|||||||
if (artnet) artnet->setArtDmxCallback(onDmxFrame);
|
if (artnet) artnet->setArtDmxCallback(onDmxFrame);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DmxWriteBuf(uint16_t chan,uint8_t val)
|
||||||
|
{
|
||||||
|
#ifdef DMX_SMOOTH
|
||||||
|
if (chan && chan<=DMXOUT_Channels)
|
||||||
|
DMXinterimBuf[chan-1] = val;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,6 +32,35 @@ e-mail anklimov@gmail.com
|
|||||||
|
|
||||||
#if defined(_dmxout)
|
#if defined(_dmxout)
|
||||||
|
|
||||||
|
#if defined DMX_SMOOTH
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
|
#include <DmxSimple.h>
|
||||||
|
#define DmxWrite DmxSimple.write
|
||||||
|
//#define DmxWrite DmxWriteBuf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
|
#include <ESPDMX.h>
|
||||||
|
extern DMXESPSerial dmxout;
|
||||||
|
#define DmxWrite dmxout.write
|
||||||
|
//#define DmxWrite DmxWriteBuf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
#include <ESPDMX.h>
|
||||||
|
extern DMXESPSerial dmxout;
|
||||||
|
#define DmxWrite dmxout.write
|
||||||
|
//#define DmxWrite DmxWriteBuf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
|
#include <DmxDue.h>
|
||||||
|
#define DmxWrite2 dmxout.write
|
||||||
|
#define DmxWrite DmxWriteBuf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
#if defined(ARDUINO_ARCH_AVR)
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
#include <DmxSimple.h>
|
#include <DmxSimple.h>
|
||||||
#define DmxWrite DmxSimple.write
|
#define DmxWrite DmxSimple.write
|
||||||
@@ -52,6 +81,8 @@ extern DMXESPSerial dmxout;
|
|||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
#include <DmxDue.h>
|
#include <DmxDue.h>
|
||||||
#define DmxWrite dmxout.write
|
#define DmxWrite dmxout.write
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -78,3 +109,5 @@ void ArtnetSetup();
|
|||||||
void DMXCheck(void);
|
void DMXCheck(void);
|
||||||
int itemCtrl2(char* name,int r,int g, int b, int w);
|
int itemCtrl2(char* name,int r,int g, int b, int w);
|
||||||
void ArtnetSetup();
|
void ArtnetSetup();
|
||||||
|
void DmxWriteBuf(uint16_t chan,uint8_t val);
|
||||||
|
void DMXOUT_propagate();
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ Item::Item(char *name) //Constructor
|
|||||||
{ char* sub;
|
{ char* sub;
|
||||||
if (sub=strchr(name,'/'))
|
if (sub=strchr(name,'/'))
|
||||||
{
|
{
|
||||||
char buf [MQTT_SUBJECT_LENGTH];
|
char buf [MQTT_SUBJECT_LENGTH+1];
|
||||||
short i;
|
short i;
|
||||||
for(i=0;(name[i] && (name[i]!='/') && (i<MQTT_SUBJECT_LENGTH));i++)
|
for(i=0;(name[i] && (name[i]!='/') && (i<MQTT_SUBJECT_LENGTH));i++)
|
||||||
buf[i]=name[i];
|
buf[i]=name[i];
|
||||||
|
|||||||
@@ -934,9 +934,10 @@ configLocked++;
|
|||||||
#endif
|
#endif
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
int maxChannels;
|
int maxChannels;
|
||||||
|
short numParams;
|
||||||
aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx");
|
aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx");
|
||||||
if (dmxoutArr && aJson.getArraySize(dmxoutArr) >=1 ) {
|
if (dmxoutArr && (numParams=aJson.getArraySize(dmxoutArr)) >=1 ) {
|
||||||
DMXoutSetup(maxChannels = aJson.getArrayItem(dmxoutArr, 1)->valueint);
|
DMXoutSetup(maxChannels = aJson.getArrayItem(dmxoutArr, numParams-1)->valueint);
|
||||||
debugSerial<<F("DMX out started. Channels: ")<<maxChannels<<endl;
|
debugSerial<<F("DMX out started. Channels: ")<<maxChannels<<endl;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1209,7 +1210,8 @@ void cmdFunctionPwd(int arg_cnt, char **args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
||||||
if (sscanf(args[1], "%x:%x:%x:%x:%x:%x%c", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) < 6) {
|
char dummy;
|
||||||
|
if (sscanf(args[1], "%x:%x:%x:%x:%x:%x%c", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5], &dummy) < 6) {
|
||||||
debugSerial<<F("could not parse: ")<<args[1];
|
debugSerial<<F("could not parse: ")<<args[1];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,6 +207,10 @@
|
|||||||
#define strncpy_P strncpy
|
#define strncpy_P strncpy
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DMX_SMOOTH_DELAY
|
||||||
|
#define DMX_SMOOTH_DELAY 10
|
||||||
|
#endif
|
||||||
|
|
||||||
//#ifdef M5STACK
|
//#ifdef M5STACK
|
||||||
//#define debugSerial M5.Lcd
|
//#define debugSerial M5.Lcd
|
||||||
//#endif
|
//#endif
|
||||||
|
|||||||
@@ -495,6 +495,7 @@ lib_ignore =
|
|||||||
ESP_EEPROM
|
ESP_EEPROM
|
||||||
EEPROM
|
EEPROM
|
||||||
M5Stack
|
M5Stack
|
||||||
|
ArduinoOTA
|
||||||
lib_deps =
|
lib_deps =
|
||||||
https://github.com/sebnil/DueFlashStorage
|
https://github.com/sebnil/DueFlashStorage
|
||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||||
|
|||||||
Reference in New Issue
Block a user