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