Add M5Tough board (#1135)

This commit is contained in:
Florian authored and GitHub committed 2022-01-17 19:22:26 -06:00
1 parent 9546f43cd6
commit 749c1592b4
8 files changed
+61 -29

No files matched your search

+2 -1
View File
@@ -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
+9 -6
View File
@@ -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 <M5StickC.h>
# endif
@@ -38,15 +38,18 @@
# ifdef ZboardM5STACK
# include <M5Stack.h>
# endif
# ifdef ZboardM5TOUGH
# include <M5Tough.h>
# 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);
+4 -4
View File
@@ -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);
+1 -1
View File
@@ -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,
+11 -2
View File
@@ -35,13 +35,22 @@
#ifdef ZboardM5STACK
# include <M5Stack.h>
#endif
#ifdef ZboardM5TOUGH
# include <M5Tough.h>
#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
+15 -15
View File
@@ -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