From ecf0a9a2fc0ba8c2110da8036035e4a9f6054e8b Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Fri, 22 Dec 2017 10:23:15 +0100 Subject: [PATCH] Add tft.enable flag, gate the use of ILI9341/STMPE610 on it. - For esp8266 (lightswitch w/o touchscreen), set tft.enable=false - For esp32 (lightswitch w/ touchscreen), set it to true. Clean up mos.yml flags per architecture type. - Button is always 0,2 - Relay0 at 16 for ESP8266, as that's NodeMCU v2's onboard LED. - Relay0 at 13 for ESP32, as that's Featherwing's onboard LED --- mos.yml | 17 ++++++++++++----- src/main.c | 8 +++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/mos.yml b/mos.yml index c7d5bc3..824866c 100644 --- a/mos.yml +++ b/mos.yml @@ -31,8 +31,9 @@ config_schema: - ["wifi.sta.ssid", "dapches-iot"] - ["wifi.sta.pass", "marielle"] - ["tft", "o", {title: "TFT settings"}] + - ["tft.enable", "b", {"title": "Enable STMPE610 and ILI9341"}] - ["tft.orientation", "i", {title: "Orientation; 0=PORTRAIT 1=LANDSCAPE 2=PORTRAIT_FLIP 3=LANDSCAPE_FLIP"}] - - ["tft.orientation", 1 ] + - ["tft.orientation", 1] - ["tft.width", "i", {title: "TFT width in pixels"}] - ["tft.height", "i", {title: "TFT height in pixels"}] - ["tft.width", 480] # Set to 320 for 2.4" Featherwing, set to 480 for 3.5" Featherwing @@ -45,11 +46,8 @@ config_schema: - ["app.inactivity_timeout", "i", {title: "Inactivity timeout in seconds"}] - ["app.inactivity_timeout", 10] - ["app.battery_calibration", i, {title: "Battery ADC value at 4000mV"}] - - ["app.battery_calibration", 2360] - ["app.buttons", "s", {title: "comma-separated list of button pins"}] - - ["app.buttons", "0,2"] - ["app.relays", "s", {title: "comma-separated list of relay pins"}] - - ["app.relays", "16,12,13,14"] - ["spi.enable", true] - ["spi.cs1_gpio", -1] - ["spi.cs2_gpio", -1] @@ -77,11 +75,20 @@ conds: - ["spi.cs1_gpio", 32] # STMPE610 - ["ili9341.dc_pin", 33] - ["stmpe610.irq_pin", 23] + - ["tft.enable", true] + - ["app.buttons", "0,2"] + - ["app.relays", "13,12,14,16"] + - ["tft.enable", true] + - ["app.battery_calibration", 2360] - when: mos.platform == "esp8266" apply: build_vars: MGOS_PLATFORM_ESP8266: 1 - + config_schema: + - ["tft.enable", false] + - ["app.buttons", "0,2"] + - ["app.relays", "16,12,13,14"] + - ["app.battery_calibration", -1] # List of libraries used by this app, in order of initialisation diff --git a/src/main.c b/src/main.c index d201e3e..2059677 100644 --- a/src/main.c +++ b/src/main.c @@ -47,7 +47,7 @@ static void touch_handler(struct mgos_stmpe610_event_data *ed) { } } -void tft_demo(void) +static void tft_init(void) { mgos_ili9341_set_dimensions(mgos_sys_config_get_tft_width(), mgos_sys_config_get_tft_height()); mgos_ili9341_set_rotation(mgos_sys_config_get_tft_orientation()); @@ -65,6 +65,8 @@ void tft_demo(void) screen_add_default_widgets(s_screen); screen_widget_broadcast(s_screen, EV_WIDGET_DRAW, NULL); LOG(LL_INFO, ("Screen '%s' has %d widgets", s_screen->name, screen_get_num_widgets(s_screen))); + + backlight_init(); } enum mgos_app_init_result mgos_app_init(void) @@ -73,9 +75,9 @@ enum mgos_app_init_result mgos_app_init(void) relays_init(mgos_sys_config_get_app_relays()); mqtt_init(); rpc_init(); - backlight_init(); - tft_demo(); + if (mgos_sys_config_get_tft_enable()) + tft_init(); return MGOS_APP_INIT_SUCCESS; }