Add network status functionality for last button

This commit is contained in:
Djuri Baars 2023-08-08 10:46:05 +02:00
parent a47b213872
commit e68c2816c6
7 changed files with 1382 additions and 2684 deletions

3
.gitignore vendored
View File

@ -7,4 +7,5 @@ data/build
data/.yarn
data/node_modules
src/config.h
.vscode/c_cpp_properties.json
.vscode/c_cpp_properties.json
node_modules

View File

@ -10,14 +10,7 @@ Don't forget to copy `config.h.example` to `config.h`. Not necessary to adapt it
## Hardware
- MCU: ESP32 or ESP32-S3 ([Wemos S3 mini](https://www.wemos.cc/en/latest/s3/s3_mini.html) recommended)<br>
**The ESP32 S2 is not supported, it does not have enough RAM**
- Seven eInk displays
- [MCP23017](https://www.microchip.com/en-us/product/mcp23017) I2C Port Expander
- 4x WS2812B leds (optional)
- 5x push buttons (optional)
Recommended to use the BTClock PCB.
See [wiki](https://github.com/dsbaars/btclock_v2/wiki) for requirements and build instructions.
## Schematic
![Schematic](doc/schematic.png)

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +0,0 @@
#pragma once
#define NTP_SERVER "nl.pool.ntp.org"
#define FONT_SMALL Antonio_SemiBold20pt7b
#define FONT_BIG Antonio_SemiBold90pt7b
#define TIME_OFFSET_SECONDS 3600
#define OTA_PASSWORD "changeme"
#ifndef HOSTNAME
#define HOSTNAME "btclock"
#endif
#define BITCOIND_HOST ""
#define BITCOIND_PORT 8332
#define BITCOIND_RPC_USER ""
#define BITCOIND_RPC_PASS ""
#define DEFAULT_FG_COLOR GxEPD_WHITE
#define DEFAULT_BG_COLOR GxEPD_BLACK
#define I2C_DEV_ADDR 0x55

View File

@ -36,31 +36,51 @@ void setupSoftAP()
byte mac[6];
WiFi.macAddress(mac);
softAP_SSID = String("BTClock" + String(mac[3], 16) + String(mac[1], 16));
softAP_password = base64::encode(String(mac[2]) + String(mac[4]) + String(mac[5])).substring(2, 12);
WiFi.setHostname(softAP_SSID.c_str());
softAP_password = base64::encode(String(mac[2], 16) + String(mac[4], 16) + String(mac[5], 16) + String(mac[6], 16)).substring(2, 12);
}
void setupComponents()
{
#ifdef WITH_RGB_LED
pixels.begin();
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
pixels.setPixelColor(1, pixels.Color(0, 255, 0));
pixels.setPixelColor(2, pixels.Color(0, 0, 255));
pixels.setPixelColor(3, pixels.Color(255, 255, 255));
pixels.show();
#endif
//delay(3000);
//Serial.println("Leds should be on");
#ifndef NO_MCP
if (!mcp.begin_I2C())
{
Serial.println("Error MCP23017");
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
pixels.setPixelColor(1, pixels.Color(255, 0, 0));
pixels.setPixelColor(2, pixels.Color(255, 0, 0));
pixels.setPixelColor(3, pixels.Color(255, 0, 0));
pixels.show();
while (1)
;
}
else
{
Serial.println("MCP23017 ok");
pixels.setPixelColor(0, pixels.Color(0, 255, 0));
pixels.setPixelColor(1, pixels.Color(0, 255, 0));
pixels.setPixelColor(2, pixels.Color(0, 255, 0));
pixels.setPixelColor(3, pixels.Color(0, 255, 0));
pixels.show();
// delay(200);
pinMode(MCP_INT_PIN, INPUT);
mcp.setupInterrupts(true, false, LOW);
}
#endif
#ifdef WITH_RGB_LED
pixels.begin();
pixels.show();
#endif
#ifdef WITH_BUTTONS
for (int i = 0; i < 4; i++)
{
@ -118,10 +138,10 @@ void setupPreferences()
#ifdef WITH_RGB_LED
pixels.setBrightness(preferences.getUInt("ledBrightness", 128));
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
pixels.setPixelColor(1, pixels.Color(0, 255, 0));
pixels.setPixelColor(2, pixels.Color(0, 0, 255));
pixels.setPixelColor(3, pixels.Color(255, 255, 255));
pixels.setPixelColor(3, pixels.Color(255, 0, 0));
pixels.setPixelColor(2, pixels.Color(0, 255, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 255));
pixels.setPixelColor(0, pixels.Color(255, 255, 255));
pixels.show();
#endif
@ -141,7 +161,9 @@ uint getCurrentScreen()
void setCurrentScreen(uint screen)
{
preferences.putUInt("currentScreen", screen);
if (screen != SCREEN_CUSTOM) {
preferences.putUInt("currentScreen", screen);
}
currentScreen = screen;
handleScreenTasks(screen);
@ -249,6 +271,30 @@ void previousScreen()
setCurrentScreen(newCurrentScreen);
}
void showNetworkSettings()
{
std::array<String, 7> epdContent = { "", "", "", "", "", "", ""};
String ipAddr = WiFi.localIP().toString();
String subNet = WiFi.subnetMask().toString();
epdContent[1] = "IP/Subnet";
int ipAddrPos = 0;
int subnetPos = 0;
for (int i = 0; i < 4; i++) {
epdContent[2 + i] = ipAddr.substring(0, ipAddr.indexOf('.')) + "/" + subNet.substring(0, subNet.indexOf('.'));
ipAddrPos = ipAddr.indexOf('.') + 1;
subnetPos = subNet.indexOf('.') + 1;
ipAddr = ipAddr.substring(ipAddrPos);
subNet = subNet.substring(subnetPos);
}
CustomTextScreen::setText(epdContent);
setCurrentScreen(SCREEN_CUSTOM);
}
void setLights(int r, int g, int b)
{
#ifdef WITH_RGB_LED

View File

@ -23,6 +23,7 @@ void onI2CRequest();
uint getCurrentScreen();
void setCurrentScreen(uint screen);
void handleScreenTasks(uint screen);
void showNetworkSettings();
void timebasedChangeTask(void *parameter);

View File

@ -30,6 +30,10 @@ void buttonTask(void *parameter)
{
previousScreen();
}
else if (pin == 0)
{
showNetworkSettings();
}
vTaskDelay(250); // debounce
mcp.clearInterrupts(); // clear