Fix turn off LEDs
This commit is contained in:
parent
ad0800c233
commit
4da04ca3ee
9 changed files with 254 additions and 37 deletions
|
@ -7,6 +7,11 @@ Adafruit_MCP23X17 mcp1;
|
|||
#ifdef IS_BTCLOCK_S3
|
||||
Adafruit_MCP23X17 mcp2;
|
||||
#endif
|
||||
|
||||
#ifdef HAS_FRONTLIGHT
|
||||
PCA9685 flArray(PCA_I2C_ADDR);
|
||||
#endif
|
||||
|
||||
std::vector<std::string> screenNameMap(SCREEN_COUNT);
|
||||
std::mutex mcpMutex;
|
||||
uint lastTimeSync;
|
||||
|
@ -352,6 +357,10 @@ void setupHardware()
|
|||
// ;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAS_FRONTLIGHT
|
||||
setupFrontlight();
|
||||
#endif
|
||||
}
|
||||
|
||||
void improvGetAvailableWifiNetworks()
|
||||
|
@ -658,4 +667,21 @@ String getMyHostname()
|
|||
|
||||
uint getLastTimeSync() {
|
||||
return lastTimeSync;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAS_FRONTLIGHT
|
||||
void setupFrontlight() {
|
||||
flArray.begin();
|
||||
flArray.setFrequency(1000);
|
||||
flArray.setOutputEnablePin(PCA_OE_PIN);
|
||||
|
||||
if (!preferences.isKey("flMaxBrightness")) {
|
||||
preferences.putUInt("flMaxBrightness", 4095);
|
||||
}
|
||||
// Initialize all LEDs to off
|
||||
// for (int ledPin = 0; ledPin < NUM_SCREENS; ledPin++) {
|
||||
// flArray.setPWM(ledPin, 0, 0); // Turn off LED
|
||||
// }
|
||||
flArray.allOFF();
|
||||
}
|
||||
#endif
|
|
@ -20,6 +20,9 @@
|
|||
#include "lib/screen_handler.hpp"
|
||||
#include "lib/shared.hpp"
|
||||
#include "lib/webserver.hpp"
|
||||
#ifdef HAS_FRONTLIGHT
|
||||
#include "PCA9685.h"
|
||||
#endif
|
||||
|
||||
#define NTP_SERVER "pool.ntp.org"
|
||||
#define DEFAULT_MEMPOOL_INSTANCE "mempool.space"
|
||||
|
@ -42,6 +45,11 @@ void tryImprovSetup();
|
|||
void setupTimers();
|
||||
void finishSetup();
|
||||
void setupMcp();
|
||||
#ifdef HAS_FRONTLIGHT
|
||||
void setupFrontlight();
|
||||
extern PCA9685 flArray;
|
||||
#endif
|
||||
|
||||
String getMyHostname();
|
||||
std::vector<std::string> getScreenNameMap();
|
||||
|
||||
|
|
|
@ -1,6 +1,65 @@
|
|||
#include "epd.hpp"
|
||||
|
||||
#ifndef IS_BTCLOCK_S3
|
||||
#ifdef IS_BTCLOCK_REV_B
|
||||
Native_Pin EPD_CS[NUM_SCREENS] = {
|
||||
Native_Pin(2),
|
||||
Native_Pin(4),
|
||||
Native_Pin(6),
|
||||
Native_Pin(10),
|
||||
Native_Pin(38),
|
||||
Native_Pin(21),
|
||||
Native_Pin(17),
|
||||
};
|
||||
Native_Pin EPD_BUSY[NUM_SCREENS] = {
|
||||
Native_Pin(3),
|
||||
Native_Pin(5),
|
||||
Native_Pin(7),
|
||||
Native_Pin(9),
|
||||
Native_Pin(37),
|
||||
Native_Pin(18),
|
||||
Native_Pin(16),
|
||||
};
|
||||
MCP23X17_Pin EPD_RESET_MPD[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),
|
||||
};
|
||||
|
||||
Native_Pin EPD_DC = Native_Pin(14);
|
||||
#elif IS_BTCLOCK_S3
|
||||
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),
|
||||
};
|
||||
#else
|
||||
Native_Pin EPD_CS[NUM_SCREENS] = {
|
||||
Native_Pin(2),
|
||||
Native_Pin(4),
|
||||
|
@ -35,36 +94,6 @@ MCP23X17_Pin EPD_RESET_MPD[NUM_SCREENS] = {
|
|||
};
|
||||
|
||||
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<EPD_CLASS, EPD_CLASS::HEIGHT> displays[NUM_SCREENS] = {
|
||||
|
@ -141,7 +170,7 @@ void setupDisplays()
|
|||
|
||||
updateQueue = xQueueCreate(UPDATE_QUEUE_SIZE, sizeof(UpdateDisplayTaskItem));
|
||||
|
||||
xTaskCreate(prepareDisplayUpdateTask, "PrepareUpd", 4096, NULL, 11, NULL);
|
||||
xTaskCreate(prepareDisplayUpdateTask, "PrepareUpd", 2048, NULL, 11, NULL);
|
||||
|
||||
for (uint i = 0; i < NUM_SCREENS; i++)
|
||||
{
|
||||
|
|
|
@ -329,4 +329,40 @@ void ledTheaterChaseRainbow(int wait) {
|
|||
}
|
||||
}
|
||||
|
||||
Adafruit_NeoPixel getPixels() { return pixels; }
|
||||
Adafruit_NeoPixel getPixels() { return pixels; }
|
||||
|
||||
#ifdef HAS_FRONTLIGHT
|
||||
int flDelayTime = 10;
|
||||
|
||||
void frontlightFadeInAll() {
|
||||
for (int dutyCycle = 0; dutyCycle <= preferences.getUInt("flMaxBrightness"); dutyCycle += 5) {
|
||||
for (int ledPin = 0; ledPin < NUM_SCREENS; ledPin++) {
|
||||
flArray.setPWM(ledPin, 0, dutyCycle);
|
||||
}
|
||||
delay(flDelayTime);
|
||||
}
|
||||
}
|
||||
|
||||
void frontlightFadeOutAll() {
|
||||
for (int dutyCycle = preferences.getUInt("flMaxBrightness"); dutyCycle >= 0; dutyCycle -= 5) {
|
||||
for (int ledPin = 0; ledPin < NUM_SCREENS; ledPin++) {
|
||||
flArray.setPWM(ledPin, 0, dutyCycle);
|
||||
}
|
||||
delay(flDelayTime);
|
||||
}
|
||||
}
|
||||
|
||||
void frontlightFadeIn(uint num) {
|
||||
for (int dutyCycle = 0; dutyCycle <= preferences.getUInt("flMaxBrightness"); dutyCycle += 5) {
|
||||
flArray.setPWM(num, 0, dutyCycle);
|
||||
delay(flDelayTime);
|
||||
}
|
||||
}
|
||||
|
||||
void frontlightFadeOut(uint num) {
|
||||
for (int dutyCycle = preferences.getUInt("flMaxBrightness"); dutyCycle >= 0; dutyCycle -= 5) {
|
||||
flArray.setPWM(num, 0, dutyCycle);
|
||||
delay(flDelayTime);
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -56,4 +56,11 @@ void setLights(uint32_t color);
|
|||
void ledRainbow(int wait);
|
||||
void ledTheaterChaseRainbow(int wait);
|
||||
void ledTheaterChase(uint32_t color, int wait);
|
||||
Adafruit_NeoPixel getPixels();
|
||||
Adafruit_NeoPixel getPixels();
|
||||
|
||||
#ifdef HAS_FRONTLIGHT
|
||||
void frontlightFadeInAll();
|
||||
void frontlightFadeOutAll();
|
||||
void frontlightFadeIn(uint num);
|
||||
void frontlightFadeOut(uint num);
|
||||
#endif
|
|
@ -45,6 +45,7 @@ void setupWebserver() {
|
|||
"/api/show/custom", onApiShowTextAdvanced);
|
||||
server.addHandler(handler);
|
||||
|
||||
|
||||
AsyncCallbackJsonWebHandler *lightsJsonHandler =
|
||||
new AsyncCallbackJsonWebHandler("/api/lights", onApiLightsSetJson);
|
||||
server.addHandler(lightsJsonHandler);
|
||||
|
@ -301,7 +302,7 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) {
|
|||
}
|
||||
}
|
||||
|
||||
String uintSettings[] = {"minSecPriceUpd", "fullRefreshMin", "ledBrightness"};
|
||||
String uintSettings[] = {"minSecPriceUpd", "fullRefreshMin", "ledBrightness", "flMaxBrightness"};
|
||||
|
||||
for (String setting : uintSettings) {
|
||||
if (settings.containsKey(setting)) {
|
||||
|
@ -418,6 +419,13 @@ void onApiSettingsGet(AsyncWebServerRequest *request) {
|
|||
root["ip"] = WiFi.localIP();
|
||||
root["txPower"] = WiFi.getTxPower();
|
||||
|
||||
#ifdef HAS_FRONTLIGHT
|
||||
root["hasFrontlight"] = true;
|
||||
root["flMaxBrightness"] = preferences.getUInt("flMaxBrightness", 4095);
|
||||
#else
|
||||
root["hasFrontlight"] = false;
|
||||
#endif
|
||||
|
||||
#ifdef GIT_REV
|
||||
root["gitRev"] = String(GIT_REV);
|
||||
#endif
|
||||
|
@ -761,6 +769,11 @@ void onApiLightsSetJson(AsyncWebServerRequest *request, JsonVariant &json) {
|
|||
JsonArray lights = json.as<JsonArray>();
|
||||
|
||||
if (lights.size() != pixels.numPixels()) {
|
||||
if (!lights.size()) {
|
||||
// if empty, assume off request
|
||||
return onApiLightsOff(request);
|
||||
}
|
||||
|
||||
Serial.printf("Invalid values for LED set %d\n", lights.size());
|
||||
request->send(400);
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue