From 749c1592b46acabc394be32e525b4ea6857542b5 Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Mon, 17 Jan 2022 19:22:26 -0600 Subject: [PATCH] Add M5Tough board (#1135) --- docs/prerequisites/board.md | 1 + main/User_config.h | 3 ++- main/ZboardM5.ino | 15 +++++++++------ main/ZgatewayBT.ino | 8 ++++---- main/ZmqttDiscovery.ino | 2 +- main/config_M5.h | 13 +++++++++++-- main/main.ino | 30 +++++++++++++++--------------- platformio.ini | 18 ++++++++++++++++++ 8 files changed, 61 insertions(+), 29 deletions(-) diff --git a/docs/prerequisites/board.md b/docs/prerequisites/board.md index 89fa396..f62bdde 100644 --- a/docs/prerequisites/board.md +++ b/docs/prerequisites/board.md @@ -18,6 +18,7 @@ The boards below doesn't need hardware modification (or a lite one). |OLIMEX ESP32 Ethernet|-|-|-|X|-|X|-|X| |ESP32-WT32-ETH01 Ethernet|-|-|-|X|-|X|-|X| |[M5Stack Basic](M5)|![](../img/OpenMQTTgateway_M5_Stack_Board_Display_Text.png)|-|-|X|-|X|X|X| +|[M5Tough](M5)|-|-|-|X|-|X|X|X| |M5Stick|-|-|send|X|-|X|-|X| |[M5Stick C](M5)|![](../img/OpenMQTTgateway_M5_StickC_Board_Display_Text.png)|-|send|X|-|X|X|X| |[M5Atom](M5)||-|send|X|-|X|X|X| diff --git a/main/User_config.h b/main/User_config.h index 80e4577..554eef3 100644 --- a/main/User_config.h +++ b/main/User_config.h @@ -320,7 +320,8 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE; //#define ZactuatorFASTLED "FASTLED" //ESP8266, Arduino, ESP32, Sonoff RF Bridge //#define ZboardM5STICKC "M5StickC" //#define ZboardM5STICKCP "M5StickCP" -//#define ZboardM5STACK "ZboardM5STACK" +//#define ZboardM5STACK "M5STACK" +//#define ZboardM5TOUGH "M5TOUGH" //#define ZradioCC1101 "CC1101" //ESP8266, ESP32 //#define ZactuatorPWM "PWM" //ESP8266, ESP32 //#define ZsensorSHTC3 "SHTC3" //ESP8266, Arduino, ESP32, Sonoff RF Bridge diff --git a/main/ZboardM5.ino b/main/ZboardM5.ino index 502ac34..d020c33 100644 --- a/main/ZboardM5.ino +++ b/main/ZboardM5.ino @@ -28,7 +28,7 @@ */ #include "User_config.h" -#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) +#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH) # ifdef ZboardM5STICKC # include # endif @@ -38,15 +38,18 @@ # ifdef ZboardM5STACK # include # endif +# ifdef ZboardM5TOUGH +# include +# endif void logToLCD(bool display) { display ? Log.begin(LOG_LEVEL_LCD, &M5.Lcd) : Log.begin(LOG_LEVEL, &Serial); // Log on LCD following LOG_LEVEL_LCD } void setBrightness(int brightness) { -# ifdef ZboardM5STACK +# if defined(ZboardM5STACK) M5.Lcd.setBrightness(brightness * 2); # endif -# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) +# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5TOUGH) (!brightness) ? M5.Axp.ScreenBreath(0) : M5.Axp.ScreenBreath(7 + (int)brightness * 0.08); # endif } @@ -84,10 +87,10 @@ void setupM5() { void sleepScreen() { Log.trace(F("Screen going to sleep" CR)); -# ifdef ZboardM5STACK +# if defined(ZboardM5STACK) M5.begin(false, false, false); // M5.lcd.sleep() provokes a reset of the ESP # endif -# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) +# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5TOUGH) M5.Axp.ScreenBreath(0); M5.Axp.SetLDO2(false); # endif @@ -214,7 +217,7 @@ void drawLogo(int logoSize, int circle1X, int circle1Y, bool circle1, bool circl } } -void M5Display(char* line1, char* line2, char* line3) { +void M5Print(char* line1, char* line2, char* line3) { if (lowpowermode == 2) digitalWrite(LED_INFO, LED_INFO_ON); wakeScreen(NORMAL_LCD_BRIGHTNESS); M5.Lcd.fillScreen(TFT_WHITE); diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 6e903f6..fbf0c6a 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -551,7 +551,7 @@ void lowPowerESP32() // low power mode } void deepSleep(uint64_t time_in_us) { -# if defined(ZboardM5STACK) || defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) +# if defined(ZboardM5STACK) || defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5TOUGH) sleepScreen(); esp_sleep_enable_ext0_wakeup((gpio_num_t)SLEEP_BUTTON, LOW); # endif @@ -570,19 +570,19 @@ void deepSleep(uint64_t time_in_us) { void changelowpowermode(int newLowPowerMode) { Log.notice(F("Changing LOW POWER mode to: %d" CR), newLowPowerMode); -# if defined(ZboardM5STACK) || defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) +# if defined(ZboardM5STACK) || defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5TOUGH) if (lowpowermode == 2) { # ifdef ZboardM5STACK M5.Lcd.wakeup(); # endif -# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) +# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5TOUGH) M5.Axp.SetLDO2(true); M5.Lcd.begin(); # endif } char lpm[2]; sprintf(lpm, "%d", newLowPowerMode); - M5Display("Changing LOW POWER mode to:", lpm, ""); + M5Print("Changing LOW POWER mode to:", lpm, ""); # endif lowpowermode = newLowPowerMode; preferences.begin(Gateway_Short_Name, false); diff --git a/main/ZmqttDiscovery.ino b/main/ZmqttDiscovery.ino index 6087e31..1ac221b 100644 --- a/main/ZmqttDiscovery.ino +++ b/main/ZmqttDiscovery.ino @@ -398,7 +398,7 @@ void pubMqttDiscovery() { "", "", "", "", false, // device name, device manufacturer, device model, device mac stateClassNone //State Class ); -# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) +# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5TOUGH) createDiscovery("sensor", //set Type subjectSYStoMQTT, "SYS: Bat voltage", (char*)getUniqueId("m5batvoltage", "").c_str(), //set state_topic,name,uniqueId "", "", "{{ value_json.m5batvoltage }}", //set availability_topic,device_class,value_template, diff --git a/main/config_M5.h b/main/config_M5.h index 885da27..1d1e01a 100644 --- a/main/config_M5.h +++ b/main/config_M5.h @@ -35,13 +35,22 @@ #ifdef ZboardM5STACK # include #endif +#ifdef ZboardM5TOUGH +# include +#endif extern void setupM5(); extern void loopM5(); /*----------------------------USER PARAMETERS-----------------------------*/ /*---------------DEFINE SCREEN BRIGHTNESS------------------*/ -#ifndef SLEEP_LCD_BRIGHTNESS -# define SLEEP_LCD_BRIGHTNESS 2 // 0 to 100 +#ifdef ZboardM5TOUGH // Sleep brightness doesn't seem to work for the moment on Tough +# ifndef SLEEP_LCD_BRIGHTNESS +# define SLEEP_LCD_BRIGHTNESS 15 // 0 to 100 +# endif +#else +# ifndef SLEEP_LCD_BRIGHTNESS +# define SLEEP_LCD_BRIGHTNESS 2 // 0 to 100 +# endif #endif #ifndef NORMAL_LCD_BRIGHTNESS # define NORMAL_LCD_BRIGHTNESS 100 // 0 to 100 diff --git a/main/main.ino b/main/main.ino index 63e1f4e..6d38d1e 100644 --- a/main/main.ino +++ b/main/main.ino @@ -150,7 +150,7 @@ struct GfSun2000Data {}; #ifdef ZactuatorSomfy # include "config_Somfy.h" #endif -#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) +#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH) # include "config_M5.h" #endif #if defined(ZgatewayRS232) @@ -519,9 +519,9 @@ void connectMQTT() { #else if (client.connect(gateway_name, mqtt_user, mqtt_pass, topic, will_QoS, will_Retain, will_Message)) { #endif -#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) +#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH) if (lowpowermode < 2) - M5Display("MQTT connected", "", ""); + M5Print("MQTT connected", "", ""); #endif Log.notice(F("Connected to broker" CR)); failure_number_mqtt = 0; @@ -613,7 +613,7 @@ void setup() { preferences.begin(Gateway_Short_Name, false); lowpowermode = preferences.getUInt("lowpowermode", DEFAULT_LOW_POWER_MODE); preferences.end(); -# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) +# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH) setupM5(); # endif Log.notice(F("OpenMQTTGateway Version: " OMG_VERSION CR)); @@ -868,8 +868,8 @@ void setOTA() { # if defined(ZgatewayBT) && defined(ESP32) stopProcessing(); # endif -# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) - M5Display("OTA in progress", "", ""); +# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH) + M5Print("OTA in progress", "", ""); # endif }); ArduinoOTA.onEnd([]() { @@ -879,8 +879,8 @@ void setOTA() { # if defined(ZgatewayBT) && defined(ESP32) startProcessing(); # endif -# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) - M5Display("OTA done", "", ""); +# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH) + M5Print("OTA done", "", ""); # endif }); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { @@ -1198,8 +1198,8 @@ void setup_wifimanager(bool reset_settings) { { # ifdef ESP32 if (lowpowermode < 2) { -# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) - M5Display("Connect your phone to WIFI AP:", WifiManager_ssid, WifiManager_password); +# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH) + M5Print("Connect your phone to WIFI AP:", WifiManager_ssid, WifiManager_password); # endif } else { // in case of low power mode we put the ESP to sleep again if we didn't get connected (typical in case the wifi is down) # ifdef ZgatewayBT @@ -1225,9 +1225,9 @@ void setup_wifimanager(bool reset_settings) { digitalWrite(LED_INFO, !LED_INFO_ON); } -# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) +# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH) if (lowpowermode < 2) - M5Display("Wifi connected", "", ""); + M5Print("Wifi connected", "", ""); # endif if (shouldSaveConfig) { @@ -1515,7 +1515,7 @@ void loop() { #endif } // Function that doesn't need an active connection -#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) +#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH) loopM5(); #endif } @@ -1584,7 +1584,7 @@ void stateMeasures() { SYSdata["m5ischarging"] = (bool)M5.Power.isCharging(); SYSdata["m5ischargefull"] = (bool)M5.Power.isChargeFull(); # endif -# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) +# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5TOUGH) M5.Axp.EnableCoulombcounter(); SYSdata["m5batvoltage"] = (float)M5.Axp.GetBatVoltage(); SYSdata["m5batcurrent"] = (float)M5.Axp.GetBatCurrent(); @@ -1730,7 +1730,7 @@ void receivingMQTT(char* topicOri, char* datacallback) { # ifdef ZactuatorPWM MQTTtoPWM(topicOri, jsondata); # endif -# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) +# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH) MQTTtoM5(topicOri, jsondata); # endif # ifdef ZactuatorONOFF diff --git a/platformio.ini b/platformio.ini index c2bd8e1..ddaef28 100644 --- a/platformio.ini +++ b/platformio.ini @@ -50,6 +50,7 @@ extra_configs = ;default_envs = esp32-wt32-eth01-ble-eth ;default_envs = esp32-m5stick-ble ;default_envs = esp32-m5stack-ble +;default_envs = esp32-m5tough-ble ;default_envs = esp32-m5stick-c-ble ;default_envs = esp32-m5stick-cp-ble ;default_envs = esp32-m5atom @@ -120,6 +121,7 @@ dallastemperature = DallasTemperature m5stickc = M5StickC@0.2.0 m5stickcp = https://github.com/m5stack/M5StickC-Plus.git#0.0.2 m5stack = M5Stack@0.3.1 +m5tough = https://github.com/m5stack/M5Tough.git#b502416 smartrc-cc1101-driver-lib = SmartRC-CC1101-Driver-Lib@2.5.7 stl = https://github.com/mike-matera/ArduinoSTL.git#7411816 shtc3 = https://github.com/sparkfun/SparkFun_SHTC3_Arduino_Library @@ -541,6 +543,22 @@ build_flags = '-DGateway_Name="OpenMQTTGateway_ESP32_M5STACK_BLE"' board_upload.speed = 921600 +[env:esp32-m5tough-ble] +platform = ${com.esp32_platform} +board = m5stack-core-esp32 +board_build.partitions = min_spiffs.csv +lib_deps = + ${com-esp.lib_deps} + ${libraries.m5tough} + ${libraries.ble} + ${libraries.decoder} +build_flags = + ${com-esp.build_flags} + '-DZgatewayBT="BT"' + '-DZboardM5TOUGH="M5Tough"' + '-DGateway_Name="OpenMQTTGateway_ESP32_M5TOUGH_BLE"' +board_upload.speed = 921600 + [env:esp32-m5stick-c-ble] platform = ${com.esp32_platform} board = m5stick-c