More code formatting improvements

This commit is contained in:
Djuri Baars 2023-11-30 22:56:50 +01:00
parent 4aab02a040
commit 86d299fd75
25 changed files with 417 additions and 467 deletions

View file

@ -177,8 +177,7 @@ void setBlockHeight(uint newBlockHeight) {
}
bool isBlockNotifyConnected() {
if (blockNotifyClient == NULL)
return false;
if (blockNotifyClient == NULL) return false;
return esp_websocket_client_is_connected(blockNotifyClient);
}

View file

@ -1,15 +1,17 @@
#pragma once
#include <Arduino.h>
#include <ArduinoJson.h>
#include <HTTPClient.h>
#include <esp_timer.h>
#include <esp_websocket_client.h>
#include <cstring>
#include <string>
#include "lib/led_handler.hpp"
#include "lib/screen_handler.hpp"
#include "lib/shared.hpp"
#include <Arduino.h>
#include <ArduinoJson.h>
#include <HTTPClient.h>
#include <cstring>
#include <esp_timer.h>
#include <esp_websocket_client.h>
#include <string>
// using namespace websockets;

View file

@ -1,8 +1,9 @@
#pragma once
#include <Arduino.h>
#include "lib/screen_handler.hpp"
#include "lib/shared.hpp"
#include <Arduino.h>
extern TaskHandle_t buttonTaskHandle;

View file

@ -222,7 +222,6 @@ void setupTimers() {
}
void finishSetup() {
if (preferences.getBool("ledStatus", false)) {
restoreLedState();
} else {
@ -389,8 +388,8 @@ bool onImprovCommandCallback(improv::ImprovCommand cmd) {
if (improv_connectWifi(cmd.ssid, cmd.password)) {
queueLedEffect(LED_EFFECT_WIFI_CONNECT_SUCCESS);
// std::array<String, NUM_SCREENS> epdContent = {"S", "U", "C", "C", "E",
// "S", "S"}; setEpdContent(epdContent);
// std::array<String, NUM_SCREENS> epdContent = {"S", "U", "C", "C",
// "E", "S", "S"}; setEpdContent(epdContent);
preferences.putBool("wifiConfigured", true);
@ -452,8 +451,7 @@ void improv_set_state(improv::State state) {
data[9] = state;
uint8_t checksum = 0x00;
for (uint8_t d : data)
checksum += d;
for (uint8_t d : data) checksum += d;
data[10] = checksum;
Serial.write(data.data(), data.size());
@ -468,8 +466,7 @@ void improv_send_response(std::vector<uint8_t> &response) {
data.insert(data.end(), response.begin(), response.end());
uint8_t checksum = 0x00;
for (uint8_t d : data)
checksum += d;
for (uint8_t d : data) checksum += d;
data.push_back(checksum);
Serial.write(data.data(), data.size());
@ -484,8 +481,7 @@ void improv_set_error(improv::Error error) {
data[9] = error;
uint8_t checksum = 0x00;
for (uint8_t d : data)
checksum += d;
for (uint8_t d : data) checksum += d;
data[10] = checksum;
Serial.write(data.data(), data.size());
@ -529,8 +525,7 @@ void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
case ARDUINO_EVENT_WIFI_STA_GOT_IP: {
Serial.print("Obtained IP address: ");
Serial.println(WiFi.localIP());
if (!first_connect)
queueLedEffect(LED_EFFECT_WIFI_CONNECT_SUCCESS);
if (!first_connect) queueLedEffect(LED_EFFECT_WIFI_CONNECT_SUCCESS);
first_connect = false;
break;
}

View file

@ -6,6 +6,7 @@
#include <WiFiManager.h>
#include <base64.h>
#include <esp_task_wdt.h>
#include <map>
#include "lib/block_notify.hpp"

View file

@ -185,7 +185,6 @@ void prepareDisplayUpdateTask(void *pvParameters) {
} else if (epdContent[epdIndex].length() > 5) {
renderText(epdIndex, epdContent[epdIndex], updatePartial);
} else {
if (epdContent[epdIndex].length() > 1) {
showChars(epdIndex, epdContent[epdIndex], updatePartial,
&FONT_MEDIUM);
@ -237,8 +236,7 @@ extern "C" void updateDisplay(void *pvParameters) noexcept {
if (displays[epdIndex].displayWithReturn(updatePartial)) {
displays[epdIndex].powerOff();
currentEpdContent[epdIndex] = epdContent[epdIndex];
if (!updatePartial)
lastFullRefresh[epdIndex] = millis();
if (!updatePartial) lastFullRefresh[epdIndex] = millis();
if (eventSourceTaskHandle != NULL)
xTaskNotifyGive(eventSourceTaskHandle);

View file

@ -1,16 +1,18 @@
#pragma once
#include "fonts/fonts.hpp"
#include "lib/config.hpp"
#include "lib/shared.hpp"
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <GxEPD2_BW.h>
#include <mcp23x17_pin.hpp>
#include <mutex>
#include <native_pin.hpp>
#include <regex>
#include "fonts/fonts.hpp"
#include "lib/config.hpp"
#include "lib/shared.hpp"
#ifdef USE_QR
#include "qrcodegen.h"
#endif

View file

@ -54,35 +54,25 @@ bool parse_improv_serial_byte(size_t position, uint8_t byte,
const uint8_t *buffer,
std::function<bool(ImprovCommand)> &&callback,
std::function<void(Error)> &&on_error) {
if (position == 0)
return byte == 'I';
if (position == 1)
return byte == 'M';
if (position == 2)
return byte == 'P';
if (position == 3)
return byte == 'R';
if (position == 4)
return byte == 'O';
if (position == 5)
return byte == 'V';
if (position == 0) return byte == 'I';
if (position == 1) return byte == 'M';
if (position == 2) return byte == 'P';
if (position == 3) return byte == 'R';
if (position == 4) return byte == 'O';
if (position == 5) return byte == 'V';
if (position == 6)
return byte == IMPROV_SERIAL_VERSION;
if (position == 6) return byte == IMPROV_SERIAL_VERSION;
if (position <= 8)
return true;
if (position <= 8) return true;
uint8_t type = buffer[7];
uint8_t data_len = buffer[8];
if (position <= 8 + data_len)
return true;
if (position <= 8 + data_len) return true;
if (position == 8 + data_len + 1) {
uint8_t checksum = 0x00;
for (size_t i = 0; i < position; i++)
checksum += buffer[i];
for (size_t i = 0; i < position; i++) checksum += buffer[i];
if (checksum != byte) {
on_error(ERROR_INVALID_RPC);

View file

@ -76,8 +76,7 @@ void ledTask(void *parameter) {
for (int i = NEOPIXEL_COUNT; i >= 0; i--) {
for (int j = NEOPIXEL_COUNT; j >= 0; j--) {
uint32_t c = pixels.Color(0, 0, 0);
if (i == j)
c = pixels.Color(0, 255, 0);
if (i == j) c = pixels.Color(0, 255, 0);
pixels.setPixelColor(j, c);
}
@ -101,11 +100,9 @@ void ledTask(void *parameter) {
delay(900);
for (int i = NEOPIXEL_COUNT; i--; i > 0) {
for (int j = NEOPIXEL_COUNT; j--; j > 0) {
uint32_t c = pixels.Color(0, 0, 0);
if (i == j)
c = pixels.Color(0, 255, 0);
if (i == j) c = pixels.Color(0, 255, 0);
pixels.setPixelColor(j, c);
}
@ -155,7 +152,6 @@ void setupLedTask() {
void blinkDelay(int d, int times) {
for (int j = 0; j < times; j++) {
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
pixels.setPixelColor(1, pixels.Color(0, 255, 0));
pixels.setPixelColor(2, pixels.Color(255, 0, 0));
@ -218,7 +214,6 @@ void clearLeds() {
void setLights(int r, int g, int b) { setLights(pixels.Color(r, g, b)); }
void setLights(uint32_t color) {
bool ledStatus = true;
for (int i = 0; i < NEOPIXEL_COUNT; i++) {

View file

@ -1,12 +1,13 @@
#pragma once
#include "lib/shared.hpp"
#include "lib/webserver.hpp"
#include <Adafruit_NeoPixel.h>
#include <Arduino.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "lib/shared.hpp"
#include "lib/webserver.hpp"
#ifndef NEOPIXEL_PIN
#define NEOPIXEL_PIN 34
#endif

View file

@ -1,8 +1,9 @@
#include "lib/config.hpp"
#include "lib/shared.hpp"
#include <Arduino.h>
#include <ArduinoOTA.h>
#include "lib/config.hpp"
#include "lib/shared.hpp"
void setupOTA();
void onOTAStart();
void handleOTATask(void *parameter);

View file

@ -1,6 +1,7 @@
#include "price_fetch.hpp"
const PROGMEM char *cgApiUrl = "https://api.coingecko.com/api/v3/simple/"
const PROGMEM char *cgApiUrl =
"https://api.coingecko.com/api/v3/simple/"
"price?ids=bitcoin&vs_currencies=usd%2Ceur";
TaskHandle_t priceFetchTaskHandle;

View file

@ -1,8 +1,9 @@
#include "lib/config.hpp"
#include "lib/shared.hpp"
#include <Arduino.h>
#include <HTTPClient.h>
#include "lib/config.hpp"
#include "lib/shared.hpp"
extern TaskHandle_t priceFetchTaskHandle;
void setupPriceFetchTask();

View file

@ -79,7 +79,6 @@ void onWebsocketPriceMessage(esp_websocket_event_data_t *event_data) {
if (doc.containsKey("bitcoin")) {
if (currentPrice != doc["bitcoin"].as<long>()) {
uint minSecPriceUpd = preferences.getUInt(
"minSecPriceUpd", DEFAULT_SECONDS_BETWEEN_PRICE_UPDATE);
uint currentTime = esp_timer_get_time() / 1000000;
@ -108,8 +107,7 @@ uint getPrice() { return currentPrice; }
void setPrice(uint newPrice) { currentPrice = newPrice; }
bool isPriceNotifyConnected() {
if (clientPrice == NULL)
return false;
if (clientPrice == NULL) return false;
return esp_websocket_client_is_connected(clientPrice);
}

View file

@ -2,13 +2,12 @@
#include <Arduino.h>
#include <ArduinoJson.h>
#include <esp_websocket_client.h>
#include <string>
#include <esp_websocket_client.h>
#include "lib/screen_handler.hpp"
// using namespace websockets;
void setupPriceNotify();
void onWebsocketPriceEvent(void *handler_args, esp_event_base_t base,

View file

@ -12,19 +12,6 @@ std::array<std::string, NUM_SCREENS> taskEpdContent = {"", "", "", "",
"", "", ""};
std::string priceString;
// typedef enum
// {
// TASK_PRICE_UPDATE,
// TASK_BLOCK_UPDATE,
// TASK_TIME_UPDATE
// } TaskType;
// typedef struct
// {
// TaskType type;
// unsigned long data;
// } WorkItem;
#define WORK_QUEUE_SIZE 10
QueueHandle_t workQueue = NULL;
@ -85,7 +72,8 @@ void workerTask(void *pvParameters) {
minute = "0" + minute;
}
timeString = std::to_string(timeinfo.tm_hour) + ":" + minute.c_str();
timeString =
std::to_string(timeinfo.tm_hour) + ":" + minute.c_str();
timeString.insert(timeString.begin(),
NUM_SCREENS - timeString.length(), ' ');
taskEpdContent[0] = std::to_string(timeinfo.tm_mday) + "/" +
@ -145,11 +133,6 @@ void IRAM_ATTR screenRotateTimerISR(void *arg) {
void setupTasks() {
workQueue = xQueueCreate(WORK_QUEUE_SIZE, sizeof(WorkItem));
// xTaskCreate(taskPriceUpdate, "updatePrice", 1024, NULL, tskIDLE_PRIORITY,
// &priceUpdateTaskHandle); xTaskCreate(taskBlockUpdate, "updateBlock", 1024,
// NULL, tskIDLE_PRIORITY, &blockUpdateTaskHandle);
// xTaskCreate(taskTimeUpdate, "updateTime", 1024, NULL, tskIDLE_PRIORITY,
// &timeUpdateTaskHandle);
xTaskCreate(workerTask, "workerTask", 4096, NULL, tskIDLE_PRIORITY,
&workerTaskHandle);
@ -214,8 +197,7 @@ void setTimerActive(bool status) {
preferences.putBool("timerActive", false);
}
if (eventSourceTaskHandle != NULL)
xTaskNotifyGive(eventSourceTaskHandle);
if (eventSourceTaskHandle != NULL) xTaskNotifyGive(eventSourceTaskHandle);
}
void toggleTimerActive() { setTimerActive(!isTimerActive()); }
@ -253,8 +235,7 @@ void setCurrentScreen(uint newScreen) {
}
}
if (eventSourceTaskHandle != NULL)
xTaskNotifyGive(eventSourceTaskHandle);
if (eventSourceTaskHandle != NULL) xTaskNotifyGive(eventSourceTaskHandle);
}
void nextScreen() {
@ -269,7 +250,6 @@ void nextScreen() {
}
void previousScreen() {
int newCurrentScreen = modulo(getCurrentScreen() - 1, SCREEN_COUNT);
String key = "screen" + String(newCurrentScreen) + "Visible";

View file

@ -1,11 +1,11 @@
#pragma once
#include <esp_timer.h>
#include <data_handler.hpp>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <data_handler.hpp>
#include "lib/epd.hpp"
#include "lib/price_fetch.hpp"
#include "lib/shared.hpp"

View file

@ -5,8 +5,8 @@
#include <Preferences.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <mutex>
#include <mutex>
#include <utils.hpp>
extern Adafruit_MCP23X17 mcp1;

View file

@ -5,7 +5,6 @@ AsyncEventSource events("/events");
TaskHandle_t eventSourceTaskHandle;
void setupWebserver() {
events.onConnect([](AsyncEventSourceClient *client) {
client->send("welcome", NULL, millis(), 1000);
});
@ -139,8 +138,7 @@ StaticJsonDocument<512> getLedStatusObject() {
}
void eventSourceUpdate() {
if (!events.count())
return;
if (!events.count()) return;
StaticJsonDocument<768> root = getStatusObject();
JsonArray data = root.createNestedArray("data");
@ -369,8 +367,7 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) {
void onApiRestart(AsyncWebServerRequest *request) {
request->send(200);
if (events.count())
events.send("closing");
if (events.count()) events.send("closing");
delay(500);
@ -742,7 +739,6 @@ void onApiLightsSetJson(AsyncWebServerRequest *request, JsonVariant &json) {
if (lights[i].containsKey("red") && lights[i].containsKey("green") &&
lights[i].containsKey("blue")) {
red = lights[i]["red"].as<uint>();
green = lights[i]["green"].as<uint>();
blue = lights[i]["blue"].as<uint>();

View file

@ -1,5 +1,6 @@
#pragma once
// Keep order of includes because of conflicts
#include "WebServer.h"
#include "ESPAsyncWebServer.h"
#include <ArduinoJson.h>
@ -8,20 +9,10 @@
#include "AsyncJson.h"
#include <iostream>
// #include "AsyncJson.h"
// #include "ESPAsyncWebServer.h"
// #include "WebServer.h"
// #include <ArduinoJson.h>
// #include <ESPmDNS.h>
// #include <LittleFS.h>
// #include <iostream>
#include "lib/block_notify.hpp"
#include "lib/led_handler.hpp"
#include "lib/price_notify.hpp"
#include "lib/screen_handler.hpp"
#include "webserver/OneParamRewrite.hpp"
extern TaskHandle_t eventSourceTaskHandle;

View file

@ -2,7 +2,6 @@
OneParamRewrite::OneParamRewrite(const char *from, const char *to)
: AsyncWebRewrite(from, to) {
_paramIndex = _from.indexOf('{');
if (_paramIndex >= 0 && _from.endsWith("}")) {