Skip to content

Commit

Permalink
fix: number matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
silvelo committed Jul 19, 2024
1 parent fdb2e95 commit 61c6a35
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 19 deletions.
24 changes: 19 additions & 5 deletions src/LedManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ void LedManager::showMinutes(int minutes) {
minutesStrip.show();
}

void LedManager::showHoursTest(int hour) {
this->showHourDigit(hour, 0, this->hourColor1);
this->showHourDigit(hour, hoursLength / 2, this->hourColor2);

hoursStrip.show();
}

void LedManager::showMinutesTest(int minutes) {
this->showMinuteDigit(minutes, 0, this->minuteColor1);
this->showMinuteDigit(minutes, minutesLength / 2, this->minuteColor2);

minutesStrip.show();
}

void LedManager::showColon() {
for (int i = 0; i < secondsLength / 2; i++) {
secondsStrip.setPixelColor(i, this->dotsColor1);
Expand Down Expand Up @@ -90,13 +104,13 @@ void LedManager::showHourDigit(int number, int startPixel, uint32_t color) {
}

void LedManager::showMinuteDigit(int number, int startPixel, uint32_t color) {
Serial.println("Number " + String(number));
/* Serial.println("Number " + String(number)); */
for (int i = 0; i < MINUTE_SEGMENT; i++) {
Serial.println("Segment number " + String(i));
/* Serial.println("Segment number " + String(i)); */
if (minuteSegments[number][i]) {
Serial.println("Power On pixels:");
/* Serial.println("Power On pixels:"); */
for (int j = 0; j < ledsPerSegment; j++) {
Serial.print("[");
/* Serial.print("[");
Serial.print(" Start Pixel: ");
Serial.print(startPixel);
Serial.print(" i: ");
Expand All @@ -107,8 +121,8 @@ void LedManager::showMinuteDigit(int number, int startPixel, uint32_t color) {
Serial.print(j);
Serial.print("] - ");
Serial.print(startPixel + (i * ledsPerSegment) + j);
Serial.println(); */
minutesStrip.setPixelColor(startPixel + (i * ledsPerSegment) + j, color);
Serial.println();
}
} else {
for (int j = 0; j < ledsPerSegment; j++) {
Expand Down
7 changes: 7 additions & 0 deletions src/PreferencesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ int PreferencesManager::getLedsPerSegment() {
return preferences.getInt(LEDS_PER_SEGMENT, DEFAULT_LEDS_PER_SEGMENT);
}

bool PreferencesManager::getDebug() {
return preferences.getBool(DEBUG, false);
}
void PreferencesManager::setDebug(boolean debug) {
preferences.putBool(DEBUG, debug);
}

void PreferencesManager::setLedsPerSegment(int numLeds) {
preferences.putInt(LEDS_PER_SEGMENT, numLeds);
}
40 changes: 40 additions & 0 deletions src/ServerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ void ServerManager::begin() {

server.on("/colors", HTTP_GET,
std::bind(&ServerManager::getColors, this, std::placeholders::_1));
server.on("/debug", HTTP_GET, std::bind(&ServerManager::getDebug, this, std::placeholders::_1));
server.on("/leds", HTTP_GET,
std::bind(&ServerManager::getLedsPerSegment, this, std::placeholders::_1));
server.on("/timezone", HTTP_GET,
std::bind(&ServerManager::getTimezone, this, std::placeholders::_1));
server.on("/deep-sleep", HTTP_GET,
std::bind(&ServerManager::getDeepSleep, this, std::placeholders::_1));

server.on(
"/debug", HTTP_POST, [](AsyncWebServerRequest *request) {}, NULL,
std::bind(&ServerManager::updateDebug, this, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, std::placeholders::_4, std::placeholders::_5));

server.on(
"/colors", HTTP_POST, [](AsyncWebServerRequest *request) {}, NULL,
std::bind(&ServerManager::updateColors, this, std::placeholders::_1, std::placeholders::_2,
Expand Down Expand Up @@ -147,6 +153,40 @@ void ServerManager::updateLedsPerSegment(AsyncWebServerRequest *request, uint8_t
request->send(400);
}

void ServerManager::getDebug(AsyncWebServerRequest *request) {
Serial.println(String("[") + request->methodToString() + "] " + request->url());
JsonDocument debugData;

debugData["debug"] = preferencesManager.getDebug();

String jsonString;
serializeJson(debugData, jsonString);

request->send(200, MIME_APPLICATION_JSON, jsonString);
}

void ServerManager::updateDebug(AsyncWebServerRequest *request, uint8_t *data, size_t len,
size_t index, size_t total) {
Serial.println(String("[") + request->methodToString() + "] " + request->url());
String bodyContent = getBodyContent(data, len);

JsonDocument body;
DeserializationError error = deserializeJson(body, bodyContent);
if (error) {
request->send(400);
return;
}

if (body.containsKey("debug")) {
bool debug = body["debug"].as<bool>();
preferencesManager.setDebug(debug);
request->send(204);
return;
}

request->send(400);
}

void ServerManager::getTimezone(AsyncWebServerRequest *request) {
Serial.println(String("[") + request->methodToString() + "] " + request->url());
JsonDocument timezoneData;
Expand Down
34 changes: 20 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,27 @@ void setup() {
void loop() {
ElegantOTA.loop();
timeManager.update();

bool isSleep = sleepManager.update(timeManager.getFormattedTime());
if (isSleep) {
Serial.println("Is Sleep:" + String(isSleep));
ledManager.end();
if (preferencesManager.getDebug()) {
for (int i = 0; i < 10; i++) {
ledManager.showHoursTest(i);
ledManager.showMinutesTest(i);
delay(1000);
}
} else {
int hours = timeManager.getHours();
int minutes = timeManager.getMinutes();
// int minutes = timeManager.getSeconds();

Serial.println(timeManager.getFormattedTime());

ledManager.showHours(hours);
ledManager.showMinutes(minutes);
ledManager.showColon();
bool isSleep = sleepManager.update(timeManager.getFormattedTime());
if (isSleep) {
Serial.println("Is Sleep:" + String(isSleep));
ledManager.end();
} else {
int hours = timeManager.getHours();
int minutes = timeManager.getMinutes();

Serial.println(timeManager.getFormattedTime());

ledManager.showHours(hours);
ledManager.showMinutes(minutes);
ledManager.showColon();
}
}

delay(1000);
Expand Down

0 comments on commit 61c6a35

Please sign in to comment.