Make better use of constants

This commit is contained in:
Djuri Baars 2023-10-30 23:50:07 +01:00
parent 6fc1dfe707
commit 62358a7c6e
8 changed files with 41 additions and 17 deletions

View File

@ -35,6 +35,7 @@ fetch('/api/settings', {
document.getElementById('bgColor').querySelector('[value="0xF800"]').remove();
}
document.getElementById('customText').setAttribute('maxlength', jsonData.numScreens);
document.getElementById('output').classList.add("fg-" + jsonData.fgColor.toString(16));
document.getElementById('output').classList.add("bg-" + jsonData.bgColor.toString(16));

View File

@ -363,7 +363,7 @@ void previousScreen()
void showNetworkSettings()
{
std::array<String, 7> epdContent = {"", "", "", "", "", "", ""};
std::array<String, NUM_SCREENS> epdContent = {"", "", "", "", "", "", ""};
String ipAddr = WiFi.localIP().toString();
String subNet = WiFi.subnetMask().toString();

View File

@ -78,7 +78,7 @@ void onApiStatus(AsyncWebServerRequest *request)
root["numScreens"] = NUM_SCREENS;
JsonArray data = root.createNestedArray("data");
JsonArray rendered = root.createNestedArray("rendered");
String epdContent[7];
String epdContent[NUM_SCREENS];
#ifdef WITH_RGB_LED
@ -166,6 +166,7 @@ void onApiActionUpdate(AsyncWebServerRequest *request)
void onApiSettingsGet(AsyncWebServerRequest *request)
{
StaticJsonDocument<768> root;
root["numScreens"] = NUM_SCREENS;
root["fgColor"] = getFgColor();
root["bgColor"] = getBgColor();
root["timerSeconds"] = timerSeconds;
@ -403,7 +404,7 @@ void onApiShowTextAdvanced(AsyncWebServerRequest *request, JsonVariant &json)
JsonArray screens = json.as<JsonArray>();
std::array<String, 7> epdContent;
std::array<String, NUM_SCREENS> epdContent;
int i = 0;
for (JsonVariant s : screens)
{

View File

@ -18,7 +18,7 @@ void CustomTextScreen::setSimpleText(const String& text)
customText.insert(customText.begin(), NUM_SCREENS - customText.length(), ' ');
for (uint i = 0; i < 7; i++)
for (uint i = 0; i < NUM_SCREENS; i++)
{
CustomTextScreen::epdContent[i] = customText[i];
}
@ -30,7 +30,7 @@ void CustomTextScreen::setText(std::array<String, NUM_SCREENS> customContent)
}
std::array<String, 7> CustomTextScreen::getEpdContent()
std::array<String, NUM_SCREENS> CustomTextScreen::getEpdContent()
{
return CustomTextScreen::epdContent;
}

View File

@ -16,5 +16,5 @@ class CustomTextScreen {
static void showScreen();
static std::array<String, NUM_SCREENS> getEpdContent();
static void setSimpleText(const String& text);
static void setText(std::array<String, 7> customContent);
static void setText(std::array<String, NUM_SCREENS> customContent);
};

View File

@ -7,13 +7,13 @@
class TimeScreen {
protected:
static std::array<String, 7> epdContent;
static std::array<String, NUM_SCREENS> epdContent;
static TimeScreen* instance_;
public:
static void init();
static void showScreen();
static void onNewMinute();
static void onActivate();
static std::array<String, 7> getEpdContent();
static std::array<String, NUM_SCREENS> getEpdContent();
static TimeScreen* getInstance();
};

View File

@ -1,9 +1,27 @@
#include "epd.hpp"
#ifdef IS_S3
Native_Pin EPD_CS[NUM_SCREENS] = {Native_Pin(2), Native_Pin(4), Native_Pin(6), Native_Pin(10), Native_Pin(33), 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(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)};
Native_Pin EPD_CS[NUM_SCREENS] = {
Native_Pin(2), Native_Pin(4), Native_Pin(6), Native_Pin(10), Native_Pin(33), Native_Pin(21), Native_Pin(17),
#if NUM_SCREENS == 9
Native_Pin(-1),
Native_Pin(-1),
#endif
};
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),
#if NUM_SCREENS == 9
Native_Pin(-1),
Native_Pin(-1),
#endif
};
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),
#if NUM_SCREENS == 9
MCP23X17_Pin(mcp, 15),
MCP23X17_Pin(mcp, 16)
#endif
};
Native_Pin EPD_DC = Native_Pin(14);
@ -15,6 +33,10 @@ 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(&EPD_CS[7], &EPD_DC, &EPD_RESET_MPD[7], &EPD_BUSY[7]),
GxEPD2_213_B74(&EPD_CS[8], &EPD_DC, &EPD_RESET_MPD[8], &EPD_BUSY[8]),
#endif
};
const int SEM_WAIT_TIME = 10000;
@ -22,8 +44,8 @@ const int SEM_WAIT_TIME = 10000;
uint32_t lastFullRefresh[NUM_SCREENS];
std::array<String, 7> currentEpdContent;
std::array<String, 7> epdContent;
std::array<String, NUM_SCREENS> currentEpdContent;
std::array<String, NUM_SCREENS> epdContent;
TaskHandle_t tasks[NUM_SCREENS];
SemaphoreHandle_t epdUpdateSemaphore[NUM_SCREENS];
@ -127,12 +149,12 @@ void taskEpd(void *pvParameters)
}
}
std::array<String, 7> getCurrentEpdContent()
std::array<String, NUM_SCREENS> getCurrentEpdContent()
{
return currentEpdContent;
}
void setEpdContent(std::array<String, 7> newEpdContent)
void setEpdContent(std::array<String, NUM_SCREENS> newEpdContent)
{
epdContent = newEpdContent;
}

View File

@ -34,9 +34,9 @@ void setupDisplays();
void initDisplays();
void taskEpd(void *pvParameters);
std::array<String, 7> getCurrentEpdContent();
std::array<String, NUM_SCREENS> getCurrentEpdContent();
void setEpdContent(std::array<String, 7> newEpdContent);
void setEpdContent(std::array<String, NUM_SCREENS> newEpdContent);
void splitText(const uint dispNum, String top, String bottom, bool partial);
void showDigit(const uint dispNum, char chr, bool partial, const GFXfont *font);