Add compile time control over SetOptions

This commit is contained in:
Theo Arends 2020-01-20 18:49:57 +01:00
parent 58a50cec8c
commit e01c1b8c45
2 changed files with 118 additions and 27 deletions

View File

@ -53,7 +53,7 @@
//#define MODULE SONOFF_BASIC // [Module] Select default model from tasmota_template.h
#define SAVE_DATA 1 // [SaveData] Save changed parameters to Flash (0 = disable, 1 - 3600 seconds)
#define SAVE_STATE 1 // [SetOption0] Save changed power state to Flash (0 = disable, 1 = enable)
#define SAVE_STATE true // [SetOption0] Save changed power state to Flash (false = disable, true = enable)
#define BOOT_LOOP_OFFSET 1 // [SetOption36] Number of boot loops before starting restoring defaults (0 = disable, 1..200 = boot loops offset)
// -- Wifi ----------------------------------------
@ -69,6 +69,8 @@
#define WIFI_CONFIG_TOOL WIFI_RETRY // [WifiConfig] Default tool if wifi fails to connect (default option: 4 - WIFI_RETRY)
// (WIFI_RESTART, WIFI_MANAGER, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, WIFI_MANAGER_RESET_ONLY)
// The configuration can be changed after first setup using WifiConfig 0, 2, 4, 5, 6 and 7.
#define WIFI_SCAN_AT_RESTART false // [SetOption56] Scan wifi network at restart for configured AP's
#define WIFI_SCAN_REGULARLY false // [SetOption57] Scan wifi network every 44 minutes for configured AP's
// -- Syslog --------------------------------------
#define SYS_LOG_HOST "" // [LogHost] (Linux) syslog host
@ -80,9 +82,10 @@
// -- Ota -----------------------------------------
#define OTA_URL "http://thehackbox.org/tasmota/release/tasmota.bin" // [OtaUrl]
#define OTA_COMPATIBILITY false // [SetOption78] Disable OTA compatibility check
// -- MQTT ----------------------------------------
#define MQTT_USE 1 // [SetOption3] Select default MQTT use (0 = Off, 1 = On)
#define MQTT_USE true // [SetOption3] Select default MQTT use (false = Off, true = On)
#define MQTT_HOST "" // [MqttHost]
#define MQTT_FINGERPRINT1 "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" // [MqttFingerprint1]
@ -91,10 +94,10 @@
#define MQTT_USER "DVES_USER" // [MqttUser] MQTT user
#define MQTT_PASS "DVES_PASS" // [MqttPassword] MQTT password
#define MQTT_BUTTON_RETAIN 0 // [ButtonRetain] Button may send retain flag (0 = off, 1 = on)
#define MQTT_POWER_RETAIN 0 // [PowerRetain] Power status message may send retain flag (0 = off, 1 = on)
#define MQTT_SWITCH_RETAIN 0 // [SwitchRetain] Switch may send retain flag (0 = off, 1 = on)
#define MQTT_BUTTON_SWITCH_FORCE_LOCAL 0 // [SetOption61] Force local operation when button/switch topic is set (0 = off, 1 = on)
#define MQTT_BUTTON_RETAIN false // [ButtonRetain] Button may send retain flag (false = off, true = on)
#define MQTT_POWER_RETAIN false // [PowerRetain] Power status message may send retain flag (false = off, true = on)
#define MQTT_SWITCH_RETAIN false // [SwitchRetain] Switch may send retain flag (false = off, true = on)
#define MQTT_BUTTON_SWITCH_FORCE_LOCAL false // [SetOption61] Force local operation when button/switch topic is set (false = off, true = on)
#define MQTT_STATUS_OFF "OFF" // [StateText1] Command or Status result when turned off (needs to be a string like "0" or "Off")
#define MQTT_STATUS_ON "ON" // [StateText2] Command or Status result when turned on (needs to be a string like "1" or "On")
@ -113,19 +116,30 @@
// %topic% token options (also ButtonTopic and SwitchTopic)
#define MQTT_TOPIC PROJECT // [Topic] (unique) MQTT device topic, set to 'PROJECT "_%06X"' for unique topic including device MAC address
#define MQTT_GRPTOPIC "tasmotas" // [GroupTopic] MQTT Group topic
#define MQTT_GROUPTOPIC_FORMAT false // [SetOption75] GroupTopic replaces %topic% (false) or fixed topic cmnd/grouptopic (true)
#define MQTT_BUTTON_TOPIC "0" // [ButtonTopic] MQTT button topic, "0" = same as MQTT_TOPIC, set to 'PROJECT "_BTN_%06X"' for unique topic including device MAC address
#define MQTT_SWITCH_TOPIC "0" // [SwitchTopic] MQTT button topic, "0" = same as MQTT_TOPIC, set to 'PROJECT "_SW_%06X"' for unique topic including device MAC address
#define MQTT_CLIENT_ID "DVES_%06X" // [MqttClient] Also fall back topic using Chip Id = last 6 characters of MAC address
// -- MQTT - Telemetry ----------------------------
#define TELE_PERIOD 300 // [TelePeriod] Telemetry (0 = disable, 10 - 3600 seconds)
#define TELE_ON_POWER 0 // [SetOption59] send tele/STATE together with stat/RESULT (0 = Disable, 1 = Enable)
#define TELE_ON_POWER false // [SetOption59] send tele/STATE together with stat/RESULT (false = Disable, true = Enable)
// -- MQTT - Domoticz -----------------------------
#define DOMOTICZ_UPDATE_TIMER 0 // [DomoticzUpdateTimer] Send relay status (0 = disable, 1 - 3600 seconds)
// -- MQTT - Home Assistant Discovery -------------
#define HOME_ASSISTANT_DISCOVERY_ENABLE 0 // [SetOption19] Home Assistant Discovery (0 = Disable, 1 = Enable)
#define HOME_ASSISTANT_DISCOVERY_ENABLE false // [SetOption19] Home Assistant Discovery (false = Disable, true = Enable)
#define HASS_AS_LIGHT false // [SetOption30] Enforce HAss autodiscovery as light
// -- MQTT - Options ------------------------------
#define MQTT_RESULT_COMMAND false // [SetOption4] Switch between MQTT RESULT or COMMAND
#define MQTT_LWT_MESSAGE false // [SetOption10] Switch between MQTT LWT OFFLINE or empty message
#define MQTT_POWER_FORMAT false // [SetOption26] Switch between POWER or POWER1 for single power devices
#define MQTT_APPEND_TIMEZONE false // [SetOption52] Append timezone to JSON time
#define MQTT_NO_HOLD_RETAIN false // [SetOption62] Disable retain flag on HOLD messages
#define MQTT_INDEX_SEPARATOR false // [SetOption64] Enable "_" instead of "-" as sensor index separator
#define MQTT_TUYA_RECEIVED false // [SetOption66] Enable TuyaMcuReceived messages over Mqtt
// -- HTTP ----------------------------------------
#define WEB_SERVER 2 // [WebServer] Web server (0 = Off, 1 = Start as User, 2 = Start as Admin)
@ -134,6 +148,9 @@
#define EMULATION EMUL_NONE // [Emulation] Select Belkin WeMo (single relay/light) or Hue Bridge emulation (multi relay/light) (EMUL_NONE, EMUL_WEMO or EMUL_HUE)
#define CORS_DOMAIN "" // [Cors] CORS Domain for preflight requests
// -- HTTP Options --------------------------------
#define GUI_SHOW_HOSTNAME false // [SetOption53] Show hostname and IP address in GUI main menu
// -- HTTP GUI Colors -----------------------------
// HTML hex color codes. Only 3 and 6 digit hex string values are supported!! See https://www.w3schools.com/colors/colors_hex.asp
// Light theme - pre v7
@ -182,7 +199,7 @@
#define COLOR_TITLE_TEXT "#eaeaea" // [WebColor19] Title text color - Very light gray
// -- mDNS ----------------------------------------
#define MDNS_ENABLED 0 // [SetOption55] Use mDNS (0 = Disable, 1 = Enable)
#define MDNS_ENABLED false // [SetOption55] Use mDNS (false = Disable, true = Enable)
// -- Time - Up to three NTP servers in your region
#define NTP_SERVER1 "pool.ntp.org" // [NtpServer1] Select first NTP server by name or IP address (129.250.35.250)
@ -214,28 +231,68 @@
#define APP_LEDSTATE LED_POWER // [LedState] Function of led
// (LED_OFF, LED_POWER, LED_MQTTSUB, LED_POWER_MQTTSUB, LED_MQTTPUB, LED_POWER_MQTTPUB, LED_MQTT, LED_POWER_MQTT)
#define APP_LEDMASK 0xFFFF // [LedMask] Assign Relay to Power led (0xFFFF is default)
#define APP_ENABLE_LEDLINK false // [SetOption31] Enable link led blinking
#define APP_PULSETIME 0 // [PulseTime] Time in 0.1 Sec to turn off power for relay 1 (0 = disabled)
#define APP_POWERON_STATE POWER_ALL_SAVED // [PowerOnState] Power On Relay state
// (POWER_ALL_OFF, POWER_ALL_ON, POWER_ALL_SAVED_TOGGLE, POWER_ALL_SAVED, POWER_ALL_ALWAYS_ON, POWER_ALL_OFF_PULSETIME_ON)
#define APP_BLINKTIME 10 // [BlinkTime] Time in 0.1 Sec to blink/toggle power for relay 1
#define APP_BLINKCOUNT 10 // [BlinkCount] Number of blinks (0 = 32000)
#define APP_NORMAL_SLEEP false // [SetOption60] Enable normal sleep instead of dynamic sleep
#define APP_SLEEP 0 // [Sleep] Sleep time to lower energy consumption (0 = Off, 1 - 250 mSec),
#define PWM_MAX_SLEEP 10 // Sleep will be lowered to this value when light is on, to avoid flickering
#define KEY_DEBOUNCE_TIME 50 // [ButtonDebounce] Number of mSeconds button press debounce time
#define KEY_HOLD_TIME 40 // [SetOption32] Number of 0.1 seconds to hold Button or external Pushbutton before sending HOLD message
#define KEY_DISABLE_MULTIPRESS false // [SetOption1] Disable button multipress
#define KEY_SWAP_DOUBLE_PRESS false // [SetOption11] Swap button single and double press functionality
#define KEY_ONLY_SINGLE_PRESS false // [SetOption13] Enable only single press to speed up button press recognition
#define SWITCH_DEBOUNCE_TIME 50 // [SwitchDebounce] Number of mSeconds switch press debounce time
#define SWITCH_MODE TOGGLE // [SwitchMode] TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, TOGGLEMULTI, FOLLOWMULTI, FOLLOWMULTI_INV (the wall switch state)
#define WS2812_LEDS 30 // [Pixels] Number of WS2812 LEDs to start with (max is 512)
#define TEMP_CONVERSION 0 // [SetOption8] Return temperature in (0 = Celsius or 1 = Fahrenheit)
#define PRESSURE_CONVERSION 0 // [SetOption24] Return pressure in (0 = hPa or 1 = mmHg)
#define TEMP_CONVERSION false // [SetOption8] Return temperature in (false = Celsius or true = Fahrenheit)
#define PRESSURE_CONVERSION false // [SetOption24] Return pressure in (false = hPa or true = mmHg)
#define TEMP_RESOLUTION 1 // [TempRes] Maximum number of decimals (0 - 3) showing sensor Temperature
#define HUMIDITY_RESOLUTION 1 // [HumRes] Maximum number of decimals (0 - 3) showing sensor Humidity
#define PRESSURE_RESOLUTION 1 // [PressRes] Maximum number of decimals (0 - 3) showing sensor Pressure
#define ENERGY_RESOLUTION 3 // [EnergyRes] Maximum number of decimals (0 - 5) showing energy usage in kWh
#define CALC_RESOLUTION 3 // [CalcRes] Maximum number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE
#define APP_FLASH_CYCLE false // [SetOption12] Switch between dynamic or fixed slot flash save location
#define APP_NO_RELAY_SCAN false // [SetOption63] Don't scan relay power state at restart
#define APP_DISABLE_POWERCYCLE false // [SetOption65] Disable fast power cycle detection for device reset
#define DEEPSLEEP_BOOTCOUNT false // [SetOption76] Enable incrementing bootcount when deepsleep is enabled
// -- Lights --------------------------------------
#define LIGHT_MODE true // [SetOption15] Switch between commands PWM or COLOR/DIMMER/CT/CHANNEL
#define LIGHT_CLOCK_DIRECTION false // [SetOption16] Switch WS2812 clock between clockwise or counter-clockwise
#define LIGHT_COLOR_RADIX false // [SetOption17] Switch between decimal or hexadecimal color output (false = hexadecimal, true = decimal)
#define LIGHT_PAIRS_CO2 false // [SetOption18] Enable Pair light signal with CO2 sensor
#define LIGHT_POWER_CONTROL false // [SetOption20] Enable power control in relation to Dimmer/Color/Ct changes
#define LIGHT_CHANNEL_MODE false // [SetOption68] Enable multi-channels PWM instead of Color PWM
#define LIGHT_SLIDER_POWER false // [SetOption77] Do not power off if slider moved to far left
#define LIGHT_ALEXA_CT_RANGE false // [SetOption82] Reduced CT range for Alexa
// -- Energy --------------------------------------
#define ENERGY_VOLTAGE_ALWAYS false // [SetOption21] Enable show voltage even if powered off
#define ENERGY_DDS2382_MODE false // [SetOption71] Enable DDS2382 different Modbus registers for Active Energy (#6531)
#define ENERGY_HARDWARE_TOTALS false // [SetOption72] Enable hardware energy total counter as reference (#6561)
// -- Other Options -------------------------------
#define RF_DATA_RADIX false // [SetOption28] RF receive data format (false = hexadecimal, true = decimal)
#define IR_DATA_RADIX false // [SetOption29] IR receive data format (false = hexadecimal, true = decimal)
#define TUYA_SETOPTION_20 false // [SetOption54] Apply SetOption20 settings to Tuya device
#define IR_ADD_RAW_DATA false // [SetOption58] Add IR Raw data to JSON message
#define BUZZER_ENABLE false // [SetOption67] Enable buzzer when available
#define DS18X20_PULL_UP false // [SetOption74] Enable internal pullup for single DS18x20 sensor
#define COUNTER_RESET false // [SetOption79] Enable resetting of counters after telemetry was sent
#define SHUTTER_SUPPORT false // [SetOption80] Enable shutter support
#define PCF8574_INVERT_PORTS false // [SetOption81] Invert all ports on PCF8574 devices
#define ZIGBEE_FRIENDLY_NAMES false // [SetOption83] Enable Zigbee FriendlyNames instead of ShortAddresses when possible
/*********************************************************************************************\
* END OF SECTION 1
*

View File

@ -782,8 +782,13 @@ void SettingsDefaultSet2(void)
{
memset((char*)&Settings +16, 0x00, sizeof(SYSCFG) -16);
// Settings.flag.value_units = 0;
// Settings.flag.stop_flash_rotate = 0;
Settings.flag.stop_flash_rotate = APP_FLASH_CYCLE;
Settings.flag.global_state = APP_ENABLE_LEDLINK;
Settings.flag3.sleep_normal = APP_NORMAL_SLEEP;
Settings.flag3.no_power_feedback = APP_NO_RELAY_SCAN;
Settings.flag3.fast_power_cycle_disable = APP_DISABLE_POWERCYCLE;
Settings.flag3.bootcount_update = DEEPSLEEP_BOOTCOUNT;
Settings.flag3.compatibility_check = OTA_COMPATIBILITY;
Settings.save_data = SAVE_DATA;
Settings.param[P_BACKLOG_DELAY] = MIN_BACKLOG_DELAY;
Settings.param[P_BOOT_LOOP_OFFSET] = BOOT_LOOP_OFFSET; // SetOption36
@ -824,6 +829,8 @@ void SettingsDefaultSet2(void)
Settings.seriallog_level = SERIAL_LOG_LEVEL;
// Wifi
Settings.flag3.use_wifi_scan = WIFI_SCAN_AT_RESTART;
Settings.flag3.use_wifi_rescan = WIFI_SCAN_REGULARLY;
Settings.wifi_output_power = 170;
ParseIp(&Settings.ip_address[0], WIFI_IP_ADDRESS);
ParseIp(&Settings.ip_address[1], WIFI_GATEWAY);
@ -844,16 +851,17 @@ void SettingsDefaultSet2(void)
// Webserver
Settings.flag2.emulation = EMULATION;
Settings.flag3.gui_hostname_ip = GUI_SHOW_HOSTNAME;
Settings.flag3.mdns_enabled = MDNS_ENABLED;
Settings.webserver = WEB_SERVER;
Settings.weblog_level = WEB_LOG_LEVEL;
SettingsUpdateText(SET_WEBPWD, WEB_PASSWORD);
Settings.flag3.mdns_enabled = MDNS_ENABLED;
SettingsUpdateText(SET_CORS, CORS_DOMAIN);
// Button
// Settings.flag.button_restrict = 0;
// Settings.flag.button_swap = 0;
// Settings.flag.button_single = 0;
Settings.flag.button_restrict = KEY_DISABLE_MULTIPRESS;
Settings.flag.button_swap = KEY_SWAP_DOUBLE_PRESS;
Settings.flag.button_single = KEY_ONLY_SINGLE_PRESS;
Settings.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
// Switch
@ -861,16 +869,19 @@ void SettingsDefaultSet2(void)
// MQTT
Settings.flag.mqtt_enabled = MQTT_USE;
// Settings.flag.mqtt_response = 0;
Settings.flag.mqtt_response = MQTT_RESULT_COMMAND;
Settings.flag.mqtt_offline = MQTT_LWT_MESSAGE;
Settings.flag.mqtt_power_retain = MQTT_POWER_RETAIN;
Settings.flag.mqtt_button_retain = MQTT_BUTTON_RETAIN;
Settings.flag.mqtt_switch_retain = MQTT_SWITCH_RETAIN;
Settings.flag3.button_switch_force_local = MQTT_BUTTON_SWITCH_FORCE_LOCAL;
Settings.flag3.hass_tele_on_power = TELE_ON_POWER;
// Settings.flag.mqtt_sensor_retain = 0;
// Settings.flag.mqtt_offline = 0;
// Settings.flag.mqtt_serial = 0;
// Settings.flag.device_index_enable = 0;
Settings.flag.device_index_enable = MQTT_POWER_FORMAT;
Settings.flag3.time_append_timezone = MQTT_APPEND_TIMEZONE;
Settings.flag3.button_switch_force_local = MQTT_BUTTON_SWITCH_FORCE_LOCAL;
Settings.flag3.no_hold_retain = MQTT_NO_HOLD_RETAIN;
Settings.flag3.use_underscore = MQTT_INDEX_SEPARATOR;
Settings.flag3.grouptopic_mode = MQTT_GROUPTOPIC_FORMAT;
SettingsUpdateText(SET_MQTT_HOST, MQTT_HOST);
Settings.mqtt_port = MQTT_PORT;
SettingsUpdateText(SET_MQTT_CLIENT, MQTT_CLIENT_ID);
@ -904,10 +915,13 @@ void SettingsDefaultSet2(void)
Settings.mqttlog_level = MQTT_LOG_LEVEL;
// Energy
Settings.flag.no_power_on_check = ENERGY_VOLTAGE_ALWAYS;
Settings.flag2.current_resolution = 3;
// Settings.flag2.voltage_resolution = 0;
// Settings.flag2.wattage_resolution = 0;
Settings.flag2.energy_resolution = ENERGY_RESOLUTION;
Settings.flag3.dds2382_model = ENERGY_DDS2382_MODE;
Settings.flag3.hardware_energy_total = ENERGY_HARDWARE_TOTALS;
Settings.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
// Settings.energy_power_delta = 0;
Settings.energy_power_calibration = HLW_PREF_PULSE;
@ -937,9 +951,12 @@ void SettingsDefaultSet2(void)
Settings.param[P_OVER_TEMP] = ENERGY_OVERTEMP;
// IRRemote
Settings.flag.ir_receive_decimal = IR_DATA_RADIX;
Settings.flag3.receive_raw = IR_ADD_RAW_DATA;
Settings.param[P_IR_UNKNOW_THRESHOLD] = IR_RCV_MIN_UNKNOWN_SIZE;
// RF Bridge
Settings.flag.rf_receive_decimal = RF_DATA_RADIX;
// for (uint32_t i = 0; i < 17; i++) { Settings.rf_code[i][0] = 0; }
memcpy_P(Settings.rf_code[0], kDefaultRfCode, 9);
@ -960,6 +977,8 @@ void SettingsDefaultSet2(void)
Settings.flag2.pressure_resolution = PRESSURE_RESOLUTION;
Settings.flag2.humidity_resolution = HUMIDITY_RESOLUTION;
Settings.flag2.temperature_resolution = TEMP_RESOLUTION;
Settings.flag3.ds18x20_internal_pullup = DS18X20_PULL_UP;
Settings.flag3.counter_reset_on_tele = COUNTER_RESET;
// Settings.altitude = 0;
// Rules
@ -969,18 +988,24 @@ void SettingsDefaultSet2(void)
Settings.flag2.calc_resolution = CALC_RESOLUTION;
// Home Assistant
Settings.flag.hass_light = HASS_AS_LIGHT;
Settings.flag.hass_discovery = HOME_ASSISTANT_DISCOVERY_ENABLE;
Settings.flag3.hass_tele_on_power = TELE_ON_POWER;
// Knx
// Settings.flag.knx_enabled = 0;
// Settings.flag.knx_enable_enhancement = 0;
// Light
Settings.flag.pwm_control = 1;
//Settings.flag.ws_clock_reverse = 0;
//Settings.flag.light_signal = 0;
//Settings.flag.not_power_linked = 0;
//Settings.flag.decimal_text = 0;
Settings.flag.pwm_control = LIGHT_MODE;
Settings.flag.ws_clock_reverse = LIGHT_CLOCK_DIRECTION;
Settings.flag.light_signal = LIGHT_PAIRS_CO2;
Settings.flag.not_power_linked = LIGHT_POWER_CONTROL;
Settings.flag.decimal_text = LIGHT_COLOR_RADIX;
Settings.flag3.pwm_multi_channels = LIGHT_CHANNEL_MODE;
Settings.flag3.slider_dimmer_stay_on = LIGHT_SLIDER_POWER;
Settings.flag4.alexa_ct_range = LIGHT_ALEXA_CT_RANGE;
Settings.pwm_frequency = PWM_FREQ;
Settings.pwm_range = PWM_RANGE;
for (uint32_t i = 0; i < MAX_PWMS; i++) {
@ -1064,6 +1089,15 @@ void SettingsDefaultSet2(void)
memset(&Settings.monitors, 0xFF, 20); // Enable all possible monitors, displays and sensors
SettingsEnableAllI2cDrivers();
// Tuya
Settings.flag3.tuya_apply_o20 = TUYA_SETOPTION_20;
Settings.flag3.tuya_serial_mqtt_publish = MQTT_TUYA_RECEIVED;
Settings.flag3.buzzer_enable = BUZZER_ENABLE;
Settings.flag3.shutter_mode = SHUTTER_SUPPORT;
Settings.flag3.pcf8574_ports_inverted = PCF8574_INVERT_PORTS;
Settings.flag4.zigbee_use_names = ZIGBEE_FRIENDLY_NAMES;
}
/********************************************************************************************/