// PRE-COMPILE CONFIGURATION


// DEBUG SETTINGS - ONLY FOR DEVELOPMENT!!!
// WARNING !!
// - possibly reveals stored passwords
// - some functions use different timeouts intended for testing (iE in heat control variant)
// - shows a "DEBUG" note in web interface
// - DO NOT USE FOR PRODUCTION!!!
//#define DEBUGMODE

// some more debug output: 
//#define DEBUG_VERBOSE

// if enabled LittleFS filesystem is formatted on every startup. 
// only applicable during development sometimes...
//#define FORCE_FILESYSTEM_FORMAT

// END OF DEBUG SETTINGS

// define language - if no other language is defined, default (EN) is used
#define LANG_DE


// serial baudrate for startup debugging
// will be overwritten by firmware configuration during start/setup
#define SERIAL_BAUDRATE 57600


// SELECT FIRMWARE VARIANT TO BUILD
// can/should be set by compiler flag from PlatformIO
// this enables all firmware features that are needed for the variant
// but if more features are desired they can be enabled below
// - setting a firmware variant will DISABLE features that are not compatible with it
//#define FIRMWARE_VARIANT_THERMOSTAT
//#define FIRMWARE_VARIANT_HEATCONTROL


// ENABLE FEATURES

#define ENABLE_FEATURE_SECRETS_ENCRYPTION

// if disabled will be stored on LittleFS in file /confSecrets
// encryption is also applied if ENABLE_FEATURE_SECRETS_ENCRYPTION is enabled and encryption is enabled in the firmware
// but for a little extra security storing the data in EEPROM is recommended
#define STORE_SECRETS_IN_EEPROM

// enable NTP time server sync - currently only used for correct time in logger ;-) 
#define ENABLE_FEATURE_NTP_TIME

// legacy (buffered) web console that does not use WebSockets
// disable this to save >4k RAM and use new WSconsole instead
#define ENABLE_FEATURE_WEB_CONSOLE

// enable Web Console using WebSockets
#define ENABLE_FEATURE_WSCONSOLE

// enable OTA Updates via Web-Interface
#define ENABLE_FEATURE_HTTP_UPDATER

// enable Arduino-OTA (direct firmware upload from PlatformIO)
// must be switched on in the device configuration afterwards
#define ENABLE_FEATURE_ARDUINO_OTA

// simple LittleFS browser - can only list, upload, download and delete files
#define ENABLE_FEATURE_FILESYSTEM_BROWSER

// I2C interface needed for some sensors, displays, etc.
// is enabled by default when a firmware variant using it is selected
//#define ENABLE_I2C_INTERFACE

//#define ENABLE_SENSOR_DHT22
//#define ENABLE_SENSORS_ONEWIRE
//#define ENABLE_LCD_I2C
//#define ENABLE_I2C_PORTEXPANDER
//#define ENABLE_INPUT_BUTTONS
//#define ENABLE_SENSOR_PIR
//#define ENABLE_OUTSIDE_TEMP_MQTT




// DEFINITIONS OF FIRMWARE VARIANTS
// DO NOT EDIT BELOW!!!

#define DISPLAY_USE_MINIMAL_LAYOUT

#ifdef FIRMWARE_VARIANT_THERMOSTAT
    #undef FIRMWARE_VARIANT_HEATCONTROL
    #define ENABLE_I2C_INTERFACE
    #define ENABLE_SENSOR_DHT22
    #define ENABLE_LCD_I2C
    #define ENABLE_INPUT_BUTTONS
    #define ENABLE_SENSOR_PIR
    
    #define PIN_THERMOSTAT_OUTPUT 15 // 16

    #define PIN_DHTSENSOR 2
    #define DHTTYPE DHT22 // DHT sensor type

    #define PIN_BUTTON_PLUS 2
    #define PIN_BUTTON_MINUS 0
    #define PIN_BUTTON_MODE 14
    #define PIN_PIRSENSOR 12
    
    #define PIN_I2C_SDA 5
    #define PIN_I2C_SCL 4

    #define PCF8574_I2C_ADDRESS 0x20

    #define LCDADDR 0x27  // I2C address LCD
    #define LCDCOLS 16    // LCD cols
    #define LCDLINES 2    // LCD lines

// default logic levels
#define BUTTONONSTATE LOW


    #define THERMOSTAT_OUTPUT_ONSTATE HIGH
    #undef DISPLAY_USE_MINIMAL_LAYOUT
    
#endif

#ifdef FIRMWARE_VARIANT_HEATCONTROL
    #undef FIRMWARE_VARIANT_THERMOSTAT
    #undef DISPLAY_USE_MINIMAL_LAYOUT
    
    #define ENABLE_I2C_INTERFACE

    #define ENABLE_SENSOR_DHT22
    #define PIN_DHTSENSOR 2
    #define DHTTYPE DHT22 // DHT sensor type

    #define PIN_BUTTON_MODE 12
    
    #define PIN_I2C_SDA 5
    #define PIN_I2C_SCL 4

    #define PCF8574_I2C_ADDRESS 0x20

    #define LCDADDR 0x27  // I2C address LCD
    #define LCDCOLS 16    // LCD cols
    #define LCDLINES 2    // LCD lines

    // default logic levels
    #define BUTTONONSTATE LOW

    #define ENABLE_SENSORS_ONEWIRE
    #define ONE_WIRE_BUS 13
    #define ONEWIRE_SENSORS_COUNT 3
    #define ONEWIRE_SENSOR_INDEX_FEED 0
    #define ONEWIRE_SENSOR_INDEX_RETURN 1
    #define ONEWIRE_SENSOR_INDEX_OUT 2

    #define ENABLE_LCD_I2C
    #define ENABLE_INPUT_BUTTONS
    #define ENABLE_I2C_PORTEXPANDER
    

    #ifdef DEBUGMODE
        #define HEATCONTROL_TESTMODE_MINUTES 2
        #define HEATCONTROL_PUMP_BACKLASH 1
    #else
        #define HEATCONTROL_TESTMODE_MINUTES 15
        #define HEATCONTROL_PUMP_BACKLASH 5
    #endif
#endif


#ifdef ENABLE_SENSOR_PIR
    #ifndef ENABLE_INPUT_BUTTONS
        #define ENABLE_INPUT_BUTTONS
    #endif
#endif

#ifdef ENABLE_LCD_I2C
    #ifndef ENABLE_I2C_INTERFACE
        #define ENABLE_I2C_INTERFACE
    #endif
#endif

#ifdef ENABLE_I2C_PORTEXPANDER
    #ifndef ENABLE_I2C_INTERFACE
        #define ENABLE_I2C_INTERFACE
    #endif
#endif



// some settings
#define WEB_CONSOLE_BUFFER_SIZE 4000

#define ARDUINO_OTA_PORT 8266

// default values, can later be overridden via configuration
#define MAX_MEASUREMENT_AGE 30000      // in ms, for measured inside Temp/Hum
#define MAX_MEASUREMENT_AGE_OUT 300000 // in ms, for received outside Temp/Hum

// NTP defaults
#ifdef ENABLE_FEATURE_NTP_TIME
    #define DEFAULT_NTP_ENABLED true
    #define DEFAULT_NTP_SERVER "pool.ntp.org"
    #define DEFAULT_NTP_SYNC_INTERVAL 7200
    #define DEFAULT_TIMEZONE "CET-1CEST,M3.5.0/02,M10.5.0/03"
#endif

// confDevWiFi
//#define DEVICE_NAME "WTherm-1" // now created from FIRMWARE_SHORTNAME + last 2 octets of MAC address
//#define DEFAULT_HOST_NAME "" // now created from FIRMWARE_SHORTNAME + last 2 octets of MAC address
#define DEFAULT_WIFI_APMODE_PASSWORD "nichtsicher" // min 8 chars!
#define DEFAULT_WIFI_APMODE_TIMEOUT 5      //min
#define DEFAULT_WIFI_RETRY_INTERVAL 5      //min
#define DEFAULT_WIFI_CONNCHECK_INTERVAL 20 //s
#define DEFAULT_WIFI_REBOOT_ONNOCONNECT 60 //min

// confWeb
#define HTTP_SET_TOKEN ""
#define DEFAULT_HTTP_USER ""
#define DEFAULT_HTTP_PASS ""
#define DEFAULT_HTTP_USER_AUTH false
#define DEFAULT_ENABLE_WEBCONSOLE true

// confMqtt
#define MQTT_ENABLE false
#define MQTT_SERVER ""
#define MQTT_PORT 1883
#define MQTT_USER ""
#define MQTT_PASS ""
#define MQTT_TOPIC_IN "Test/ESPHeiz"
#define MQTT_TOPIC_OUT "Test/ESPHeiz/stat"
#define MQTT_OUT_RETAIN false
#define MQTT_OUT_RETAIN_SENSORS false
#define MQTT_OUT_PUBLISH_INTERVAL 0         // min, 0=only on change
#define MQTT_OUT_PUBLISH_INTERVAL_SENSORS 5 // min, 0=only on change
#define MQTT_WILLTOPIC "Test/ESPHeiz/availability"
#define MQTT_WILLQOS 2
#define MQTT_WILLRETAIN false
#define MQTT_WILLMSG "offline"
#define MQTT_CONNMSG "online"
#define MQTT_ENABLE_HEARTBEAT true

// max interval for MQTT heartbeat message. only applicable if MQTT
// IN-topic is defined. after this timeout MQTT reconnect is forced
#define MQTT_HEARTBEAT_MAXAGE 180000

// max interval for MQTT heartbeat message. only applicable if MQTT
// IN-topic is defined. after this timeout the ESP will reboot
#define MQTT_HEARTBEAT_MAXAGE_REBOOT 1800000

// confBas
#define DEFAULT_SETTEMP_MIN 16.0 // minimal temperature that can be set
#define DEFAULT_SETTEMP_MAX 26.0 // maximal temperature that can be set
#define AUTOSAVE_SETTEMP true
#define AUTOSAVE_SETMODE false
#define SAVE_TO_MQTT_RETAINED false
#define DEFAULT_MEASURE_INTERVAL 15 // interval for temp/hum measurement

// interval for display updates (if out-temp is active, display will toggle
// in this interval)
#define DEFAULT_DISPLAY_INTERVAL 5
#define DEFAULT_DISPLAY_TIMEOUT 30 // display timeout after keypress (illumination)
#define DEFAULT_PIR_ENABLES_DISPLAY false
#define DEFAULT_PIR_ENABLES_DISPLAY_PRESET0_ONLY true
#define DEFAULT_TOGGLING_I_O_TEMPHUM false

// confAdv
#define DEFAULT_HYSTERESIS 0.15         // hysteresis, normally 0.1 - 0.3
#define DEFAULT_HEATING_MIN_OFFTIME 300 // minimal time the heating must keep turned off until it can start again, in s

// correction value for temperature sensor reading
#define TEMPSENSOR_CORRECTION_VALUE 0.0
#define HUMSENSOR_CORRECTION_VALUE 0 // correction value for humidity sensor reading

// decreases the set temp to overcome further temperature rise when the
// heating is already switched off
#define SETTEMP_DECREASE_VALUE 0.0
#define OFF_MESSAGE "HEATING OFF"
#define INSIDE_TEMP_LABEL "I"
#define OUTSIDE_TEMP_LABEL "O"
#define MODE_NAME_0 "off"
#define MODE_NAME_1 "heat"
#define PRESET_NAME_0 "Normal"
#define PRESET_NAME_1 "Reduction 1"
#define PRESET_NAME_2 "Reduction 2"

// confAdd
#define OUTTEMP_TOPIC_IN ""
#define OUTHUM_TOPIC_IN ""
#define MQTT_TOPIC_PIR "" // extra publish topic for PIR sensor
#define MQTT_TOPIC_PIR_ON "ON"
#define MQTT_TOPIC_PIR_OFF "OFF"

// confLog
#define DEFAULT_LOGLEVEL_SERIAL LOGLEVEL_DEBUG
#define DEFAULT_LOGLEVEL_WEB LOGLEVEL_INFO
#define DEFAULT_LOGLEVEL_MQTT LOGLEVEL_INFO
#define DEFAULT_LOGLEVEL_SYSLOG LOGLEVEL_DEBUG // SYSLOG not implemented yet
#define LOG_WEB_REQUESTS false

// other (not configurable via commands/WebIF)
#define DEFAULT_SETTEMP_HEATOFF 5.0 // heating target temperature in OFF mode (freezing guard, therefore > 0)
#define SETTEMP_LOW_MIN 14.0        // minimal configurable temperature for reduction mode
#define SETTEMP_LOW_MAX 21.5        // maximal configurable temperature for reduction mode

// default initial values
#define DEFAULT_SETTEMP 21.5
#define DEFAULT_HEATINGMODE 1
#define DEFAULT_PRESET 1
#define DEFAULT_SETTEMP_LOW 20.0  // set temperature in night/low mode
#define DEFAULT_SETTEMP_LOW2 17.0 // set temperature in night/low mode

// COMPILE TIME SETTINGS
// default values that can only be configured at compile time / hardware configuration
#define BUTTON_DEBOUNCE_TIME 120
#define BUTTON_HOLD_TIME 750

// pin assignments and I2C addresses






//#define USE_MQTT_TLS
// currently does not work



#ifdef USE_MQTT_TLS
static const char *MQTT_TLS_fingerprint PROGMEM = "EC 0E 4B 32 77 6B 6A 03 C6 60 37 A4 DD 0C 4C 47 BC 2D 11 23";
//static const char *MQTT_TLS_fingerprint PROGMEM = "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
#endif





// ---------------------------------------------------------


//#define DEBUG_SECRETS_ENCRYPTION   // WARNING - reveals secrets on the console!!!

