mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 04:36:31 +00:00
Enable DALI light control if other Tasmota light is enabled
This commit is contained in:
parent
66d69e09c9
commit
2dc5c6e234
@ -19,6 +19,7 @@
|
|||||||
--------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------
|
||||||
Version yyyymmdd Action Description
|
Version yyyymmdd Action Description
|
||||||
--------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------
|
||||||
|
1.1.0.1 20241101 update - Enable DALI if another light is already claimed
|
||||||
1.1.0.0 20241031 update - Add GUI sliders with feedback when `DaliLight 0`
|
1.1.0.0 20241031 update - Add GUI sliders with feedback when `DaliLight 0`
|
||||||
- Add command `DaliGroupSliders 0..16` to show GUI sliders
|
- Add command `DaliGroupSliders 0..16` to show GUI sliders
|
||||||
1.0.0.2 20241025 update - Fix GPIO detection
|
1.0.0.2 20241025 update - Fix GPIO detection
|
||||||
@ -300,6 +301,7 @@ struct DALI {
|
|||||||
uint8_t dimmer[DALI_MAX_STORED];
|
uint8_t dimmer[DALI_MAX_STORED];
|
||||||
uint8_t web_dimmer[DALI_MAX_STORED];
|
uint8_t web_dimmer[DALI_MAX_STORED];
|
||||||
uint8_t target;
|
uint8_t target;
|
||||||
|
bool allow_light;
|
||||||
bool last_power;
|
bool last_power;
|
||||||
bool power[DALI_MAX_STORED];
|
bool power[DALI_MAX_STORED];
|
||||||
bool web_power[DALI_MAX_STORED];
|
bool web_power[DALI_MAX_STORED];
|
||||||
@ -648,8 +650,6 @@ uint32_t DaliGearPresent(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DaliInitLight(void) {
|
void DaliInitLight(void) {
|
||||||
Settings->light_fade = 0; // Use Dali fading
|
|
||||||
Settings->light_correction = 0; // Use Dali light correction
|
|
||||||
// Taken from Shelly Dali Dimmer ;-)
|
// Taken from Shelly Dali Dimmer ;-)
|
||||||
DaliSendData(DALI_DATA_TRANSFER_REGISTER0, DALI_INIT_FADE); // Fade x second
|
DaliSendData(DALI_DATA_TRANSFER_REGISTER0, DALI_INIT_FADE); // Fade x second
|
||||||
DaliSendData(0xFF, DALI_SET_FADE_TIME);
|
DaliSendData(0xFF, DALI_SET_FADE_TIME);
|
||||||
@ -826,7 +826,7 @@ void DaliLoop(void) {
|
|||||||
|
|
||||||
bool show_response = true;
|
bool show_response = true;
|
||||||
#ifdef USE_LIGHT
|
#ifdef USE_LIGHT
|
||||||
if (DaliTarget2Address() == Dali->address) {
|
if (Dali->allow_light && (DaliTarget2Address() == Dali->address)) {
|
||||||
if (Settings->sbflag1.dali_light) { // DaliLight 1
|
if (Settings->sbflag1.dali_light) { // DaliLight 1
|
||||||
uint8_t dim_old = changeUIntScale(Dali->last_dimmer, 0, 254, 0, 100);
|
uint8_t dim_old = changeUIntScale(Dali->last_dimmer, 0, 254, 0, 100);
|
||||||
uint8_t dim_new = changeUIntScale(Dali->dimmer[index], 0, 254, 0, 100);
|
uint8_t dim_new = changeUIntScale(Dali->dimmer[index], 0, 254, 0, 100);
|
||||||
@ -854,15 +854,15 @@ void DaliLoop(void) {
|
|||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef USE_LIGHT
|
|
||||||
void DaliEverySecond(void) {
|
void DaliEverySecond(void) {
|
||||||
if (Settings->sbflag1.dali_light) { // DaliLight 1
|
|
||||||
if (5 == TasmotaGlobal.uptime) {
|
if (5 == TasmotaGlobal.uptime) {
|
||||||
DaliInitLight();
|
DaliInitLight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifdef USE_LIGHT
|
||||||
bool DaliSetChannels(void) {
|
bool DaliSetChannels(void) {
|
||||||
if (Settings->sbflag1.dali_light) { // DaliLight 1
|
if (Settings->sbflag1.dali_light) { // DaliLight 1
|
||||||
Settings->light_fade = 0; // Use Dali fading
|
Settings->light_fade = 0; // Use Dali fading
|
||||||
@ -881,7 +881,7 @@ bool DaliSetChannels(void) {
|
|||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
bool DaliInit(void) {
|
bool DaliInit(uint32_t function) {
|
||||||
int pin_tx = -1;
|
int pin_tx = -1;
|
||||||
bool invert_tx = false;
|
bool invert_tx = false;
|
||||||
if (PinUsed(GPIO_DALI_TX)) {
|
if (PinUsed(GPIO_DALI_TX)) {
|
||||||
@ -910,6 +910,8 @@ bool DaliInit(void) {
|
|||||||
Dali->pin_rx = pin_rx;
|
Dali->pin_rx = pin_rx;
|
||||||
Dali->invert_rx = invert_rx;
|
Dali->invert_rx = invert_rx;
|
||||||
|
|
||||||
|
Dali->allow_light = (FUNC_MODULE_INIT == function); // Light control is possible
|
||||||
|
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("DLI: GPIO%d(RX%s) and GPIO%d(TX%s)"),
|
AddLog(LOG_LEVEL_INFO, PSTR("DLI: GPIO%d(RX%s) and GPIO%d(TX%s)"),
|
||||||
Dali->pin_rx, (Dali->invert_rx)?"i":"", Dali->pin_tx, (Dali->invert_tx)?"i":"");
|
Dali->pin_rx, (Dali->invert_rx)?"i":"", Dali->pin_tx, (Dali->invert_tx)?"i":"");
|
||||||
|
|
||||||
@ -931,6 +933,9 @@ bool DaliInit(void) {
|
|||||||
|
|
||||||
DaliEnableRxInterrupt();
|
DaliEnableRxInterrupt();
|
||||||
|
|
||||||
|
if (!Dali->allow_light) {
|
||||||
|
Settings->sbflag1.dali_light = false; // No light control possible
|
||||||
|
}
|
||||||
#ifdef USE_LIGHT
|
#ifdef USE_LIGHT
|
||||||
if (!Settings->sbflag1.dali_light) { // DaliLight 0
|
if (!Settings->sbflag1.dali_light) { // DaliLight 0
|
||||||
return false;
|
return false;
|
||||||
@ -1203,9 +1208,8 @@ void CmndDaliScan(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CmndDaliGroupSliders(void) {
|
void CmndDaliGroupSliders(void) {
|
||||||
// DaliGroupSliders 0..16 - Disable light controls and add group sliders
|
// DaliGroupSliders 0..16 - Add group sliders
|
||||||
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 16)) {
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 16)) {
|
||||||
Settings->sbflag1.dali_light = 0; // Disable DaliLight
|
|
||||||
Settings->mbflag2.dali_group_sliders = XdrvMailbox.payload;
|
Settings->mbflag2.dali_group_sliders = XdrvMailbox.payload;
|
||||||
TasmotaGlobal.restart_flag = 2; // Restart to update GUI
|
TasmotaGlobal.restart_flag = 2; // Restart to update GUI
|
||||||
}
|
}
|
||||||
@ -1216,7 +1220,7 @@ void CmndDaliGroupSliders(void) {
|
|||||||
void CmndDaliLight(void) {
|
void CmndDaliLight(void) {
|
||||||
// DaliLight 0 - Disable light controls
|
// DaliLight 0 - Disable light controls
|
||||||
// DaliLight 1 - Enable light controls
|
// DaliLight 1 - Enable light controls
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (Dali->allow_light && (XdrvMailbox.data_len > 0)) {
|
||||||
Settings->sbflag1.dali_light = XdrvMailbox.payload &1;
|
Settings->sbflag1.dali_light = XdrvMailbox.payload &1;
|
||||||
TasmotaGlobal.restart_flag = 2; // Restart to update GUI
|
TasmotaGlobal.restart_flag = 2; // Restart to update GUI
|
||||||
}
|
}
|
||||||
@ -1239,8 +1243,7 @@ const char HTTP_MSG_SLIDER_DALI[] PROGMEM =
|
|||||||
void DaliWebAddMainSlider(void) {
|
void DaliWebAddMainSlider(void) {
|
||||||
WSContentSend_P(HTTP_TABLE100);
|
WSContentSend_P(HTTP_TABLE100);
|
||||||
char number[12];
|
char number[12];
|
||||||
uint32_t max_sliders = 1 + Settings->mbflag2.dali_group_sliders;
|
for (uint32_t i = Settings->sbflag1.dali_light; i <= Settings->mbflag2.dali_group_sliders; i++) {
|
||||||
for (uint32_t i = 0; i < max_sliders; i++) {
|
|
||||||
Dali->web_dimmer[i] = Dali->dimmer[i];
|
Dali->web_dimmer[i] = Dali->dimmer[i];
|
||||||
Dali->web_power[i] = Dali->power[i];
|
Dali->web_power[i] = Dali->power[i];
|
||||||
WSContentSend_P(HTTP_MSG_SLIDER_DALI, // Brightness - Black to White
|
WSContentSend_P(HTTP_MSG_SLIDER_DALI, // Brightness - Black to White
|
||||||
@ -1263,8 +1266,7 @@ void DaliWebGetArg(void) {
|
|||||||
char webindex[8]; // WebGetArg name
|
char webindex[8]; // WebGetArg name
|
||||||
|
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
uint32_t max_sliders = 1 + Settings->mbflag2.dali_group_sliders;
|
for (uint32_t i = Settings->sbflag1.dali_light; i <= Settings->mbflag2.dali_group_sliders; i++) {
|
||||||
for (uint32_t i = 0; i < max_sliders; i++) {
|
|
||||||
snprintf_P(webindex, sizeof(webindex), PSTR("i75%d"), i);
|
snprintf_P(webindex, sizeof(webindex), PSTR("i75%d"), i);
|
||||||
WebGetArg(webindex, tmp, sizeof(tmp)); // 0 - 100 percent
|
WebGetArg(webindex, tmp, sizeof(tmp)); // 0 - 100 percent
|
||||||
if (strlen(tmp)) {
|
if (strlen(tmp)) {
|
||||||
@ -1290,8 +1292,7 @@ void DaliShow(bool json) {
|
|||||||
ResponseAppendDali(0);
|
ResponseAppendDali(0);
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
} else {
|
} else {
|
||||||
uint32_t max_sliders = 1 + Settings->mbflag2.dali_group_sliders;
|
for (uint32_t i = Settings->sbflag1.dali_light; i <= Settings->mbflag2.dali_group_sliders; i++) {
|
||||||
for (uint32_t i = 0; i < max_sliders; i++) {
|
|
||||||
if (Dali->power[i] != Dali->web_power[i]) {
|
if (Dali->power[i] != Dali->web_power[i]) {
|
||||||
Dali->web_power[i] = Dali->power[i];
|
Dali->web_power[i] = Dali->power[i];
|
||||||
WSContentSend_P(HTTP_MSG_SLIDER_UPDATE); // "<img style='display:none;' src onerror="
|
WSContentSend_P(HTTP_MSG_SLIDER_UPDATE); // "<img style='display:none;' src onerror="
|
||||||
@ -1318,18 +1319,21 @@ void DaliShow(bool json) {
|
|||||||
bool Xdrv75(uint32_t function) {
|
bool Xdrv75(uint32_t function) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (FUNC_MODULE_INIT == function) {
|
if (FUNC_MODULE_INIT == function) { // Try to claim DALI as light
|
||||||
result = DaliInit();
|
result = DaliInit(function);
|
||||||
|
}
|
||||||
|
else if ((FUNC_PRE_INIT == function) && !Dali) { // If claim failed then use DALI controls only
|
||||||
|
DaliInit(function);
|
||||||
}
|
}
|
||||||
else if (Dali) {
|
else if (Dali) {
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_LOOP:
|
case FUNC_LOOP:
|
||||||
DaliLoop();
|
DaliLoop();
|
||||||
break;
|
break;
|
||||||
#ifdef USE_LIGHT
|
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
DaliEverySecond();
|
DaliEverySecond();
|
||||||
break;
|
break;
|
||||||
|
#ifdef USE_LIGHT
|
||||||
case FUNC_SET_CHANNELS:
|
case FUNC_SET_CHANNELS:
|
||||||
result = DaliSetChannels();
|
result = DaliSetChannels();
|
||||||
break;
|
break;
|
||||||
@ -1339,19 +1343,13 @@ bool Xdrv75(uint32_t function) {
|
|||||||
break;
|
break;
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
case FUNC_WEB_SENSOR:
|
case FUNC_WEB_SENSOR:
|
||||||
if (!Settings->sbflag1.dali_light) { // DaliLight 0
|
|
||||||
DaliShow(false);
|
DaliShow(false);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case FUNC_WEB_ADD_MAIN_BUTTON:
|
case FUNC_WEB_ADD_MAIN_BUTTON:
|
||||||
if (!Settings->sbflag1.dali_light) { // DaliLight 0
|
|
||||||
DaliWebAddMainSlider();
|
DaliWebAddMainSlider();
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case FUNC_WEB_GET_ARG:
|
case FUNC_WEB_GET_ARG:
|
||||||
if (!Settings->sbflag1.dali_light) { // DaliLight 0
|
|
||||||
DaliWebGetArg();
|
DaliWebGetArg();
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
case FUNC_COMMAND:
|
case FUNC_COMMAND:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user