Implemented LED brightness setting, started I2C slave code, made reset pin consistent with wiring for DOIT DevKit.
This commit is contained in:
parent
81885e3f15
commit
cc22692992
8 changed files with 94 additions and 30 deletions
|
@ -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";
|
||||||
|
|
|
@ -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">
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -58,10 +58,6 @@ void setupComponents()
|
||||||
|
|
||||||
#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()
|
||||||
|
@ -253,3 +260,31 @@ 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");
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
|
@ -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) + "]";
|
||||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -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,6 +54,10 @@ void setup()
|
||||||
#endif
|
#endif
|
||||||
setupWifi();
|
setupWifi();
|
||||||
|
|
||||||
|
bool slaveMode = preferences.getBool("I2CSlaveMode", false);
|
||||||
|
|
||||||
|
if (!slaveMode)
|
||||||
|
{
|
||||||
synchronizeTime();
|
synchronizeTime();
|
||||||
setupWebserver();
|
setupWebserver();
|
||||||
|
|
||||||
|
@ -67,7 +71,7 @@ void setup()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_RGB_LED
|
#ifdef WITH_RGB_LED
|
||||||
setLights(0,0,0);
|
setLights(0, 0, 0);
|
||||||
setupLedHandlerTask();
|
setupLedHandlerTask();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -78,6 +82,9 @@ void setup()
|
||||||
registerNewPriceCallback(SatsPerDollarScreen::onPriceUpdate);
|
registerNewPriceCallback(SatsPerDollarScreen::onPriceUpdate);
|
||||||
|
|
||||||
setupDisplays();
|
setupDisplays();
|
||||||
|
} else {
|
||||||
|
setupI2C();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue