Restart if after 10 minutes no connection
This commit is contained in:
parent
5f971cfee3
commit
8ed4bb8aa6
10 changed files with 215 additions and 30 deletions
|
@ -18,7 +18,7 @@ void buttonTask(void *parameter)
|
|||
|
||||
if (!digitalRead(MCP_INT_PIN))
|
||||
{
|
||||
uint pin = mcp.getLastInterruptPin();
|
||||
uint pin = mcp1.getLastInterruptPin();
|
||||
|
||||
switch (pin)
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ void buttonTask(void *parameter)
|
|||
break;
|
||||
}
|
||||
}
|
||||
mcp.clearInterrupts();
|
||||
mcp1.clearInterrupts();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ void buttonTask(void *parameter)
|
|||
// Very ugly, but for some reason this is necessary
|
||||
while (!digitalRead(MCP_INT_PIN))
|
||||
{
|
||||
mcp.clearInterrupts();
|
||||
mcp1.clearInterrupts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
#define MAX_ATTEMPTS_WIFI_CONNECTION 20
|
||||
|
||||
Preferences preferences;
|
||||
Adafruit_MCP23X17 mcp;
|
||||
Adafruit_MCP23X17 mcp1;
|
||||
#ifdef IS_BTCLOCK_S3
|
||||
Adafruit_MCP23X17 mcp2;
|
||||
#endif
|
||||
std::vector<std::string> screenNameMap(SCREEN_COUNT);
|
||||
std::mutex mcpMutex;
|
||||
|
||||
|
@ -18,7 +21,7 @@ void setup()
|
|||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lockMcp(mcpMutex);
|
||||
if (mcp.digitalRead(3) == LOW)
|
||||
if (mcp1.digitalRead(3) == LOW)
|
||||
{
|
||||
preferences.putBool("wifiConfigured", false);
|
||||
preferences.remove("txPower");
|
||||
|
@ -65,7 +68,7 @@ void tryImprovSetup()
|
|||
bool buttonPress = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lockMcp(mcpMutex);
|
||||
buttonPress = (mcp.digitalRead(2) == LOW);
|
||||
buttonPress = (mcp1.digitalRead(2) == LOW);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -230,6 +233,33 @@ std::vector<std::string> getScreenNameMap()
|
|||
return screenNameMap;
|
||||
}
|
||||
|
||||
|
||||
void setupMcp()
|
||||
{
|
||||
#ifdef IS_BTCLOCK_S3
|
||||
const int mcp1AddrPins[] = {MCP1_A0_PIN, MCP1_A1_PIN, MCP1_A2_PIN};
|
||||
const int mcp1AddrValues[] = {LOW, LOW, LOW};
|
||||
|
||||
const int mcp2AddrPins[] = {MCP2_A0_PIN, MCP2_A1_PIN, MCP2_A2_PIN};
|
||||
const int mcp2AddrValues[] = {LOW, LOW, HIGH};
|
||||
|
||||
pinMode(MCP_RESET_PIN, OUTPUT);
|
||||
digitalWrite(MCP_RESET_PIN, HIGH);
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
pinMode(mcp1AddrPins[i], OUTPUT);
|
||||
digitalWrite(mcp1AddrPins[i], mcp1AddrValues[i]);
|
||||
|
||||
pinMode(mcp2AddrPins[i], OUTPUT);
|
||||
digitalWrite(mcp2AddrPins[i], mcp2AddrValues[i]);
|
||||
}
|
||||
|
||||
digitalWrite(MCP_RESET_PIN, LOW);
|
||||
delay(30);
|
||||
digitalWrite(MCP_RESET_PIN, HIGH);
|
||||
#endif
|
||||
}
|
||||
|
||||
void setupHardware()
|
||||
{
|
||||
if (!LittleFS.begin(true))
|
||||
|
@ -250,9 +280,11 @@ void setupHardware()
|
|||
Serial.println(F("PSRAM not available"));
|
||||
}
|
||||
|
||||
Wire.begin(35, 36, 400000);
|
||||
setupMcp();
|
||||
|
||||
if (!mcp.begin_I2C(0x20))
|
||||
Wire.begin(I2C_SDA_PIN, I2C_SCK_PIN, 400000);
|
||||
|
||||
if (!mcp1.begin_I2C(0x20))
|
||||
{
|
||||
Serial.println(F("Error MCP23017"));
|
||||
|
||||
|
@ -262,18 +294,30 @@ void setupHardware()
|
|||
else
|
||||
{
|
||||
pinMode(MCP_INT_PIN, INPUT_PULLUP);
|
||||
mcp.setupInterrupts(false, false, LOW);
|
||||
mcp1.setupInterrupts(false, false, LOW);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
mcp.pinMode(i, INPUT_PULLUP);
|
||||
mcp.setupInterruptPin(i, LOW);
|
||||
mcp1.pinMode(i, INPUT_PULLUP);
|
||||
mcp1.setupInterruptPin(i, LOW);
|
||||
}
|
||||
#ifndef IS_BTCLOCK_S3
|
||||
for (int i = 8; i <= 14; i++)
|
||||
{
|
||||
mcp.pinMode(i, OUTPUT);
|
||||
mcp1.pinMode(i, OUTPUT);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef IS_BTCLOCK_S3
|
||||
if (!mcp2.begin_I2C(0x21))
|
||||
{
|
||||
Serial.println(F("Error MCP23017"));
|
||||
|
||||
// while (1)
|
||||
// ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void improvGetAvailableWifiNetworks()
|
||||
|
|
|
@ -41,6 +41,7 @@ void setupHardware();
|
|||
void tryImprovSetup();
|
||||
void setupTimers();
|
||||
void finishSetup();
|
||||
void setupMcp();
|
||||
std::vector<std::string> getScreenNameMap();
|
||||
|
||||
std::vector<std::string> getLocalUrl();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "epd.hpp"
|
||||
|
||||
#ifndef IS_BTCLOCK_S3
|
||||
Native_Pin EPD_CS[NUM_SCREENS] = {
|
||||
Native_Pin(2),
|
||||
Native_Pin(4),
|
||||
|
@ -24,16 +25,53 @@ Native_Pin EPD_BUSY[NUM_SCREENS] = {
|
|||
Native_Pin(16),
|
||||
};
|
||||
MCP23X17_Pin EPD_RESET_MPD[NUM_SCREENS] = {
|
||||
MCP23X17_Pin(mcp, 8),
|
||||
MCP23X17_Pin(mcp, 9),
|
||||
MCP23X17_Pin(mcp, 10),
|
||||
MCP23X17_Pin(mcp, 11),
|
||||
MCP23X17_Pin(mcp, 12),
|
||||
MCP23X17_Pin(mcp, 13),
|
||||
MCP23X17_Pin(mcp, 14),
|
||||
MCP23X17_Pin(mcp1, 8),
|
||||
MCP23X17_Pin(mcp1, 9),
|
||||
MCP23X17_Pin(mcp1, 10),
|
||||
MCP23X17_Pin(mcp1, 11),
|
||||
MCP23X17_Pin(mcp1, 12),
|
||||
MCP23X17_Pin(mcp1, 13),
|
||||
MCP23X17_Pin(mcp1, 14),
|
||||
};
|
||||
|
||||
Native_Pin EPD_DC = Native_Pin(14);
|
||||
#else
|
||||
Native_Pin EPD_DC = Native_Pin(38);
|
||||
|
||||
MCP23X17_Pin EPD_BUSY[NUM_SCREENS] = {
|
||||
MCP23X17_Pin(mcp1, 8),
|
||||
MCP23X17_Pin(mcp1, 9),
|
||||
MCP23X17_Pin(mcp1, 10),
|
||||
MCP23X17_Pin(mcp1, 11),
|
||||
MCP23X17_Pin(mcp1, 12),
|
||||
MCP23X17_Pin(mcp1, 13),
|
||||
MCP23X17_Pin(mcp1, 14),
|
||||
MCP23X17_Pin(mcp1, 4),
|
||||
};
|
||||
|
||||
MCP23X17_Pin EPD_CS[NUM_SCREENS] = {
|
||||
MCP23X17_Pin(mcp2, 8),
|
||||
MCP23X17_Pin(mcp2, 10),
|
||||
MCP23X17_Pin(mcp2, 12),
|
||||
MCP23X17_Pin(mcp2, 14),
|
||||
MCP23X17_Pin(mcp2, 0),
|
||||
MCP23X17_Pin(mcp2, 2),
|
||||
MCP23X17_Pin(mcp2, 4),
|
||||
MCP23X17_Pin(mcp2, 6)
|
||||
};
|
||||
|
||||
MCP23X17_Pin EPD_RESET_MPD[NUM_SCREENS] = {
|
||||
MCP23X17_Pin(mcp2, 9),
|
||||
MCP23X17_Pin(mcp2, 11),
|
||||
MCP23X17_Pin(mcp2, 13),
|
||||
MCP23X17_Pin(mcp2, 15),
|
||||
MCP23X17_Pin(mcp2, 1),
|
||||
MCP23X17_Pin(mcp2, 3),
|
||||
MCP23X17_Pin(mcp2, 5),
|
||||
MCP23X17_Pin(mcp2, 7),
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
GxEPD2_BW<GxEPD2_213_B74, GxEPD2_213_B74::HEIGHT> displays[NUM_SCREENS] = {
|
||||
GxEPD2_213_B74(&EPD_CS[0], &EPD_DC, &EPD_RESET_MPD[0], &EPD_BUSY[0]),
|
||||
|
@ -43,9 +81,8 @@ GxEPD2_BW<GxEPD2_213_B74, GxEPD2_213_B74::HEIGHT> displays[NUM_SCREENS] = {
|
|||
GxEPD2_213_B74(&EPD_CS[4], &EPD_DC, &EPD_RESET_MPD[4], &EPD_BUSY[4]),
|
||||
GxEPD2_213_B74(&EPD_CS[5], &EPD_DC, &EPD_RESET_MPD[5], &EPD_BUSY[5]),
|
||||
GxEPD2_213_B74(&EPD_CS[6], &EPD_DC, &EPD_RESET_MPD[6], &EPD_BUSY[6]),
|
||||
#if NUM_SCREENS == 9
|
||||
GxEPD2_213_B74(&EPD8_CS, &EPD_DC, &EPD_RESET_MPD[7], &EPD8_BUSY),
|
||||
GxEPD2_213_B74(&EPD9_CS, &EPD_DC, &EPD_RESET_MPD[8], &EPD9_BUSY),
|
||||
#ifdef IS_BTCLOCK_S3
|
||||
GxEPD2_213_B74(&EPD_CS[7], &EPD_DC, &EPD_RESET_MPD[6], &EPD_BUSY[7]),
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -9,7 +9,10 @@
|
|||
|
||||
#include "utils.hpp"
|
||||
|
||||
extern Adafruit_MCP23X17 mcp;
|
||||
extern Adafruit_MCP23X17 mcp1;
|
||||
#ifdef IS_BTCLOCK_S3
|
||||
extern Adafruit_MCP23X17 mcp2;
|
||||
#endif
|
||||
extern Preferences preferences;
|
||||
extern std::mutex mcpMutex;
|
||||
|
||||
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -4,10 +4,11 @@
|
|||
#include "ESPAsyncWebServer.h"
|
||||
|
||||
#include "lib/config.hpp"
|
||||
#define USE_QR
|
||||
|
||||
//char ptrTaskList[400];
|
||||
|
||||
uint wifiLostConnection;
|
||||
|
||||
extern "C" void app_main()
|
||||
{
|
||||
initArduino();
|
||||
|
@ -27,7 +28,21 @@ extern "C" void app_main()
|
|||
xTaskNotifyGive(eventSourceTaskHandle);
|
||||
|
||||
if (!WiFi.isConnected()) {
|
||||
if (!wifiLostConnection) {
|
||||
wifiLostConnection = esp_timer_get_time() / 1000000;
|
||||
Serial.println("Lost WiFi connection, trying to reconnect...");
|
||||
}
|
||||
|
||||
if (((esp_timer_get_time() / 1000000) - wifiLostConnection) > 600) {
|
||||
Serial.println("Still no connection after 10 minutes, restarting...");
|
||||
delay(2000);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
WiFi.begin();
|
||||
} else if (wifiLostConnection) {
|
||||
wifiLostConnection = 0;
|
||||
Serial.println("Connection restored, reset timer.");
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue