Implemented LED brightness setting, started I2C slave code, made reset pin consistent with wiring for DOIT DevKit.

This commit is contained in:
Djuri Baars 2023-06-25 15:06:29 +02:00
parent 81885e3f15
commit cc22692992
8 changed files with 94 additions and 30 deletions

View file

@ -4,6 +4,8 @@
@import "../node_modules/bootstrap/scss/variables"; @import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/variables-dark"; @import "../node_modules/bootstrap/scss/variables-dark";
$form-range-track-bg: #fff;
@import "../node_modules/bootstrap/scss/mixins"; @import "../node_modules/bootstrap/scss/mixins";
@import "../node_modules/bootstrap/scss/maps"; @import "../node_modules/bootstrap/scss/maps";
@import "../node_modules/bootstrap/scss/utilities"; @import "../node_modules/bootstrap/scss/utilities";

View file

@ -133,6 +133,12 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<label class="col-sm-6 col-form-label" for="ledBrightness">LED brightness</label>
<div class="col-sm-6">
<input type="range" class="form-range" id="ledBrightness" name="ledBrightness" value="128" min="0" max="255">
</div>
</div>
<div class="row"> <div class="row">
<div class=" col-sm-6"> <div class=" col-sm-6">
<div class="form-check form-switch"> <div class="form-check form-switch">

View file

@ -51,6 +51,7 @@ fetch('/api/settings', {
} }
document.getElementById('timePerScreen').value = jsonData.timerSeconds / 60; document.getElementById('timePerScreen').value = jsonData.timerSeconds / 60;
document.getElementById('ledBrightness').value = jsonData.ledBrightness;
var source = document.getElementById("screens-template").innerHTML; var source = document.getElementById("screens-template").innerHTML;
var template = Handlebars.compile(source); var template = Handlebars.compile(source);

View file

@ -7,7 +7,7 @@ std::map<int, std::string> screenNameMap;
#ifndef NO_MCP #ifndef NO_MCP
Adafruit_MCP23X17 mcp; Adafruit_MCP23X17 mcp;
const int MCP_INT_PIN = 8; const int MCP_INT_PIN = 8;
#endif #endif
bool timerRunning = true; bool timerRunning = true;
@ -51,17 +51,13 @@ void setupComponents()
else else
{ {
Serial.println("MCP23017 ok"); Serial.println("MCP23017 ok");
pinMode(MCP_INT_PIN, INPUT); pinMode(MCP_INT_PIN, INPUT);
mcp.setupInterrupts(true, false, LOW); mcp.setupInterrupts(true, false, LOW);
} }
#endif #endif
#ifdef WITH_RGB_LED #ifdef WITH_RGB_LED
pixels.begin(); 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(); pixels.show();
#endif #endif
@ -114,13 +110,21 @@ void setupPreferences()
bgColor = preferences.getUInt("bgColor", DEFAULT_BG_COLOR); bgColor = preferences.getUInt("bgColor", DEFAULT_BG_COLOR);
preferences.getBool("ledFlashOnUpd", false); preferences.getBool("ledFlashOnUpd", false);
screenNameMap = {{SCREEN_BLOCK_HEIGHT, "Block Height"}, screenNameMap = {{SCREEN_BLOCK_HEIGHT, "Block Height"},
{SCREEN_MSCW_TIME, "Sats per dollar"}, {SCREEN_MSCW_TIME, "Sats per dollar"},
{SCREEN_BTC_TICKER, "Ticker"}, {SCREEN_BTC_TICKER, "Ticker"},
{SCREEN_TIME, "Time"}, {SCREEN_TIME, "Time"},
{SCREEN_HALVING_COUNTDOWN, "Halving countdown"}}; {SCREEN_HALVING_COUNTDOWN, "Halving countdown"}};
#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.show();
#endif
for (int i = 0; i < screenNameMap.size(); i++) for (int i = 0; i < screenNameMap.size(); i++)
{ {
String key = "screen" + String(i) + "Visible"; String key = "screen" + String(i) + "Visible";
@ -154,7 +158,8 @@ void handleScreenTasks(uint screen)
switch (currentScreen) switch (currentScreen)
{ {
case SCREEN_BLOCK_HEIGHT: case SCREEN_BLOCK_HEIGHT:
if (blockNotifyTaskHandle) { if (blockNotifyTaskHandle)
{
vTaskResume(blockNotifyTaskHandle); vTaskResume(blockNotifyTaskHandle);
} }
break; break;
@ -171,7 +176,8 @@ void handleScreenTasks(uint screen)
vTaskResume(getPriceTaskHandle); vTaskResume(getPriceTaskHandle);
break; break;
case SCREEN_TIME: case SCREEN_TIME:
if (minuteTaskHandle) { if (minuteTaskHandle)
{
TimeScreen::onActivate(); TimeScreen::onActivate();
vTaskResume(minuteTaskHandle); vTaskResume(minuteTaskHandle);
} }
@ -212,8 +218,9 @@ void timebasedChangeTask(void *parameter)
} }
} }
int modulo(int x,int N) { int modulo(int x, int N)
return (x % N + N) %N; {
return (x % N + N) % N;
} }
void nextScreen() void nextScreen()
@ -236,7 +243,7 @@ void previousScreen()
while (!preferences.getBool(key.c_str(), true)) while (!preferences.getBool(key.c_str(), true))
{ {
newCurrentScreen = modulo(newCurrentScreen - 1, screenCount); newCurrentScreen = modulo(newCurrentScreen - 1, screenCount);
key = "screen" + String(newCurrentScreen) + "Visible"; key = "screen" + String(newCurrentScreen) + "Visible";
} }
setCurrentScreen(newCurrentScreen); setCurrentScreen(newCurrentScreen);
@ -252,4 +259,32 @@ void setLights(int r, int g, int b)
pixels.show(); pixels.show();
#endif #endif
}
void setupI2C()
{
bool slaveMode = preferences.getBool("I2CSlaveMode", false);
if (slaveMode)
{
Serial.println("I2C Slave Mode enabled");
Wire.onReceive(onI2CReceive);
Wire.begin((uint8_t)I2C_DEV_ADDR);
}
}
void onI2CReceive(int len)
{
Serial.printf("onReceive[%d]: ", len);
while (Wire.available())
{
Serial.write(Wire.read());
}
Serial.println();
}
void onI2CRequest()
{
Wire.print("I2C Packets.");
Serial.println("onRequest");
} }

View file

@ -16,6 +16,9 @@ void setupWifi();
void synchronizeTime(); void synchronizeTime();
void setupPreferences(); void setupPreferences();
void setLights(int r, int g, int b); void setLights(int r, int g, int b);
void setupI2C();
void onI2CReceive(int len);
void onI2CRequest();
uint getCurrentScreen(); uint getCurrentScreen();
void setCurrentScreen(uint screen); void setCurrentScreen(uint screen);

View file

@ -153,7 +153,7 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
root["epdColors"] = 3; root["epdColors"] = 3;
#endif #endif
root["ledFlashOnUpdate"] = preferences.getBool("ledFlashOnUpd", false); root["ledFlashOnUpdate"] = preferences.getBool("ledFlashOnUpd", false);
root["ledBrightness"] = preferences.getUInt("ledBrightness", 128);
JsonArray screens = root.createNestedArray("screens"); JsonArray screens = root.createNestedArray("screens");
for (int i = 0; i < screenNameMap.size(); i++) for (int i = 0; i < screenNameMap.size(); i++)
@ -208,6 +208,16 @@ void onApiSettingsPost(AsyncWebServerRequest *request)
settingsChanged = true; settingsChanged = true;
} }
if (request->hasParam("ledBrightness", true))
{
AsyncWebParameter *ledBrightness = request->getParam("ledBrightness", true);
preferences.putUInt("ledBrightness", ledBrightness->value().toInt());
Serial.print("Setting brightness to ");
Serial.println(ledBrightness->value().c_str());
settingsChanged = true;
}
for (int i = 0; i < screenNameMap.size(); i++) for (int i = 0; i < screenNameMap.size(); i++)
{ {
String key = "screen[" + String(i) + "]"; String key = "screen[" + String(i) + "]";

View file

@ -3,7 +3,7 @@
#include <shared.hpp> #include <shared.hpp>
#include <WiFi.h> #include <WiFi.h>
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
//#include <ESP32Time.h> // #include <ESP32Time.h>
#include <WiFiManager.h> #include <WiFiManager.h>
#ifdef CONFIG_BT_ENABLED #ifdef CONFIG_BT_ENABLED
@ -54,30 +54,37 @@ void setup()
#endif #endif
setupWifi(); setupWifi();
synchronizeTime(); bool slaveMode = preferences.getBool("I2CSlaveMode", false);
setupWebserver();
TimeScreen::init(); if (!slaveMode)
BlockHeightScreen::init(); {
TickerScreen::init(); synchronizeTime();
SatsPerDollarScreen::init(); setupWebserver();
TimeScreen::init();
BlockHeightScreen::init();
TickerScreen::init();
SatsPerDollarScreen::init();
#ifdef WITH_BUTTONS #ifdef WITH_BUTTONS
setupButtonTask(); setupButtonTask();
#endif #endif
#ifdef WITH_RGB_LED #ifdef WITH_RGB_LED
setLights(0,0,0); setLights(0, 0, 0);
setupLedHandlerTask(); setupLedHandlerTask();
#endif #endif
registerNewMinuteCallback(TimeScreen::onNewMinute); registerNewMinuteCallback(TimeScreen::onNewMinute);
registerNewBlockCallback(BlockHeightScreen::onNewBlock); registerNewBlockCallback(BlockHeightScreen::onNewBlock);
registerNewBlockCallback(HalvingCountdownScreen::onNewBlock); registerNewBlockCallback(HalvingCountdownScreen::onNewBlock);
registerNewPriceCallback(TickerScreen::onPriceUpdate); registerNewPriceCallback(TickerScreen::onPriceUpdate);
registerNewPriceCallback(SatsPerDollarScreen::onPriceUpdate); registerNewPriceCallback(SatsPerDollarScreen::onPriceUpdate);
setupDisplays(); setupDisplays();
} else {
setupI2C();
}
} }
void loop() void loop()

View file

@ -41,7 +41,7 @@ const int EPD_BUSY[7] = {36, 39, 34, 35, 32, 33, 25};
const int EPD_RESET_MPD[7] = {8, 9, 10, 11, 12, 13, 14}; const int EPD_RESET_MPD[7] = {8, 9, 10, 11, 12, 13, 14};
const int EPD_DC = 22; const int EPD_DC = 22;
const int RST_PIN = 12; const int RST_PIN = 2;
#endif #endif
#ifdef IS_BW #ifdef IS_BW