mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 12:46:34 +00:00
Clean up some comments and little refactor
This commit is contained in:
parent
1bf69fd310
commit
c1c0b25c17
@ -1034,6 +1034,10 @@
|
|||||||
|
|
||||||
#define USE_ESP32_SENSORS // Add support for ESP32 temperature and optional hall effect sensor
|
#define USE_ESP32_SENSORS // Add support for ESP32 temperature and optional hall effect sensor
|
||||||
|
|
||||||
|
#define USE_DALI // Add support for DALI
|
||||||
|
#define DALI_IN_INVERT 0 // DALI RX inverted ?
|
||||||
|
#define DALI_OUT_INVERT 0 // DALI TX inverted ?
|
||||||
|
|
||||||
//#define USE_SONOFF_SPM // Add support for ESP32 based Sonoff Smart Stackable Power Meter (+11k code)
|
//#define USE_SONOFF_SPM // Add support for ESP32 based Sonoff Smart Stackable Power Meter (+11k code)
|
||||||
//#define USE_DISPLAY_TM1621_SONOFF // Add support for TM1621 dsiplay driver used by Sonoff POWR3xxD and THR3xxD
|
//#define USE_DISPLAY_TM1621_SONOFF // Add support for TM1621 dsiplay driver used by Sonoff POWR3xxD and THR3xxD
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#define XDRV_89 89
|
#define XDRV_89 89
|
||||||
|
|
||||||
#define BROADCAST_DP 0b11111110 // 0xFE
|
#define BROADCAST_DP 0b11111110 // 0xFE
|
||||||
|
#define DALI_TOPIC "DALI"
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -57,9 +58,6 @@ enum DALI_Commands { // commands for Console
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
// Communication ports and pins
|
|
||||||
bool DALIOUT_invert = false;
|
|
||||||
bool DALIIN_invert = false;
|
|
||||||
// Data variables
|
// Data variables
|
||||||
uint16_t send_dali_data; // data to send to DALI bus
|
uint16_t send_dali_data; // data to send to DALI bus
|
||||||
uint16_t received_dali_data; // data received from DALI bus
|
uint16_t received_dali_data; // data received from DALI bus
|
||||||
@ -163,7 +161,7 @@ void receiveDaliData()
|
|||||||
bool get_DALIIN(void)
|
bool get_DALIIN(void)
|
||||||
{
|
{
|
||||||
bool dali_read = digitalRead(Pin(GPIO_DALI_RX));
|
bool dali_read = digitalRead(Pin(GPIO_DALI_RX));
|
||||||
return (false == DALIIN_invert) ? dali_read : !dali_read;
|
return (false == DALI_IN_INVERT) ? dali_read : !dali_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -266,7 +264,7 @@ void receive_tick(void)
|
|||||||
*/
|
*/
|
||||||
void set_DALIOUT(bool pin_value)
|
void set_DALIOUT(bool pin_value)
|
||||||
{
|
{
|
||||||
digitalWrite(Pin(GPIO_DALI_TX), pin_value == DALIOUT_invert ? LOW : HIGH);
|
digitalWrite(Pin(GPIO_DALI_TX), pin_value == DALI_OUT_INVERT ? LOW : HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -277,7 +275,7 @@ void set_DALIOUT(bool pin_value)
|
|||||||
bool get_DALIOUT(void)
|
bool get_DALIOUT(void)
|
||||||
{
|
{
|
||||||
bool dali_read = digitalRead(Pin(GPIO_DALI_TX));
|
bool dali_read = digitalRead(Pin(GPIO_DALI_TX));
|
||||||
return (false == DALIOUT_invert) ? dali_read : !dali_read;
|
return (false == DALI_OUT_INVERT) ? dali_read : !dali_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -394,7 +392,6 @@ void DaliPreInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DaliPwr(uint8_t val){
|
void DaliPwr(uint8_t val){
|
||||||
// AddLog(LOG_LEVEL_INFO, PSTR("DLI: Send to address %d value %d"), 0, val);
|
|
||||||
sendDaliData(BROADCAST_DP, val);
|
sendDaliData(BROADCAST_DP, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,14 +407,11 @@ bool DaliCmd(void)
|
|||||||
case CMND_DALI_PWR:
|
case CMND_DALI_PWR:
|
||||||
if (XdrvMailbox.data_len)
|
if (XdrvMailbox.data_len)
|
||||||
{
|
{
|
||||||
// AddLog(LOG_LEVEL_INFO, PSTR("DLI: XdrvMailbox.data_len %d"), XdrvMailbox.data_len);
|
|
||||||
// AddLog(LOG_LEVEL_INFO, PSTR("DLI: XdrvMailbox.payload %d"), XdrvMailbox.payload);
|
|
||||||
if (254 >= XdrvMailbox.payload)
|
if (254 >= XdrvMailbox.payload)
|
||||||
{
|
{
|
||||||
DaliPwr(XdrvMailbox.payload);
|
DaliPwr(XdrvMailbox.payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Response_P(S_JSON_DALI_COMMAND_NVALUE, command, DaliGetPwr());
|
|
||||||
Response_P(S_JSON_DALI_COMMAND_NVALUE, command, XdrvMailbox.payload);
|
Response_P(S_JSON_DALI_COMMAND_NVALUE, command, XdrvMailbox.payload);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -431,23 +425,6 @@ bool DaliCmd(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************************\
|
|
||||||
* Presentation
|
|
||||||
\*********************************************************************************************/
|
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
|
||||||
|
|
||||||
#define WEB_HANDLE_DALI "dali"
|
|
||||||
|
|
||||||
const char HTTP_BTN_MENU_DALI[] PROGMEM =
|
|
||||||
"<p><form action='" WEB_HANDLE_DALI "' method='get'><button>" D_CONFIGURE_DALI "</button></form></p>";
|
|
||||||
|
|
||||||
#endif // USE_WEBSERVER
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define DALI_TOPIC "DALI"
|
|
||||||
static char tmp[120];
|
|
||||||
|
|
||||||
bool DaliMqtt()
|
bool DaliMqtt()
|
||||||
{
|
{
|
||||||
@ -455,9 +432,6 @@ bool DaliMqtt()
|
|||||||
strncpy(stopic, XdrvMailbox.topic, TOPSZ);
|
strncpy(stopic, XdrvMailbox.topic, TOPSZ);
|
||||||
XdrvMailbox.topic[TOPSZ - 1] = 0;
|
XdrvMailbox.topic[TOPSZ - 1] = 0;
|
||||||
|
|
||||||
// AddLog(LOG_LEVEL_DEBUG, PSTR("DALI mqtt: %s:%s"), stopic, XdrvMailbox.data);
|
|
||||||
|
|
||||||
// Разберем топик на слова по "/"
|
|
||||||
char *items[10];
|
char *items[10];
|
||||||
char *p = stopic;
|
char *p = stopic;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
@ -475,27 +449,20 @@ bool DaliMqtt()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cnt-4 cnt -3 cnt-2 cnt-1
|
|
||||||
// cmnd/tasmota_078480/DALI/power :70
|
|
||||||
// cnt-5 cnt -4 cnt-3 cnt-2 cnt-1
|
|
||||||
// cmnd/tasmota_078480/DALI/power/0 :70
|
|
||||||
int DALIindex = 0;
|
int DALIindex = 0;
|
||||||
int ADRindex = 0;
|
int ADRindex = 0;
|
||||||
int CMDindex = 0;
|
int CMDindex = 0;
|
||||||
uint8_t DALIaddr = BROADCAST_DP;
|
uint8_t DALIaddr = BROADCAST_DP;
|
||||||
if (strcasecmp_P(items[cnt - 3], PSTR(DALI_TOPIC)) != 0)
|
if (strcasecmp_P(items[cnt - 3], PSTR(DALI_TOPIC)) != 0)
|
||||||
{
|
{
|
||||||
// AddLog(LOG_LEVEL_INFO,PSTR("cnt-3 not %s"), PSTR(DALI_TOPIC));
|
|
||||||
if (strcasecmp_P(items[cnt - 2], PSTR(DALI_TOPIC)) != 0)
|
if (strcasecmp_P(items[cnt - 2], PSTR(DALI_TOPIC)) != 0)
|
||||||
{
|
{
|
||||||
// AddLog(LOG_LEVEL_INFO,PSTR("cnt-2 not %s"), PSTR(DALI_TOPIC));
|
|
||||||
if (strcasecmp_P(items[cnt - 1], PSTR(DALI_TOPIC)) != 0)
|
if (strcasecmp_P(items[cnt - 1], PSTR(DALI_TOPIC)) != 0)
|
||||||
{
|
{
|
||||||
return false; // not for us
|
return false; // not for us
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// AddLog(LOG_LEVEL_INFO,PSTR("DLI: handle json"));
|
|
||||||
if (true == DaliJsonParse()) { return true; }
|
if (true == DaliJsonParse()) { return true; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -510,11 +477,10 @@ bool DaliMqtt()
|
|||||||
DALIindex = cnt - 3;
|
DALIindex = cnt - 3;
|
||||||
CMDindex = cnt - 2;
|
CMDindex = cnt - 2;
|
||||||
ADRindex = cnt - 1;
|
ADRindex = cnt - 1;
|
||||||
DALIaddr = ((int)CharToFloat(items[ADRindex])) << 1; // !!! ВАЖНО !!! Номер лампы должен быть сдвинут << 1
|
DALIaddr = ((int)CharToFloat(items[ADRindex])) << 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddLog(LOG_LEVEL_INFO,PSTR("DLI: handle topic + data"));
|
|
||||||
uint8_t level;
|
uint8_t level;
|
||||||
uint8_t value = (uint8_t)CharToFloat(XdrvMailbox.data);
|
uint8_t value = (uint8_t)CharToFloat(XdrvMailbox.data);
|
||||||
if (strcasecmp_P(items[CMDindex], PSTR("percent")) == 0) {
|
if (strcasecmp_P(items[CMDindex], PSTR("percent")) == 0) {
|
||||||
@ -538,8 +504,6 @@ bool DaliMqtt()
|
|||||||
bool DaliJsonParse()
|
bool DaliJsonParse()
|
||||||
{
|
{
|
||||||
bool served = false;
|
bool served = false;
|
||||||
|
|
||||||
// if (strlen(XdrvMailbox.data) > 8) { // Workaround exception if empty JSON like {} - Needs checks
|
|
||||||
JsonParser parser((char *)XdrvMailbox.data);
|
JsonParser parser((char *)XdrvMailbox.data);
|
||||||
JsonParserObject root = parser.getRootObject();
|
JsonParserObject root = parser.getRootObject();
|
||||||
if (root)
|
if (root)
|
||||||
@ -549,7 +513,7 @@ bool DaliJsonParse()
|
|||||||
int8_t DALIdim = -1;
|
int8_t DALIdim = -1;
|
||||||
uint8_t DALIaddr = BROADCAST_DP;
|
uint8_t DALIaddr = BROADCAST_DP;
|
||||||
|
|
||||||
JsonParserToken val = root[PSTR("cmd")]; // Команда
|
JsonParserToken val = root[PSTR("cmd")];
|
||||||
if (val)
|
if (val)
|
||||||
{
|
{
|
||||||
uint8_t cmd = val.getUInt();
|
uint8_t cmd = val.getUInt();
|
||||||
@ -571,30 +535,19 @@ bool DaliJsonParse()
|
|||||||
{
|
{
|
||||||
uint8_t addr = val.getUInt();
|
uint8_t addr = val.getUInt();
|
||||||
if ((addr >= 0) && (addr < 64))
|
if ((addr >= 0) && (addr < 64))
|
||||||
DALIaddr = addr << 1; // !!! ВАЖНО !!! Номер лампы должен быть сдвинут << 1
|
DALIaddr = addr << 1;
|
||||||
// AddLog(LOG_LEVEL_DEBUG, PSTR("DLI: mqtt->json addr = %d"), val.getUInt());
|
|
||||||
}
|
}
|
||||||
val = root[PSTR("dim")];
|
val = root[PSTR("dim")];
|
||||||
if (val)
|
if (val)
|
||||||
{
|
{
|
||||||
uint8_t dim = val.getUInt();
|
uint8_t dim = val.getUInt();
|
||||||
if ((dim >= 0) && (dim < 255))
|
if (dim < 255)
|
||||||
DALIdim = dim;
|
DALIdim = dim;
|
||||||
// AddLog(LOG_LEVEL_DEBUG, PSTR("DLI: mqtt->json dimmer = %d"), val.getUInt());
|
|
||||||
}
|
}
|
||||||
// val = root[PSTR("power")];
|
|
||||||
// if (val)
|
|
||||||
// {
|
|
||||||
// // FMqtt.file_type = val.getUInt();
|
|
||||||
// // AddLog(LOG_LEVEL_DEBUG, PSTR("DLI: mqtt->json power = %d"), val.getUInt());
|
|
||||||
// }
|
|
||||||
sendDaliData(DALIaddr, DALIdim);
|
sendDaliData(DALIaddr, DALIdim);
|
||||||
served = true;
|
served = true;
|
||||||
}
|
}
|
||||||
// else {
|
|
||||||
// AddLog(LOG_LEVEL_DEBUG, PSTR("DLI: mqtt->json ERROR - not json"));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
return served;
|
return served;
|
||||||
}
|
}
|
||||||
@ -621,19 +574,6 @@ bool Xdrv89(uint8_t function)
|
|||||||
case FUNC_COMMAND:
|
case FUNC_COMMAND:
|
||||||
result = DaliCmd();
|
result = DaliCmd();
|
||||||
break;
|
break;
|
||||||
#ifdef USE_WEBSERVER
|
|
||||||
// case FUNC_WEB_ADD_BUTTON:
|
|
||||||
// WSContentSend_P(HTTP_BTN_MENU_DALI);
|
|
||||||
// break;
|
|
||||||
// case FUNC_WEB_ADD_HANDLER:
|
|
||||||
// WebServer_on(PSTR("/" WEB_HANDLE_DALI), HandleDali);
|
|
||||||
// break;
|
|
||||||
#ifdef USE_DALI_DISPLAYINPUT
|
|
||||||
// case FUNC_WEB_SENSOR:
|
|
||||||
// DaliShow(0);
|
|
||||||
// break;
|
|
||||||
#endif // #ifdef USE_DALI_DISPLAYINPUT
|
|
||||||
#endif // USE_WEBSERVER
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user