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 USE_ARMTRONIX_DIMMERS // Add support for Armtronix Dimmers (+1k4 code)
#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_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)

View File

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

View File

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

View File

@ -846,6 +846,16 @@ uint8_t ModuleNr()
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)
{
if (USER_MODULE == index) {

View File

@ -1038,7 +1038,7 @@ void HandleTemplateConfiguration(void)
if (WebServer->hasArg("m")) {
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);
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), midx +1);
}
@ -1159,7 +1159,7 @@ void HandleModuleConfiguration(void)
if (WebServer->hasArg("m")) {
WSContentBegin(200, CT_PLAIN);
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) {
midx = USER_MODULE;
vidx = 0;