From 377386dd66d79768c1d38a3642108ab503cd4a0a Mon Sep 17 00:00:00 2001 From: Yakumo Saki Date: Fri, 12 Feb 2021 23:19:17 +0900 Subject: [PATCH] v40 (#69) * start v40 development * CHANGE: CO2 alert lower values to 300 * [Feature] Enter setup mode API Fixes #46 * update readme * [Enhance] Add moving something to Setup mode display Fixes #44 * update readme * [Enhance] mDNS code ESP32 and ESP8266 are duplicated Fixes #60 * [Enhance] Alerts should not occur if no sensor connected Fixes #49 * update readme * fIX: compile error * fix #64 * CHANGE: Dont timer read if sensor not connected * CHANGE: No sensor No alert * FIX: Wait for reconfigure bar length invalid * update readme * refs #54 * [Feature] Air pressure delta Fixes #54 * [Feature] Air pressure delta Fixes #54 bigmode * v40 --- .editorconfig | 3 - README.md | 81 +++-- include/config.h | 6 +- include/{ => display}/display.h | 1 + include/{ => display}/display_formatter.h | 0 include/{ => display}/display_ssd1306.h | 7 +- include/{ => display}/display_st7789.h | 4 +- include/{ => display}/display_st7789_big.h | 0 include/{ => display}/display_st7789_normal.h | 0 include/display/display_util.h | 16 + include/{ => display}/scan_alert.h | 0 include/display/st7789_utils.h | 18 ++ include/display/u8g2_utils.h | 18 ++ include/display_util.h | 4 - include/global.h | 1 + include/log.h | 1 + include/main_normal.h | 2 +- include/sensors/adt7410.h | 8 +- include/sensors/am2320.h | 9 +- include/sensors/bh1750.h | 8 +- include/sensors/bme280.h | 7 +- include/sensors/lps22hb.h | 6 +- include/sensors/mhz19.h | 6 +- include/sensors/pressure_delta.h | 10 + include/sensors/tsl2561.h | 6 +- include/structs.h | 17 +- include/u8g2_utils.h | 13 - src/config.cpp | 14 +- src/display/display.cpp | 34 ++- src/display/display_formatter.cpp | 6 +- src/display/display_ssd1306.cpp | 81 ++++- ...89_big.cpp => display_st7789_mode_big.cpp} | 49 ++- ..._mock.cpp => display_st7789_mode_mock.cpp} | 2 +- ...mal.cpp => display_st7789_mode_normal.cpp} | 102 +++++-- ...789_impl.cpp => display_st7789_shared.cpp} | 26 +- src/display/display_util.cpp | 59 ++++ src/display/scan_alert.cpp | 35 ++- src/display/st7789_utils.cpp | 83 +++++ src/display/u8g2_utils.cpp | 64 +++- src/global.cpp | 11 +- src/halt.cpp | 2 +- src/main_normal mqtt.cpp | 2 +- src/main_normal.cpp | 288 ++++++++++-------- src/main_setup.cpp | 15 +- src/network/http_normal_esp32.cpp | 83 ----- src/network/http_normal_web.cpp | 12 +- src/network/http_setup.cpp | 2 +- src/network/http_setup_esp32.cpp | 86 ------ src/network/http_setup_web.cpp | 6 +- src/network/{mdns_esp32.cpp => mdns.cpp} | 8 +- src/network/mdns_esp8266_mdns.cpp | 31 -- src/network/wifi.cpp | 2 +- src/sensors/adt7410.cpp | 99 +++--- src/sensors/am2320.cpp | 14 +- src/sensors/bh1750.cpp | 14 +- src/sensors/bme280.cpp | 19 +- src/sensors/lps22hb.cpp | 64 ++-- src/sensors/mhz19b/mhz19_main.cpp | 16 +- src/sensors/mhz19b/mhz19_uart.cpp | 4 +- src/sensors/pressure_delta.cpp | 54 ++++ src/sensors/tsl2561.cpp | 79 +++-- src/utils/log.cpp | 4 + 62 files changed, 1105 insertions(+), 617 deletions(-) rename include/{ => display}/display.h (95%) rename include/{ => display}/display_formatter.h (100%) rename include/{ => display}/display_ssd1306.h (93%) rename include/{ => display}/display_st7789.h (92%) rename include/{ => display}/display_st7789_big.h (100%) rename include/{ => display}/display_st7789_normal.h (100%) create mode 100644 include/display/display_util.h rename include/{ => display}/scan_alert.h (100%) create mode 100644 include/display/st7789_utils.h create mode 100644 include/display/u8g2_utils.h delete mode 100644 include/display_util.h create mode 100644 include/sensors/pressure_delta.h delete mode 100644 include/u8g2_utils.h rename src/display/{display_st7789_big.cpp => display_st7789_mode_big.cpp} (70%) rename src/display/{display_st7789_mock.cpp => display_st7789_mode_mock.cpp} (93%) rename src/display/{display_st7789_normal.cpp => display_st7789_mode_normal.cpp} (59%) rename src/display/{display_st7789_impl.cpp => display_st7789_shared.cpp} (89%) create mode 100644 src/display/st7789_utils.cpp delete mode 100644 src/network/http_normal_esp32.cpp delete mode 100644 src/network/http_setup_esp32.cpp rename src/network/{mdns_esp32.cpp => mdns.cpp} (88%) delete mode 100644 src/network/mdns_esp8266_mdns.cpp create mode 100644 src/sensors/pressure_delta.cpp diff --git a/.editorconfig b/.editorconfig index 6cba485..e69de29 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,3 +0,0 @@ -[*.cpp, *.h] -indent_size = 4 -indent_style = tab \ No newline at end of file diff --git a/README.md b/README.md index ef4a10d..48b0707 100644 --- a/README.md +++ b/README.md @@ -118,14 +118,18 @@ Maybe I can support ST7789 on ESP8266. but not in TODO. ### http server -All endpoints are using GET Method +EnvBoyX has http API. -| ENDPOINT | description | -| ------------- | -------------------------- | -| / | returns sensor value as JSON.| -| /ping | returns pong. | -| /brightness?value= | set display brightness (0-255) 0 means OFF | -| /display?value=<1 or 0> | set display power (1 = ON / 0 = OFF) | +| METHOD | ENDPOINT | RETURN | description | +| ------ | ------------- | -------------------------- | +| GET | / | JSON | sensor value as JSON.| +| GET | /ping | TEXT | returns pong. | +| GET | /stastics | JSON | stastics JSON | +| GET | /brightness?value= | TEXT | set display brightness (0-255) 0 means OFF | +| GET | /display?value=<1 or 0> | TEXT | set display power (1 = ON / 0 = OFF) | +| POST | /goto_setup | TEXT | Go to setup mode at next boot | + +NOTE: There is no reboot API, because of security reason. #### note @@ -162,6 +166,27 @@ esptool.py write_flash 0x1000 filename.bin ## Version History +* BUGFIX: Bug fix +* FIX: Fix not bug, but not friendly behavior +* CHANGE: Change some behavior +* ADD: Add new function +* DROP: Delete some functions +* NOTE: other things + +### v40 + +* FIX: CO2 ppm alert value is not good. +* ADD: Add POST /goto_setup API. +* FIX: Delete unused source code. +* ADD: Add display invert (3sec) on setup mode (ST7789 / SSD1306) +* NOTE: platformio/espressif8266 @ 2.6.3 +* FIX: MHZ19B RX, TX Pin settings are fixed to GPIO 14,0 +* CHANGE: Stop prefixing "*" when co2ppm below 400 (use alerts for this purpose) +* FIX: Wait for reconfigure bar length invalid +* FIX: BME280: improve pressure precision (fix decimal values are truncated) +* ADD: Pressure delta +* CHANGE: ST7789: Normal: Dont show co2 when no co2 sensor. + ### v39 * CHANGE: CONFIG: Add SSD1306 / SH1106 switch @@ -196,12 +221,12 @@ esptool.py write_flash 0x1000 filename.bin ### v3.5 -* Config: version 9 (was 8) and using JSON format -* Config: Migration between versions +* CHANGE: Config: version 9 (was 8) and using JSON format +* ADD: Config: Migration between versions ### v3.4 -* Config: version 8 (was 6) +* CHANGE: Config: version 8 (was 6) * BUGFIX: SSD1306 not shown in Setup Mode * ADD: Default Brightness setting * ADD: Screen Flip setting @@ -216,46 +241,44 @@ esptool.py write_flash 0x1000 filename.bin ### v3.2 -* Avoid using delay +* FIX: Avoid using delay * ADD: I2C scan on startup. * BUGFIX: ESP8266: I2C not working * DROP: ESP8266: ST7789 is not supported (because of Pin config) ### v3.1 -* Add vertical display mode(bigger font. ST7789 only) -* Refactoring +* ADD: vertical display mode(bigger font. ST7789 only) +* FIX: Refactoring ### v3.0 -* Add ST7789 Support (T-Display) -* ST7789 is initial support, some screens are simplifyed. - -### v2.7 +* ADD: ST7789 Support (T-Display) +* NOTE: ST7789 is initial support, some screens are simplifyed. -Display item change. +### v2.7: Display item change update -* Delete alive indicator "*" after EnvBoyX string. -* Add alive indicator. EnvBoyX's "X" character now blinks. -* Delete prefix "IP:" before IP address -* Add mDNS name display. IP/mDNS display switches 3 sec interval. -* Abort TFT display implementation. +* CHANGE: Delete alive indicator "*" after EnvBoyX string. +* ADD: alive indicator. EnvBoyX's "X" character now blinks. +* CHANGE: prefix "IP:" before IP address +* ADD: mDNS name display. IP/mDNS display switches 3 sec interval. +* NOTE: Abort TFT display implementation. ### v2.6 -* Fix mDNS not working +* BUGFIX: Fix mDNS not working ### v2.5 -* Add /display endpoint. +* ADD: /display endpoint. ### v2.4 -* Add /brightness endpoint. +* ADD: /brightness endpoint. ### v2.3 -* Unifing EnvBoyX (ESP8266) and EnvBoyX32 (ESP32) again. +* FIX: Unifing EnvBoyX (ESP8266) and EnvBoyX32 (ESP32) again. ### v2.2 @@ -263,11 +286,11 @@ Display item change. ### v2.1 -* Split EnvBoyX (8266) and EnvBoyX32 (ESP32) +* FIX: Split EnvBoyX (8266) and EnvBoyX32 (ESP32) ### v2.0 -* Move to Platform.IO from Arduino IDE +* FIX: Move Arduino IDE to Platform.IO ### before v2.0 diff --git a/include/config.h b/include/config.h index 49120a4..fc6ddfd 100644 --- a/include/config.h +++ b/include/config.h @@ -13,7 +13,10 @@ void save_config(); void list_dir(); +/** config ok フラグファイルを作成する */ void create_configure_flag_file(); + +/** config ok フラグファイルを削除する */ void remove_configure_flag_file(); bool has_valid_config_file(); bool has_valid_config(); @@ -35,4 +38,5 @@ void trim_config(); void write_config_file(File f); /** ファイルを読んでconfig値にセット。closeはしない */ -bool read_config_file(File f, bool dump_config = false); \ No newline at end of file +bool read_config_file(File f, bool dump_config); +bool read_config_file(File f); \ No newline at end of file diff --git a/include/display.h b/include/display/display.h similarity index 95% rename from include/display.h rename to include/display/display.h index ef566be..6f18d57 100644 --- a/include/display.h +++ b/include/display/display.h @@ -1,5 +1,6 @@ #include +// セットアップモード表示 void disp_setup_startup_screen(String ipAddr); void disp_wifi_info(String ip, String mDNS); diff --git a/include/display_formatter.h b/include/display/display_formatter.h similarity index 100% rename from include/display_formatter.h rename to include/display/display_formatter.h diff --git a/include/display_ssd1306.h b/include/display/display_ssd1306.h similarity index 93% rename from include/display_ssd1306.h rename to include/display/display_ssd1306.h index 65a041d..5e3c59b 100644 --- a/include/display_ssd1306.h +++ b/include/display/display_ssd1306.h @@ -1,10 +1,13 @@ #include -void disp_ssd1306_wifi_info(String ip, String mDNS); +void disp_ssd1306_setup_startup_screen(String ipAddr, int disp_switch); + void disp_ssd1306_normal_startup_screen(String product_long); -void disp_ssd1306_setup_startup_screen(String ipAddr); + void disp_ssd1306_wait_for_reconfig_init(); void disp_ssd1306_wait_for_reconfig_bar(int now, const int max); + +void disp_ssd1306_wifi_info(String ip, String mDNS); void disp_ssd1306_wifi_starting(); void disp_ssd1306_wifi_error(); void disp_ssd1306_all_initialize_complete(); diff --git a/include/display_st7789.h b/include/display/display_st7789.h similarity index 92% rename from include/display_st7789.h rename to include/display/display_st7789.h index 9ae26d1..35d94c2 100644 --- a/include/display_st7789.h +++ b/include/display/display_st7789.h @@ -1,10 +1,12 @@ +#pragma once + #include // 使える使えないの判断フラグ ST7789_SUPPORTED -> define.cpp // このフラグで呼び出される実態が空っぽなのと実装されているものに分かれる。 /** ST7789V セットアップモード */ -void disp_st7789_setup_startup_screen(String ipAddr); +void disp_st7789_setup_startup_screen(String ipAddr, int disp_switch); void disp_st7789_wifi_info(String ip, String mDNS); void disp_st7789_normal_startup_screen(String product_long); diff --git a/include/display_st7789_big.h b/include/display/display_st7789_big.h similarity index 100% rename from include/display_st7789_big.h rename to include/display/display_st7789_big.h diff --git a/include/display_st7789_normal.h b/include/display/display_st7789_normal.h similarity index 100% rename from include/display_st7789_normal.h rename to include/display/display_st7789_normal.h diff --git a/include/display/display_util.h b/include/display/display_util.h new file mode 100644 index 0000000..d661143 --- /dev/null +++ b/include/display/display_util.h @@ -0,0 +1,16 @@ +#pragma once + +#include "structs.h" +typedef struct { + float value; + bool positive = false; // 値が0.1以上のプラス。プラスでもマイナスでもない場合に注意 + bool negative = false; // 絶対値が0.1以上のマイナス。プラスでもマイナスでもない場合に注意 + bool drawIcon = true; // 絶対値0.2以上 + String formattedValue; // プラス・マイナスを除去した数字だけフォーマット +} pressure_delta_t; + +bool has_caution(value_alerts_t alerts); +bool has_warning(value_alerts_t alerts); + +String format_air_pressure_delta(float value); +pressure_delta_t get_pressure_delta_struct(float pressureDelta); \ No newline at end of file diff --git a/include/scan_alert.h b/include/display/scan_alert.h similarity index 100% rename from include/scan_alert.h rename to include/display/scan_alert.h diff --git a/include/display/st7789_utils.h b/include/display/st7789_utils.h new file mode 100644 index 0000000..ec306fd --- /dev/null +++ b/include/display/st7789_utils.h @@ -0,0 +1,18 @@ +#include +#include + +extern TFT_eSPI tft; + +enum class ARROW_ICON { + NONE = 0, UP = 1, DOWN = 2, PLUS = 3, MINUS = 4 +}; + +/** + * 矢印を書く + */ +void draw_arrow(int x, int y, ARROW_ICON type, uint16_t color, int height, int width); + +/** + * 矢印を書く(12 x 22) + */ +void draw_arrow(int x, int y, ARROW_ICON type, uint16_t color); \ No newline at end of file diff --git a/include/display/u8g2_utils.h b/include/display/u8g2_utils.h new file mode 100644 index 0000000..f1f4f4c --- /dev/null +++ b/include/display/u8g2_utils.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +enum class TextAlign { LEFT = 1 , RIGHT = 2 }; + +enum class TextDecoration { NONE = 0 , BOX = 2, INVERT = 4 }; + +void draw_string(int x, int y, String valueString, TextAlign align, const uint8_t *font); +void draw_string(int x, int y, String valueString, TextAlign align); + +uint16_t draw_value(int x, int y, TextDecoration deco, TextAlign align, String valueString, const uint8_t *valueFont, String unitString, const uint8_t *unitFont); + +/** + * 画面反転切り替え。画面の内容は変更せずに反転する。 + * @param inverse true 反転する false しない + */ +void set_invert(bool inverse); \ No newline at end of file diff --git a/include/display_util.h b/include/display_util.h deleted file mode 100644 index e31eb0f..0000000 --- a/include/display_util.h +++ /dev/null @@ -1,4 +0,0 @@ -#include "structs.h" - -bool has_caution(value_alerts_t alerts); -bool has_warning(value_alerts_t alerts); \ No newline at end of file diff --git a/include/global.h b/include/global.h index ee54f5a..084d8b1 100644 --- a/include/global.h +++ b/include/global.h @@ -58,6 +58,7 @@ extern config_t config; // センサー値 // -------------------------------------------------------------------- extern sensor_values_t sensorValues; +extern sensor_characters_t sensorCharacters; // -------------------------------------------------------------------- // 統計情報 diff --git a/include/log.h b/include/log.h index a679c0b..5e8bee2 100644 --- a/include/log.h +++ b/include/log.h @@ -17,6 +17,7 @@ void i2clog(String msg); void stlog(String msg); void ssdlog(String msg); void statlog(String msg); +void pdeltalog(String msg); void haltlog(String msg); void debuglog(String msg); void sectionlog(String msg); diff --git a/include/main_normal.h b/include/main_normal.h index 491e2f5..92ab8b2 100644 --- a/include/main_normal.h +++ b/include/main_normal.h @@ -2,4 +2,4 @@ void init_sensors(); void setup_normal(); void loop_normal(); void read_data(); -void init_timer(); \ No newline at end of file +void add_timer_tasks(); \ No newline at end of file diff --git a/include/sensors/adt7410.h b/include/sensors/adt7410.h index 0362e6d..72c60ed 100644 --- a/include/sensors/adt7410.h +++ b/include/sensors/adt7410.h @@ -1,2 +1,8 @@ -void adt_setup(void); +#include "structs.h" + +sensor_characters_t adt_characters(); + +// 初期化 +bool adt_setup(void); + void adt_read_data(void); \ No newline at end of file diff --git a/include/sensors/am2320.h b/include/sensors/am2320.h index cdd6000..482fe65 100644 --- a/include/sensors/am2320.h +++ b/include/sensors/am2320.h @@ -1,2 +1,9 @@ -void am_setup(); +#include "structs.h" + +// +sensor_characters_t am_characters(); + +// 初期化 +bool am_setup(); + void am_read_data(); diff --git a/include/sensors/bh1750.h b/include/sensors/bh1750.h index ba7dd6a..055e3af 100644 --- a/include/sensors/bh1750.h +++ b/include/sensors/bh1750.h @@ -1,2 +1,8 @@ -void bh_setup(); +#include "structs.h" + +sensor_characters_t bh_characters(); + +// 初期化 +bool bh_setup(); + void bh_read_data(); diff --git a/include/sensors/bme280.h b/include/sensors/bme280.h index ddbe74b..b285a2b 100644 --- a/include/sensors/bme280.h +++ b/include/sensors/bme280.h @@ -1,2 +1,7 @@ -void bme_setup(); +#include "structs.h" + +sensor_characters_t bme_characters(); + +bool bme_setup(); + void bme_read_data(); \ No newline at end of file diff --git a/include/sensors/lps22hb.h b/include/sensors/lps22hb.h index cfc63e4..7269b76 100644 --- a/include/sensors/lps22hb.h +++ b/include/sensors/lps22hb.h @@ -1,2 +1,6 @@ -void lps_setup(void); +#include "structs.h" + +sensor_characters_t lps_characters(); + +bool lps_setup(void); void lps_read_data(); \ No newline at end of file diff --git a/include/sensors/mhz19.h b/include/sensors/mhz19.h index 7bb2a3b..22f712b 100644 --- a/include/sensors/mhz19.h +++ b/include/sensors/mhz19.h @@ -1,2 +1,6 @@ -void mhz_setup(); +#include "structs.h" + +sensor_characters_t mhz_characters(); + +bool mhz_setup(); void mhz_read_data(); \ No newline at end of file diff --git a/include/sensors/pressure_delta.h b/include/sensors/pressure_delta.h new file mode 100644 index 0000000..41c1f71 --- /dev/null +++ b/include/sensors/pressure_delta.h @@ -0,0 +1,10 @@ +// +// Air Pressure delta +// + +/** + * 差分比較用に今の気圧を蓄積します。 + */ +void store_air_pressure_history(); + +void store_air_pressure_delta(); diff --git a/include/sensors/tsl2561.h b/include/sensors/tsl2561.h index 83ec1ea..22b0c6c 100644 --- a/include/sensors/tsl2561.h +++ b/include/sensors/tsl2561.h @@ -1,2 +1,6 @@ -void tsl_setup(); +#include "structs.h" + +sensor_characters_t tsl_characters(); + +bool tsl_setup(); void read_data_tsl2561(); \ No newline at end of file diff --git a/include/structs.h b/include/structs.h index ed263dc..21fd65f 100644 --- a/include/structs.h +++ b/include/structs.h @@ -6,11 +6,12 @@ typedef struct { float temperature; float humidity; float pressure; + float pressureDelta; // not sensor value. computed from pressure float lux; float luxIr; int co2ppm; String co2ppmAccuracy; - int rssi; + int rssi; // not sensor value. get from wifi } sensor_values_t; typedef struct { @@ -75,3 +76,17 @@ typedef struct { config_alert_t luxAlerts; config_alert_t co2Alerts; } config_t; + +/** + * センサーごとにどの項目を測定できるかのフラグ + */ +typedef struct { + bool temperature = false; + bool humidity = false; + bool pressure = false; + bool lux = false; + bool luxIr = false; + bool co2ppm = false; + bool co2ppmAccuracy = false; + // int rssi; センサーじゃないので入れない +} sensor_characters_t; diff --git a/include/u8g2_utils.h b/include/u8g2_utils.h deleted file mode 100644 index bc36386..0000000 --- a/include/u8g2_utils.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -enum class TextAlign { LEFT = 1 , RIGHT = 2 }; - -enum class TextDecoration { NONE = 0 , BOX = 2, INVERT = 4 }; - -void draw_string(int x, int y, String valueString, TextAlign align, const uint8_t *font); - -void draw_string(int x, int y, String valueString, TextAlign align); - -void draw_value(int x, int y, String valueString, TextDecoration deco, TextAlign align); \ No newline at end of file diff --git a/src/config.cpp b/src/config.cpp index c634d50..b70ee4a 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -108,9 +108,9 @@ void set_default_config_value() config.luxAlerts.warning2.high = "99999"; config.co2Alerts.warning1.low = "0"; - config.co2Alerts.warning1.high = "390"; - config.co2Alerts.caution1.low = "390"; - config.co2Alerts.caution1.high = "398"; + config.co2Alerts.warning1.high = "200"; + config.co2Alerts.caution1.low = "200"; + config.co2Alerts.caution1.high = "300"; config.co2Alerts.caution2.low = "800"; config.co2Alerts.caution2.high = "1000"; config.co2Alerts.warning2.low = "1000"; @@ -305,7 +305,7 @@ bool read_config_alerts(config_alert_t& alerts, DynamicJsonDocument doc, String return ret; } -bool read_config_file(File f, bool dump_config = false) { +bool read_config_file(File f, bool dump_config) { set_default_config_value(); // とりあえずデフォルト値をロードしておく。 @@ -359,4 +359,8 @@ bool read_config_file(File f, bool dump_config = false) { ret = ret && read_config_alerts(config.co2Alerts, doc, CFG_CO2_ALERT); return ret; -} \ No newline at end of file +} + +bool read_config_file(File f) { + return read_config_file(f, false); +} diff --git a/src/display/display.cpp b/src/display/display.cpp index 726a047..12b2928 100644 --- a/src/display/display.cpp +++ b/src/display/display.cpp @@ -6,18 +6,19 @@ #include -#include "scan_alert.h" +#include "display/scan_alert.h" -#include "display_formatter.h" -#include "display_ssd1306.h" -#include "display_st7789.h" +#include "display/display_formatter.h" +#include "display/display_ssd1306.h" +#include "display/display_st7789.h" disp_values_t disp_values; -/** 右下のver表示を点滅させる為のフラグ - * 0~5 奇数 偶数= EnvBoyXのXの点滅 0,1,2 = IP表示 3,4,5 = mDNS名表示 +/** + * 表示変更用フラグ。 描画ごとに1カウントアップ。 0 ~ 15 */ int disp_switch = 0; +const int DISP_SWITCH_MAX = 15; /** SSD1306を使うか否か。 I2C接続なので自動チェック可能 */ bool use_ssd1306() { @@ -45,14 +46,21 @@ void disp_normal_startup_screen(String product_long) { /** * セットアップモード時のディスプレイ表示 - * SSD1306のみ対応。 */ void disp_setup_startup_screen(String ipAddr) { + + static int disp_switch = 0; + if (use_ssd1306()) { - disp_ssd1306_setup_startup_screen(ipAddr); + disp_ssd1306_setup_startup_screen(ipAddr, disp_switch); } if (use_st7789()) { - disp_st7789_setup_startup_screen(ipAddr); + disp_st7789_setup_startup_screen(ipAddr, disp_switch); + } + + disp_switch++; + if (disp_switch > 5) { + disp_switch = 0; } } @@ -104,7 +112,7 @@ void disp_wifi_error() { */ void disp_wait_for_reconfig() { - const int WAIT_PER_BAR = 30; + const int WAIT_PER_BAR = 33; // ms per bar const int MAX_BAR = 30; if (use_st7789()) { @@ -115,13 +123,13 @@ void disp_wait_for_reconfig() { } displog(F("Wait for reconfigure start")); - for (int i = 1; i <= (MAX_BAR + 1); i++) + for (int i = 0; i < MAX_BAR; i++) { if (use_st7789()) { - disp_st7789_wait_for_reconfig_bar(i, MAX_BAR); + disp_st7789_wait_for_reconfig_bar(i + 1, MAX_BAR); } if (use_ssd1306()) { - disp_ssd1306_wait_for_reconfig_bar(i, MAX_BAR); + disp_ssd1306_wait_for_reconfig_bar(i + 1, MAX_BAR); } delay(WAIT_PER_BAR); diff --git a/src/display/display_formatter.cpp b/src/display/display_formatter.cpp index 8fe78a3..30eacad 100644 --- a/src/display/display_formatter.cpp +++ b/src/display/display_formatter.cpp @@ -13,7 +13,7 @@ String format_humidity(float humi) { } String format_pressure(float pres) { - return String(pres, 0) + "hpa"; + return String(pres, 1); } String format_lux(float lux) { @@ -25,13 +25,11 @@ String format_co2_ppm(int ppm) { String result = String(ppm); if (ppm < 0) { result = "****"; // 計測エラー - } else if (ppm < 399) { - result = "*" + String(ppm); // あり得ない値(最低399ppmなはず) } else { result = String(ppm); // OK } - return result + "ppm"; + return result; } diff --git a/src/display/display_ssd1306.cpp b/src/display/display_ssd1306.cpp index 5c82d10..86ee854 100644 --- a/src/display/display_ssd1306.cpp +++ b/src/display/display_ssd1306.cpp @@ -6,7 +6,8 @@ #include "global.h" #include "log.h" -#include "u8g2_utils.h" +#include "display/display_util.h" +#include "display/u8g2_utils.h" // The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2_sh1106(U8G2_R0, U8X8_PIN_NONE, I2C_SCL, I2C_SDA); @@ -16,11 +17,21 @@ U8G2 u8g2; extern int disp_switch; +#if false +const String FONT_ARROW_UP = "@"; +const String FONT_ARROW_DOWN = "C"; +const uint8_t *FONT_ARROW = u8g2_font_open_iconic_arrow_1x_t; +#endif + +const String FONT_ARROW_UP = "["; +const String FONT_ARROW_DOWN = "]"; +const uint8_t *FONT_ARROW = u8g2_font_twelvedings_t_all; + +const uint8_t *FONT_SMALL_VERSION = u8g2_font_chikita_tn; const uint8_t *FONT_SMALL_NARROW = u8g2_font_t0_11_tr; -//const uint8_t *FONT_SMALL = u8g2_font_synchronizer_nbp_tr; const uint8_t *FONT_SMALL = u8g2_font_roentgen_nbp_tr; const uint8_t *FONT_BOOT = u8g2_font_ncenR10_tr; -const uint8_t *FONT_PLAIN_10 = u8g2_font_9x15_mr; +const uint8_t *FONT_PLAIN_10 = u8g2_font_9x15_tr; const uint8_t *FONT_SSID = u8g2_font_8x13_tr; const uint8_t WHITE = 1; @@ -90,12 +101,15 @@ void disp_ssd1306_normal_startup_screen(String product_long) { /** * セットアップモード時のディスプレイ表示 */ -void disp_ssd1306_setup_startup_screen(String ipAddr) { +void disp_ssd1306_setup_startup_screen(String ipAddr, int disp_switch) { if (!has_ssd1306()) return; init_u8g2(); + // 3秒ごとに反転 + set_invert(int(disp_switch / 3) == 0 ); + u8g2.setFont(FONT_BOOT); // u8g2.setTextAlignment(TextAlign::LEFT); u8g2.drawStr(0, 0, product_long.c_str()); @@ -166,7 +180,8 @@ void disp_ssd1306_wait_for_reconfig_init() { } void disp_ssd1306_wait_for_reconfig_bar(int now, const int max) { - int length = 127 / max * now; + float lengthF = 127.0 / max * now; + int length = (int)lengthF; if (now >= max) { length = 127; @@ -181,16 +196,36 @@ void disp_ssd1306_all_initialize_complete() { // do nothing. ssd1306 code is everytime rewrite entire screen. } -void write_value(int x, int y, String valueString, value_alert_t alert, TextAlign align) { +TextDecoration get_decoration_from_alert(value_alert_t alert) { if (alert.warning) { - draw_value(x, y, valueString, TextDecoration::INVERT, align); + return TextDecoration::INVERT; } else if (alert.caution) { - draw_value(x, y, valueString, TextDecoration::BOX, align); + return TextDecoration::BOX; } else { - draw_value(x, y, valueString, TextDecoration::NONE, align); + return TextDecoration::NONE; } } +void write_value(int x, int y, String valueString, value_alert_t alert, TextAlign align) { + String empty = String(""); + draw_value(x, y, get_decoration_from_alert(alert), align, valueString, FONT_PLAIN_10, empty, FONT_PLAIN_10); +} + +void _draw_pressure_delta(int y) { + // pressure delta + pressure_delta_t delta = get_pressure_delta_struct(sensorValues.pressureDelta); + + const int ICON_X = 80; + if (delta.drawIcon && delta.positive) { + draw_string(ICON_X, y, FONT_ARROW_UP, TextAlign::LEFT, FONT_ARROW); + } else if (delta.drawIcon && delta.negative) { + draw_string(ICON_X, y, FONT_ARROW_DOWN, TextAlign::LEFT, FONT_ARROW); + } else { + // ほぼ変わらないのでアイコンなし (-0.09 ~ 0.09) + } + draw_string(127, y, delta.formattedValue, TextAlign::RIGHT, FONT_PLAIN_10); +} + /** * 通常画面 */ @@ -213,16 +248,27 @@ void disp_ssd1306_sensor_value(disp_values_t values, value_alerts_t alerts) { write_value(127, R1, values.humidity, alerts.humidity, TextAlign::RIGHT); - write_value(0, R2, values.pressure, alerts.pressure, TextAlign::LEFT); + // 2行目:ひだり:気圧 + int presWidth = 0; + u8g2.setFont(FONT_PLAIN_10); + presWidth += u8g2.getStrWidth(values.pressure.c_str()); + u8g2.setFont(FONT_SMALL_NARROW); + presWidth += 4 + u8g2.getStrWidth("hPa"); - write_value(127, R2, values.lux, alerts.lux, TextAlign::RIGHT); + // write_value(0, R2, values.pressure, alerts.pressure, TextAlign::LEFT); + // draw_value(0, R2, get_decoration_from_alert(alerts.pressure), TextAlign::LEFT, values.pressure, FONT_PLAIN_10, "hPa", FONT_PLAIN_10); + draw_value(0, R2, TextDecoration::INVERT, TextAlign::LEFT, values.pressure, FONT_PLAIN_10, "hPa", FONT_SMALL_NARROW); - // CO2: に関しては値ではないので枠で囲まれることを想定したマージンが取られないのでここで位置をずらす - draw_string(1, R3, "CO2:", TextAlign::LEFT); - write_value(38, R3, values.co2ppm, alerts.co2, TextAlign::LEFT); // 9999ppm + // 2行目:みぎ:気圧の差 + _draw_pressure_delta(R2); - // バージョン表示 - draw_string(127, 54, ver, TextAlign::RIGHT, FONT_SMALL); + // 3行目:CO2センサーがないならその場所に照度を表示する + if (sensorCharacters.co2ppm) { + write_value(127, R3, values.lux, alerts.lux, TextAlign::RIGHT); + draw_value(0, R3, get_decoration_from_alert(alerts.co2), TextAlign::LEFT, values.co2ppm, FONT_PLAIN_10, "ppm", FONT_SMALL_NARROW); // 9999ppm + } else { + write_value(0, R3, values.lux, alerts.lux, TextAlign::LEFT); + } // みぎ上、IPアドレス or mDNS名表示 if (disp_switch < 3) { @@ -233,6 +279,9 @@ void disp_ssd1306_sensor_value(disp_values_t values, value_alerts_t alerts) { // 左上、EnvBoyX の表示 draw_string(0 , R0 + 1, product_short, TextAlign::LEFT, FONT_SMALL); + // バージョン表示 + draw_string(40, R0, ver, TextAlign::RIGHT, FONT_SMALL_VERSION); + disp_switch++; if (disp_switch > 5) { diff --git a/src/display/display_st7789_big.cpp b/src/display/display_st7789_mode_big.cpp similarity index 70% rename from src/display/display_st7789_big.cpp rename to src/display/display_st7789_mode_big.cpp index 0c93142..0e9de71 100644 --- a/src/display/display_st7789_big.cpp +++ b/src/display/display_st7789_mode_big.cpp @@ -1,11 +1,15 @@ -#ifdef ESP32 +#ifdef USER_SETUP_LOADED #include +#include "display/st7789_utils.h" +#include "display/display_util.h" + #include "global.h" #include "structs.h" #include "log.h" + #include #include @@ -47,7 +51,6 @@ const long R3_Y = R2_Y + R_HEIGHT + Y_PADDING + 4; const long R4_X = 127; const long R4_Y = R3_Y + R_HEIGHT + Y_PADDING + 6; - void _clear_screen_big() { tft.fillScreen(TFT_BLACK); @@ -59,7 +62,6 @@ void _clear_screen_big() { } } - /** * BIGモード:ヘッダ部分のみを表示する(この部分は変更されない) */ @@ -96,6 +98,9 @@ void write_values(int x, int y, String value, value_alert_t alert, int align) { */ void _disp_sensor_value_big(disp_values_t values, value_alerts_t alerts) { + static int tick = 0; + static bool showDelta = false; + sensor_values_t v = sensorValues; tft.setTextColor(TFT_WHITE, TFT_BLACK); @@ -119,7 +124,33 @@ void _disp_sensor_value_big(disp_values_t values, value_alerts_t alerts) tft.drawString("p", R3_X + 1, R3_Y + 15, SMALL_FONT); tft.drawString("a", R3_X + 1, R3_Y + 31, SMALL_FONT); - write_values(R3_X, R3_Y, String(v.pressure, 0), alerts.pressure, TR_DATUM); + if (showDelta) { + // 気圧差分表示 + pressure_delta_t delta = get_pressure_delta_struct(sensorValues.pressureDelta); + + tft.setTextDatum(TR_DATUM); + if (delta.positive) { + tft.setTextColor(TFT_GREENYELLOW, TFT_BLACK); + tft.drawString(delta.formattedValue, R3_X, R3_Y, DIGIT_FONT); + } else if (delta.negative) { + tft.setTextColor(TFT_ORANGE, TFT_BLACK); + tft.drawString(delta.formattedValue, R3_X, R3_Y, DIGIT_FONT); + } else { + tft.setTextColor(TFT_WHITE, TFT_BLACK); // ゼロ + tft.drawString(delta.formattedValue, R3_X, R3_Y, DIGIT_FONT); + } + + if (delta.drawIcon && delta.positive) { + draw_arrow(0 + 3, R3_Y + 8, ARROW_ICON::PLUS, TFT_GREENYELLOW, 34, 22); + } else if (delta.drawIcon && delta.negative) { + draw_arrow(0 + 3, R3_Y + 8, ARROW_ICON::MINUS, TFT_ORANGE, 34, 22); + } else { + draw_arrow(0 + 3, R3_Y + 8, ARROW_ICON::NONE, TFT_BLACK, 34, 22); + } + } else { + // 気圧表示 + write_values(R3_X, R3_Y, String(v.pressure, 0), alerts.pressure, TR_DATUM); + } tft.drawFastHLine(4, R3_Y + 28 + 27, TFT_WIDTH - 6, TFT_DARKGREY); tft.drawFastHLine(4, R3_Y + 28 + 28, TFT_WIDTH - 6, TFT_DARKGREY); @@ -128,8 +159,8 @@ void _disp_sensor_value_big(disp_values_t values, value_alerts_t alerts) tft.setTextDatum(TL_DATUM); if (config.mhz19b == MHZ_NOUSE) { - tft.drawString("l", R4_X + 1, R4_Y + 20, SMALL_FONT); - tft.drawString("x", R4_X + 1, R4_Y + 36, SMALL_FONT); + tft.drawString("L", R4_X + 1, R4_Y + 20, SMALL_FONT); + tft.drawString("X", R4_X + 1, R4_Y + 36, SMALL_FONT); write_values(R4_X, R4_Y, String(v.lux, 0), alerts.lux, TR_DATUM); } else { tft.drawString("p", R4_X + 1, R4_Y + 2, SMALL_FONT); @@ -137,6 +168,12 @@ void _disp_sensor_value_big(disp_values_t values, value_alerts_t alerts) tft.drawString("m", R4_X + 1, R4_Y + 36, SMALL_FONT); write_values(R4_X, R4_Y, String(v.co2ppm), alerts.co2, TR_DATUM); } + + tick++; + if (tick > 5) { + tick = 0; + showDelta = !showDelta; + } } #endif \ No newline at end of file diff --git a/src/display/display_st7789_mock.cpp b/src/display/display_st7789_mode_mock.cpp similarity index 93% rename from src/display/display_st7789_mock.cpp rename to src/display/display_st7789_mode_mock.cpp index 330488c..f97d58d 100644 --- a/src/display/display_st7789_mock.cpp +++ b/src/display/display_st7789_mode_mock.cpp @@ -6,7 +6,7 @@ #include "global.h" #include "structs.h" -void disp_st7789_setup_startup_screen(String ipAddr) {} +void disp_st7789_setup_startup_screen(String ipAddr, int disp_switch) {} void disp_st7789_wifi_info(String ip, String mDNS) {} void disp_st7789_normal_startup_screen(String product_long) {} diff --git a/src/display/display_st7789_normal.cpp b/src/display/display_st7789_mode_normal.cpp similarity index 59% rename from src/display/display_st7789_normal.cpp rename to src/display/display_st7789_mode_normal.cpp index 392b6ad..60b70a8 100644 --- a/src/display/display_st7789_normal.cpp +++ b/src/display/display_st7789_mode_normal.cpp @@ -1,11 +1,12 @@ -#ifdef ESP32 +#ifdef USER_SETUP_LOADED #include #include "global.h" #include "structs.h" #include "log.h" -#include "display_util.h" +#include "display/display_util.h" +#include "display/st7789_utils.h" #include #include @@ -42,7 +43,7 @@ const int LEFT_VAL_X = LEFT_HEAD_X + HEAD_WIDTH; const int RIGHT_VAL_X = RIGHT_HEAD_X + HEAD_WIDTH; const int VALUE_WIDTH = RIGHT_HEAD_X - LEFT_HEAD_X - HEAD_WIDTH; -const int VALUE_WIDTH_LONG = 180; // Pressure or CO2 ppm +const int VALUE_WIDTH_LONG = VALUE_WIDTH + 12; // Pressure or CO2 ppm const int ROW_HEIGHT = 28; const int ROW1_Y = 24; @@ -81,7 +82,7 @@ void _disp_header_normal(String ip, String mDNS) // X 影→本体の順で書かないと重なった部分が上書きされるのに注意 tft.setTextColor(TFT_SILVER); - tft.drawString("X", 53, 2, SMALL_FONT); + tft.drawString("X", 51, 2, SMALL_FONT); tft.setTextColor(TFT_WHITE); tft.drawString("X", 50, 0, SMALL_FONT); @@ -102,8 +103,10 @@ void _disp_header_normal(String ip, String mDNS) tft.setTextDatum(TR_DATUM); tft.drawString("T:", LEFT_HEAD_R_ALIGN_X, ROW1_Y, DEFAULT_FONT); - tft.setTextDatum(TL_DATUM); - tft.drawString("L:", RIGHT_HEAD_X, ROW1_Y, DEFAULT_FONT); + if (sensorCharacters.co2ppm) { + tft.setTextDatum(TL_DATUM); + tft.drawString("L:", RIGHT_HEAD_X, ROW1_Y, DEFAULT_FONT); + } // Row 2 tft.setTextColor(TFT_WHITE); @@ -116,55 +119,112 @@ void _disp_header_normal(String ip, String mDNS) tft.drawString("P:", LEFT_HEAD_R_ALIGN_X, ROW3_Y, DEFAULT_FONT); // Row 4 - tft.setTextColor(TFT_WHITE); - tft.setTextDatum(TL_DATUM); - tft.drawString("CO2:", LEFT_HEAD_X, ROW4_Y, DEFAULT_FONT); - + if (sensorCharacters.co2ppm) { + tft.setTextColor(TFT_WHITE); + tft.setTextDatum(TL_DATUM); + tft.drawString("CO2:", LEFT_HEAD_X, ROW4_Y, DEFAULT_FONT); + } else { + tft.setTextDatum(TR_DATUM); + tft.drawString("L:", LEFT_HEAD_R_ALIGN_X, ROW4_Y, DEFAULT_FONT); + } } -void write_value(String value, int x, int y, int width, int font, value_alert_t alert) { +// 値を書き込む(単位あり、フォント違い) +void write_value(String value, int x, int y, int width, int valueFont, value_alert_t alert, String unit, int unitFont) { + + // 値と単位のフォントの高さを調整するための値を決める + int unitFontDiffY = 0; + if (valueFont == DEFAULT_FONT) { + if (unitFont == SMALL_FONT) { + unitFontDiffY = 6; + } + } + if (alert.warning) { tft.setTextColor(TFT_RED, TFT_BLACK); } else if (alert.caution) { tft.setTextColor(TFT_YELLOW, TFT_BLACK); } else { - tft.setTextColor(TFT_WHITE, TFT_BLACK); + tft.setTextColor(TFT_WHITE, TFT_BLACK); } tft.setTextPadding(width); - tft.drawString(value, x, y, font); + int written = tft.drawString(value, x, y, valueFont); + + if (unit != "") { + tft.setTextPadding(width - written); + tft.drawString(unit, x + written + 1, y + unitFontDiffY, unitFont); + } tft.setTextColor(TFT_WHITE, TFT_BLACK); +} +// 値を書き込む(単位無し or 値と同じフォント) +void write_value(String value, int x, int y, int width, int font, value_alert_t alert) { + write_value(value, x, y, width, font, alert, "", DEFAULT_FONT); } /** * @param val 値 - * @param erase true => 黒文字で書く(要するに消す) false => 普通に書く - * eraseは一応機能するが */ void _disp_sensor_value_normal(disp_values_t values, value_alerts_t alerts) { tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextSize(1); + tft.setTextDatum(TL_DATUM); // Row 1 write_value(values.temperature, LEFT_VAL_X, ROW1_Y, VALUE_WIDTH, DEFAULT_FONT, alerts.temperature); - write_value(values.lux, RIGHT_VAL_X, ROW1_Y, VALUE_WIDTH, DEFAULT_FONT, alerts.lux); + if (sensorCharacters.co2ppm) { + write_value(values.lux, RIGHT_VAL_X, ROW1_Y, VALUE_WIDTH, DEFAULT_FONT, alerts.lux); + } // Row 2 - tft.setTextPadding(VALUE_WIDTH); write_value(values.humidity, LEFT_VAL_X, ROW2_Y, VALUE_WIDTH, DEFAULT_FONT, alerts.humidity); // Row 3 - tft.setTextPadding(VALUE_WIDTH_LONG); - write_value(values.pressure, LEFT_VAL_X, ROW3_Y, VALUE_WIDTH_LONG, DEFAULT_FONT, alerts.pressure); + write_value(values.pressure, LEFT_VAL_X, ROW3_Y, VALUE_WIDTH_LONG, DEFAULT_FONT, alerts.pressure, "hPa", SMALL_FONT); + + // Air pressure delta + tft.setTextPadding(VALUE_WIDTH); + + int presDeltaX = LEFT_VAL_X + VALUE_WIDTH_LONG + 20; + pressure_delta_t delta = get_pressure_delta_struct(sensorValues.pressureDelta); + + // 気圧の変化 + int presDeltaStrX = presDeltaX + 20; + tft.setTextPadding(60); + + // 気圧deltaの文字 + if (delta.positive) { + tft.setTextColor(TFT_GREENYELLOW, TFT_BLACK); + } else if (delta.negative) { + tft.setTextColor(TFT_ORANGE, TFT_BLACK); + } else { + tft.setTextColor(TFT_WHITE, TFT_BLACK); + } + + tft.drawString(delta.formattedValue, presDeltaStrX, ROW3_Y, DEFAULT_FONT); + + // 気圧deltaのアイコン + if (delta.positive && delta.drawIcon) { + draw_arrow(presDeltaX, ROW3_Y, ARROW_ICON::UP, TFT_GREENYELLOW); + } else if (delta.negative && delta.drawIcon) { + draw_arrow(presDeltaX, ROW3_Y, ARROW_ICON::DOWN, TFT_ORANGE); + } else { + draw_arrow(presDeltaX, ROW3_Y, ARROW_ICON::NONE, TFT_ORANGE); + } // Row 4 - tft.setTextPadding(VALUE_WIDTH_LONG); - write_value(values.co2ppm, LEFT_VAL_X + HEAD_WIDTH, ROW4_Y, VALUE_WIDTH_LONG, DEFAULT_FONT, alerts.co2); + if (sensorCharacters.co2ppm) { + tft.setTextColor(TFT_WHITE, TFT_BLACK); + write_value(values.co2ppm, LEFT_VAL_X + HEAD_WIDTH, ROW4_Y, VALUE_WIDTH_LONG, DEFAULT_FONT, alerts.co2, "ppm", SMALL_FONT); + } else { + write_value(values.lux, LEFT_VAL_X, ROW4_Y, VALUE_WIDTH, DEFAULT_FONT, alerts.lux); + } + // Alert color if (has_caution(alerts)) { tft.fillRect(0, ROW1_Y, SIDE_LINE_WIDTH, MAX_Y, TFT_YELLOW); tft.fillRect(MAX_X - SIDE_LINE_WIDTH, ROW1_Y, MAX_X, MAX_Y, TFT_YELLOW); diff --git a/src/display/display_st7789_impl.cpp b/src/display/display_st7789_shared.cpp similarity index 89% rename from src/display/display_st7789_impl.cpp rename to src/display/display_st7789_shared.cpp index 3df38ed..ae6426a 100644 --- a/src/display/display_st7789_impl.cpp +++ b/src/display/display_st7789_shared.cpp @@ -13,8 +13,8 @@ #include #include -#include "display_st7789_big.h" -#include "display_st7789_normal.h" +#include "display/display_st7789_big.h" +#include "display/display_st7789_normal.h" extern int disp_switch; const int ST7789_PWM_LED_CHANNEL = 0; @@ -76,13 +76,25 @@ void disp_st7789_normal_startup_screen(String product_long) /** * セットアップモード時のディスプレイ表示 */ -void disp_st7789_setup_startup_screen(String ipAddr) +void disp_st7789_setup_startup_screen(String ipAddr, int disp_switch) { + static bool inverted = false; + if (disp_switch % 3 == 0) { + inverted = !inverted; + } else { + return; // 変更ないので抜ける。書き直すとチラつく。 + } + tft.startWrite(); clear_screen(true); + if (inverted) { + tft.fillScreen(TFT_WHITE); + tft.setTextColor(TFT_BLACK, TFT_WHITE); + } else { + tft.fillScreen(TFT_BLACK); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + } tft.setCursor(0, 0, DEFAULT_FONT); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - tft.println(product_long); tft.println("Setup Mode"); @@ -163,7 +175,6 @@ void disp_st7789_message(bool isError, String msg1, String msg2, String msg3, St */ void disp_st7789_wait_for_reconfig_init() { - tft.startWrite(); clear_screen(); @@ -181,7 +192,7 @@ void disp_st7789_wait_for_reconfig_init() void disp_st7789_wait_for_reconfig_bar(int now, const int max) { - int length = getWidth() / max * now; + int length = (float)getWidth() / max * now; if (now >= max) { length = getWidth(); @@ -194,6 +205,7 @@ void disp_st7789_wait_for_reconfig_bar(int now, const int max) void disp_st7789_power_off() { // display.displayOff(); + stlog("Not implemented."); } diff --git a/src/display/display_util.cpp b/src/display/display_util.cpp index f2ea9ff..da81414 100644 --- a/src/display/display_util.cpp +++ b/src/display/display_util.cpp @@ -1,6 +1,9 @@ #include #include "structs.h" +#include "log.h" +#include "display/display_util.h" + bool has_caution(value_alerts_t alerts) { if (alerts.temperature.caution || alerts.humidity.caution @@ -21,4 +24,60 @@ bool has_warning(value_alerts_t alerts) { return true; } return false; +} + +/** + * 気圧の差を表示形式にして返す + * マイナス値はアイコンで表示するので符号は不要 + */ +String format_air_pressure_delta(float value) { + + String pressureDelta; + + // 0.05の計算は、String()で切り上げをしてほしくないため + if (value == 0.0) { + pressureDelta = "0.0"; + } else if (0.0 < value && value < 0.1) { + pressureDelta = "0.0"; + } else if (-0.1 < value && value < 0.0) { + pressureDelta = "0.0"; + } else if (value < 0.0) { + float v = value + 0.09; + pressureDelta = String(-1.0 * v, 1); + } else if (value > 0.0) { + float v = value - 0.09; + pressureDelta = String(1.0 * v, 1); + } else { + pdeltalog("Unknown value " + String(value)); + } + + return pressureDelta; +} + +pressure_delta_t get_pressure_delta_struct(float pressureDelta) { + + pressure_delta_t ret; + + ret.value = pressureDelta; + + if (-0.1 < pressureDelta && pressureDelta < 0.1) { + // -0.1〜0.1までの間は表示上 0.0 になるので 0と同じ扱い + } else if (pressureDelta > 0) { + ret.positive = true; + } else if (pressureDelta < 0) { + ret.negative = true; + } + + // アイコンを書くか否か + if (pressureDelta > 0.2) { + ret.drawIcon = true; + } else if (pressureDelta < -0.2) { + ret.drawIcon = true; + } else { + ret.drawIcon = false; + } + + ret.formattedValue = format_air_pressure_delta(pressureDelta); + + return ret; } \ No newline at end of file diff --git a/src/display/scan_alert.cpp b/src/display/scan_alert.cpp index e78dfc6..8b4cdde 100644 --- a/src/display/scan_alert.cpp +++ b/src/display/scan_alert.cpp @@ -4,6 +4,7 @@ #include "log.h" #include "structs.h" +/** 指定された値が範囲内かチェックする */ bool in_range(float value, config_alert_range_t range) { float low = atof(range.low.c_str()); float high = atof(range.high.c_str()); @@ -15,6 +16,7 @@ bool in_range(float value, config_alert_range_t range) { return false; } +/** 指定された値がアラートor警告範囲内かチェックして結果を返す */ value_alert_t check_alert(float value, config_alert_t alerts) { value_alert_t ans; @@ -27,26 +29,31 @@ void log_alert(value_alert_t alert, String name) { displog(name + " CAUTION = " + String(alert.caution) + " WARNING=" + String(alert.warning)); } +/** + * アラートをスキャンするエントリポイント + */ value_alerts_t check_for_alerts() { value_alerts_t alerts; - alerts.temperature = check_alert(sensorValues.temperature, config.temperatureAlerts); - alerts.humidity = check_alert(sensorValues.humidity, config.humidityAlerts); - alerts.lux = check_alert(sensorValues.lux, config.luxAlerts); - alerts.pressure = check_alert(sensorValues.pressure, config.pressureAlerts); + if (sensorCharacters.temperature) { + alerts.temperature = check_alert(sensorValues.temperature, config.temperatureAlerts); + } - if (config.mhz19b != MHZ_NOUSE) { - alerts.co2 = check_alert(sensorValues.co2ppm, config.co2Alerts); - } else { - alerts.co2.caution = false; - alerts.co2.warning = false; + if (sensorCharacters.humidity) { + alerts.humidity = check_alert(sensorValues.humidity, config.humidityAlerts); + } + + if (sensorCharacters.lux) { + alerts.lux = check_alert(sensorValues.lux, config.luxAlerts); } - // log_alert(alerts.temperature, "Temperature"); - // log_alert(alerts.humidity, "Humidity "); - // log_alert(alerts.lux, "lux "); - // log_alert(alerts.pressure, "Pressure "); - // log_alert(alerts.co2, "CO2 "); + if (sensorCharacters.pressure) { + alerts.pressure = check_alert(sensorValues.pressure, config.pressureAlerts); + } + + if (sensorCharacters.co2ppm) { + alerts.co2 = check_alert(sensorValues.co2ppm, config.co2Alerts); + } return alerts; } \ No newline at end of file diff --git a/src/display/st7789_utils.cpp b/src/display/st7789_utils.cpp new file mode 100644 index 0000000..bf2995a --- /dev/null +++ b/src/display/st7789_utils.cpp @@ -0,0 +1,83 @@ +#ifdef USER_SETUP_LOADED + +#include +#include +#include "display/st7789_utils.h" + +#include "log.h" + +extern TFT_eSPI tft; + +void _draw_arrow_up(int x, int y, int width, int height, uint16_t color) { + int half = width / 2; + int halfX = x + half; + int rightX = x + width; + int halfY = y + (height / 2); + int bottomY = y + height; + + tft.drawLine(halfX, y, halfX, bottomY, color); + tft.drawLine(x, halfY, halfX, y, color); + tft.drawLine(halfX, y, rightX, halfY, color); +} + +void _draw_arrow_down(int x, int y, int width, int height, uint16_t color) { + int half = width / 2; + int halfX = x + half; + int rightX = x + width; + int halfY = y + (height / 2); + int bottomY = y + height; + + tft.drawLine(x, y, rightX, bottomY, color); + tft.drawLine(x - 1, y, rightX, bottomY, color); + tft.drawLine(x + 1, y, rightX, bottomY, color); + tft.drawTriangle(rightX, halfY, rightX, bottomY, halfX, bottomY, color); + + halfX--; + rightX--; + halfY--; + bottomY--; + tft.drawTriangle(rightX, halfY, rightX, bottomY, halfX, bottomY, color); +} + +void _draw_plus_minus(int x, int y, int width, int height, uint16_t color, bool isPlus) { + const int RADIUS = 2; + const int FUTOSA = 7; + int half = width / 2; + int halfX = x + half - (FUTOSA / 2.0); + int halfY = y + (height / 2.0) - (FUTOSA / 2.0); + + tft.fillRoundRect(x, halfY, width, FUTOSA, RADIUS, color); // 横 + + if (isPlus) { + tft.fillRoundRect(halfX, y, FUTOSA, height, RADIUS, color); // たて + } +} + + +void draw_arrow(int x, int y, ARROW_ICON type, uint16_t color, int height, int width) { + int HEIGHT = height; + int WIDTH = width; + + tft.fillRect(x - 1, y, WIDTH + 3, HEIGHT + 1, TFT_BLACK); + + if (type == ARROW_ICON::UP) { + _draw_arrow_up(x, y, WIDTH, HEIGHT, color); + _draw_arrow_up(x + 1, y, WIDTH, HEIGHT, color); + } else if (type == ARROW_ICON::DOWN) { + _draw_arrow_down(x, y, WIDTH, HEIGHT, color); + } else if (type == ARROW_ICON::PLUS) { + _draw_plus_minus(x, y, WIDTH, HEIGHT, color, true); + } else if (type == ARROW_ICON::MINUS) { + _draw_plus_minus(x, y, WIDTH, HEIGHT, color, false); + } else if (type == ARROW_ICON::NONE) { + // 削除済みなのでOK + } else { + stlog("BUG: Unknown type"); + } +} + +void draw_arrow(int x, int y, ARROW_ICON type, uint16_t color) { + draw_arrow(x, y, type, color, 22, 12); +} + +#endif \ No newline at end of file diff --git a/src/display/u8g2_utils.cpp b/src/display/u8g2_utils.cpp index 4d75f20..dc330bf 100644 --- a/src/display/u8g2_utils.cpp +++ b/src/display/u8g2_utils.cpp @@ -36,27 +36,49 @@ void draw_string(int x, int y, String valueString, TextAlign align, const uint8_ draw_string(x, y, valueString, align); } -void draw_value(int x, int y, String valueString, TextDecoration deco, TextAlign align) { - - const int HEIGHT = u8g2.getMaxCharHeight(); - - // 警告表示の時用のマージン。通常表示と警告表示で場所が変わるのはイマイチなので通常時も適用する - const int MARGIN = 1; +// 値を描画する +uint16_t draw_value(int x, int y, TextDecoration deco, TextAlign align, String valueString, const uint8_t *valueFont, String unitString, const uint8_t *unitFont) { + + const int MARGIN = 1; // 警告表示の時用のマージン。通常表示と警告表示で場所が変わるのはイマイチなので通常時も適用する const int RECT_MARGIN = 1 + MARGIN; // 枠 1px + マージン 2px - uint16_t boxWidth = u8g2.getStrWidth(valueString.c_str()) + (RECT_MARGIN * 2); // *2 = 左右 + // フォントの高さを求める + u8g2.setFont(valueFont); + const int HEIGHT = u8g2.getMaxCharHeight(); + u8g2.setFont(unitFont); + // 単位が値より背が低い場合、下方向にずらす + int UNIT_HEIGHT_MARGIN = (HEIGHT - u8g2.getMaxCharHeight()) < 0 ? 0 : HEIGHT - u8g2.getMaxCharHeight(); + + // 幅を求める + int valueWidth = 0, unitWidth = 0; + u8g2.setFont(valueFont); + valueWidth = u8g2.getStrWidth(valueString.c_str()); + if (unitString != "") { + u8g2.setFont(unitFont); + unitWidth = u8g2.getStrWidth(unitString.c_str()); + } + + const int MARGIN_VAL_UNIT = (unitWidth == 0 ? 0 : 2); // 単位と値の間のマージン + + uint16_t boxWidth = valueWidth + MARGIN_VAL_UNIT + unitWidth + (RECT_MARGIN * 2); // *2 = 左右 int boxStartX = 0; // 枠を描画する位置 int strStartX = 0; // 文字を描画する位置 + int unitStartX = 0; // 単位を描画する位置 if (align == TextAlign::LEFT) { boxStartX = x; strStartX = boxStartX + MARGIN; + unitStartX = strStartX + valueWidth + MARGIN_VAL_UNIT; } else if (align == TextAlign::RIGHT) { - boxStartX = x - boxWidth; // 枠の描画位置は左から指定しないといけない マージンは左右にあるので二回 - strStartX = x - RECT_MARGIN; // 文字は右端を指定する + boxStartX = x - boxWidth; // 枠の描画位置は左から指定 + strStartX = x - RECT_MARGIN - (unitWidth + MARGIN_VAL_UNIT); + unitStartX = x - RECT_MARGIN; } + // 背景塗りつぶし無し + u8g2.setFontMode(1); + if (deco == TextDecoration::BOX || deco == TextDecoration::INVERT) { // 枠 or 塗りつぶし @@ -67,20 +89,40 @@ void draw_value(int x, int y, String valueString, TextDecoration deco, TextAlign // 反転した際は太字にする(細いとよみづらい) u8g2.setDrawColor(BLACK); u8g2.setFontMode(1); // これをしないと DrawColor = BLACK の時 背景の白も書かれてしまう + + u8g2.setFont(valueFont); draw_string(strStartX, y, valueString, align); draw_string(strStartX - 1, y, valueString, align); - - u8g2.setFontMode(0); // もとに戻す + + u8g2.setFont(unitFont); + draw_string(unitStartX, y + UNIT_HEIGHT_MARGIN, unitString, align); + draw_string(unitStartX - 1, y + UNIT_HEIGHT_MARGIN, unitString, align); } else if (deco == TextDecoration::BOX) { + u8g2.setFont(valueFont); draw_string(strStartX, y, valueString, align); + + u8g2.setFont(unitFont); + draw_string(unitStartX, y + UNIT_HEIGHT_MARGIN, unitString, align); + u8g2.drawFrame(boxStartX, y - 1, boxWidth, HEIGHT); } } else { // 通常表示 u8g2.setDrawColor(WHITE); draw_string(strStartX, y, valueString, align); + } + u8g2.setFontMode(0); u8g2.setDrawColor(WHITE); // + return boxWidth; } + +void set_invert(bool inverse) { + if (inverse) { + u8g2.sendF("c", 0xa7); + } else { + u8g2.sendF("c", 0xa6); + } +} \ No newline at end of file diff --git a/src/global.cpp b/src/global.cpp index 1d5683a..c3f1a12 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -1,6 +1,7 @@ #include #include #include "structs.h" +#include "TimerCall.h" // -------------------------------------------------------------------- // プロダクト名定数 @@ -9,7 +10,7 @@ extern const String product_short = "EBX"; // EnvBoyX extern const String product = "EnvBoyX"; -extern const String ver = "39"; +extern const String ver = "40"; // EnvBoyX Ver.3.0 extern const String product_long = product + " Ver." + ver; @@ -80,8 +81,14 @@ config_t config; // センサー値 // -------------------------------------------------------------------- sensor_values_t sensorValues; +sensor_characters_t sensorCharacters; // -------------------------------------------------------------------- // 統計情報 // -------------------------------------------------------------------- -String stasticsJSON; \ No newline at end of file +String stasticsJSON; + +// -------------------------------------------------------------------- +// タイマー +// -------------------------------------------------------------------- +TimerCall timer = TimerCall(); diff --git a/src/halt.cpp b/src/halt.cpp index ac050fa..fa34229 100644 --- a/src/halt.cpp +++ b/src/halt.cpp @@ -1,5 +1,5 @@ #include -#include "display.h" +#include "display/display.h" #include "log.h" #include "watchdog.h" diff --git a/src/main_normal mqtt.cpp b/src/main_normal mqtt.cpp index 7b7f068..3ede2f5 100644 --- a/src/main_normal mqtt.cpp +++ b/src/main_normal mqtt.cpp @@ -63,7 +63,7 @@ void send_and_sleep() { } mainlog(F("MQTT Connect OK")); - init_timer(); + add_timer_tasks(); timer.forceOnce(); mqtt_publish("lux", String(sensorValues.lux, 0)); diff --git a/src/main_normal.cpp b/src/main_normal.cpp index 1c5d7f4..11767e1 100644 --- a/src/main_normal.cpp +++ b/src/main_normal.cpp @@ -1,193 +1,217 @@ #include - +#include #include #include -#include -#include "log.h" +#include "config.h" +#include "display/display.h" #include "global.h" -#include "display.h" -#include "sensors/bme280.h" +#include "halt.h" +#include "http_normal.h" +#include "i2c.h" +#include "log.h" +#include "main_normal_mqtt.h" +#include "mdns_client.h" #include "sensors/adt7410.h" #include "sensors/am2320.h" #include "sensors/bh1750.h" +#include "sensors/bme280.h" #include "sensors/lps22hb.h" #include "sensors/mhz19.h" #include "sensors/tsl2561.h" -#include "http_normal.h" -#include "config.h" -#include "wifi.h" -#include "mdns_client.h" - -#include "i2c.h" -#include "main_normal_mqtt.h" +#include "sensors/pressure_delta.h" #include "watchdog.h" -#include "halt.h" +#include "wifi.h" WiFiClient net; -TimerCall timer = TimerCall(); +extern TimerCall timer; extern String stasticsJSON; -void init_sensors() -{ - sectionlog(F("Initializing sensors start.")); - bme_setup(); - adt_setup(); - am_setup(); - bh_setup(); - lps_setup(); - tsl_setup(); - - if (config.mhz19b != MHZ_NOUSE) - { - mhz_setup(); +bool merge_sensor_characters(sensor_characters_t c) { + sensorCharacters.temperature = sensorCharacters.temperature || c.temperature; + sensorCharacters.humidity = sensorCharacters.humidity || c.humidity; + sensorCharacters.pressure = sensorCharacters.pressure || c.pressure; + sensorCharacters.lux = sensorCharacters.lux || c.lux; + sensorCharacters.luxIr = sensorCharacters.luxIr || c.luxIr; + sensorCharacters.co2ppm = sensorCharacters.co2ppm || c.co2ppm; + sensorCharacters.co2ppmAccuracy = + sensorCharacters.co2ppmAccuracy || c.co2ppmAccuracy; + + return true; +} + +void init_sensors() { + sectionlog(F("Initializing sensors start.")); + if (bme_setup()) { + merge_sensor_characters(bme_characters()); + timer.add(bme_read_data, "BME280", 1000); + } + + if (adt_setup()) { + merge_sensor_characters(adt_characters()); + timer.add(adt_read_data, "ADT7410", 1000); + } + + if (am_setup()) { + merge_sensor_characters(am_characters()); + timer.add(am_read_data, "AM2320", 2000); + } + + if (bh_setup()) { + merge_sensor_characters(bh_characters()); + timer.add(bh_read_data, "BH1750", 2000); + } + + if (lps_setup()) { + merge_sensor_characters(lps_characters()); + timer.add(lps_read_data, "LPS22HB", 1000); + } + + if (tsl_setup()) { + merge_sensor_characters(tsl_characters()); + timer.add(read_data_tsl2561, "TSL2561", 1000); + } + + if (mhz_setup()) { + merge_sensor_characters(mhz_characters()); + timer.add(mhz_read_data, "MHZ19B", 3000); } - sectionlog(F("Initializing sensors done.")); + + sectionlog(F("Initializing sensors done.")); } void call_disp_sensor_value() { - disp_sensor_value(get_wifi_ip_addr(), config.mDNS); + disp_sensor_value(get_wifi_ip_addr(), config.mDNS); } // 統計情報を取得 void updateStastics(std::vector &tasks) { + const String STAT = "stastics"; + + DynamicJsonDocument doc(500); + doc["time"] = millis(); + + int idx = 0; + for (auto it = tasks.begin(), e = tasks.end(); it != e; ++it) { + statlog(+"name=" + String(it->info.name) + + " last=" + String(it->info.lastExecMills) + + " last exec=" + String(it->info.lastElapsedMills) + + " total=" + String(it->info.totalElapsedMills) + + " count=" + String(it->info.callCount)); + + // 統計 + doc[STAT][idx]["name"] = String(it->info.name); + doc[STAT][idx]["lastExecMs"] = it->info.lastExecMills; + doc[STAT][idx]["lastElapsedMs"] = it->info.lastElapsedMills; + doc[STAT][idx]["totalElapsedMs"] = it->info.totalElapsedMills; + doc[STAT][idx]["callCount"] = it->info.callCount; + idx++; + } + +#ifdef ESP32 + doc["cputemp"] = temperatureRead(); // CPU温度 +#endif + + String json = ""; + serializeJson(doc, json); + stasticsJSON = json; +} - const String STAT = "stastics"; - - DynamicJsonDocument doc(500); - doc["time"] = millis(); - - int idx = 0; - for (auto it = tasks.begin(), e = tasks.end(); it != e; ++it) { - statlog( - + "name=" + String(it->info.name) - + " last=" + String(it->info.lastExecMills) - + " last exec=" + String(it->info.lastElapsedMills) - + " total=" + String(it->info.totalElapsedMills) - + " count=" + String(it->info.callCount) - ); - - // 統計 - doc[STAT][idx]["name"] = String(it->info.name); - doc[STAT][idx]["lastExecMs"] = it->info.lastExecMills; - doc[STAT][idx]["lastElapsedMs"] = it->info.lastElapsedMills; - doc[STAT][idx]["totalElapsedMs"] = it->info.totalElapsedMills; - doc[STAT][idx]["callCount"] = it->info.callCount; - idx++; - } - - #ifdef ESP32 - doc["cputemp"] = temperatureRead(); // CPU温度 - #endif - - String json = ""; - serializeJson(doc, json); - stasticsJSON = json; +// センサー読み込み以外のタスクをタイマーに追加する +void add_timer_tasks() { + timer.add(wifi_store_rssi, "WIFI", 1000); -} + if (sensorCharacters.pressure) { + timer.add(store_air_pressure_history, "STORE_PRESSURE", 60000); // 履歴を毎分保存 + timer.add(store_air_pressure_delta, "STORE_PRESSURE_DELTA", 1000); // 履歴と今の気圧の差を保存 + } -void init_timer() { - mainlog("TimerCall version: " + String(timer.VERSION, 2)); - timer.add(bme_read_data, "BME280", 1000); - timer.add(am_read_data, "AM2320", 2000); - timer.add(adt_read_data, "ADT7410", 1000); - timer.add(lps_read_data, "LPS22HB", 1000); - timer.add(read_data_tsl2561, "TSL2561", 1000); - timer.add(bh_read_data, "BH1750", 2000); - timer.add(mhz_read_data, "MHZ19B", 3000); - - timer.add(wifi_store_rssi, "WIFI", 1000); - - - // 画面表示はセンサー読み込みよりあとに実行したいので最後に追加する - timer.add(call_disp_sensor_value, "DISP", 1000); - timer.addStasticsFunction(updateStastics, "STAT", 60000); + // 画面表示はセンサー読み込みよりあとに実行したいので最後に追加する + timer.add(call_disp_sensor_value, "DISP", 1000); + timer.addStasticsFunction(updateStastics, "STAT", 60000); } /** * 通常起動モードのSETUP */ -void setup_normal() -{ - // Init I2C Serial - init_i2c(I2C_SDA, I2C_SCL); +void setup_normal() { + // Init I2C Serial + init_i2c(I2C_SDA, I2C_SCL); - bool config_ok = read_config(); + bool config_ok = read_config(); - sectionlog(F("Setup display")); - setup_display(); + sectionlog(F("Setup display")); + setup_display(); - if (!config_ok) { - mainlog("[MAYBE BUG] Config read failed dropping to setup mode"); - remove_configure_flag_file(); - halt("config err", "setup again", "Reset now"); - } - - if (config.opMode == OPMODE_MQTT) - { - setup_normal_mqtt(); - return; // MQTTモードの場合はもう戻ってこない(ディープスリープする) - } + if (!config_ok) { + mainlog("[MAYBE BUG] Config read failed dropping to setup mode"); + remove_configure_flag_file(); + halt("config err", "setup again", "Reset now"); + } - sectionlog(F("Start watchdog")); - setup_watchdog(); + if (config.opMode == OPMODE_MQTT) { + setup_normal_mqtt(); + return; // MQTTモードの場合はもう戻ってこない(ディープスリープする) + } - // 起動画面 - disp_normal_startup_screen(product_long); + sectionlog(F("Start watchdog")); + setup_watchdog(); - // setupモードに入りやすくするための処理 - sectionlog(F("Reset to reconfig start.")); - remove_configure_flag_file(); + // 起動画面 + disp_normal_startup_screen(product_long); - disp_wait_for_reconfig(); + // setupモードに入りやすくするための処理 + sectionlog(F("Reset to reconfig start.")); + remove_configure_flag_file(); - // 設定済みフラグファイル - create_configure_flag_file(); + disp_wait_for_reconfig(); - sectionlog(F("Reconfigure timeout. continue.")); + // 設定済みフラグファイル + create_configure_flag_file(); - // start WiFi - sectionlog(F("Connecting WiFi.")); - disp_wifi_starting(1); - make_sure_wifi_connected(); - disp_wifi_info(get_wifi_ip_addr(), config.mDNS); + sectionlog(F("Reconfigure timeout. continue.")); - mdns_setup(); + // start WiFi + sectionlog(F("Connecting WiFi.")); + disp_wifi_starting(1); + make_sure_wifi_connected(); + disp_wifi_info(get_wifi_ip_addr(), config.mDNS); - sectionlog(F("Starting HTTP server.")); - http_setup_normal(); + mdns_setup(); - init_sensors(); + sectionlog(F("Starting HTTP server.")); + http_setup_normal(); - // TimerCall - init_timer(); - timer.forceRunStasticsOnce(); + mainlog("TimerCall version: " + String(timer.VERSION, 2)); + init_sensors(); - // 初期化終了時に画面表示をどうにかできるフック - disp_all_initialize_complete(get_wifi_ip_addr(), config.mDNS); + // TimerCall + add_timer_tasks(); + timer.forceRunStasticsOnce(); + // 初期化終了時に画面表示をどうにかできるフック + disp_all_initialize_complete(get_wifi_ip_addr(), config.mDNS); } /** * LOOP */ -void loop_normal() -{ - // sectionlog("loop start"); - watchdog_feed(); +void loop_normal() { + // sectionlog("loop start"); + watchdog_feed(); - // WiFiが繋がってなければ意味がないので接続チェック - make_sure_wifi_connected(); + // WiFiが繋がってなければ意味がないので接続チェック + make_sure_wifi_connected(); - // mainlog("WiFi connected. IP=" + get_wifi_ip_addr()); + // mainlog("WiFi connected. IP=" + get_wifi_ip_addr()); - timer.start(); - timer.loop(); + timer.start(); + timer.loop(); - http_loop_normal(); + http_loop_normal(); - // mainlog("Wait for Next tick."); + // mainlog("Wait for Next tick."); - watchdog_feed(); + watchdog_feed(); } diff --git a/src/main_setup.cpp b/src/main_setup.cpp index 5b9c1c8..5cb1131 100644 --- a/src/main_setup.cpp +++ b/src/main_setup.cpp @@ -7,12 +7,19 @@ #endif #include "log.h" -#include "display.h" +#include "display/display.h" #include "global.h" #include "config.h" #include "http_setup.h" #include "wifi.h" #include "i2c.h" +#include "TimerCall.h" + +extern TimerCall timer; + +void show_setup_startup_screen() { + disp_setup_startup_screen(WiFi.softAPIP().toString()); +} /** * 初期化 @@ -34,11 +41,15 @@ void setup_setupmode() { init_i2c(I2C_SDA, I2C_SCL); setup_display(); - disp_setup_startup_screen(WiFi.softAPIP().toString()); + show_setup_startup_screen(); + + timer.add(show_setup_startup_screen, "DISP", 1000); + timer.start(); mainlog(F("Setup complete.")); } void loop_setupmode() { + timer.loop(); loop_http_setup(); } \ No newline at end of file diff --git a/src/network/http_normal_esp32.cpp b/src/network/http_normal_esp32.cpp deleted file mode 100644 index f2defc3..0000000 --- a/src/network/http_normal_esp32.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#ifdef false - -#include - -#include "log.h" -#include "global.h" - -#include "http_normal.h" -#include "display.h" - -#include -#include -#include - -extern AsyncWebServer server; - -void http_handle_not_found(AsyncWebServerRequest *request) { - String message = http_normal_not_found_html(); - request->send ( 404, MIME_TEXT, message ); -} - -void http_handle_data(AsyncWebServerRequest *request) { - String message = http_normal_data_json(); - request->send ( 200, MIME_JSON, message ); -} - -void http_handle_ping(AsyncWebServerRequest *request) { - String message = http_normal_ping_json(); - request->send ( 200, MIME_JSON, message ); -} - -void http_handle_stastics(AsyncWebServerRequest *request) { - request->send ( 200, MIME_JSON, stasticsJSON ); -} - - -void http_handle_brightness(AsyncWebServerRequest *request) { - if (!request->hasParam("value")) { - request->send ( 400, MIME_TEXT, "no value param"); - return; - } - - int brightness = request->getParam("value")->value().toInt(); - String msg = disp_set_brightness(brightness); - - String message = "OK\n" + msg; - request->send ( 200, MIME_TEXT, message ); -} - -void http_handle_power(AsyncWebServerRequest *request) { - if (!request->hasParam("value")) { - request->send ( 400, MIME_TEXT, "no value param"); - return; - } - - int power = request->getParam("value")->value().toInt(); - - if (power == 1) { - disp_set_power(true); - } else { - disp_set_power(false); - } - - String message = "OK"; - request->send ( 200, MIME_TEXT, message ); -} - -void http_setup_normal() { - httplog(F("HTTP web server initializing")); - server.on ( "/ping", HTTP_GET, http_handle_ping); - server.on ( "/", HTTP_GET, http_handle_data ); - server.on ( "/brightness", HTTP_GET, http_handle_brightness ); - server.on ( "/display", HTTP_GET, http_handle_brightness ); - server.on ( "/stastics", HTTP_GET, http_handle_stastics ); - server.onNotFound ( http_handle_not_found ); - server.begin(); - httplog(F("HTTP web server initialized")); -} - -void http_loop_normal() { -} - -#endif \ No newline at end of file diff --git a/src/network/http_normal_web.cpp b/src/network/http_normal_web.cpp index 3430add..ede0019 100644 --- a/src/network/http_normal_web.cpp +++ b/src/network/http_normal_web.cpp @@ -6,7 +6,8 @@ #include "config.h" #include "http_normal.h" -#include "display.h" +#include "display/display.h" +#include "config.h" #ifdef ESP32 #include @@ -57,6 +58,14 @@ void http_handle_power() { server.send( 200, MIME_TEXT, message ); } +void http_handle_goto_setup() { + + remove_configure_flag_file(); + + String message = "OK. Entering setup mode at next boot."; + server.send( 200, MIME_TEXT, message ); +} + void http_setup_normal() { httplog("HTTP web server initializing"); server.on ( "/ping", HTTP_GET, http_handle_ping); @@ -64,6 +73,7 @@ void http_setup_normal() { server.on ( "/brightness", HTTP_GET, http_handle_brightness ); server.on ( "/display", HTTP_GET, http_handle_power ); server.on ( "/stastics", HTTP_GET, http_handle_stastics ); + server.on ( "/goto_setup", HTTP_POST, http_handle_goto_setup ); server.onNotFound ( http_handle_not_found ); server.begin(); diff --git a/src/network/http_setup.cpp b/src/network/http_setup.cpp index 5c834fe..8445bcd 100644 --- a/src/network/http_setup.cpp +++ b/src/network/http_setup.cpp @@ -7,7 +7,7 @@ #endif #include "log.h" -#include "display.h" +#include "display/display.h" #include "global.h" #include "config.h" diff --git a/src/network/http_setup_esp32.cpp b/src/network/http_setup_esp32.cpp deleted file mode 100644 index 986f231..0000000 --- a/src/network/http_setup_esp32.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#ifdef false - -#include - -#include "log.h" -#include "global.h" -#include "config.h" - -#include "http_setup.h" - -#include -#include -#include - -extern AsyncWebServer server; - -/** - * GET 設定画面 - */ -void handle_get_root(AsyncWebServerRequest *request) { - - String html = http_setup_get_root_content(); - - request->send(200, "text/html", html); -} - -void alerts_to_config(AsyncWebServerRequest *request, config_alert_t& alerts, String prefix) { - alerts.caution1.low = request->getParam(prefix + "caution1.low", true)->value(); - alerts.caution1.high = request->getParam(prefix + "caution1.high", true)->value(); - alerts.caution2.low = request->getParam(prefix + "caution2.low", true)->value(); - alerts.caution2.high = request->getParam(prefix + "caution2.high", true)->value(); - - alerts.warning1.low = request->getParam(prefix + "warning1.low", true)->value(); - alerts.warning1.high = request->getParam(prefix + "warning1.high", true)->value(); - alerts.warning2.low = request->getParam(prefix + "warning2.low", true)->value(); - alerts.warning2.high = request->getParam(prefix + "warning2.high", true)->value(); -} - -/** - * Post 設定 ( config の post。 ファイルに設定を保存) - */ -void handle_post_root(AsyncWebServerRequest *request) { - - config.ssid = request->getParam("ssid", true)->value(); - config.password = request->getParam("pass", true)->value(); - config.mDNS = request->getParam("mdnsname", true)->value(); - config.opMode = request->getParam("opmode", true)->value(); - config.displayFlip = request->getParam("displayFlip", true)->value(); - config.displayBrightness = request->getParam("displayBrightness", true)->value(); - config.st7789 = request->getParam("st7789", true)->value(); - config.st7789Mode = request->getParam("st7789Mode", true)->value(); - config.mhz19b = request->getParam("mhz19b", true)->value(); - config.mhz19bPwmPin = request->getParam("mhz19bPwmPin", true)->value(); - config.mhz19bRxPin = request->getParam("mhz19bRxPin", true)->value(); - config.mhz19bTxPin = request->getParam("mhz19bTxPin", true)->value(); - config.mqttBroker = request->getParam("mqttbroker", true)->value(); - config.mqttName = request->getParam("mqttname", true)->value(); - - alerts_to_config(request, config.temperatureAlerts, "tempAlerts."); - alerts_to_config(request, config.humidityAlerts, "humiAlerts."); - alerts_to_config(request, config.luxAlerts, "luxAlerts."); - alerts_to_config(request, config.pressureAlerts, "presAlerts."); - alerts_to_config(request, config.co2Alerts, "co2Alerts."); - - trim_config(); - String html = http_setup_post_root_content(); - - request->send(200, "text/html", html); -} - -/** - * 初期化(設定用Webサーバモード) - */ -void setup_http_setup() { - httplog("HTTP web server initializing"); - server.on("/", HTTP_GET, handle_get_root); - server.on("/", HTTP_POST, handle_post_root); - server.begin(); - httplog("HTTP web server initialized"); -} - -void loop_http_setup() { - -} - -#endif \ No newline at end of file diff --git a/src/network/http_setup_web.cpp b/src/network/http_setup_web.cpp index b38a52e..4dc4f0f 100644 --- a/src/network/http_setup_web.cpp +++ b/src/network/http_setup_web.cpp @@ -54,9 +54,9 @@ void handle_post_root() { config.st7789Mode = server.arg("st7789Mode"); config.mhz19b = server.arg("mhz19b"); config.mhz19bPwmPin = server.arg("mhz19bPwmPin"); - // SoftwareSerialの初期化時にこれを渡す方法がわからないので固定 - config.mhz19bRxPin = "14"; - config.mhz19bTxPin = "0"; + + config.mhz19bRxPin = server.arg("mhz19bRxPin"); + config.mhz19bTxPin = server.arg("mhz19bTxPin");; config.mqttBroker = server.arg("mqttbroker"); config.mqttName = server.arg("mqttname"); diff --git a/src/network/mdns_esp32.cpp b/src/network/mdns.cpp similarity index 88% rename from src/network/mdns_esp32.cpp rename to src/network/mdns.cpp index 01a7254..6d02466 100644 --- a/src/network/mdns_esp32.cpp +++ b/src/network/mdns.cpp @@ -1,8 +1,12 @@ -#ifdef ESP32 #include +#ifdef ESP32 #include +#endif +#ifdef ESP8266 +#include +#endif #include "global.h" #include "config.h" @@ -28,5 +32,5 @@ void mdns_setup() { } void mdns_loop() { + // do nothing } -#endif \ No newline at end of file diff --git a/src/network/mdns_esp8266_mdns.cpp b/src/network/mdns_esp8266_mdns.cpp deleted file mode 100644 index c213ba5..0000000 --- a/src/network/mdns_esp8266_mdns.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifdef ESP8266 - -#include -#include - -#include "global.h" -#include "config.h" -#include "log.h" - -bool start_mdns(String name) { - char n[name.length() + 1]; - name.toCharArray(n, sizeof n); - - mdnslog("mDNS responder starting"); - - if (!MDNS.begin(n)) { - mdnslog("Error setting up MDNS responder!"); - return false; - } - mdnslog("mDNS responder started name=" + name); - return true; -} - -void mdns_setup() { - sectionlog("Starting mDNS server."); - start_mdns(config.mDNS); -} - -void mdns_loop() { -} -#endif \ No newline at end of file diff --git a/src/network/wifi.cpp b/src/network/wifi.cpp index bf2963d..80788b1 100644 --- a/src/network/wifi.cpp +++ b/src/network/wifi.cpp @@ -10,7 +10,7 @@ #include "log.h" #include "global.h" #include "watchdog.h" -#include "display.h" +#include "display/display.h" std::vector rssiArray; diff --git a/src/sensors/adt7410.cpp b/src/sensors/adt7410.cpp index da3ef87..da9af8f 100644 --- a/src/sensors/adt7410.cpp +++ b/src/sensors/adt7410.cpp @@ -8,55 +8,68 @@ const uint8_t ADT7410_ADDR = 0x48; bool use_adt7410 = false; -bool has_adt7410() { +sensor_characters_t adt_characters() { + sensor_characters_t sensor; - Wire.beginTransmission(ADT7410_ADDR); // S.C発行,CB送信 - byte error = Wire.endTransmission(); + sensor.temperature = true; + return sensor; +} + +bool has_adt7410() +{ + + Wire.beginTransmission(ADT7410_ADDR); // S.C発行,CB送信 + byte error = Wire.endTransmission(); -// if (error != 0) { -// Serial.print("Error adt7410 connection: " + error); -// } - return (error == 0); + // if (error != 0) { + // Serial.print("Error adt7410 connection: " + error); + // } + return (error == 0); } // 初期化 -void adt_setup(void) { - - if (!has_adt7410()) { - adtlog(F("ADT7410 disabled")); - return; - } - - Wire.beginTransmission(ADT7410_ADDR); - Wire.write(0x03); - Wire.write(0x00 | 0x80); - Wire.endTransmission(); - use_adt7410 = true; +bool adt_setup(void) +{ + if (!has_adt7410()) + { + adtlog(F("ADT7410 disabled")); + return false; + } + + Wire.beginTransmission(ADT7410_ADDR); + Wire.write(0x03); + Wire.write(0x00 | 0x80); + Wire.endTransmission(); + use_adt7410 = true; + return true; } // メインループ -void adt_read_data(void) { - - if (!use_adt7410) { - return; - } - - uint16_t val0; - float tmp0; - long int ival0; - - Wire.requestFrom(ADT7410_ADDR, (uint8_t) 2); // S.C発行,CB送信 - val0 = (uint16_t) Wire.read() << 8; // データの読み出し(上位) - val0 |= Wire.read(); // データの読み出し(下位) - - ival0 = (long int)val0; - if(val0 & 0x8000) { // 符号判定 - // 負数 - ival0 = ival0 - 65536; - } - tmp0 = (float)ival0 / 128.0; - - adtlog("Temp is " + String(tmp0)); - - sensorValues.temperature = tmp0; +void adt_read_data(void) +{ + + if (!use_adt7410) + { + return; + } + + uint16_t val0; + float tmp0; + long int ival0; + + Wire.requestFrom(ADT7410_ADDR, (uint8_t)2); // S.C発行,CB送信 + val0 = (uint16_t)Wire.read() << 8; // データの読み出し(上位) + val0 |= Wire.read(); // データの読み出し(下位) + + ival0 = (long int)val0; + if (val0 & 0x8000) + { // 符号判定 + // 負数 + ival0 = ival0 - 65536; + } + tmp0 = (float)ival0 / 128.0; + + adtlog("Temp is " + String(tmp0)); + + sensorValues.temperature = tmp0; } diff --git a/src/sensors/am2320.cpp b/src/sensors/am2320.cpp index cd65270..f2e51f0 100644 --- a/src/sensors/am2320.cpp +++ b/src/sensors/am2320.cpp @@ -11,18 +11,26 @@ AM232X AM2320; const uint8_t AM2320_ADDR = 0x5C; bool use_am2320 = false; -void am_setup(void) { +sensor_characters_t am_characters() { + sensor_characters_t sensor; - AM2320.begin(I2C_SDA, I2C_SCL); + sensor.temperature = true; + sensor.humidity = true; + return sensor; +} + +bool am_setup(void) { + AM2320.begin(I2C_SDA, I2C_SCL); if (!AM2320.isConnected()) { amlog(F("AM2320 disabled. ")); - return; + return false; } amlog(F("AM2320 Enabled")); use_am2320 = true; + return true; } void am_read_data() { diff --git a/src/sensors/bh1750.cpp b/src/sensors/bh1750.cpp index c1e242d..b97e137 100644 --- a/src/sensors/bh1750.cpp +++ b/src/sensors/bh1750.cpp @@ -11,23 +11,31 @@ BH1750 bh1750(0x23); const byte BH1750_ADDR = 0x23; bool use_bh1750 = false; -void bh_setup(void) { +sensor_characters_t bh_characters() { + sensor_characters_t sensor; + + sensor.lux = true; + return sensor; +} + +bool bh_setup(void) { Wire.beginTransmission(BH1750_ADDR); byte error = Wire.endTransmission(); if (!(error == 0)) { amlog(F("BH1750 disabled. ")); - return; + return false; } if (!bh1750.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) { amlog(F("BH1750 disabled: Device found but initialize error. ")); - return; + return false; } amlog(F("BH1750 Enabled")); use_bh1750 = true; + return true; } void bh_read_data() { diff --git a/src/sensors/bme280.cpp b/src/sensors/bme280.cpp index 36ae3c7..c1277f3 100644 --- a/src/sensors/bme280.cpp +++ b/src/sensors/bme280.cpp @@ -18,6 +18,16 @@ const uint8_t BME_ADDR = 0x76; static bool use_bme = false; +sensor_characters_t bme_characters() { + sensor_characters_t sensor; + + sensor.temperature = true; + sensor.humidity = true; + sensor.pressure = true; + + return sensor; +} + bool has_bme() { // check i2c 0x76 Wire.beginTransmission(BME_ADDR); @@ -31,22 +41,23 @@ bool has_bme() { return true; } -void bme_setup() { +bool bme_setup() { if (!has_bme()) { use_bme = false; bmelog(F("BME280 disabled.")); - return; + return false; } // init BME while(!bme.init()){ bmelog(F("Initloop: Could not find BME280 sensor!")); - delay(1000); + return false; } bmelog(F("BME280 Enabled")); use_bme = true; + return true; } void bme_read_data() { @@ -67,7 +78,7 @@ void bme_read_data() { // pres = pres / 100; temp = bme.getTemperature(); - pres = bme.getPressure() / 100; + pres = bme.getPressure() / 100.0; hum = bme.getHumidity(); char log[80]; diff --git a/src/sensors/lps22hb.cpp b/src/sensors/lps22hb.cpp index 2ec8272..7b4bfaa 100644 --- a/src/sensors/lps22hb.cpp +++ b/src/sensors/lps22hb.cpp @@ -13,29 +13,47 @@ Sodaq_LPS22HB lps22hb; bool use_lps22hb = false; -void lps_setup(void) { - - // init LPS22HB if found (0x5d) - if (lps22hb.init()) { - lpslog(F("LPS22HB Enabled. Barometric sensor initialization succeeded!")); - lps22hb.enableSensor(Sodaq_LPS22HB::OdrOneShot); - use_lps22hb = true; - } else { - lpslog(F("LPS22HB disabled. Barometric sensor initialization failed.")); - use_lps22hb = false; - } +sensor_characters_t lps_characters() { + sensor_characters_t sensor; + + sensor.temperature = true; + sensor.humidity = true; + sensor.pressure = true; + + return sensor; +} + +bool lps_setup(void) +{ + // init LPS22HB if found (0x5d) + if (lps22hb.init()) + { + lpslog(F("LPS22HB Enabled. Barometric sensor initialization succeeded!")); + lps22hb.enableSensor(Sodaq_LPS22HB::OdrOneShot); + use_lps22hb = true; + return true; + } + else + { + lpslog(F("LPS22HB disabled. Barometric sensor initialization failed.")); + use_lps22hb = false; + return false; + } } -void lps_read_data() { - if (!use_lps22hb) { - return; - } - - float tempPres(NAN); - tempPres = lps22hb.readPressureHPA(); - if (tempPres != 0) { - sensorValues.pressure = tempPres; - - lpslog("Pressure=" + String(tempPres, 2) + "hPa"); - } +void lps_read_data() +{ + if (!use_lps22hb) + { + return; + } + + float tempPres(NAN); + tempPres = lps22hb.readPressureHPA(); + if (tempPres != 0) + { + sensorValues.pressure = tempPres; + + lpslog("Pressure=" + String(tempPres, 2) + "hPa"); + } } diff --git a/src/sensors/mhz19b/mhz19_main.cpp b/src/sensors/mhz19b/mhz19_main.cpp index b22f477..708e2e4 100644 --- a/src/sensors/mhz19b/mhz19_main.cpp +++ b/src/sensors/mhz19b/mhz19_main.cpp @@ -11,6 +11,16 @@ bool USE_PWM = true; int CO2_PPM_INVALID = -999; +sensor_characters_t mhz_characters() { + sensor_characters_t sensor; + + sensor.co2ppm = true; + sensor.co2ppmAccuracy = true; + + return sensor; +} + + void mhz_read_data() { if (config.mhz19b == MHZ_NOUSE) { @@ -25,10 +35,11 @@ void mhz_read_data() { } -void mhz_setup() { +bool mhz_setup() { if (config.mhz19b == MHZ_NOUSE) { mhzlog(F("disabled.")); - return; + sensorValues.co2ppm = CO2_PPM_INVALID; + return false; } USE_PWM = (config.mhz19b == MHZ_USE_PWM); @@ -40,4 +51,5 @@ void mhz_setup() { mhzlog(F("Using UART mode.")); mhz_setup_uart(); } + return true; } diff --git a/src/sensors/mhz19b/mhz19_uart.cpp b/src/sensors/mhz19b/mhz19_uart.cpp index 31f6db4..64337d3 100644 --- a/src/sensors/mhz19b/mhz19_uart.cpp +++ b/src/sensors/mhz19b/mhz19_uart.cpp @@ -50,7 +50,7 @@ void mhz_setup_check_device_uart() { mhzlog("ABC Status : " + String(mhz19.getABC()) + " " + String(mhz19.getABC() ? "ON" : "OFF")); } -void mhz_setup_uart() { +bool mhz_setup_uart() { sensorValues.co2ppm = CO2_PPM_INVALID; @@ -88,7 +88,7 @@ void mhz_setup_uart() { mhz_setup_check_device_uart(); mhzlog(F("initialized.")); - + return true; } void mhz_read_data_uart() { diff --git a/src/sensors/pressure_delta.cpp b/src/sensors/pressure_delta.cpp new file mode 100644 index 0000000..528941b --- /dev/null +++ b/src/sensors/pressure_delta.cpp @@ -0,0 +1,54 @@ +// +// Air Pressure delta +// +#include + +#include "display/display_util.h" + +#include "global.h" +#include "log.h" + +const int DELTA_MINUTE = 60; + +// ここに毎分の気圧を保存する。 +// なので、DELTA_MINUTE分前の気圧と今の気圧の差を表示する +std::vector airPressureHistory(DELTA_MINUTE, 0.0); + +void store_air_pressure_history() { + if (airPressureHistory.size() >= DELTA_MINUTE) { + airPressureHistory.erase(airPressureHistory.begin()); + } + airPressureHistory.push_back(sensorValues.pressure); + // airPressureHistory.push_back(sensorValues.pressure + random(-20.0, 20.0)); // for debug + // airPressureHistory.push_back(sensorValues.pressure + 0.2); // for debug + + pdeltalog("Pressure history pushed = " + String(sensorValues.pressure)); +} + +void store_air_pressure_delta() { + if (airPressureHistory.size() == 0) { + sensorValues.pressureDelta = 0.0; + pdeltalog(F("No history. Assume delta = 0.0")); + return; + } + + float base = -1.0; + + for (const float& p : airPressureHistory) { + if (p != 0.0) { + base = p; + break; + } + } + + if (base == -1.0) { + sensorValues.pressureDelta = 0.0; + } else { + sensorValues.pressureDelta = sensorValues.pressure - base; + } + + pdeltalog("Pressure Delta=" + String(sensorValues.pressureDelta) + + " PRES=" + String(sensorValues.pressure, 2) + + " BASE=" + String(base, 2) + + " FORMATTED=" + format_air_pressure_delta(sensorValues.pressureDelta)); +} diff --git a/src/sensors/tsl2561.cpp b/src/sensors/tsl2561.cpp index 6ba8cac..3016954 100644 --- a/src/sensors/tsl2561.cpp +++ b/src/sensors/tsl2561.cpp @@ -10,44 +10,61 @@ Tsl2561 Tsl(Wire); bool use_tsl = false; -void tsl_setup() { - // init TSL2561 - Tsl.begin(); - if( !Tsl.available() ) { - tsllog(F("TSL2561 disabled.")); - } else { - tsllog(F("TSL2561 Enabled")); - use_tsl = true; - } +sensor_characters_t tsl_characters() { + sensor_characters_t sensor; + + sensor.lux = true; + sensor.luxIr = true; + + return sensor; +} + + +bool tsl_setup() +{ + // init TSL2561 + Tsl.begin(); + if (!Tsl.available()) + { + tsllog(F("TSL2561 disabled.")); + return false; + } + else + { + tsllog(F("TSL2561 Enabled")); + use_tsl = true; + return true; + } } -// -void read_data_tsl2561() { - - uint8_t id; - uint16_t full, ir; +// +void read_data_tsl2561() +{ + uint8_t id; + uint16_t full, ir; - if( !use_tsl || !Tsl.available() ) { - return; - } + if (!use_tsl || !Tsl.available()) + { + return; + } - Tsl.on(); + Tsl.on(); - Tsl.setSensitivity(false, Tsl2561::EXP_402); - //delay(16); - //delay(110); - delay(402 + 10); + Tsl.setSensitivity(false, Tsl2561::EXP_402); + //delay(16); + //delay(110); + delay(402 + 10); - Tsl.id(id); - Tsl.fullLuminosity(full); - Tsl.irLuminosity(ir); + Tsl.id(id); + Tsl.fullLuminosity(full); + Tsl.irLuminosity(ir); - char log[80]; - snprintf(log, sizeof log, "Luminosity: %5u lx IR: %5u lx", full, ir); - tsllog(String(log)); + char log[80]; + snprintf(log, sizeof log, "Luminosity: %5u lx IR: %5u lx", full, ir); + tsllog(String(log)); - sensorValues.lux = full; - sensorValues.luxIr = ir; + sensorValues.lux = full; + sensorValues.luxIr = ir; - Tsl.off(); + Tsl.off(); } diff --git a/src/utils/log.cpp b/src/utils/log.cpp index 197648d..561c73a 100644 --- a/src/utils/log.cpp +++ b/src/utils/log.cpp @@ -80,6 +80,10 @@ void haltlog(String msg) { real_log(msg, F("HALT")); } +void pdeltalog(String msg) { + real_log(msg, F("PS_DELTA")); +} + void debuglog(String msg) { real_log(msg, F("DEBUG")); }