/*
 * RBPXPLRTERM environmental configuration definitions
 */

#ifndef _RBPXPLRTERM_config_h
#define _RBPXPLRTERM_config_h

#include "RBPXPLRTERM_base.h"

#define _CONFIGFILETIME __FILE__ " " __DATE__ " " __TIME__

//
// --------------- hardware configuration -----------------------------------------------------------
//
// Raspberry Pi Pico Explorer Hardware connection definitions
//
#define RELAY_PIN         28
//
#define BUZZER_PIN        27
//
#define NEOPIXEL_PIN      1
#define NEOPIXEL_COUNT    4
//
// keyboard is RBPXPLR buttons:
//
#define KBD_RBPXPLR
//
// display is RBPXPLR TFT:
//
#define DSP_ST7735_eSPI
#define DSP_MAXCOL 20
#define DSP_MAXROW 20
//
// in RBPXPLR board, a DHT11 Sensor is connected to GPIO 0
//
#define PRT_ADAFRUIT_THERMAL_SERIAL
#define PRT_SERIAL1
#define PRT_SERIAL1_BAUDRATE 9600
#define PRT_SERIAL1_RX_PIN 13
#define PRT_SERIAL1_TX_PIN 12
//
#define DHT11_PIN         0
//
// DHT11 temperature / rel. humidty sensor
//
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
//
// RBPXPLRTERM has a serial printer attached to Serial1 with RX=GP
//
#define    UI_MENU
// #define  UI_TTY
//
// --------------- environment -----------------------------------------------------------------------
//
// timezone is Europe/Vienna with DST
//
#define NET_TIMEZONE "CET-1CEST,M3.5.0,M10.5.0/3"
//
// server and port of REST event registering service
// TODO: API key and endpoint URLs are still hard coded in commands.cpp
//
#define EVENTMARKERSERVER_OLD "puconsrv06.fritz.box"
// changed when switching PUCONWLAN central router  
// #define EVENTMARKERSERVER "puconsrv06"       
#define EVENTMARKERSERVER "puconsrv06.fritz.box"     
#define EVENTMARKERPORT   8421

//
// --------------- definitions for flags and counters ------------------------------------------------
//
#define NUMFLAGS                 20
#define FLG_DEBUG                 0
#define FLG_ECHO                  1
#define FLG_INPUTHADDOTCOMMAND    2

#define NUMCOUNTERS              20
#define CNT_REPEATCOUNT           0

#define PAR_CONFIGFILENAME        0
#define PAR_CONFIGFILEDATE        1
#define PAR_CONFIGFILETIME        2

#define EVT_NET_UP   4401
#define EVT_NET_DOWN 4402

//
// ========= variant control =============================================
//

// #define KEYMATRIX_ENABLED

// #define DISABLE_LEDS

// #define DIS_WIFI

#ifdef ENV_ESP32
#ifndef DIS_WIFI
#define ENA_WEBSERVER
#define ENA_WIFI
#endif
#endif

#ifdef ENV_RP2040
#ifndef DIS_WIFI
#define ENA_WEBSERVER
#define ENA_WIFI
#endif
#endif

//
// ========= peripheral components =======================================
//
// #define LED_BUILTIN 2

// maximum number of characters per line that can be printed
#if defined(PRT_ADAFRUIT_THERMAL_SERIAL)
#define CHARSPERPRINTLINE 32
#else
#define CHARSPERPRINTLINE     40
#endif

// maximum number of characters per line that can be displayed
#define CHARSPERDISPLINE      20

//
// ====== keyboard ========
//
#ifdef KEYMATRIX_ENABLED
#include <Wire.h>
#define WIRE_ENABLED
#define I2C_SDA 14
#define I2C_SCL 13
#endif

//
// ========= components only applicable in AVR environment ==============
//
#ifdef ENV_AVR
#include <TimerOne.h>
#endif

//
// ============ common derived definitions ============
//
#define LED LED_BUILTIN              // use built-in LED for blinking indicator

#ifdef ENV_NANO
#define LOGBUFSIZE        4           // number of slots in log buffer
#define MAXBUFENTRIES    10             // maximum number of lines kept in buffer
#define MAXQUEUEENTRIES  15
#define MAXEVENTHANDLERS 15
#define SIZES_DEFINED
#endif

#ifdef ENV_ESP32
#define LOGBUFSIZE      400
#define MAXBUFENTRIES   200
#define MAXQUEUEENTRIES 100
#define MAXEVENTHANDLERS 15
#define SIZES_DEFINED
#endif

#ifdef ENV_RP2040
#define LOGBUFSIZE      100
#define MAXBUFENTRIES    50
#define MAXQUEUEENTRIES  25
#define MAXEVENTHANDLERS 10
#define SIZES_DEFINED
#endif

#ifndef SIZES_DEFINED
#error memory structure sizes not defined (probably due to unknown architecture)
#endif

#define NUM_TIMEOUTS   20                         // 20 timeouts available
#define BASIC_TICK_US  10000                      // timeout basic tick is 10 ms (10.000 us)

#define TIMEOUT_MS(ticks) (ticks*BASIC_TICK_US/1000)

#define MAXWLANRETRY        30
#define WLANSETUPDELAY    2000
#define WLANRETRYDELAY     500

#define MAXINT        0x7FFF
#define MAXLONG       0x7FFFFFF
#define MAXCOUNT      MAXLONG

#define NUMOFBLINKTICKS 50                    /* 50ms per blink phase */

#define DISPLAYSAVERTIMEOUTTICKS    3000      /* display saver  timeout in ticks of 10ms, after 30 sec. with no input display is switched off */
#define POPUPTIMEOUTTICKS            200      /* pop-up display timeout in ticks of 10ms, after  2 sec. */

#define ENABLE_LOG logEnabled = true;
#define DISABLE_LOG logEnabled = false;

const String ConfigFileName;
const String ConfigFileDate;
//
// ================ accessor functions =========================================
//
bool getFlag(int nflag);
bool setFlag(int nflag, bool newFlag);
bool toggleFlag(int nflag);
int getCounter(int ncounter);
int setCounter(int ncounter, int newCounter);
int incrementCounter(int ncounter);
int decrementCounter(int ncounter);
String getParameter(int nparam);
bool getInputHadDotCommand();
void setInputHadDotCommand(bool newInputHadDotCommand);
extern bool getEcho();
extern bool setEcho(bool newEcho);
bool toggleEcho();
int getRepeatCount();
int setRepeatCount(int newRepeatCount);
int incrementRepeatCount();
bool decrementRepeatCount();
bool getDebug();
bool setDebug(bool newDebug);
bool toggleDebug();
String formatLongGrouped(unsigned long val, boolean leadzeroblank = true);
const char* millisf();
const char* microsf();
String millisfs();
String microsfs();

// end of RBPXPLRTERM_config.h
#endif
