More code formatting improvements
This commit is contained in:
parent
4aab02a040
commit
86d299fd75
25 changed files with 417 additions and 467 deletions
|
@ -104,25 +104,25 @@ void onWebsocketEvent(void *handler_args, esp_event_base_t base,
|
||||||
esp_websocket_event_data_t *data = (esp_websocket_event_data_t *)event_data;
|
esp_websocket_event_data_t *data = (esp_websocket_event_data_t *)event_data;
|
||||||
const String sub = "{\"action\": \"want\", \"data\":[\"blocks\"]}";
|
const String sub = "{\"action\": \"want\", \"data\":[\"blocks\"]}";
|
||||||
switch (event_id) {
|
switch (event_id) {
|
||||||
case WEBSOCKET_EVENT_CONNECTED:
|
case WEBSOCKET_EVENT_CONNECTED:
|
||||||
Serial.println(F("Connected to Mempool.space WebSocket"));
|
Serial.println(F("Connected to Mempool.space WebSocket"));
|
||||||
|
|
||||||
Serial.println(sub);
|
Serial.println(sub);
|
||||||
if (esp_websocket_client_send_text(blockNotifyClient, sub.c_str(),
|
if (esp_websocket_client_send_text(blockNotifyClient, sub.c_str(),
|
||||||
sub.length(), portMAX_DELAY) == -1) {
|
sub.length(), portMAX_DELAY) == -1) {
|
||||||
Serial.println(F("Mempool.space WS Block Subscribe Error"));
|
Serial.println(F("Mempool.space WS Block Subscribe Error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case WEBSOCKET_EVENT_DATA:
|
case WEBSOCKET_EVENT_DATA:
|
||||||
onWebsocketMessage(data);
|
onWebsocketMessage(data);
|
||||||
break;
|
break;
|
||||||
case WEBSOCKET_EVENT_ERROR:
|
case WEBSOCKET_EVENT_ERROR:
|
||||||
Serial.println(F("Mempool.space WS Connnection error"));
|
Serial.println(F("Mempool.space WS Connnection error"));
|
||||||
break;
|
break;
|
||||||
case WEBSOCKET_EVENT_DISCONNECTED:
|
case WEBSOCKET_EVENT_DISCONNECTED:
|
||||||
Serial.println(F("Mempool.space WS Connnection Closed"));
|
Serial.println(F("Mempool.space WS Connnection Closed"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ void onWebsocketMessage(esp_websocket_event_data_t *event_data) {
|
||||||
|
|
||||||
if (getCurrentScreen() == SCREEN_BLOCK_HEIGHT &&
|
if (getCurrentScreen() == SCREEN_BLOCK_HEIGHT &&
|
||||||
preferences.getBool("ledFlashOnUpd", false)) {
|
preferences.getBool("ledFlashOnUpd", false)) {
|
||||||
vTaskDelay(pdMS_TO_TICKS(250)); // Wait until screens are updated
|
vTaskDelay(pdMS_TO_TICKS(250)); // Wait until screens are updated
|
||||||
queueLedEffect(LED_FLASH_BLOCK_NOTIFY);
|
queueLedEffect(LED_FLASH_BLOCK_NOTIFY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,8 +177,7 @@ void setBlockHeight(uint newBlockHeight) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isBlockNotifyConnected() {
|
bool isBlockNotifyConnected() {
|
||||||
if (blockNotifyClient == NULL)
|
if (blockNotifyClient == NULL) return false;
|
||||||
return false;
|
|
||||||
return esp_websocket_client_is_connected(blockNotifyClient);
|
return esp_websocket_client_is_connected(blockNotifyClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
#pragma once
|
#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/led_handler.hpp"
|
||||||
#include "lib/screen_handler.hpp"
|
#include "lib/screen_handler.hpp"
|
||||||
#include "lib/shared.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;
|
// using namespace websockets;
|
||||||
|
|
||||||
|
|
|
@ -17,18 +17,18 @@ void buttonTask(void *parameter) {
|
||||||
uint pin = mcp1.getLastInterruptPin();
|
uint pin = mcp1.getLastInterruptPin();
|
||||||
|
|
||||||
switch (pin) {
|
switch (pin) {
|
||||||
case 3:
|
case 3:
|
||||||
toggleTimerActive();
|
toggleTimerActive();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
nextScreen();
|
nextScreen();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
previousScreen();
|
previousScreen();
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
showSystemStatusScreen();
|
showSystemStatusScreen();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mcp1.clearInterrupts();
|
mcp1.clearInterrupts();
|
||||||
|
@ -51,7 +51,7 @@ void IRAM_ATTR handleButtonInterrupt() {
|
||||||
|
|
||||||
void setupButtonTask() {
|
void setupButtonTask() {
|
||||||
xTaskCreate(buttonTask, "ButtonTask", 4096, NULL, tskIDLE_PRIORITY,
|
xTaskCreate(buttonTask, "ButtonTask", 4096, NULL, tskIDLE_PRIORITY,
|
||||||
&buttonTaskHandle); // Create the FreeRTOS task
|
&buttonTaskHandle); // Create the FreeRTOS task
|
||||||
// Use interrupt instead of task
|
// Use interrupt instead of task
|
||||||
attachInterrupt(MCP_INT_PIN, handleButtonInterrupt, CHANGE);
|
attachInterrupt(MCP_INT_PIN, handleButtonInterrupt, CHANGE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "lib/screen_handler.hpp"
|
#include "lib/screen_handler.hpp"
|
||||||
#include "lib/shared.hpp"
|
#include "lib/shared.hpp"
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
extern TaskHandle_t buttonTaskHandle;
|
extern TaskHandle_t buttonTaskHandle;
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,6 @@ void setupTimers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void finishSetup() {
|
void finishSetup() {
|
||||||
|
|
||||||
if (preferences.getBool("ledStatus", false)) {
|
if (preferences.getBool("ledStatus", false)) {
|
||||||
restoreLedState();
|
restoreLedState();
|
||||||
} else {
|
} else {
|
||||||
|
@ -364,80 +363,80 @@ std::vector<std::string> getLocalUrl() {
|
||||||
|
|
||||||
bool onImprovCommandCallback(improv::ImprovCommand cmd) {
|
bool onImprovCommandCallback(improv::ImprovCommand cmd) {
|
||||||
switch (cmd.command) {
|
switch (cmd.command) {
|
||||||
case improv::Command::GET_CURRENT_STATE: {
|
case improv::Command::GET_CURRENT_STATE: {
|
||||||
if ((WiFi.status() == WL_CONNECTED)) {
|
if ((WiFi.status() == WL_CONNECTED)) {
|
||||||
improv_set_state(improv::State::STATE_PROVISIONED);
|
improv_set_state(improv::State::STATE_PROVISIONED);
|
||||||
std::vector<uint8_t> data = improv::build_rpc_response(
|
std::vector<uint8_t> data = improv::build_rpc_response(
|
||||||
improv::GET_CURRENT_STATE, getLocalUrl(), false);
|
improv::GET_CURRENT_STATE, getLocalUrl(), false);
|
||||||
improv_send_response(data);
|
improv_send_response(data);
|
||||||
} else {
|
} else {
|
||||||
improv_set_state(improv::State::STATE_AUTHORIZED);
|
improv_set_state(improv::State::STATE_AUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case improv::Command::WIFI_SETTINGS: {
|
|
||||||
if (cmd.ssid.length() == 0) {
|
|
||||||
improv_set_error(improv::Error::ERROR_INVALID_RPC);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
improv_set_state(improv::STATE_PROVISIONING);
|
case improv::Command::WIFI_SETTINGS: {
|
||||||
queueLedEffect(LED_EFFECT_WIFI_CONNECTING);
|
if (cmd.ssid.length() == 0) {
|
||||||
|
improv_set_error(improv::Error::ERROR_INVALID_RPC);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (improv_connectWifi(cmd.ssid, cmd.password)) {
|
improv_set_state(improv::STATE_PROVISIONING);
|
||||||
queueLedEffect(LED_EFFECT_WIFI_CONNECT_SUCCESS);
|
queueLedEffect(LED_EFFECT_WIFI_CONNECTING);
|
||||||
|
|
||||||
// std::array<String, NUM_SCREENS> epdContent = {"S", "U", "C", "C", "E",
|
if (improv_connectWifi(cmd.ssid, cmd.password)) {
|
||||||
// "S", "S"}; setEpdContent(epdContent);
|
queueLedEffect(LED_EFFECT_WIFI_CONNECT_SUCCESS);
|
||||||
|
|
||||||
preferences.putBool("wifiConfigured", true);
|
// std::array<String, NUM_SCREENS> epdContent = {"S", "U", "C", "C",
|
||||||
|
// "E", "S", "S"}; setEpdContent(epdContent);
|
||||||
|
|
||||||
improv_set_state(improv::STATE_PROVISIONED);
|
preferences.putBool("wifiConfigured", true);
|
||||||
std::vector<uint8_t> data = improv::build_rpc_response(
|
|
||||||
improv::WIFI_SETTINGS, getLocalUrl(), false);
|
|
||||||
improv_send_response(data);
|
|
||||||
|
|
||||||
delay(2500);
|
improv_set_state(improv::STATE_PROVISIONED);
|
||||||
ESP.restart();
|
std::vector<uint8_t> data = improv::build_rpc_response(
|
||||||
setupWebserver();
|
improv::WIFI_SETTINGS, getLocalUrl(), false);
|
||||||
} else {
|
improv_send_response(data);
|
||||||
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
|
|
||||||
|
|
||||||
improv_set_state(improv::STATE_STOPPED);
|
delay(2500);
|
||||||
improv_set_error(improv::Error::ERROR_UNABLE_TO_CONNECT);
|
ESP.restart();
|
||||||
|
setupWebserver();
|
||||||
|
} else {
|
||||||
|
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
|
||||||
|
|
||||||
|
improv_set_state(improv::STATE_STOPPED);
|
||||||
|
improv_set_error(improv::Error::ERROR_UNABLE_TO_CONNECT);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
case improv::Command::GET_DEVICE_INFO: {
|
||||||
}
|
std::vector<std::string> infos = {// Firmware name
|
||||||
|
"BTClock",
|
||||||
|
// Firmware version
|
||||||
|
"1.0.0",
|
||||||
|
// Hardware chip/variant
|
||||||
|
"ESP32S3",
|
||||||
|
// Device name
|
||||||
|
"BTClock"};
|
||||||
|
std::vector<uint8_t> data =
|
||||||
|
improv::build_rpc_response(improv::GET_DEVICE_INFO, infos, false);
|
||||||
|
improv_send_response(data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case improv::Command::GET_DEVICE_INFO: {
|
case improv::Command::GET_WIFI_NETWORKS: {
|
||||||
std::vector<std::string> infos = {// Firmware name
|
improvGetAvailableWifiNetworks();
|
||||||
"BTClock",
|
// std::array<String, NUM_SCREENS> epdContent = {"W", "E", "B", "W", "I",
|
||||||
// Firmware version
|
// "F", "I"}; setEpdContent(epdContent);
|
||||||
"1.0.0",
|
break;
|
||||||
// Hardware chip/variant
|
}
|
||||||
"ESP32S3",
|
|
||||||
// Device name
|
|
||||||
"BTClock"};
|
|
||||||
std::vector<uint8_t> data =
|
|
||||||
improv::build_rpc_response(improv::GET_DEVICE_INFO, infos, false);
|
|
||||||
improv_send_response(data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case improv::Command::GET_WIFI_NETWORKS: {
|
default: {
|
||||||
improvGetAvailableWifiNetworks();
|
improv_set_error(improv::ERROR_UNKNOWN_RPC);
|
||||||
// std::array<String, NUM_SCREENS> epdContent = {"W", "E", "B", "W", "I",
|
return false;
|
||||||
// "F", "I"}; setEpdContent(epdContent);
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: {
|
|
||||||
improv_set_error(improv::ERROR_UNKNOWN_RPC);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -452,8 +451,7 @@ void improv_set_state(improv::State state) {
|
||||||
data[9] = state;
|
data[9] = state;
|
||||||
|
|
||||||
uint8_t checksum = 0x00;
|
uint8_t checksum = 0x00;
|
||||||
for (uint8_t d : data)
|
for (uint8_t d : data) checksum += d;
|
||||||
checksum += d;
|
|
||||||
data[10] = checksum;
|
data[10] = checksum;
|
||||||
|
|
||||||
Serial.write(data.data(), data.size());
|
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());
|
data.insert(data.end(), response.begin(), response.end());
|
||||||
|
|
||||||
uint8_t checksum = 0x00;
|
uint8_t checksum = 0x00;
|
||||||
for (uint8_t d : data)
|
for (uint8_t d : data) checksum += d;
|
||||||
checksum += d;
|
|
||||||
data.push_back(checksum);
|
data.push_back(checksum);
|
||||||
|
|
||||||
Serial.write(data.data(), data.size());
|
Serial.write(data.data(), data.size());
|
||||||
|
@ -484,8 +481,7 @@ void improv_set_error(improv::Error error) {
|
||||||
data[9] = error;
|
data[9] = error;
|
||||||
|
|
||||||
uint8_t checksum = 0x00;
|
uint8_t checksum = 0x00;
|
||||||
for (uint8_t d : data)
|
for (uint8_t d : data) checksum += d;
|
||||||
checksum += d;
|
|
||||||
data[10] = checksum;
|
data[10] = checksum;
|
||||||
|
|
||||||
Serial.write(data.data(), data.size());
|
Serial.write(data.data(), data.size());
|
||||||
|
@ -497,74 +493,73 @@ void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
Serial.printf("[WiFi-event] event: %d\n", event);
|
Serial.printf("[WiFi-event] event: %d\n", event);
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case ARDUINO_EVENT_WIFI_READY:
|
case ARDUINO_EVENT_WIFI_READY:
|
||||||
Serial.println("WiFi interface ready");
|
Serial.println("WiFi interface ready");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_SCAN_DONE:
|
case ARDUINO_EVENT_WIFI_SCAN_DONE:
|
||||||
Serial.println("Completed scan for access points");
|
Serial.println("Completed scan for access points");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_STA_START:
|
case ARDUINO_EVENT_WIFI_STA_START:
|
||||||
Serial.println("WiFi client started");
|
Serial.println("WiFi client started");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_STA_STOP:
|
case ARDUINO_EVENT_WIFI_STA_STOP:
|
||||||
Serial.println("WiFi clients stopped");
|
Serial.println("WiFi clients stopped");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
||||||
Serial.println("Connected to access point");
|
Serial.println("Connected to access point");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: {
|
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: {
|
||||||
if (!first_connect) {
|
if (!first_connect) {
|
||||||
Serial.println("Disconnected from WiFi access point");
|
Serial.println("Disconnected from WiFi access point");
|
||||||
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
|
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
|
||||||
uint8_t reason = info.wifi_sta_disconnected.reason;
|
uint8_t reason = info.wifi_sta_disconnected.reason;
|
||||||
if (reason)
|
if (reason)
|
||||||
Serial.printf("Disconnect reason: %s, ",
|
Serial.printf("Disconnect reason: %s, ",
|
||||||
WiFi.disconnectReasonName((wifi_err_reason_t)reason));
|
WiFi.disconnectReasonName((wifi_err_reason_t)reason));
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE:
|
||||||
}
|
Serial.println("Authentication mode of access point has changed");
|
||||||
case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE:
|
break;
|
||||||
Serial.println("Authentication mode of access point has changed");
|
case ARDUINO_EVENT_WIFI_STA_GOT_IP: {
|
||||||
break;
|
Serial.print("Obtained IP address: ");
|
||||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP: {
|
Serial.println(WiFi.localIP());
|
||||||
Serial.print("Obtained IP address: ");
|
if (!first_connect) queueLedEffect(LED_EFFECT_WIFI_CONNECT_SUCCESS);
|
||||||
Serial.println(WiFi.localIP());
|
first_connect = false;
|
||||||
if (!first_connect)
|
break;
|
||||||
queueLedEffect(LED_EFFECT_WIFI_CONNECT_SUCCESS);
|
}
|
||||||
first_connect = false;
|
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
||||||
break;
|
Serial.println("Lost IP address and IP address is reset to 0");
|
||||||
}
|
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
|
||||||
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
WiFi.reconnect();
|
||||||
Serial.println("Lost IP address and IP address is reset to 0");
|
break;
|
||||||
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
|
case ARDUINO_EVENT_WIFI_AP_START:
|
||||||
WiFi.reconnect();
|
Serial.println("WiFi access point started");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_AP_START:
|
case ARDUINO_EVENT_WIFI_AP_STOP:
|
||||||
Serial.println("WiFi access point started");
|
Serial.println("WiFi access point stopped");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_AP_STOP:
|
case ARDUINO_EVENT_WIFI_AP_STACONNECTED:
|
||||||
Serial.println("WiFi access point stopped");
|
Serial.println("Client connected");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_AP_STACONNECTED:
|
case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED:
|
||||||
Serial.println("Client connected");
|
Serial.println("Client disconnected");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED:
|
case ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED:
|
||||||
Serial.println("Client disconnected");
|
Serial.println("Assigned IP address to client");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED:
|
case ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED:
|
||||||
Serial.println("Assigned IP address to client");
|
Serial.println("Received probe request");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED:
|
case ARDUINO_EVENT_WIFI_AP_GOT_IP6:
|
||||||
Serial.println("Received probe request");
|
Serial.println("AP IPv6 is preferred");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_AP_GOT_IP6:
|
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
|
||||||
Serial.println("AP IPv6 is preferred");
|
Serial.println("STA IPv6 is preferred");
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
|
default:
|
||||||
Serial.println("STA IPv6 is preferred");
|
break;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <WiFiManager.h>
|
#include <WiFiManager.h>
|
||||||
#include <base64.h>
|
#include <base64.h>
|
||||||
#include <esp_task_wdt.h>
|
#include <esp_task_wdt.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "lib/block_notify.hpp"
|
#include "lib/block_notify.hpp"
|
||||||
|
|
|
@ -124,7 +124,7 @@ void setupDisplays() {
|
||||||
*taskParam = i;
|
*taskParam = i;
|
||||||
|
|
||||||
xTaskCreate(updateDisplay, ("EpdUpd" + String(i)).c_str(), 2048, taskParam,
|
xTaskCreate(updateDisplay, ("EpdUpd" + String(i)).c_str(), 2048, taskParam,
|
||||||
11, &tasks[i]); // create task
|
11, &tasks[i]); // create task
|
||||||
}
|
}
|
||||||
|
|
||||||
epdContent = {"B", "T", "C", "L", "O", "C", "K"};
|
epdContent = {"B", "T", "C", "L", "O", "C", "K"};
|
||||||
|
@ -185,7 +185,6 @@ void prepareDisplayUpdateTask(void *pvParameters) {
|
||||||
} else if (epdContent[epdIndex].length() > 5) {
|
} else if (epdContent[epdIndex].length() > 5) {
|
||||||
renderText(epdIndex, epdContent[epdIndex], updatePartial);
|
renderText(epdIndex, epdContent[epdIndex], updatePartial);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (epdContent[epdIndex].length() > 1) {
|
if (epdContent[epdIndex].length() > 1) {
|
||||||
showChars(epdIndex, epdContent[epdIndex], updatePartial,
|
showChars(epdIndex, epdContent[epdIndex], updatePartial,
|
||||||
&FONT_MEDIUM);
|
&FONT_MEDIUM);
|
||||||
|
@ -237,8 +236,7 @@ extern "C" void updateDisplay(void *pvParameters) noexcept {
|
||||||
if (displays[epdIndex].displayWithReturn(updatePartial)) {
|
if (displays[epdIndex].displayWithReturn(updatePartial)) {
|
||||||
displays[epdIndex].powerOff();
|
displays[epdIndex].powerOff();
|
||||||
currentEpdContent[epdIndex] = epdContent[epdIndex];
|
currentEpdContent[epdIndex] = epdContent[epdIndex];
|
||||||
if (!updatePartial)
|
if (!updatePartial) lastFullRefresh[epdIndex] = millis();
|
||||||
lastFullRefresh[epdIndex] = millis();
|
|
||||||
|
|
||||||
if (eventSourceTaskHandle != NULL)
|
if (eventSourceTaskHandle != NULL)
|
||||||
xTaskNotifyGive(eventSourceTaskHandle);
|
xTaskNotifyGive(eventSourceTaskHandle);
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "fonts/fonts.hpp"
|
|
||||||
#include "lib/config.hpp"
|
|
||||||
#include "lib/shared.hpp"
|
|
||||||
#include <Fonts/FreeSans9pt7b.h>
|
#include <Fonts/FreeSans9pt7b.h>
|
||||||
#include <Fonts/FreeSansBold9pt7b.h>
|
#include <Fonts/FreeSansBold9pt7b.h>
|
||||||
#include <GxEPD2_BW.h>
|
#include <GxEPD2_BW.h>
|
||||||
|
|
||||||
#include <mcp23x17_pin.hpp>
|
#include <mcp23x17_pin.hpp>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <native_pin.hpp>
|
#include <native_pin.hpp>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
|
#include "fonts/fonts.hpp"
|
||||||
|
#include "lib/config.hpp"
|
||||||
|
#include "lib/shared.hpp"
|
||||||
|
|
||||||
#ifdef USE_QR
|
#ifdef USE_QR
|
||||||
#include "qrcodegen.h"
|
#include "qrcodegen.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -54,35 +54,25 @@ bool parse_improv_serial_byte(size_t position, uint8_t byte,
|
||||||
const uint8_t *buffer,
|
const uint8_t *buffer,
|
||||||
std::function<bool(ImprovCommand)> &&callback,
|
std::function<bool(ImprovCommand)> &&callback,
|
||||||
std::function<void(Error)> &&on_error) {
|
std::function<void(Error)> &&on_error) {
|
||||||
if (position == 0)
|
if (position == 0) return byte == 'I';
|
||||||
return byte == 'I';
|
if (position == 1) return byte == 'M';
|
||||||
if (position == 1)
|
if (position == 2) return byte == 'P';
|
||||||
return byte == 'M';
|
if (position == 3) return byte == 'R';
|
||||||
if (position == 2)
|
if (position == 4) return byte == 'O';
|
||||||
return byte == 'P';
|
if (position == 5) return byte == 'V';
|
||||||
if (position == 3)
|
|
||||||
return byte == 'R';
|
|
||||||
if (position == 4)
|
|
||||||
return byte == 'O';
|
|
||||||
if (position == 5)
|
|
||||||
return byte == 'V';
|
|
||||||
|
|
||||||
if (position == 6)
|
if (position == 6) return byte == IMPROV_SERIAL_VERSION;
|
||||||
return byte == IMPROV_SERIAL_VERSION;
|
|
||||||
|
|
||||||
if (position <= 8)
|
if (position <= 8) return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
uint8_t type = buffer[7];
|
uint8_t type = buffer[7];
|
||||||
uint8_t data_len = buffer[8];
|
uint8_t data_len = buffer[8];
|
||||||
|
|
||||||
if (position <= 8 + data_len)
|
if (position <= 8 + data_len) return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
if (position == 8 + data_len + 1) {
|
if (position == 8 + data_len + 1) {
|
||||||
uint8_t checksum = 0x00;
|
uint8_t checksum = 0x00;
|
||||||
for (size_t i = 0; i < position; i++)
|
for (size_t i = 0; i < position; i++) checksum += buffer[i];
|
||||||
checksum += buffer[i];
|
|
||||||
|
|
||||||
if (checksum != byte) {
|
if (checksum != byte) {
|
||||||
on_error(ERROR_INVALID_RPC);
|
on_error(ERROR_INVALID_RPC);
|
||||||
|
@ -148,6 +138,6 @@ std::vector<uint8_t> build_rpc_response(Command command,
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
#endif // ARDUINO
|
#endif // ARDUINO
|
||||||
|
|
||||||
} // namespace improv
|
} // namespace improv
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#ifdef ARDUINO
|
#ifdef ARDUINO
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#endif // ARDUINO
|
#endif // ARDUINO
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -81,6 +81,6 @@ std::vector<uint8_t> build_rpc_response(Command command,
|
||||||
std::vector<uint8_t> build_rpc_response(Command command,
|
std::vector<uint8_t> build_rpc_response(Command command,
|
||||||
const std::vector<String> &datum,
|
const std::vector<String> &datum,
|
||||||
bool add_checksum = true);
|
bool add_checksum = true);
|
||||||
#endif // ARDUINO
|
#endif // ARDUINO
|
||||||
|
|
||||||
} // namespace improv
|
} // namespace improv
|
|
@ -18,106 +18,103 @@ void ledTask(void *parameter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ledTaskParams) {
|
switch (ledTaskParams) {
|
||||||
case LED_POWER_TEST:
|
case LED_POWER_TEST:
|
||||||
ledRainbow(20);
|
ledRainbow(20);
|
||||||
pixels.clear();
|
pixels.clear();
|
||||||
break;
|
break;
|
||||||
case LED_EFFECT_WIFI_CONNECT_ERROR:
|
case LED_EFFECT_WIFI_CONNECT_ERROR:
|
||||||
blinkDelayTwoColor(100, 3, pixels.Color(8, 161, 236),
|
blinkDelayTwoColor(100, 3, pixels.Color(8, 161, 236),
|
||||||
pixels.Color(255, 0, 0));
|
pixels.Color(255, 0, 0));
|
||||||
break;
|
break;
|
||||||
case LED_FLASH_ERROR:
|
case LED_FLASH_ERROR:
|
||||||
blinkDelayColor(250, 3, 255, 0, 0);
|
blinkDelayColor(250, 3, 255, 0, 0);
|
||||||
break;
|
break;
|
||||||
case LED_EFFECT_HEARTBEAT:
|
case LED_EFFECT_HEARTBEAT:
|
||||||
blinkDelayColor(150, 2, 0, 0, 255);
|
blinkDelayColor(150, 2, 0, 0, 255);
|
||||||
break;
|
break;
|
||||||
case LED_EFFECT_WIFI_CONNECT_SUCCESS:
|
case LED_EFFECT_WIFI_CONNECT_SUCCESS:
|
||||||
case LED_FLASH_SUCCESS:
|
case LED_FLASH_SUCCESS:
|
||||||
blinkDelayColor(150, 3, 0, 255, 0);
|
blinkDelayColor(150, 3, 0, 255, 0);
|
||||||
break;
|
break;
|
||||||
case LED_PROGRESS_100:
|
case LED_PROGRESS_100:
|
||||||
pixels.setPixelColor(0, pixels.Color(0, 255, 0));
|
pixels.setPixelColor(0, pixels.Color(0, 255, 0));
|
||||||
case LED_PROGRESS_75:
|
case LED_PROGRESS_75:
|
||||||
pixels.setPixelColor(1, pixels.Color(0, 255, 0));
|
pixels.setPixelColor(1, pixels.Color(0, 255, 0));
|
||||||
case LED_PROGRESS_50:
|
case LED_PROGRESS_50:
|
||||||
pixels.setPixelColor(2, pixels.Color(0, 255, 0));
|
pixels.setPixelColor(2, pixels.Color(0, 255, 0));
|
||||||
case LED_PROGRESS_25:
|
case LED_PROGRESS_25:
|
||||||
pixels.setPixelColor(3, pixels.Color(0, 255, 0));
|
pixels.setPixelColor(3, pixels.Color(0, 255, 0));
|
||||||
pixels.show();
|
pixels.show();
|
||||||
break;
|
break;
|
||||||
case LED_FLASH_UPDATE:
|
case LED_FLASH_UPDATE:
|
||||||
break;
|
break;
|
||||||
case LED_FLASH_BLOCK_NOTIFY:
|
case LED_FLASH_BLOCK_NOTIFY:
|
||||||
blinkDelayTwoColor(250, 3, pixels.Color(224, 67, 0),
|
blinkDelayTwoColor(250, 3, pixels.Color(224, 67, 0),
|
||||||
pixels.Color(8, 2, 0));
|
pixels.Color(8, 2, 0));
|
||||||
break;
|
break;
|
||||||
case LED_EFFECT_WIFI_WAIT_FOR_CONFIG:
|
case LED_EFFECT_WIFI_WAIT_FOR_CONFIG:
|
||||||
blinkDelayTwoColor(100, 1, pixels.Color(8, 161, 236),
|
blinkDelayTwoColor(100, 1, pixels.Color(8, 161, 236),
|
||||||
pixels.Color(156, 225, 240));
|
pixels.Color(156, 225, 240));
|
||||||
break;
|
break;
|
||||||
case LED_EFFECT_WIFI_ERASE_SETTINGS:
|
case LED_EFFECT_WIFI_ERASE_SETTINGS:
|
||||||
blinkDelay(100, 3);
|
blinkDelay(100, 3);
|
||||||
break;
|
break;
|
||||||
case LED_EFFECT_WIFI_CONNECTING:
|
case LED_EFFECT_WIFI_CONNECTING:
|
||||||
for (int i = NEOPIXEL_COUNT; i >= 0; i--) {
|
for (int i = NEOPIXEL_COUNT; i >= 0; i--) {
|
||||||
for (int j = NEOPIXEL_COUNT; j >= 0; j--) {
|
for (int j = NEOPIXEL_COUNT; j >= 0; j--) {
|
||||||
if (j == i) {
|
if (j == i) {
|
||||||
pixels.setPixelColor(i, pixels.Color(16, 197, 236));
|
pixels.setPixelColor(i, pixels.Color(16, 197, 236));
|
||||||
} else {
|
} else {
|
||||||
pixels.setPixelColor(j, pixels.Color(0, 0, 0));
|
pixels.setPixelColor(j, pixels.Color(0, 0, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
pixels.show();
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
}
|
}
|
||||||
pixels.show();
|
break;
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
case LED_EFFECT_PAUSE_TIMER:
|
||||||
}
|
for (int i = NEOPIXEL_COUNT; i >= 0; i--) {
|
||||||
break;
|
for (int j = NEOPIXEL_COUNT; j >= 0; j--) {
|
||||||
case LED_EFFECT_PAUSE_TIMER:
|
uint32_t c = pixels.Color(0, 0, 0);
|
||||||
for (int i = NEOPIXEL_COUNT; i >= 0; i--) {
|
if (i == j) c = pixels.Color(0, 255, 0);
|
||||||
for (int j = NEOPIXEL_COUNT; j >= 0; j--) {
|
pixels.setPixelColor(j, c);
|
||||||
uint32_t c = pixels.Color(0, 0, 0);
|
}
|
||||||
if (i == j)
|
|
||||||
c = pixels.Color(0, 255, 0);
|
|
||||||
pixels.setPixelColor(j, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
pixels.show();
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
|
||||||
pixels.show();
|
pixels.show();
|
||||||
|
|
||||||
delay(100);
|
delay(900);
|
||||||
}
|
|
||||||
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
|
|
||||||
pixels.show();
|
|
||||||
|
|
||||||
delay(900);
|
|
||||||
|
|
||||||
pixels.clear();
|
|
||||||
pixels.show();
|
|
||||||
break;
|
|
||||||
case LED_EFFECT_START_TIMER:
|
|
||||||
pixels.clear();
|
|
||||||
pixels.setPixelColor((NEOPIXEL_COUNT - 1), pixels.Color(255, 0, 0));
|
|
||||||
pixels.show();
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
pixels.setPixelColor(j, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
pixels.clear();
|
||||||
|
pixels.show();
|
||||||
|
break;
|
||||||
|
case LED_EFFECT_START_TIMER:
|
||||||
|
pixels.clear();
|
||||||
|
pixels.setPixelColor((NEOPIXEL_COUNT - 1), pixels.Color(255, 0, 0));
|
||||||
pixels.show();
|
pixels.show();
|
||||||
|
|
||||||
delay(100);
|
delay(900);
|
||||||
}
|
|
||||||
|
|
||||||
pixels.clear();
|
for (int i = NEOPIXEL_COUNT; i--; i > 0) {
|
||||||
pixels.show();
|
for (int j = NEOPIXEL_COUNT; j--; j > 0) {
|
||||||
break;
|
uint32_t c = pixels.Color(0, 0, 0);
|
||||||
|
if (i == j) c = pixels.Color(0, 255, 0);
|
||||||
|
|
||||||
|
pixels.setPixelColor(j, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
pixels.show();
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
pixels.clear();
|
||||||
|
pixels.show();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// revert to previous state unless power test
|
// revert to previous state unless power test
|
||||||
|
@ -155,7 +152,6 @@ void setupLedTask() {
|
||||||
|
|
||||||
void blinkDelay(int d, int times) {
|
void blinkDelay(int d, int times) {
|
||||||
for (int j = 0; j < times; j++) {
|
for (int j = 0; j < times; j++) {
|
||||||
|
|
||||||
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
|
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
|
||||||
pixels.setPixelColor(1, pixels.Color(0, 255, 0));
|
pixels.setPixelColor(1, pixels.Color(0, 255, 0));
|
||||||
pixels.setPixelColor(2, pixels.Color(255, 0, 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(int r, int g, int b) { setLights(pixels.Color(r, g, b)); }
|
||||||
|
|
||||||
void setLights(uint32_t color) {
|
void setLights(uint32_t color) {
|
||||||
|
|
||||||
bool ledStatus = true;
|
bool ledStatus = true;
|
||||||
|
|
||||||
for (int i = 0; i < NEOPIXEL_COUNT; i++) {
|
for (int i = 0; i < NEOPIXEL_COUNT; i++) {
|
||||||
|
@ -282,43 +277,43 @@ void ledRainbow(int wait) {
|
||||||
pixels.rainbow(firstPixelHue);
|
pixels.rainbow(firstPixelHue);
|
||||||
// Above line is equivalent to:
|
// Above line is equivalent to:
|
||||||
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
|
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
|
||||||
pixels.show(); // Update strip with new contents
|
pixels.show(); // Update strip with new contents
|
||||||
delayMicroseconds(wait);
|
delayMicroseconds(wait);
|
||||||
// vTaskDelay(pdMS_TO_TICKS(wait)); // Pause for a moment
|
// vTaskDelay(pdMS_TO_TICKS(wait)); // Pause for a moment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ledTheaterChase(uint32_t color, int wait) {
|
void ledTheaterChase(uint32_t color, int wait) {
|
||||||
for (int a = 0; a < 10; a++) { // Repeat 10 times...
|
for (int a = 0; a < 10; a++) { // Repeat 10 times...
|
||||||
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
|
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
|
||||||
pixels.clear(); // Set all pixels in RAM to 0 (off)
|
pixels.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
// 'c' counts up from 'b' to end of strip in steps of 3...
|
// 'c' counts up from 'b' to end of strip in steps of 3...
|
||||||
for (int c = b; c < pixels.numPixels(); c += 3) {
|
for (int c = b; c < pixels.numPixels(); c += 3) {
|
||||||
pixels.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
pixels.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
}
|
}
|
||||||
pixels.show(); // Update strip with new contents
|
pixels.show(); // Update strip with new contents
|
||||||
vTaskDelay(pdMS_TO_TICKS(wait)); // Pause for a moment
|
vTaskDelay(pdMS_TO_TICKS(wait)); // Pause for a moment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ledTheaterChaseRainbow(int wait) {
|
void ledTheaterChaseRainbow(int wait) {
|
||||||
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||||
for (int a = 0; a < 30; a++) { // Repeat 30 times...
|
for (int a = 0; a < 30; a++) { // Repeat 30 times...
|
||||||
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
|
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
|
||||||
pixels.clear(); // Set all pixels in RAM to 0 (off)
|
pixels.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
// 'c' counts up from 'b' to end of strip in increments of 3...
|
// 'c' counts up from 'b' to end of strip in increments of 3...
|
||||||
for (int c = b; c < pixels.numPixels(); c += 3) {
|
for (int c = b; c < pixels.numPixels(); c += 3) {
|
||||||
// hue of pixel 'c' is offset by an amount to make one full
|
// hue of pixel 'c' is offset by an amount to make one full
|
||||||
// revolution of the color wheel (range 65536) along the length
|
// revolution of the color wheel (range 65536) along the length
|
||||||
// of the strip (strip.numPixels() steps):
|
// of the strip (strip.numPixels() steps):
|
||||||
int hue = firstPixelHue + c * 65536L / pixels.numPixels();
|
int hue = firstPixelHue + c * 65536L / pixels.numPixels();
|
||||||
uint32_t color = pixels.gamma32(pixels.ColorHSV(hue)); // hue -> RGB
|
uint32_t color = pixels.gamma32(pixels.ColorHSV(hue)); // hue -> RGB
|
||||||
pixels.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
pixels.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
}
|
}
|
||||||
pixels.show(); // Update strip with new contents
|
pixels.show(); // Update strip with new contents
|
||||||
vTaskDelay(pdMS_TO_TICKS(wait)); // Pause for a moment
|
vTaskDelay(pdMS_TO_TICKS(wait)); // Pause for a moment
|
||||||
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "lib/shared.hpp"
|
|
||||||
#include "lib/webserver.hpp"
|
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
|
|
||||||
|
#include "lib/shared.hpp"
|
||||||
|
#include "lib/webserver.hpp"
|
||||||
|
|
||||||
#ifndef NEOPIXEL_PIN
|
#ifndef NEOPIXEL_PIN
|
||||||
#define NEOPIXEL_PIN 34
|
#define NEOPIXEL_PIN 34
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -64,7 +64,7 @@ void onOTAStart() {
|
||||||
|
|
||||||
void handleOTATask(void *parameter) {
|
void handleOTATask(void *parameter) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ArduinoOTA.handle(); // Allow OTA updates to occur
|
ArduinoOTA.handle(); // Allow OTA updates to occur
|
||||||
vTaskDelay(pdMS_TO_TICKS(2500));
|
vTaskDelay(pdMS_TO_TICKS(2500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
#include "lib/config.hpp"
|
|
||||||
#include "lib/shared.hpp"
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
|
|
||||||
|
#include "lib/config.hpp"
|
||||||
|
#include "lib/shared.hpp"
|
||||||
|
|
||||||
void setupOTA();
|
void setupOTA();
|
||||||
void onOTAStart();
|
void onOTAStart();
|
||||||
void handleOTATask(void *parameter);
|
void handleOTATask(void *parameter);
|
||||||
void onOTAProgress(unsigned int progress, unsigned int total);
|
void onOTAProgress(unsigned int progress, unsigned int total);
|
||||||
void downloadUpdate();
|
void downloadUpdate();
|
||||||
void onOTAError(ota_error_t error);
|
void onOTAError(ota_error_t error);
|
||||||
void onOTAComplete();
|
void onOTAComplete();
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include "price_fetch.hpp"
|
#include "price_fetch.hpp"
|
||||||
|
|
||||||
const PROGMEM char *cgApiUrl = "https://api.coingecko.com/api/v3/simple/"
|
const PROGMEM char *cgApiUrl =
|
||||||
"price?ids=bitcoin&vs_currencies=usd%2Ceur";
|
"https://api.coingecko.com/api/v3/simple/"
|
||||||
|
"price?ids=bitcoin&vs_currencies=usd%2Ceur";
|
||||||
|
|
||||||
TaskHandle_t priceFetchTaskHandle;
|
TaskHandle_t priceFetchTaskHandle;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#include "lib/config.hpp"
|
|
||||||
#include "lib/shared.hpp"
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
|
|
||||||
|
#include "lib/config.hpp"
|
||||||
|
#include "lib/shared.hpp"
|
||||||
|
|
||||||
extern TaskHandle_t priceFetchTaskHandle;
|
extern TaskHandle_t priceFetchTaskHandle;
|
||||||
|
|
||||||
void setupPriceFetchTask();
|
void setupPriceFetchTask();
|
||||||
|
|
|
@ -57,18 +57,18 @@ void onWebsocketPriceEvent(void *handler_args, esp_event_base_t base,
|
||||||
esp_websocket_event_data_t *data = (esp_websocket_event_data_t *)event_data;
|
esp_websocket_event_data_t *data = (esp_websocket_event_data_t *)event_data;
|
||||||
|
|
||||||
switch (event_id) {
|
switch (event_id) {
|
||||||
case WEBSOCKET_EVENT_CONNECTED:
|
case WEBSOCKET_EVENT_CONNECTED:
|
||||||
Serial.println(F("Connected to CoinCap.io WebSocket"));
|
Serial.println(F("Connected to CoinCap.io WebSocket"));
|
||||||
break;
|
break;
|
||||||
case WEBSOCKET_EVENT_DATA:
|
case WEBSOCKET_EVENT_DATA:
|
||||||
onWebsocketPriceMessage(data);
|
onWebsocketPriceMessage(data);
|
||||||
break;
|
break;
|
||||||
case WEBSOCKET_EVENT_ERROR:
|
case WEBSOCKET_EVENT_ERROR:
|
||||||
Serial.println(F("Price WS Connnection error"));
|
Serial.println(F("Price WS Connnection error"));
|
||||||
break;
|
break;
|
||||||
case WEBSOCKET_EVENT_DISCONNECTED:
|
case WEBSOCKET_EVENT_DISCONNECTED:
|
||||||
Serial.println(F("Price WS Connnection Closed"));
|
Serial.println(F("Price WS Connnection Closed"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,6 @@ void onWebsocketPriceMessage(esp_websocket_event_data_t *event_data) {
|
||||||
|
|
||||||
if (doc.containsKey("bitcoin")) {
|
if (doc.containsKey("bitcoin")) {
|
||||||
if (currentPrice != doc["bitcoin"].as<long>()) {
|
if (currentPrice != doc["bitcoin"].as<long>()) {
|
||||||
|
|
||||||
uint minSecPriceUpd = preferences.getUInt(
|
uint minSecPriceUpd = preferences.getUInt(
|
||||||
"minSecPriceUpd", DEFAULT_SECONDS_BETWEEN_PRICE_UPDATE);
|
"minSecPriceUpd", DEFAULT_SECONDS_BETWEEN_PRICE_UPDATE);
|
||||||
uint currentTime = esp_timer_get_time() / 1000000;
|
uint currentTime = esp_timer_get_time() / 1000000;
|
||||||
|
@ -108,8 +107,7 @@ uint getPrice() { return currentPrice; }
|
||||||
void setPrice(uint newPrice) { currentPrice = newPrice; }
|
void setPrice(uint newPrice) { currentPrice = newPrice; }
|
||||||
|
|
||||||
bool isPriceNotifyConnected() {
|
bool isPriceNotifyConnected() {
|
||||||
if (clientPrice == NULL)
|
if (clientPrice == NULL) return false;
|
||||||
return false;
|
|
||||||
return esp_websocket_client_is_connected(clientPrice);
|
return esp_websocket_client_is_connected(clientPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,12 @@
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
#include <esp_websocket_client.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <esp_websocket_client.h>
|
|
||||||
#include "lib/screen_handler.hpp"
|
#include "lib/screen_handler.hpp"
|
||||||
|
|
||||||
// using namespace websockets;
|
|
||||||
|
|
||||||
void setupPriceNotify();
|
void setupPriceNotify();
|
||||||
|
|
||||||
void onWebsocketPriceEvent(void *handler_args, esp_event_base_t base,
|
void onWebsocketPriceEvent(void *handler_args, esp_event_base_t base,
|
||||||
|
|
|
@ -12,19 +12,6 @@ std::array<std::string, NUM_SCREENS> taskEpdContent = {"", "", "", "",
|
||||||
"", "", ""};
|
"", "", ""};
|
||||||
std::string priceString;
|
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
|
#define WORK_QUEUE_SIZE 10
|
||||||
QueueHandle_t workQueue = NULL;
|
QueueHandle_t workQueue = NULL;
|
||||||
|
|
||||||
|
@ -40,66 +27,67 @@ void workerTask(void *pvParameters) {
|
||||||
|
|
||||||
// Process the work item based on its type
|
// Process the work item based on its type
|
||||||
switch (receivedItem.type) {
|
switch (receivedItem.type) {
|
||||||
case TASK_PRICE_UPDATE: {
|
case TASK_PRICE_UPDATE: {
|
||||||
uint price = getPrice();
|
uint price = getPrice();
|
||||||
char priceSymbol = '$';
|
char priceSymbol = '$';
|
||||||
if (preferences.getBool("fetchEurPrice", false)) {
|
if (preferences.getBool("fetchEurPrice", false)) {
|
||||||
priceSymbol = '[';
|
priceSymbol = '[';
|
||||||
}
|
}
|
||||||
if (getCurrentScreen() == SCREEN_BTC_TICKER) {
|
if (getCurrentScreen() == SCREEN_BTC_TICKER) {
|
||||||
taskEpdContent = parsePriceData(price, priceSymbol);
|
taskEpdContent = parsePriceData(price, priceSymbol);
|
||||||
} else if (getCurrentScreen() == SCREEN_MSCW_TIME) {
|
} else if (getCurrentScreen() == SCREEN_MSCW_TIME) {
|
||||||
taskEpdContent = parseSatsPerCurrency(price, priceSymbol);
|
taskEpdContent = parseSatsPerCurrency(price, priceSymbol);
|
||||||
} else {
|
} else {
|
||||||
taskEpdContent =
|
taskEpdContent =
|
||||||
parseMarketCap(getBlockHeight(), price, priceSymbol,
|
parseMarketCap(getBlockHeight(), price, priceSymbol,
|
||||||
preferences.getBool("mcapBigChar", true));
|
preferences.getBool("mcapBigChar", true));
|
||||||
}
|
|
||||||
|
|
||||||
setEpdContent(taskEpdContent);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TASK_BLOCK_UPDATE: {
|
|
||||||
if (getCurrentScreen() != SCREEN_HALVING_COUNTDOWN) {
|
|
||||||
taskEpdContent = parseBlockHeight(getBlockHeight());
|
|
||||||
} else {
|
|
||||||
taskEpdContent = parseHalvingCountdown(getBlockHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getCurrentScreen() == SCREEN_HALVING_COUNTDOWN ||
|
|
||||||
getCurrentScreen() == SCREEN_BLOCK_HEIGHT) {
|
|
||||||
setEpdContent(taskEpdContent);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TASK_TIME_UPDATE: {
|
|
||||||
if (getCurrentScreen() == SCREEN_TIME) {
|
|
||||||
time_t currentTime;
|
|
||||||
struct tm timeinfo;
|
|
||||||
time(¤tTime);
|
|
||||||
localtime_r(¤tTime, &timeinfo);
|
|
||||||
std::string timeString;
|
|
||||||
|
|
||||||
String minute = String(timeinfo.tm_min);
|
|
||||||
if (minute.length() < 2) {
|
|
||||||
minute = "0" + minute;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) + "/" +
|
|
||||||
std::to_string(timeinfo.tm_mon + 1);
|
|
||||||
|
|
||||||
for (uint i = 1; i < NUM_SCREENS; i++) {
|
|
||||||
taskEpdContent[i] = timeString[i];
|
|
||||||
}
|
|
||||||
setEpdContent(taskEpdContent);
|
setEpdContent(taskEpdContent);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
case TASK_BLOCK_UPDATE: {
|
||||||
|
if (getCurrentScreen() != SCREEN_HALVING_COUNTDOWN) {
|
||||||
|
taskEpdContent = parseBlockHeight(getBlockHeight());
|
||||||
|
} else {
|
||||||
|
taskEpdContent = parseHalvingCountdown(getBlockHeight());
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
if (getCurrentScreen() == SCREEN_HALVING_COUNTDOWN ||
|
||||||
}
|
getCurrentScreen() == SCREEN_BLOCK_HEIGHT) {
|
||||||
// Add more cases for additional task types
|
setEpdContent(taskEpdContent);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TASK_TIME_UPDATE: {
|
||||||
|
if (getCurrentScreen() == SCREEN_TIME) {
|
||||||
|
time_t currentTime;
|
||||||
|
struct tm timeinfo;
|
||||||
|
time(¤tTime);
|
||||||
|
localtime_r(¤tTime, &timeinfo);
|
||||||
|
std::string timeString;
|
||||||
|
|
||||||
|
String minute = String(timeinfo.tm_min);
|
||||||
|
if (minute.length() < 2) {
|
||||||
|
minute = "0" + minute;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) + "/" +
|
||||||
|
std::to_string(timeinfo.tm_mon + 1);
|
||||||
|
|
||||||
|
for (uint i = 1; i < NUM_SCREENS; i++) {
|
||||||
|
taskEpdContent[i] = timeString[i];
|
||||||
|
}
|
||||||
|
setEpdContent(taskEpdContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Add more cases for additional task types
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,11 +133,6 @@ void IRAM_ATTR screenRotateTimerISR(void *arg) {
|
||||||
void setupTasks() {
|
void setupTasks() {
|
||||||
workQueue = xQueueCreate(WORK_QUEUE_SIZE, sizeof(WorkItem));
|
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,
|
xTaskCreate(workerTask, "workerTask", 4096, NULL, tskIDLE_PRIORITY,
|
||||||
&workerTaskHandle);
|
&workerTaskHandle);
|
||||||
|
|
||||||
|
@ -214,8 +197,7 @@ void setTimerActive(bool status) {
|
||||||
preferences.putBool("timerActive", false);
|
preferences.putBool("timerActive", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventSourceTaskHandle != NULL)
|
if (eventSourceTaskHandle != NULL) xTaskNotifyGive(eventSourceTaskHandle);
|
||||||
xTaskNotifyGive(eventSourceTaskHandle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleTimerActive() { setTimerActive(!isTimerActive()); }
|
void toggleTimerActive() { setTimerActive(!isTimerActive()); }
|
||||||
|
@ -230,31 +212,30 @@ void setCurrentScreen(uint newScreen) {
|
||||||
currentScreen = newScreen;
|
currentScreen = newScreen;
|
||||||
|
|
||||||
switch (currentScreen) {
|
switch (currentScreen) {
|
||||||
case SCREEN_TIME: {
|
case SCREEN_TIME: {
|
||||||
WorkItem timeUpdate = {TASK_TIME_UPDATE, 0};
|
WorkItem timeUpdate = {TASK_TIME_UPDATE, 0};
|
||||||
xQueueSend(workQueue, &timeUpdate, portMAX_DELAY);
|
xQueueSend(workQueue, &timeUpdate, portMAX_DELAY);
|
||||||
// xTaskNotifyGive(timeUpdateTaskHandle);
|
// xTaskNotifyGive(timeUpdateTaskHandle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SCREEN_HALVING_COUNTDOWN:
|
case SCREEN_HALVING_COUNTDOWN:
|
||||||
case SCREEN_BLOCK_HEIGHT: {
|
case SCREEN_BLOCK_HEIGHT: {
|
||||||
WorkItem blockUpdate = {TASK_BLOCK_UPDATE, 0};
|
WorkItem blockUpdate = {TASK_BLOCK_UPDATE, 0};
|
||||||
xQueueSend(workQueue, &blockUpdate, portMAX_DELAY);
|
xQueueSend(workQueue, &blockUpdate, portMAX_DELAY);
|
||||||
// xTaskNotifyGive(blockUpdateTaskHandle);
|
// xTaskNotifyGive(blockUpdateTaskHandle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SCREEN_MARKET_CAP:
|
case SCREEN_MARKET_CAP:
|
||||||
case SCREEN_MSCW_TIME:
|
case SCREEN_MSCW_TIME:
|
||||||
case SCREEN_BTC_TICKER: {
|
case SCREEN_BTC_TICKER: {
|
||||||
WorkItem priceUpdate = {TASK_PRICE_UPDATE, 0};
|
WorkItem priceUpdate = {TASK_PRICE_UPDATE, 0};
|
||||||
xQueueSend(workQueue, &priceUpdate, portMAX_DELAY);
|
xQueueSend(workQueue, &priceUpdate, portMAX_DELAY);
|
||||||
// xTaskNotifyGive(priceUpdateTaskHandle);
|
// xTaskNotifyGive(priceUpdateTaskHandle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventSourceTaskHandle != NULL)
|
if (eventSourceTaskHandle != NULL) xTaskNotifyGive(eventSourceTaskHandle);
|
||||||
xTaskNotifyGive(eventSourceTaskHandle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void nextScreen() {
|
void nextScreen() {
|
||||||
|
@ -269,7 +250,6 @@ void nextScreen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void previousScreen() {
|
void previousScreen() {
|
||||||
|
|
||||||
int newCurrentScreen = modulo(getCurrentScreen() - 1, SCREEN_COUNT);
|
int newCurrentScreen = modulo(getCurrentScreen() - 1, SCREEN_COUNT);
|
||||||
String key = "screen" + String(newCurrentScreen) + "Visible";
|
String key = "screen" + String(newCurrentScreen) + "Visible";
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <esp_timer.h>
|
#include <esp_timer.h>
|
||||||
|
|
||||||
#include <data_handler.hpp>
|
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
|
|
||||||
|
#include <data_handler.hpp>
|
||||||
|
|
||||||
#include "lib/epd.hpp"
|
#include "lib/epd.hpp"
|
||||||
#include "lib/price_fetch.hpp"
|
#include "lib/price_fetch.hpp"
|
||||||
#include "lib/shared.hpp"
|
#include "lib/shared.hpp"
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
#include <utils.hpp>
|
#include <utils.hpp>
|
||||||
|
|
||||||
extern Adafruit_MCP23X17 mcp1;
|
extern Adafruit_MCP23X17 mcp1;
|
||||||
|
|
|
@ -5,7 +5,6 @@ AsyncEventSource events("/events");
|
||||||
TaskHandle_t eventSourceTaskHandle;
|
TaskHandle_t eventSourceTaskHandle;
|
||||||
|
|
||||||
void setupWebserver() {
|
void setupWebserver() {
|
||||||
|
|
||||||
events.onConnect([](AsyncEventSourceClient *client) {
|
events.onConnect([](AsyncEventSourceClient *client) {
|
||||||
client->send("welcome", NULL, millis(), 1000);
|
client->send("welcome", NULL, millis(), 1000);
|
||||||
});
|
});
|
||||||
|
@ -139,8 +138,7 @@ StaticJsonDocument<512> getLedStatusObject() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void eventSourceUpdate() {
|
void eventSourceUpdate() {
|
||||||
if (!events.count())
|
if (!events.count()) return;
|
||||||
return;
|
|
||||||
StaticJsonDocument<768> root = getStatusObject();
|
StaticJsonDocument<768> root = getStatusObject();
|
||||||
JsonArray data = root.createNestedArray("data");
|
JsonArray data = root.createNestedArray("data");
|
||||||
|
|
||||||
|
@ -232,7 +230,7 @@ void onApiShowText(AsyncWebServerRequest *request) {
|
||||||
if (request->hasParam("t")) {
|
if (request->hasParam("t")) {
|
||||||
AsyncWebParameter *p = request->getParam("t");
|
AsyncWebParameter *p = request->getParam("t");
|
||||||
String t = p->value();
|
String t = p->value();
|
||||||
t.toUpperCase(); // This is needed as long as lowercase letters are glitchy
|
t.toUpperCase(); // This is needed as long as lowercase letters are glitchy
|
||||||
|
|
||||||
std::array<String, NUM_SCREENS> textEpdContent;
|
std::array<String, NUM_SCREENS> textEpdContent;
|
||||||
for (uint i = 0; i < NUM_SCREENS; i++) {
|
for (uint i = 0; i < NUM_SCREENS; i++) {
|
||||||
|
@ -369,8 +367,7 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) {
|
||||||
void onApiRestart(AsyncWebServerRequest *request) {
|
void onApiRestart(AsyncWebServerRequest *request) {
|
||||||
request->send(200);
|
request->send(200);
|
||||||
|
|
||||||
if (events.count())
|
if (events.count()) events.send("closing");
|
||||||
events.send("closing");
|
|
||||||
|
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
|
@ -474,7 +471,7 @@ void onApiSettingsPost(AsyncWebServerRequest *request) {
|
||||||
int params = request->params();
|
int params = request->params();
|
||||||
for (int i = 0; i < params; i++) {
|
for (int i = 0; i < params; i++) {
|
||||||
AsyncWebParameter *p = request->getParam(i);
|
AsyncWebParameter *p = request->getParam(i);
|
||||||
if (p->isFile()) { // p->isPost() is also true
|
if (p->isFile()) { // p->isPost() is also true
|
||||||
Serial.printf("FILE[%s]: %s, size: %u\n", p->name().c_str(),
|
Serial.printf("FILE[%s]: %s, size: %u\n", p->name().c_str(),
|
||||||
p->value().c_str(), p->size());
|
p->value().c_str(), p->size());
|
||||||
} else if (p->isPost()) {
|
} else if (p->isPost()) {
|
||||||
|
@ -742,7 +739,6 @@ void onApiLightsSetJson(AsyncWebServerRequest *request, JsonVariant &json) {
|
||||||
|
|
||||||
if (lights[i].containsKey("red") && lights[i].containsKey("green") &&
|
if (lights[i].containsKey("red") && lights[i].containsKey("green") &&
|
||||||
lights[i].containsKey("blue")) {
|
lights[i].containsKey("blue")) {
|
||||||
|
|
||||||
red = lights[i]["red"].as<uint>();
|
red = lights[i]["red"].as<uint>();
|
||||||
green = lights[i]["green"].as<uint>();
|
green = lights[i]["green"].as<uint>();
|
||||||
blue = lights[i]["blue"].as<uint>();
|
blue = lights[i]["blue"].as<uint>();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// Keep order of includes because of conflicts
|
||||||
#include "WebServer.h"
|
#include "WebServer.h"
|
||||||
#include "ESPAsyncWebServer.h"
|
#include "ESPAsyncWebServer.h"
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
@ -8,20 +9,10 @@
|
||||||
#include "AsyncJson.h"
|
#include "AsyncJson.h"
|
||||||
#include <iostream>
|
#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/block_notify.hpp"
|
||||||
#include "lib/led_handler.hpp"
|
#include "lib/led_handler.hpp"
|
||||||
#include "lib/price_notify.hpp"
|
#include "lib/price_notify.hpp"
|
||||||
#include "lib/screen_handler.hpp"
|
#include "lib/screen_handler.hpp"
|
||||||
|
|
||||||
#include "webserver/OneParamRewrite.hpp"
|
#include "webserver/OneParamRewrite.hpp"
|
||||||
|
|
||||||
extern TaskHandle_t eventSourceTaskHandle;
|
extern TaskHandle_t eventSourceTaskHandle;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
OneParamRewrite::OneParamRewrite(const char *from, const char *to)
|
OneParamRewrite::OneParamRewrite(const char *from, const char *to)
|
||||||
: AsyncWebRewrite(from, to) {
|
: AsyncWebRewrite(from, to) {
|
||||||
|
|
||||||
_paramIndex = _from.indexOf('{');
|
_paramIndex = _from.indexOf('{');
|
||||||
|
|
||||||
if (_paramIndex >= 0 && _from.endsWith("}")) {
|
if (_paramIndex >= 0 && _from.endsWith("}")) {
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
#include "ESPAsyncWebServer.h"
|
#include "ESPAsyncWebServer.h"
|
||||||
|
|
||||||
class OneParamRewrite : public AsyncWebRewrite {
|
class OneParamRewrite : public AsyncWebRewrite {
|
||||||
protected:
|
protected:
|
||||||
String _urlPrefix;
|
String _urlPrefix;
|
||||||
int _paramIndex;
|
int _paramIndex;
|
||||||
String _paramsBackup;
|
String _paramsBackup;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OneParamRewrite(const char *from, const char *to);
|
OneParamRewrite(const char *from, const char *to);
|
||||||
bool match(AsyncWebServerRequest *request) override;
|
bool match(AsyncWebServerRequest *request) override;
|
||||||
};
|
};
|
Loading…
Reference in a new issue