Make MI Desk Lamp optional

Make MI Desk Lamp optional
This commit is contained in:
Theo Arends 2019-04-05 15:27:06 +02:00
parent 15d475c3e6
commit 5e1cbcf94f
5 changed files with 48 additions and 35 deletions

View File

@ -369,7 +369,7 @@
#define TUYA_DIMMER_ID 0 // Default dimmer Id #define TUYA_DIMMER_ID 0 // Default dimmer Id
#define USE_ARMTRONIX_DIMMERS // Add support for Armtronix Dimmers (+1k4 code) #define USE_ARMTRONIX_DIMMERS // Add support for Armtronix Dimmers (+1k4 code)
#define USE_PS_16_DZ // Add support for PS-16-DZ Dimmer #define USE_PS_16_DZ // Add support for PS-16-DZ Dimmer
//#define ROTARY_V1 // Add support for MI Desk Lamp //#define ROTARY_V1 // Add support for MI Desk Lamp
//#define USE_AZ7798 // Add support for AZ-Instrument 7798 CO2 datalogger (+1k6 code) //#define USE_AZ7798 // Add support for AZ-Instrument 7798 CO2 datalogger (+1k6 code)
//#define USE_PN532_HSU // Add support for PN532 using HSU (Serial) interface (+1k8 code, 140 bytes mem) //#define USE_PN532_HSU // Add support for PN532 using HSU (Serial) interface (+1k8 code, 140 bytes mem)
// #define USE_PN532_CAUSE_EVENTS // Cause event execution for PN532_UID= and PN532_DATA=[if defined] (+ 30 bytes code) // #define USE_PN532_CAUSE_EVENTS // Cause event execution for PN532_UID= and PN532_DATA=[if defined] (+ 30 bytes code)

View File

@ -874,35 +874,40 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
} }
else if (CMND_MODULE == command_code) { else if (CMND_MODULE == command_code) {
if ((payload >= 0) && (payload <= MAXMODULE)) { if ((payload >= 0) && (payload <= MAXMODULE)) {
if (0 == payload) { payload = 256; } bool present = false;
payload--; if (0 == payload) {
Settings.last_module = Settings.module; payload = 255;
Settings.module = payload; present = true;
SetModuleType(); } else {
if (Settings.last_module != payload) { payload--;
for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) { present = ValidModule(payload);
Settings.my_gp.io[i] = GPIO_NONE; }
} if (present) {
Settings.last_module = Settings.module;
Settings.module = payload;
SetModuleType();
if (Settings.last_module != payload) {
for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
Settings.my_gp.io[i] = GPIO_NONE;
}
}
restart_flag = 2;
} }
restart_flag = 2;
} }
Response_P(S_JSON_COMMAND_NVALUE_SVALUE, command, ModuleNr(), ModuleName().c_str()); Response_P(S_JSON_COMMAND_NVALUE_SVALUE, command, ModuleNr(), ModuleName().c_str());
} }
else if (CMND_MODULES == command_code) { else if (CMND_MODULES == command_code) {
for (uint8_t i = 0; i <= MAXMODULE; i++) { uint8_t midx = USER_MODULE;
for (uint8_t i = 0; i <= sizeof(kModuleNiceList); i++) {
if (i > 0) { midx = pgm_read_byte(kModuleNiceList + i -1); }
if (!jsflg) { if (!jsflg) {
Response_P(PSTR("{\"" D_CMND_MODULES "%d\":["), lines); Response_P(PSTR("{\"" D_CMND_MODULES "%d\":["), lines);
} else { } else {
ResponseAppend_P(PSTR(",")); ResponseAppend_P(PSTR(","));
} }
jsflg = true; jsflg = true;
uint8_t j = i; uint8_t j = i ? midx +1 : 0;
if (0 == i) { j = USER_MODULE; } else { j--; } if ((ResponseAppend_P(PSTR("\"%d (%s)\""), j, AnyModuleName(midx).c_str()) > (LOGSZ - TOPSZ)) || (i == sizeof(kModuleNiceList))) {
// ResponseAppend_P(PSTR("\"%d (%s)\""), i, AnyModuleName(j).c_str());
// if ((strlen(mqtt_data) > (LOGSZ - TOPSZ)) || (i == MAXMODULE)) {
if ((ResponseAppend_P(PSTR("\"%d (%s)\""), i, AnyModuleName(j).c_str()) > (LOGSZ - TOPSZ)) || (i == MAXMODULE)) {
ResponseAppend_P(PSTR("]}")); ResponseAppend_P(PSTR("]}"));
MqttPublishPrefixTopic_P(RESULT_OR_STAT, type); MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);
jsflg = false; jsflg = false;
@ -957,10 +962,6 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
ResponseAppend_P(PSTR(",")); ResponseAppend_P(PSTR(","));
} }
jsflg = true; jsflg = true;
// ResponseAppend_P(PSTR("\"%d (%s)\""), midx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames));
// if ((strlen(mqtt_data) > (LOGSZ - TOPSZ)) || (i == sizeof(kGpioNiceList) -1)) {
if ((ResponseAppend_P(PSTR("\"%d (%s)\""), midx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames)) > (LOGSZ - TOPSZ)) || (i == sizeof(kGpioNiceList) -1)) { if ((ResponseAppend_P(PSTR("\"%d (%s)\""), midx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames)) > (LOGSZ - TOPSZ)) || (i == sizeof(kGpioNiceList) -1)) {
ResponseAppend_P(PSTR("]}")); ResponseAppend_P(PSTR("]}"));
MqttPublishPrefixTopic_P(RESULT_OR_STAT, type); MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);
@ -2324,9 +2325,11 @@ void GpioInit(void)
{ {
uint8_t mpin; uint8_t mpin;
if ((Settings.module >= MAXMODULE) && (Settings.module < USER_MODULE)) { if (!ValidModule(Settings.module)) {
Settings.module = MODULE; uint8_t module = MODULE;
Settings.last_module = MODULE; if (!ValidModule(MODULE)) { module = SONOFF_BASIC; }
Settings.module = module;
Settings.last_module = module;
} }
SetModuleType(); SetModuleType();
@ -2509,7 +2512,7 @@ void GpioInit(void)
SwitchInit(); SwitchInit();
#ifdef ROTARY_V1 #ifdef ROTARY_V1
RotaryInit(); RotaryInit();
#endif #endif
#ifdef USE_WS2812 #ifdef USE_WS2812
if (!light_type && (pin[GPIO_WS2812] < 99)) { // RGB led if (!light_type && (pin[GPIO_WS2812] < 99)) { // RGB led
@ -2702,9 +2705,9 @@ void loop(void)
ButtonLoop(); ButtonLoop();
SwitchLoop(); SwitchLoop();
#ifdef ROTARY_V1 #ifdef ROTARY_V1
RotaryLoop(); RotaryLoop();
#endif #endif
if (TimeReached(state_50msecond)) { if (TimeReached(state_50msecond)) {
SetNextTimeInterval(state_50msecond, 50); SetNextTimeInterval(state_50msecond, 50);

View File

@ -588,15 +588,15 @@ const uint8_t kGpioNiceList[] PROGMEM = {
GPIO_ROT1B, // Rotary switch1 B Pin GPIO_ROT1B, // Rotary switch1 B Pin
GPIO_ROT2A, // Rotary switch2 A Pin GPIO_ROT2A, // Rotary switch2 A Pin
GPIO_ROT2B, // Rotary switch2 B Pin GPIO_ROT2B, // Rotary switch2 B Pin
#endif #endif
GPIO_ARIRFRCV, // AliLux RF Receive input GPIO_ARIRFRCV, // AliLux RF Receive input
#ifdef USE_HRE #ifdef USE_HRE
GPIO_HRE_CLOCK, GPIO_HRE_CLOCK,
GPIO_HRE_DATA GPIO_HRE_DATA
#endif #endif
}; };
const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = { const uint8_t kModuleNiceList[] PROGMEM = {
SONOFF_BASIC, // Sonoff Relay Devices SONOFF_BASIC, // Sonoff Relay Devices
SONOFF_RF, SONOFF_RF,
SONOFF_TH, SONOFF_TH,
@ -660,7 +660,7 @@ const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = {
HUAFAN_SS, HUAFAN_SS,
#ifdef ROTARY_V1 #ifdef ROTARY_V1
MI_DESK_LAMP, MI_DESK_LAMP,
#endif #endif
KMC_70011, KMC_70011,
AILIGHT, // Light Bulbs AILIGHT, // Light Bulbs
PHILIPS, PHILIPS,

View File

@ -846,6 +846,16 @@ uint8_t ModuleNr()
return (USER_MODULE == Settings.module) ? 0 : Settings.module +1; return (USER_MODULE == Settings.module) ? 0 : Settings.module +1;
} }
bool ValidModule(uint8_t index)
{
for (uint8_t i = 0; i < sizeof(kModuleNiceList); i++) {
if (index == pgm_read_byte(kModuleNiceList + i)) {
return true;
}
}
return false;
}
String AnyModuleName(uint8_t index) String AnyModuleName(uint8_t index)
{ {
if (USER_MODULE == index) { if (USER_MODULE == index) {

View File

@ -1038,7 +1038,7 @@ void HandleTemplateConfiguration(void)
if (WebServer->hasArg("m")) { if (WebServer->hasArg("m")) {
WSContentBegin(200, CT_PLAIN); WSContentBegin(200, CT_PLAIN);
for (uint8_t i = 0; i < MAXMODULE; i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3" for (uint8_t i = 0; i < sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3"
uint8_t midx = pgm_read_byte(kModuleNiceList + i); uint8_t midx = pgm_read_byte(kModuleNiceList + i);
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), midx +1); WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), midx +1);
} }
@ -1159,7 +1159,7 @@ void HandleModuleConfiguration(void)
if (WebServer->hasArg("m")) { if (WebServer->hasArg("m")) {
WSContentBegin(200, CT_PLAIN); WSContentBegin(200, CT_PLAIN);
uint8_t vidx = 0; uint8_t vidx = 0;
for (uint8_t i = 0; i <= MAXMODULE; i++) { // "}2'%d'>%s (%d)}3" - "}2'255'>UserTemplate (0)}3" - "}2'0'>Sonoff Basic (1)}3" for (uint8_t i = 0; i <= sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'255'>UserTemplate (0)}3" - "}2'0'>Sonoff Basic (1)}3"
if (0 == i) { if (0 == i) {
midx = USER_MODULE; midx = USER_MODULE;
vidx = 0; vidx = 0;