From c1ce13a689935b49786c7bcdf3e95bcdfccbfd0c Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 9 Aug 2020 15:31:37 +0200 Subject: [PATCH] Some refactoring --- lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.h | 3 +- tasmota/support_switch.ino | 10 +++++-- tasmota/tasmota.h | 30 ++++++++------------ 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.h b/lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.h index 2b81db6f6..f2571a104 100755 --- a/lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.h +++ b/lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.h @@ -37,8 +37,7 @@ typedef unsigned char prog_uchar; #endif -#define SPI_HAS_TRANSACTION - +//#define SPI_HAS_TRANSACTION // already defined in SPI.h #define ST7789_TFTWIDTH 240 #define ST7789_TFTHEIGHT 240 diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index bd127d6c5..1c0a8e12d 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -29,6 +29,12 @@ const uint8_t SWITCH_PROBE_INTERVAL = 10; // Time in milliseconds between swit const uint8_t SWITCH_FAST_PROBE_INTERVAL =2;// Time in milliseconds between switch input probe for AC detection const uint8_t AC_PERIOD = (20 + SWITCH_FAST_PROBE_INTERVAL - 1) / SWITCH_FAST_PROBE_INTERVAL; // Duration of an AC wave in probe intervals +// Switch Mode definietions +#define SM_TIMER_MASK 0x3F +#define SM_NO_TIMER_MASK 0xFF +#define SM_FIRST_PRESS 0x40 +#define SM_SECOND_PRESS 0x80 + #include Ticker TickerSwitch; @@ -330,7 +336,7 @@ void SwitchHandler(uint8_t mode) case PUSHHOLDMULTI: if (NOT_PRESSED == button) { if ((Switch.hold_timer[i] & SM_TIMER_MASK) != 0) { - Switch.hold_timer[i] = ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS) ? SM_SECOND_PRESS : 0; + Switch.hold_timer[i] = ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS) ? SM_SECOND_PRESS : 0; SendKey(KEY_SWITCH, i +1, POWER_INV); // Execute command via MQTT } } else { @@ -353,7 +359,7 @@ void SwitchHandler(uint8_t mode) case PUSHHOLDMULTI_INV: if (PRESSED == button) { if ((Switch.hold_timer[i] & SM_TIMER_MASK) != 0) { - Switch.hold_timer[i] = ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS) ? SM_SECOND_PRESS : 0; + Switch.hold_timer[i] = ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS) ? SM_SECOND_PRESS : 0; SendKey(KEY_SWITCH, i +1, POWER_INV); // Execute command via MQTT } } else { diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index ba8c9e302..b56f00880 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -82,10 +82,10 @@ const uint8_t MAX_FRIENDLYNAMES = 8; // Max number of Friendly names const uint8_t MAX_BUTTON_TEXT = 16; // Max number of GUI button labels const uint8_t MAX_GROUP_TOPICS = 4; // Max number of Group Topics const uint8_t MAX_DEV_GROUP_NAMES = 4; // Max number of Device Group names +const uint8_t MAX_ADCS = 8; // Max number of ESP32 ADC pins (ADC2 pins are unusable with Wifi enabled) const uint8_t MAX_HUE_DEVICES = 15; // Max number of Philips Hue device per emulation const uint8_t MAX_ROTARIES = 2; // Max number of Rotary Encoders -const uint8_t MAX_ADCS = 8; // Max number of ESP32 ADC pins (ADC2 pins are unusable with Wifi enabled) const char MQTT_TOKEN_PREFIX[] PROGMEM = "%prefix%"; // To be substituted by mqtt_prefix[x] const char MQTT_TOKEN_TOPIC[] PROGMEM = "%topic%"; // To be substituted by mqtt_topic, mqtt_grptopic, mqtt_buttontopic, mqtt_switchtopic @@ -209,12 +209,6 @@ const uint32_t LOOP_SLEEP_DELAY = 50; // Lowest number of milliseconds to #define KNX_MAX_device_param 31 #define MAX_KNXTX_CMNDS 5 -// Switch Mode definietions -#define SM_TIMER_MASK 0x3F -#define SM_NO_TIMER_MASK 0xFF -#define SM_FIRST_PRESS 0x40 -#define SM_SECOND_PRESS 0x80 - /*********************************************************************************************\ * Enumeration \*********************************************************************************************/ @@ -281,30 +275,30 @@ enum XsnsFunctions {FUNC_SETTINGS_OVERRIDE, FUNC_PIN_STATE, FUNC_MODULE_INIT, FU enum AddressConfigSteps { ADDR_IDLE, ADDR_RECEIVE, ADDR_SEND }; enum SettingsTextIndex { SET_OTAURL, - SET_MQTTPREFIX1, SET_MQTTPREFIX2, SET_MQTTPREFIX3, - SET_STASSID1, SET_STASSID2, - SET_STAPWD1, SET_STAPWD2, + SET_MQTTPREFIX1, SET_MQTTPREFIX2, SET_MQTTPREFIX3, // MAX_MQTT_PREFIXES + SET_STASSID1, SET_STASSID2, // MAX_SSIDS + SET_STAPWD1, SET_STAPWD2, // MAX_SSIDS SET_HOSTNAME, SET_SYSLOG_HOST, SET_WEBPWD, SET_CORS, SET_MQTT_HOST, SET_MQTT_CLIENT, SET_MQTT_USER, SET_MQTT_PWD, SET_MQTT_FULLTOPIC, SET_MQTT_TOPIC, SET_MQTT_BUTTON_TOPIC, SET_MQTT_SWITCH_TOPIC, SET_MQTT_GRP_TOPIC, - SET_STATE_TXT1, SET_STATE_TXT2, SET_STATE_TXT3, SET_STATE_TXT4, - SET_NTPSERVER1, SET_NTPSERVER2, SET_NTPSERVER3, + SET_STATE_TXT1, SET_STATE_TXT2, SET_STATE_TXT3, SET_STATE_TXT4, // MAX_STATE_TEXT + SET_NTPSERVER1, SET_NTPSERVER2, SET_NTPSERVER3, // MAX_NTP_SERVERS SET_MEM1, SET_MEM2, SET_MEM3, SET_MEM4, SET_MEM5, SET_MEM6, SET_MEM7, SET_MEM8, - SET_MEM9, SET_MEM10, SET_MEM11, SET_MEM12, SET_MEM13, SET_MEM14, SET_MEM15, SET_MEM16, + SET_MEM9, SET_MEM10, SET_MEM11, SET_MEM12, SET_MEM13, SET_MEM14, SET_MEM15, SET_MEM16, // MAX_RULE_MEMS SET_FRIENDLYNAME1, SET_FRIENDLYNAME2, SET_FRIENDLYNAME3, SET_FRIENDLYNAME4, - SET_FRIENDLYNAME5, SET_FRIENDLYNAME6, SET_FRIENDLYNAME7, SET_FRIENDLYNAME8, + SET_FRIENDLYNAME5, SET_FRIENDLYNAME6, SET_FRIENDLYNAME7, SET_FRIENDLYNAME8, // MAX_FRIENDLYNAMES SET_BUTTON1, SET_BUTTON2, SET_BUTTON3, SET_BUTTON4, SET_BUTTON5, SET_BUTTON6, SET_BUTTON7, SET_BUTTON8, - SET_BUTTON9, SET_BUTTON10, SET_BUTTON11, SET_BUTTON12, SET_BUTTON13, SET_BUTTON14, SET_BUTTON15, SET_BUTTON16, - SET_MQTT_GRP_TOPIC2, SET_MQTT_GRP_TOPIC3, SET_MQTT_GRP_TOPIC4, + SET_BUTTON9, SET_BUTTON10, SET_BUTTON11, SET_BUTTON12, SET_BUTTON13, SET_BUTTON14, SET_BUTTON15, SET_BUTTON16, // MAX_BUTTON_TEXT + SET_MQTT_GRP_TOPIC2, SET_MQTT_GRP_TOPIC3, SET_MQTT_GRP_TOPIC4, // MAX_GROUP_TOPICS SET_TEMPLATE_NAME, - SET_DEV_GROUP_NAME1, SET_DEV_GROUP_NAME2, SET_DEV_GROUP_NAME3, SET_DEV_GROUP_NAME4, + SET_DEV_GROUP_NAME1, SET_DEV_GROUP_NAME2, SET_DEV_GROUP_NAME3, SET_DEV_GROUP_NAME4, // MAX_DEV_GROUP_NAMES SET_DEVICENAME, SET_TELEGRAM_TOKEN, SET_TELEGRAM_CHATID, #ifdef ESP32 - SET_ADC_PARAM1, SET_ADC_PARAM2, SET_ADC_PARAM3, SET_ADC_PARAM4, SET_ADC_PARAM5, SET_ADC_PARAM6, SET_ADC_PARAM7, SET_ADC_PARAM8, // Relates to MAX_ADCS + SET_ADC_PARAM1, SET_ADC_PARAM2, SET_ADC_PARAM3, SET_ADC_PARAM4, SET_ADC_PARAM5, SET_ADC_PARAM6, SET_ADC_PARAM7, SET_ADC_PARAM8, // MAX_ADCS #endif SET_MAX };