Skip to content

Commit

Permalink
fix: add linter and fix default values
Browse files Browse the repository at this point in the history
  • Loading branch information
silvelo committed May 27, 2024
1 parent bacabb4 commit fc0d8a3
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 181 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 100
AllowShortFunctionsOnASingleLine: false
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
"platformio.platformio-ide",
"xaver.clang-format"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"istream": "cpp",
"functional": "cpp"
},
"html.format.wrapAttributes": "aligned-multiple",
"editor.formatOnSave": true,
"html.format.wrapAttributes": "aligned-multiple"
"C_Cpp.clang_format_fallbackStyle": "Google"
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Download `firmware.bin` and `spiffs.bin` from [releases](https://github.com/silvelo/7_segments_clock/releases)
8 changes: 4 additions & 4 deletions include/PreferencesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#define MINUTES_LED_2_COLOR "ml2c"

#include <Preferences.h>
class PreferencesManager
{
public:
#include <SPIFFS.h>
class PreferencesManager {
public:
static PreferencesManager &getInstance();

void begin();
Expand All @@ -38,7 +38,7 @@ class PreferencesManager
uint32_t getMinutesLed2Color();
void setMinutesLed2Color(uint32_t color);

private:
private:
PreferencesManager() = default;
PreferencesManager(const PreferencesManager &) = delete;
PreferencesManager &operator=(const PreferencesManager &) = delete;
Expand Down
25 changes: 15 additions & 10 deletions include/ServerManager.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
#ifndef SERVER_MANAGER_H
#define SERVER_MANAGER_H

#include <ArduinoJson.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ArduinoJson.h>
#include "PreferencesManager.h"
#include <SPIFFS.h>

#include "LedManager.h"
#include "PreferencesManager.h"
#include "TimeManager.h"

#define MIME_APPLICATION_JSON "application/json"

class ServerManager
{
public:
class ServerManager {
public:
static ServerManager &getInstance();

AsyncWebServer *getServer();
void begin();

private:
private:
ServerManager();
ServerManager(const ServerManager &) = delete;
ServerManager &operator=(const ServerManager &) = delete;
Expand All @@ -29,15 +30,19 @@ class ServerManager
TimeManager &timeManager;

void getColors(AsyncWebServerRequest *request);
void updateColors(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total);
void updateColors(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index,
size_t total);
void getTimezone(AsyncWebServerRequest *request);
void updateTimezone(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total);
void updateTimezone(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index,
size_t total);
void getDeepSleep(AsyncWebServerRequest *request);
void updateDeepSleep(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total);
void updateDeepSleep(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index,
size_t total);
void handleRoot(AsyncWebServerRequest *request);
void handleCSS(AsyncWebServerRequest *request);
void handleJS(AsyncWebServerRequest *request);
void serveFile(const String &filePath, const String &contentType, AsyncWebServerRequest *request);
void serveFile(const String &filePath, const String &contentType,
AsyncWebServerRequest *request);
JsonDocument createColorJson();
uint32_t stringToHex(const String &hexString);
String hexToString(uint32_t hex);
Expand Down
48 changes: 16 additions & 32 deletions src/LedManager.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "LedManager.h"

LedManager &LedManager::getInstance()
{
LedManager &LedManager::getInstance() {
static LedManager instance;
return instance;
}
Expand All @@ -10,44 +9,39 @@ LedManager::LedManager()
: hoursStrip(NUM_PIXELS, HOUR_PIN, NEO_GRB + NEO_KHZ800),
minutesStrip(NUM_PIXELS, MINUTE_PIN, NEO_GRB + NEO_KHZ800),
secondsStrip(SECOND_NUM_PIXELS, SECOND_PIN, NEO_GRB + NEO_KHZ800),
preferencesManager(PreferencesManager::getInstance())
{
preferencesManager(PreferencesManager::getInstance()) {
}

void LedManager::begin()
{
void LedManager::begin() {
Serial.begin(115200);
hoursStrip.begin();
minutesStrip.begin();
secondsStrip.begin();
updateColorsFromPreferences();
Serial.println("Led Manager inicializado.");
}

void LedManager::showHours(int hour)
{
void LedManager::showHours(int hour) {
this->showHourDigit(hour % 10, 0, this->hourColor1);
this->showHourDigit(hour / 10, NUM_PIXELS / 2, this->hourColor2);

hoursStrip.show();
}

void LedManager::showMinutes(int minutes)
{
void LedManager::showMinutes(int minutes) {
this->showMinuteDigit(minutes / 10, 0, this->minuteColor1);
this->showMinuteDigit(minutes % 10, NUM_PIXELS / 2, this->minuteColor2);

minutesStrip.show();
}

void LedManager::showColon()
{
void LedManager::showColon() {
secondsStrip.setPixelColor(0, this->dotsColor1);
secondsStrip.setPixelColor(1, this->dotsColor2);
secondsStrip.show();
}

void LedManager::updateColorsFromPreferences()
{
void LedManager::updateColorsFromPreferences() {
hourColor1 = preferencesManager.getHourLed1Color();
hourColor2 = preferencesManager.getHourLed2Color();
minuteColor1 = preferencesManager.getMinutesLed1Color();
Expand All @@ -56,34 +50,24 @@ void LedManager::updateColorsFromPreferences()
dotsColor2 = preferencesManager.getDotsLed2Color();
}

void LedManager::showHourDigit(int number, int startPixel, uint32_t color)
{
for (int i = 0; i < 7; i++)
{
if (hourSegments[number][i])
{
void LedManager::showHourDigit(int number, int startPixel, uint32_t color) {
for (int i = 0; i < 7; i++) {
if (hourSegments[number][i]) {
hoursStrip.setPixelColor(startPixel + (i * 2), color);
hoursStrip.setPixelColor(startPixel + (i * 2) + 1, color);
}
else
{
} else {
hoursStrip.setPixelColor(startPixel + (i * 2), hoursStrip.Color(0, 0, 0));
hoursStrip.setPixelColor(startPixel + (i * 2) + 1, hoursStrip.Color(0, 0, 0));
}
}
}

void LedManager::showMinuteDigit(int number, int startPixel, uint32_t color)
{
for (int i = 0; i < 7; i++)
{
if (minuteSegments[number][i])
{
void LedManager::showMinuteDigit(int number, int startPixel, uint32_t color) {
for (int i = 0; i < 7; i++) {
if (minuteSegments[number][i]) {
minutesStrip.setPixelColor(startPixel + (i * 2), color);
minutesStrip.setPixelColor(startPixel + (i * 2) + 1, color);
}
else
{
} else {
minutesStrip.setPixelColor(startPixel + (i * 2), minutesStrip.Color(0, 0, 0));
minutesStrip.setPixelColor(startPixel + (i * 2) + 1, minutesStrip.Color(0, 0, 0));
}
Expand Down
64 changes: 21 additions & 43 deletions src/PreferencesManager.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
#include <SPIFFS.h>
#include "PreferencesManager.h"

PreferencesManager &PreferencesManager::getInstance()
{
PreferencesManager &PreferencesManager::getInstance() {
static PreferencesManager instance;
return instance;
}

void PreferencesManager::begin()
{
void PreferencesManager::begin() {
Serial.begin(115200);

if (!SPIFFS.begin())
{
if (!SPIFFS.begin()) {
Serial.println("Error al montar el sistema de archivos");
return;
}
Expand All @@ -21,97 +17,79 @@ void PreferencesManager::begin()
Serial.println("Preferences inicializado.");
}

int PreferencesManager::getTimeOffset()
{
int PreferencesManager::getTimeOffset() {
return preferences.getInt(TIME_OFFSET);
}

void PreferencesManager::setTimeOffset(int timeOffset)
{
void PreferencesManager::setTimeOffset(int timeOffset) {
Serial.println("Set time offset: " + String(timeOffset) + " hours.");
preferences.putInt(TIME_OFFSET, timeOffset);
}

uint32_t PreferencesManager::getStartTimestamp()
{
uint32_t PreferencesManager::getStartTimestamp() {
Serial.println("Get start timestamp");
return preferences.getUInt(START_TIMESTAMP);
}

void PreferencesManager::setStartTimestamp(uint32_t startTimestamp)
{
void PreferencesManager::setStartTimestamp(uint32_t startTimestamp) {
Serial.println("Set start timestamp: " + String(startTimestamp));
preferences.putUInt(START_TIMESTAMP, startTimestamp);
}

uint32_t PreferencesManager::getEndTimestamp()
{
uint32_t PreferencesManager::getEndTimestamp() {
Serial.println("Get end timestamp");
return preferences.getUInt(END_TIMESTAMP, 0);
}

void PreferencesManager::setEndTimestamp(uint32_t endTimestamp)
{
void PreferencesManager::setEndTimestamp(uint32_t endTimestamp) {
Serial.println("Set end timestamp: " + String(endTimestamp));
preferences.putUInt(END_TIMESTAMP, endTimestamp);
}

uint32_t PreferencesManager::getHourLed1Color()
{
uint32_t PreferencesManager::getHourLed1Color() {
return preferences.getUInt(HOUR_LED_1_COLOR, DEFAULT_LED_COLOR);
}

void PreferencesManager::setHourLed1Color(uint32_t color)
{
void PreferencesManager::setHourLed1Color(uint32_t color) {
preferences.putUInt(HOUR_LED_1_COLOR, color);
}

uint32_t PreferencesManager::getHourLed2Color()
{
uint32_t PreferencesManager::getHourLed2Color() {
return preferences.getUInt(HOUR_LED_2_COLOR, DEFAULT_LED_COLOR);
}

void PreferencesManager::setHourLed2Color(uint32_t color)
{
void PreferencesManager::setHourLed2Color(uint32_t color) {
preferences.putUInt(HOUR_LED_2_COLOR, color);
}

uint32_t PreferencesManager::getDotsLed1Color()
{
uint32_t PreferencesManager::getDotsLed1Color() {
return preferences.getUInt(DOTS_LED_1_COLOR, DEFAULT_LED_COLOR);
}

void PreferencesManager::setDotsLed1Color(uint32_t color)
{
void PreferencesManager::setDotsLed1Color(uint32_t color) {
preferences.putUInt(DOTS_LED_1_COLOR, color);
}

uint32_t PreferencesManager::getDotsLed2Color()
{
uint32_t PreferencesManager::getDotsLed2Color() {
return preferences.getUInt(DOTS_LED_2_COLOR, DEFAULT_LED_COLOR);
}

void PreferencesManager::setDotsLed2Color(uint32_t color)
{
void PreferencesManager::setDotsLed2Color(uint32_t color) {
preferences.putUInt(DOTS_LED_2_COLOR, color);
}

uint32_t PreferencesManager::getMinutesLed1Color()
{
uint32_t PreferencesManager::getMinutesLed1Color() {
return preferences.getUInt(MINUTES_LED_1_COLOR, DEFAULT_LED_COLOR);
}

void PreferencesManager::setMinutesLed1Color(uint32_t color)
{
void PreferencesManager::setMinutesLed1Color(uint32_t color) {
preferences.putUInt(MINUTES_LED_1_COLOR, color);
}

uint32_t PreferencesManager::getMinutesLed2Color()
{
uint32_t PreferencesManager::getMinutesLed2Color() {
return preferences.getUInt(MINUTES_LED_2_COLOR, DEFAULT_LED_COLOR);
}

void PreferencesManager::setMinutesLed2Color(uint32_t color)
{
void PreferencesManager::setMinutesLed2Color(uint32_t color) {
preferences.putUInt(MINUTES_LED_2_COLOR, color);
}
Loading

0 comments on commit fc0d8a3

Please sign in to comment.