Enable DALI light control if other Tasmota light is enabled

This commit is contained in:
Theo Arends 2024-11-01 11:23:55 +01:00
parent 66d69e09c9
commit 2dc5c6e234
1 changed files with 28 additions and 30 deletions

View File

@ -19,6 +19,7 @@
--------------------------------------------------------------------------------------------
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`
- Add command `DaliGroupSliders 0..16` to show GUI sliders
1.0.0.2 20241025 update - Fix GPIO detection
@ -300,6 +301,7 @@ struct DALI {
uint8_t dimmer[DALI_MAX_STORED];
uint8_t web_dimmer[DALI_MAX_STORED];
uint8_t target;
bool allow_light;
bool last_power;
bool power[DALI_MAX_STORED];
bool web_power[DALI_MAX_STORED];
@ -648,8 +650,6 @@ uint32_t DaliGearPresent(void) {
}
void DaliInitLight(void) {
Settings->light_fade = 0; // Use Dali fading
Settings->light_correction = 0; // Use Dali light correction
// Taken from Shelly Dali Dimmer ;-)
DaliSendData(DALI_DATA_TRANSFER_REGISTER0, DALI_INIT_FADE); // Fade x second
DaliSendData(0xFF, DALI_SET_FADE_TIME);
@ -826,7 +826,7 @@ void DaliLoop(void) {
bool show_response = true;
#ifdef USE_LIGHT
if (DaliTarget2Address() == Dali->address) {
if (Dali->allow_light && (DaliTarget2Address() == Dali->address)) {
if (Settings->sbflag1.dali_light) { // DaliLight 1
uint8_t dim_old = changeUIntScale(Dali->last_dimmer, 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) {
if (Settings->sbflag1.dali_light) { // DaliLight 1
if (5 == TasmotaGlobal.uptime) {
DaliInitLight();
}
}
}
/*-------------------------------------------------------------------------------------------*/
#ifdef USE_LIGHT
bool DaliSetChannels(void) {
if (Settings->sbflag1.dali_light) { // DaliLight 1
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;
bool invert_tx = false;
if (PinUsed(GPIO_DALI_TX)) {
@ -910,6 +910,8 @@ bool DaliInit(void) {
Dali->pin_rx = pin_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)"),
Dali->pin_rx, (Dali->invert_rx)?"i":"", Dali->pin_tx, (Dali->invert_tx)?"i":"");
@ -931,6 +933,9 @@ bool DaliInit(void) {
DaliEnableRxInterrupt();
if (!Dali->allow_light) {
Settings->sbflag1.dali_light = false; // No light control possible
}
#ifdef USE_LIGHT
if (!Settings->sbflag1.dali_light) { // DaliLight 0
return false;
@ -1203,9 +1208,8 @@ void CmndDaliScan(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)) {
Settings->sbflag1.dali_light = 0; // Disable DaliLight
Settings->mbflag2.dali_group_sliders = XdrvMailbox.payload;
TasmotaGlobal.restart_flag = 2; // Restart to update GUI
}
@ -1216,7 +1220,7 @@ void CmndDaliGroupSliders(void) {
void CmndDaliLight(void) {
// DaliLight 0 - Disable 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;
TasmotaGlobal.restart_flag = 2; // Restart to update GUI
}
@ -1239,8 +1243,7 @@ const char HTTP_MSG_SLIDER_DALI[] PROGMEM =
void DaliWebAddMainSlider(void) {
WSContentSend_P(HTTP_TABLE100);
char number[12];
uint32_t max_sliders = 1 + Settings->mbflag2.dali_group_sliders;
for (uint32_t i = 0; i < max_sliders; i++) {
for (uint32_t i = Settings->sbflag1.dali_light; i <= Settings->mbflag2.dali_group_sliders; i++) {
Dali->web_dimmer[i] = Dali->dimmer[i];
Dali->web_power[i] = Dali->power[i];
WSContentSend_P(HTTP_MSG_SLIDER_DALI, // Brightness - Black to White
@ -1263,8 +1266,7 @@ void DaliWebGetArg(void) {
char webindex[8]; // WebGetArg name
uint32_t index;
uint32_t max_sliders = 1 + Settings->mbflag2.dali_group_sliders;
for (uint32_t i = 0; i < max_sliders; i++) {
for (uint32_t i = Settings->sbflag1.dali_light; i <= Settings->mbflag2.dali_group_sliders; i++) {
snprintf_P(webindex, sizeof(webindex), PSTR("i75%d"), i);
WebGetArg(webindex, tmp, sizeof(tmp)); // 0 - 100 percent
if (strlen(tmp)) {
@ -1290,8 +1292,7 @@ void DaliShow(bool json) {
ResponseAppendDali(0);
#ifdef USE_WEBSERVER
} else {
uint32_t max_sliders = 1 + Settings->mbflag2.dali_group_sliders;
for (uint32_t i = 0; i < max_sliders; i++) {
for (uint32_t i = Settings->sbflag1.dali_light; i <= Settings->mbflag2.dali_group_sliders; i++) {
if (Dali->power[i] != Dali->web_power[i]) {
Dali->web_power[i] = Dali->power[i];
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 result = false;
if (FUNC_MODULE_INIT == function) {
result = DaliInit();
if (FUNC_MODULE_INIT == function) { // Try to claim DALI as light
result = DaliInit(function);
}
else if ((FUNC_PRE_INIT == function) && !Dali) { // If claim failed then use DALI controls only
DaliInit(function);
}
else if (Dali) {
switch (function) {
case FUNC_LOOP:
DaliLoop();
break;
#ifdef USE_LIGHT
case FUNC_EVERY_SECOND:
DaliEverySecond();
break;
#ifdef USE_LIGHT
case FUNC_SET_CHANNELS:
result = DaliSetChannels();
break;
@ -1339,19 +1343,13 @@ bool Xdrv75(uint32_t function) {
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
if (!Settings->sbflag1.dali_light) { // DaliLight 0
DaliShow(false);
}
break;
case FUNC_WEB_ADD_MAIN_BUTTON:
if (!Settings->sbflag1.dali_light) { // DaliLight 0
DaliWebAddMainSlider();
}
break;
case FUNC_WEB_GET_ARG:
if (!Settings->sbflag1.dali_light) { // DaliLight 0
DaliWebGetArg();
}
break;
#endif // USE_WEBSERVER
case FUNC_COMMAND: