config.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #pragma once
  2. // Board- and application-wide configuration.
  3. //
  4. // Wi-Fi credentials, the outdoor sensor URL, the timezone and the NTP server
  5. // are runtime settings held in NVS and entered through the setup portal — see
  6. // src/settings.h and src/portal.h. The values below are compile-time
  7. // constants and safe to commit.
  8. // ---------------------------------------------------------------- display ---
  9. // The panel is a 300 x 400 ST7305 reflective LCD. The application runs it
  10. // rotated (U8G2_R1), so the drawing surface is 400 wide by 300 high.
  11. #define LCD_NATIVE_WIDTH 300
  12. #define LCD_NATIVE_HEIGHT 400
  13. #define DISPLAY_WIDTH 400
  14. #define DISPLAY_HEIGHT 300
  15. #define RLCD_SCK_PIN 11
  16. #define RLCD_MOSI_PIN 12
  17. #define RLCD_DC_PIN 5
  18. #define RLCD_CS_PIN 40
  19. #define RLCD_RST_PIN 41
  20. #define RLCD_TE_PIN 6 // tearing effect output, unused
  21. // Layout: top 60% is time + date, bottom 40% is indoor | outdoor.
  22. #define LAYOUT_SPLIT_Y 180
  23. #define LAYOUT_MID_X 200
  24. // ------------------------------------------------------------------- i2c ---
  25. #define I2C_SDA_PIN 13
  26. #define I2C_SCL_PIN 14
  27. #define I2C_FREQ_HZ 400000
  28. #define PCF85063_ADDR 0x51
  29. #define SHTC3_ADDR 0x70
  30. // BH1750 ambient light sensor, wired to the same bus on the expansion header.
  31. // Optional: without it the display falls back to quiet hours from the clock.
  32. // The part answers on 0x23 with ADDR low and 0x5C with ADDR high; both are
  33. // probed at boot.
  34. #define BH1750_ADDR_LOW 0x23
  35. #define BH1750_ADDR_HIGH 0x5C
  36. // --------------------------------------------------------------- battery ---
  37. // 18650 voltage divider, per the vendor's 03_ADC_Test: ADC1 channel 3 with a
  38. // 1:3 divider, so the measured millivolts are multiplied by three.
  39. #define BATTERY_ADC_PIN 4
  40. #define BATTERY_DIVIDER 3.0f
  41. #define BATTERY_SAMPLES 16 // oversampling per reading
  42. #define BATTERY_READ_MS 60000UL
  43. // --------------------------------------------------------------- buttons ---
  44. // Both onboard buttons are active low. KEY is the application button; BOOT is
  45. // avoided because holding it at reset also enters the ROM download mode.
  46. #define KEY_BUTTON_PIN 18
  47. #define BOOT_BUTTON_PIN 0
  48. // Hold KEY for this long during power-up to force the setup portal.
  49. #define KEY_FORCE_SETUP_MS 1500
  50. // ------------------------------------------------------------------ time ---
  51. // Defaults for a freshly erased device; both are editable in the setup portal.
  52. #define NTP_SERVER_1 "pool.ntp.org"
  53. #define NTP_SERVER_2 "time.google.com"
  54. // POSIX TZ string for Australia/Hobart (AEST-10, AEDT from Oct to Apr).
  55. #define TIMEZONE_POSIX "AEST-10AEDT,M10.1.0,M4.1.0/3"
  56. // Clock and date presentation defaults; all three are editable in the setup
  57. // portal. DATE_FORMAT is a strftime(3) string — "%A %e %B" is "MONDAY 24
  58. // AUGUST".
  59. #define CLOCK_24H_DEFAULT true
  60. #define DATE_FORMAT "%A %e %B"
  61. #define DATE_UPPERCASE_DEFAULT true
  62. // ----------------------------------------------------------------- setup ---
  63. // Soft-AP the device raises when it has nothing to connect to. The password
  64. // must be at least 8 characters or the AP comes up open.
  65. #define SETUP_AP_SSID "TempDisplay-Setup"
  66. #define SETUP_AP_PASSWORD "temp1234"
  67. #define DEVICE_HOSTNAME "temp-display"
  68. // ------------------------------------------------------------ power save ---
  69. // 80 MHz is the lowest the ESP32-S3 can run with Wi-Fi active and leaves the
  70. // 80 MHz APB clock — and so the display SPI — untouched.
  71. #define CPU_FREQ_MHZ 80
  72. // Defaults for the power-saving settings, all editable in the setup portal.
  73. #define SHOW_BATTERY_DEFAULT true
  74. #define SLEEP_WHEN_DARK_DEFAULT true
  75. #define PANEL_LOW_POWER_DEFAULT true
  76. #define DARK_LUX_DEFAULT 5 // below this the room is unreadable
  77. #define QUIET_START_HOUR_DEFAULT 23 // used only when no sensor is fitted
  78. #define QUIET_END_HOUR_DEFAULT 6
  79. // Hysteresis, so a flickering or marginal reading cannot chatter the display
  80. // in and out of sleep. Waking needs a clearly brighter room than sleeping.
  81. #define DARK_LUX_HYSTERESIS 3.0f
  82. // While asleep in a dark room, wake this often to re-check the light level.
  83. // Short enough that the clock is at most one minute stale when the lights come
  84. // on, long enough that the duty cycle is well under 1%.
  85. #define DARK_RECHECK_MS 20000UL
  86. // -------------------------------------------------------------- intervals ---
  87. #define WIFI_CONNECT_TIMEOUT_MS 20000UL // give up on a connect attempt
  88. #define WIFI_RETRY_MS 60000UL // then retry this often
  89. #define NTP_RESYNC_MS (6UL * 60UL * 60UL * 1000UL)
  90. #define INDOOR_READ_MS 30000UL
  91. #define OUTDOOR_POLL_MS 30000UL
  92. #define OUTDOOR_STALE_MS (10UL * 60UL * 1000UL) // mark reading stale
  93. #define DISPLAY_TICK_MS 1000UL // check-for-change rate
  94. // ---------------------------------------------------------------- outdoor ---
  95. // HTTP timeout for one outdoor poll.
  96. #define OUTDOOR_HTTP_TIMEOUT_MS 5000
  97. // Plausible temperature range; readings outside it are rejected.
  98. #define TEMP_MIN_VALID -50.0f
  99. #define TEMP_MAX_VALID 80.0f
  100. // Optional development conveniences. include/secrets.h is gitignored; when it
  101. // exists its values seed a freshly erased device so a bench unit does not need
  102. // to be re-provisioned through the portal after every flash erase.
  103. #if __has_include("secrets.h")
  104. #include "secrets.h"
  105. #endif