mirror of
https://github.com/btclock/btclock_v3.git
synced 2024-11-19 02:10:00 +01:00
More code formatting improvements
This commit is contained in:
parent
4aab02a040
commit
86d299fd75
@ -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;
|
||||
const String sub = "{\"action\": \"want\", \"data\":[\"blocks\"]}";
|
||||
switch (event_id) {
|
||||
case WEBSOCKET_EVENT_CONNECTED:
|
||||
Serial.println(F("Connected to Mempool.space WebSocket"));
|
||||
case WEBSOCKET_EVENT_CONNECTED:
|
||||
Serial.println(F("Connected to Mempool.space WebSocket"));
|
||||
|
||||
Serial.println(sub);
|
||||
if (esp_websocket_client_send_text(blockNotifyClient, sub.c_str(),
|
||||
sub.length(), portMAX_DELAY) == -1) {
|
||||
Serial.println(F("Mempool.space WS Block Subscribe Error"));
|
||||
}
|
||||
Serial.println(sub);
|
||||
if (esp_websocket_client_send_text(blockNotifyClient, sub.c_str(),
|
||||
sub.length(), portMAX_DELAY) == -1) {
|
||||
Serial.println(F("Mempool.space WS Block Subscribe Error"));
|
||||
}
|
||||
|
||||
break;
|
||||
case WEBSOCKET_EVENT_DATA:
|
||||
onWebsocketMessage(data);
|
||||
break;
|
||||
case WEBSOCKET_EVENT_ERROR:
|
||||
Serial.println(F("Mempool.space WS Connnection error"));
|
||||
break;
|
||||
case WEBSOCKET_EVENT_DISCONNECTED:
|
||||
Serial.println(F("Mempool.space WS Connnection Closed"));
|
||||
break;
|
||||
break;
|
||||
case WEBSOCKET_EVENT_DATA:
|
||||
onWebsocketMessage(data);
|
||||
break;
|
||||
case WEBSOCKET_EVENT_ERROR:
|
||||
Serial.println(F("Mempool.space WS Connnection error"));
|
||||
break;
|
||||
case WEBSOCKET_EVENT_DISCONNECTED:
|
||||
Serial.println(F("Mempool.space WS Connnection Closed"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ void onWebsocketMessage(esp_websocket_event_data_t *event_data) {
|
||||
|
||||
if (getCurrentScreen() == SCREEN_BLOCK_HEIGHT &&
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -17,18 +17,18 @@ void buttonTask(void *parameter) {
|
||||
uint pin = mcp1.getLastInterruptPin();
|
||||
|
||||
switch (pin) {
|
||||
case 3:
|
||||
toggleTimerActive();
|
||||
break;
|
||||
case 2:
|
||||
nextScreen();
|
||||
break;
|
||||
case 1:
|
||||
previousScreen();
|
||||
break;
|
||||
case 0:
|
||||
showSystemStatusScreen();
|
||||
break;
|
||||
case 3:
|
||||
toggleTimerActive();
|
||||
break;
|
||||
case 2:
|
||||
nextScreen();
|
||||
break;
|
||||
case 1:
|
||||
previousScreen();
|
||||
break;
|
||||
case 0:
|
||||
showSystemStatusScreen();
|
||||
break;
|
||||
}
|
||||
}
|
||||
mcp1.clearInterrupts();
|
||||
@ -51,7 +51,7 @@ void IRAM_ATTR handleButtonInterrupt() {
|
||||
|
||||
void setupButtonTask() {
|
||||
xTaskCreate(buttonTask, "ButtonTask", 4096, NULL, tskIDLE_PRIORITY,
|
||||
&buttonTaskHandle); // Create the FreeRTOS task
|
||||
&buttonTaskHandle); // Create the FreeRTOS task
|
||||
// Use interrupt instead of task
|
||||
attachInterrupt(MCP_INT_PIN, handleButtonInterrupt, CHANGE);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -222,7 +222,6 @@ void setupTimers() {
|
||||
}
|
||||
|
||||
void finishSetup() {
|
||||
|
||||
if (preferences.getBool("ledStatus", false)) {
|
||||
restoreLedState();
|
||||
} else {
|
||||
@ -364,80 +363,80 @@ std::vector<std::string> getLocalUrl() {
|
||||
|
||||
bool onImprovCommandCallback(improv::ImprovCommand cmd) {
|
||||
switch (cmd.command) {
|
||||
case improv::Command::GET_CURRENT_STATE: {
|
||||
if ((WiFi.status() == WL_CONNECTED)) {
|
||||
improv_set_state(improv::State::STATE_PROVISIONED);
|
||||
std::vector<uint8_t> data = improv::build_rpc_response(
|
||||
improv::GET_CURRENT_STATE, getLocalUrl(), false);
|
||||
improv_send_response(data);
|
||||
} else {
|
||||
improv_set_state(improv::State::STATE_AUTHORIZED);
|
||||
}
|
||||
case improv::Command::GET_CURRENT_STATE: {
|
||||
if ((WiFi.status() == WL_CONNECTED)) {
|
||||
improv_set_state(improv::State::STATE_PROVISIONED);
|
||||
std::vector<uint8_t> data = improv::build_rpc_response(
|
||||
improv::GET_CURRENT_STATE, getLocalUrl(), false);
|
||||
improv_send_response(data);
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
improv_set_state(improv::STATE_PROVISIONING);
|
||||
queueLedEffect(LED_EFFECT_WIFI_CONNECTING);
|
||||
case improv::Command::WIFI_SETTINGS: {
|
||||
if (cmd.ssid.length() == 0) {
|
||||
improv_set_error(improv::Error::ERROR_INVALID_RPC);
|
||||
break;
|
||||
}
|
||||
|
||||
if (improv_connectWifi(cmd.ssid, cmd.password)) {
|
||||
queueLedEffect(LED_EFFECT_WIFI_CONNECT_SUCCESS);
|
||||
improv_set_state(improv::STATE_PROVISIONING);
|
||||
queueLedEffect(LED_EFFECT_WIFI_CONNECTING);
|
||||
|
||||
// std::array<String, NUM_SCREENS> epdContent = {"S", "U", "C", "C", "E",
|
||||
// "S", "S"}; setEpdContent(epdContent);
|
||||
if (improv_connectWifi(cmd.ssid, cmd.password)) {
|
||||
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);
|
||||
std::vector<uint8_t> data = improv::build_rpc_response(
|
||||
improv::WIFI_SETTINGS, getLocalUrl(), false);
|
||||
improv_send_response(data);
|
||||
preferences.putBool("wifiConfigured", true);
|
||||
|
||||
delay(2500);
|
||||
ESP.restart();
|
||||
setupWebserver();
|
||||
} else {
|
||||
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
|
||||
improv_set_state(improv::STATE_PROVISIONED);
|
||||
std::vector<uint8_t> data = improv::build_rpc_response(
|
||||
improv::WIFI_SETTINGS, getLocalUrl(), false);
|
||||
improv_send_response(data);
|
||||
|
||||
improv_set_state(improv::STATE_STOPPED);
|
||||
improv_set_error(improv::Error::ERROR_UNABLE_TO_CONNECT);
|
||||
delay(2500);
|
||||
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: {
|
||||
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_WIFI_NETWORKS: {
|
||||
improvGetAvailableWifiNetworks();
|
||||
// std::array<String, NUM_SCREENS> epdContent = {"W", "E", "B", "W", "I",
|
||||
// "F", "I"}; setEpdContent(epdContent);
|
||||
break;
|
||||
}
|
||||
|
||||
case improv::Command::GET_WIFI_NETWORKS: {
|
||||
improvGetAvailableWifiNetworks();
|
||||
// std::array<String, NUM_SCREENS> epdContent = {"W", "E", "B", "W", "I",
|
||||
// "F", "I"}; setEpdContent(epdContent);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
improv_set_error(improv::ERROR_UNKNOWN_RPC);
|
||||
return false;
|
||||
}
|
||||
default: {
|
||||
improv_set_error(improv::ERROR_UNKNOWN_RPC);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return 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());
|
||||
@ -497,74 +493,73 @@ void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
Serial.printf("[WiFi-event] event: %d\n", event);
|
||||
|
||||
switch (event) {
|
||||
case ARDUINO_EVENT_WIFI_READY:
|
||||
Serial.println("WiFi interface ready");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_SCAN_DONE:
|
||||
Serial.println("Completed scan for access points");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_START:
|
||||
Serial.println("WiFi client started");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_STOP:
|
||||
Serial.println("WiFi clients stopped");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
||||
Serial.println("Connected to access point");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: {
|
||||
if (!first_connect) {
|
||||
Serial.println("Disconnected from WiFi access point");
|
||||
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
|
||||
uint8_t reason = info.wifi_sta_disconnected.reason;
|
||||
if (reason)
|
||||
Serial.printf("Disconnect reason: %s, ",
|
||||
WiFi.disconnectReasonName((wifi_err_reason_t)reason));
|
||||
case ARDUINO_EVENT_WIFI_READY:
|
||||
Serial.println("WiFi interface ready");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_SCAN_DONE:
|
||||
Serial.println("Completed scan for access points");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_START:
|
||||
Serial.println("WiFi client started");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_STOP:
|
||||
Serial.println("WiFi clients stopped");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
||||
Serial.println("Connected to access point");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: {
|
||||
if (!first_connect) {
|
||||
Serial.println("Disconnected from WiFi access point");
|
||||
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
|
||||
uint8_t reason = info.wifi_sta_disconnected.reason;
|
||||
if (reason)
|
||||
Serial.printf("Disconnect reason: %s, ",
|
||||
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");
|
||||
break;
|
||||
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);
|
||||
first_connect = false;
|
||||
break;
|
||||
}
|
||||
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
||||
Serial.println("Lost IP address and IP address is reset to 0");
|
||||
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
|
||||
WiFi.reconnect();
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_START:
|
||||
Serial.println("WiFi access point started");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STOP:
|
||||
Serial.println("WiFi access point stopped");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STACONNECTED:
|
||||
Serial.println("Client connected");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED:
|
||||
Serial.println("Client disconnected");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED:
|
||||
Serial.println("Assigned IP address to client");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED:
|
||||
Serial.println("Received probe request");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_GOT_IP6:
|
||||
Serial.println("AP IPv6 is preferred");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
|
||||
Serial.println("STA IPv6 is preferred");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE:
|
||||
Serial.println("Authentication mode of access point has changed");
|
||||
break;
|
||||
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);
|
||||
first_connect = false;
|
||||
break;
|
||||
}
|
||||
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
||||
Serial.println("Lost IP address and IP address is reset to 0");
|
||||
queueLedEffect(LED_EFFECT_WIFI_CONNECT_ERROR);
|
||||
WiFi.reconnect();
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_START:
|
||||
Serial.println("WiFi access point started");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STOP:
|
||||
Serial.println("WiFi access point stopped");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STACONNECTED:
|
||||
Serial.println("Client connected");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED:
|
||||
Serial.println("Client disconnected");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED:
|
||||
Serial.println("Assigned IP address to client");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_PROBEREQRECVED:
|
||||
Serial.println("Received probe request");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_AP_GOT_IP6:
|
||||
Serial.println("AP IPv6 is preferred");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
|
||||
Serial.println("STA IPv6 is preferred");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <WiFiManager.h>
|
||||
#include <base64.h>
|
||||
#include <esp_task_wdt.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "lib/block_notify.hpp"
|
||||
|
@ -124,7 +124,7 @@ void setupDisplays() {
|
||||
*taskParam = i;
|
||||
|
||||
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"};
|
||||
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
@ -148,6 +138,6 @@ std::vector<uint8_t> build_rpc_response(Command command,
|
||||
}
|
||||
return out;
|
||||
}
|
||||
#endif // ARDUINO
|
||||
#endif // ARDUINO
|
||||
|
||||
} // namespace improv
|
||||
} // namespace improv
|
@ -2,7 +2,7 @@
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include <Arduino.h>
|
||||
#endif // ARDUINO
|
||||
#endif // ARDUINO
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
@ -81,6 +81,6 @@ std::vector<uint8_t> build_rpc_response(Command command,
|
||||
std::vector<uint8_t> build_rpc_response(Command command,
|
||||
const std::vector<String> &datum,
|
||||
bool add_checksum = true);
|
||||
#endif // ARDUINO
|
||||
#endif // ARDUINO
|
||||
|
||||
} // namespace improv
|
||||
} // namespace improv
|
@ -18,106 +18,103 @@ void ledTask(void *parameter) {
|
||||
}
|
||||
|
||||
switch (ledTaskParams) {
|
||||
case LED_POWER_TEST:
|
||||
ledRainbow(20);
|
||||
pixels.clear();
|
||||
break;
|
||||
case LED_EFFECT_WIFI_CONNECT_ERROR:
|
||||
blinkDelayTwoColor(100, 3, pixels.Color(8, 161, 236),
|
||||
pixels.Color(255, 0, 0));
|
||||
break;
|
||||
case LED_FLASH_ERROR:
|
||||
blinkDelayColor(250, 3, 255, 0, 0);
|
||||
break;
|
||||
case LED_EFFECT_HEARTBEAT:
|
||||
blinkDelayColor(150, 2, 0, 0, 255);
|
||||
break;
|
||||
case LED_EFFECT_WIFI_CONNECT_SUCCESS:
|
||||
case LED_FLASH_SUCCESS:
|
||||
blinkDelayColor(150, 3, 0, 255, 0);
|
||||
break;
|
||||
case LED_PROGRESS_100:
|
||||
pixels.setPixelColor(0, pixels.Color(0, 255, 0));
|
||||
case LED_PROGRESS_75:
|
||||
pixels.setPixelColor(1, pixels.Color(0, 255, 0));
|
||||
case LED_PROGRESS_50:
|
||||
pixels.setPixelColor(2, pixels.Color(0, 255, 0));
|
||||
case LED_PROGRESS_25:
|
||||
pixels.setPixelColor(3, pixels.Color(0, 255, 0));
|
||||
pixels.show();
|
||||
break;
|
||||
case LED_FLASH_UPDATE:
|
||||
break;
|
||||
case LED_FLASH_BLOCK_NOTIFY:
|
||||
blinkDelayTwoColor(250, 3, pixels.Color(224, 67, 0),
|
||||
pixels.Color(8, 2, 0));
|
||||
break;
|
||||
case LED_EFFECT_WIFI_WAIT_FOR_CONFIG:
|
||||
blinkDelayTwoColor(100, 1, pixels.Color(8, 161, 236),
|
||||
pixels.Color(156, 225, 240));
|
||||
break;
|
||||
case LED_EFFECT_WIFI_ERASE_SETTINGS:
|
||||
blinkDelay(100, 3);
|
||||
break;
|
||||
case LED_EFFECT_WIFI_CONNECTING:
|
||||
for (int i = NEOPIXEL_COUNT; i >= 0; i--) {
|
||||
for (int j = NEOPIXEL_COUNT; j >= 0; j--) {
|
||||
if (j == i) {
|
||||
pixels.setPixelColor(i, pixels.Color(16, 197, 236));
|
||||
} else {
|
||||
pixels.setPixelColor(j, pixels.Color(0, 0, 0));
|
||||
case LED_POWER_TEST:
|
||||
ledRainbow(20);
|
||||
pixels.clear();
|
||||
break;
|
||||
case LED_EFFECT_WIFI_CONNECT_ERROR:
|
||||
blinkDelayTwoColor(100, 3, pixels.Color(8, 161, 236),
|
||||
pixels.Color(255, 0, 0));
|
||||
break;
|
||||
case LED_FLASH_ERROR:
|
||||
blinkDelayColor(250, 3, 255, 0, 0);
|
||||
break;
|
||||
case LED_EFFECT_HEARTBEAT:
|
||||
blinkDelayColor(150, 2, 0, 0, 255);
|
||||
break;
|
||||
case LED_EFFECT_WIFI_CONNECT_SUCCESS:
|
||||
case LED_FLASH_SUCCESS:
|
||||
blinkDelayColor(150, 3, 0, 255, 0);
|
||||
break;
|
||||
case LED_PROGRESS_100:
|
||||
pixels.setPixelColor(0, pixels.Color(0, 255, 0));
|
||||
case LED_PROGRESS_75:
|
||||
pixels.setPixelColor(1, pixels.Color(0, 255, 0));
|
||||
case LED_PROGRESS_50:
|
||||
pixels.setPixelColor(2, pixels.Color(0, 255, 0));
|
||||
case LED_PROGRESS_25:
|
||||
pixels.setPixelColor(3, pixels.Color(0, 255, 0));
|
||||
pixels.show();
|
||||
break;
|
||||
case LED_FLASH_UPDATE:
|
||||
break;
|
||||
case LED_FLASH_BLOCK_NOTIFY:
|
||||
blinkDelayTwoColor(250, 3, pixels.Color(224, 67, 0),
|
||||
pixels.Color(8, 2, 0));
|
||||
break;
|
||||
case LED_EFFECT_WIFI_WAIT_FOR_CONFIG:
|
||||
blinkDelayTwoColor(100, 1, pixels.Color(8, 161, 236),
|
||||
pixels.Color(156, 225, 240));
|
||||
break;
|
||||
case LED_EFFECT_WIFI_ERASE_SETTINGS:
|
||||
blinkDelay(100, 3);
|
||||
break;
|
||||
case LED_EFFECT_WIFI_CONNECTING:
|
||||
for (int i = NEOPIXEL_COUNT; i >= 0; i--) {
|
||||
for (int j = NEOPIXEL_COUNT; j >= 0; j--) {
|
||||
if (j == i) {
|
||||
pixels.setPixelColor(i, pixels.Color(16, 197, 236));
|
||||
} else {
|
||||
pixels.setPixelColor(j, pixels.Color(0, 0, 0));
|
||||
}
|
||||
}
|
||||
pixels.show();
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
}
|
||||
pixels.show();
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
}
|
||||
break;
|
||||
case LED_EFFECT_PAUSE_TIMER:
|
||||
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);
|
||||
pixels.setPixelColor(j, c);
|
||||
}
|
||||
break;
|
||||
case LED_EFFECT_PAUSE_TIMER:
|
||||
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);
|
||||
pixels.setPixelColor(j, c);
|
||||
}
|
||||
|
||||
pixels.show();
|
||||
|
||||
delay(100);
|
||||
}
|
||||
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
|
||||
pixels.show();
|
||||
|
||||
delay(100);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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(100);
|
||||
}
|
||||
delay(900);
|
||||
|
||||
pixels.clear();
|
||||
pixels.show();
|
||||
break;
|
||||
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.show();
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
pixels.clear();
|
||||
pixels.show();
|
||||
break;
|
||||
}
|
||||
|
||||
// revert to previous state unless power test
|
||||
@ -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++) {
|
||||
@ -282,43 +277,43 @@ void ledRainbow(int wait) {
|
||||
pixels.rainbow(firstPixelHue);
|
||||
// Above line is equivalent to:
|
||||
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
|
||||
pixels.show(); // Update strip with new contents
|
||||
pixels.show(); // Update strip with new contents
|
||||
delayMicroseconds(wait);
|
||||
// vTaskDelay(pdMS_TO_TICKS(wait)); // Pause for a moment
|
||||
}
|
||||
}
|
||||
|
||||
void ledTheaterChase(uint32_t color, int wait) {
|
||||
for (int a = 0; a < 10; a++) { // Repeat 10 times...
|
||||
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
|
||||
pixels.clear(); // Set all pixels in RAM to 0 (off)
|
||||
for (int a = 0; a < 10; a++) { // Repeat 10 times...
|
||||
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
|
||||
pixels.clear(); // Set all pixels in RAM to 0 (off)
|
||||
// 'c' counts up from 'b' to end of strip in steps of 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
|
||||
vTaskDelay(pdMS_TO_TICKS(wait)); // Pause for a moment
|
||||
pixels.show(); // Update strip with new contents
|
||||
vTaskDelay(pdMS_TO_TICKS(wait)); // Pause for a moment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ledTheaterChaseRainbow(int wait) {
|
||||
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||
for (int a = 0; a < 30; a++) { // Repeat 30 times...
|
||||
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
|
||||
pixels.clear(); // Set all pixels in RAM to 0 (off)
|
||||
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||
for (int a = 0; a < 30; a++) { // Repeat 30 times...
|
||||
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
|
||||
pixels.clear(); // Set all pixels in RAM to 0 (off)
|
||||
// 'c' counts up from 'b' to end of strip in increments of 3...
|
||||
for (int c = b; c < pixels.numPixels(); c += 3) {
|
||||
// hue of pixel 'c' is offset by an amount to make one full
|
||||
// revolution of the color wheel (range 65536) along the length
|
||||
// of the strip (strip.numPixels() steps):
|
||||
int hue = firstPixelHue + c * 65536L / pixels.numPixels();
|
||||
uint32_t color = pixels.gamma32(pixels.ColorHSV(hue)); // hue -> RGB
|
||||
pixels.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||
uint32_t color = pixels.gamma32(pixels.ColorHSV(hue)); // hue -> RGB
|
||||
pixels.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||
}
|
||||
pixels.show(); // Update strip with new contents
|
||||
vTaskDelay(pdMS_TO_TICKS(wait)); // Pause for a moment
|
||||
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||
pixels.show(); // Update strip with new contents
|
||||
vTaskDelay(pdMS_TO_TICKS(wait)); // Pause for a moment
|
||||
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -64,7 +64,7 @@ void onOTAStart() {
|
||||
|
||||
void handleOTATask(void *parameter) {
|
||||
for (;;) {
|
||||
ArduinoOTA.handle(); // Allow OTA updates to occur
|
||||
ArduinoOTA.handle(); // Allow OTA updates to occur
|
||||
vTaskDelay(pdMS_TO_TICKS(2500));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
#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);
|
||||
void onOTAProgress(unsigned int progress, unsigned int total);
|
||||
void downloadUpdate();
|
||||
void onOTAError(ota_error_t error);
|
||||
void onOTAComplete();
|
||||
void onOTAComplete();
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include "price_fetch.hpp"
|
||||
|
||||
const PROGMEM char *cgApiUrl = "https://api.coingecko.com/api/v3/simple/"
|
||||
"price?ids=bitcoin&vs_currencies=usd%2Ceur";
|
||||
const PROGMEM char *cgApiUrl =
|
||||
"https://api.coingecko.com/api/v3/simple/"
|
||||
"price?ids=bitcoin&vs_currencies=usd%2Ceur";
|
||||
|
||||
TaskHandle_t priceFetchTaskHandle;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
||||
switch (event_id) {
|
||||
case WEBSOCKET_EVENT_CONNECTED:
|
||||
Serial.println(F("Connected to CoinCap.io WebSocket"));
|
||||
break;
|
||||
case WEBSOCKET_EVENT_DATA:
|
||||
onWebsocketPriceMessage(data);
|
||||
break;
|
||||
case WEBSOCKET_EVENT_ERROR:
|
||||
Serial.println(F("Price WS Connnection error"));
|
||||
break;
|
||||
case WEBSOCKET_EVENT_DISCONNECTED:
|
||||
Serial.println(F("Price WS Connnection Closed"));
|
||||
break;
|
||||
case WEBSOCKET_EVENT_CONNECTED:
|
||||
Serial.println(F("Connected to CoinCap.io WebSocket"));
|
||||
break;
|
||||
case WEBSOCKET_EVENT_DATA:
|
||||
onWebsocketPriceMessage(data);
|
||||
break;
|
||||
case WEBSOCKET_EVENT_ERROR:
|
||||
Serial.println(F("Price WS Connnection error"));
|
||||
break;
|
||||
case WEBSOCKET_EVENT_DISCONNECTED:
|
||||
Serial.println(F("Price WS Connnection Closed"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
||||
@ -40,66 +27,67 @@ void workerTask(void *pvParameters) {
|
||||
|
||||
// Process the work item based on its type
|
||||
switch (receivedItem.type) {
|
||||
case TASK_PRICE_UPDATE: {
|
||||
uint price = getPrice();
|
||||
char priceSymbol = '$';
|
||||
if (preferences.getBool("fetchEurPrice", false)) {
|
||||
priceSymbol = '[';
|
||||
}
|
||||
if (getCurrentScreen() == SCREEN_BTC_TICKER) {
|
||||
taskEpdContent = parsePriceData(price, priceSymbol);
|
||||
} else if (getCurrentScreen() == SCREEN_MSCW_TIME) {
|
||||
taskEpdContent = parseSatsPerCurrency(price, priceSymbol);
|
||||
} else {
|
||||
taskEpdContent =
|
||||
parseMarketCap(getBlockHeight(), price, priceSymbol,
|
||||
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;
|
||||
case TASK_PRICE_UPDATE: {
|
||||
uint price = getPrice();
|
||||
char priceSymbol = '$';
|
||||
if (preferences.getBool("fetchEurPrice", false)) {
|
||||
priceSymbol = '[';
|
||||
}
|
||||
if (getCurrentScreen() == SCREEN_BTC_TICKER) {
|
||||
taskEpdContent = parsePriceData(price, priceSymbol);
|
||||
} else if (getCurrentScreen() == SCREEN_MSCW_TIME) {
|
||||
taskEpdContent = parseSatsPerCurrency(price, priceSymbol);
|
||||
} else {
|
||||
taskEpdContent =
|
||||
parseMarketCap(getBlockHeight(), price, priceSymbol,
|
||||
preferences.getBool("mcapBigChar", true));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
case TASK_BLOCK_UPDATE: {
|
||||
if (getCurrentScreen() != SCREEN_HALVING_COUNTDOWN) {
|
||||
taskEpdContent = parseBlockHeight(getBlockHeight());
|
||||
} else {
|
||||
taskEpdContent = parseHalvingCountdown(getBlockHeight());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
// Add more cases for additional task types
|
||||
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);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
// Add more cases for additional task types
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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()); }
|
||||
@ -230,31 +212,30 @@ void setCurrentScreen(uint newScreen) {
|
||||
currentScreen = newScreen;
|
||||
|
||||
switch (currentScreen) {
|
||||
case SCREEN_TIME: {
|
||||
WorkItem timeUpdate = {TASK_TIME_UPDATE, 0};
|
||||
xQueueSend(workQueue, &timeUpdate, portMAX_DELAY);
|
||||
// xTaskNotifyGive(timeUpdateTaskHandle);
|
||||
break;
|
||||
}
|
||||
case SCREEN_HALVING_COUNTDOWN:
|
||||
case SCREEN_BLOCK_HEIGHT: {
|
||||
WorkItem blockUpdate = {TASK_BLOCK_UPDATE, 0};
|
||||
xQueueSend(workQueue, &blockUpdate, portMAX_DELAY);
|
||||
// xTaskNotifyGive(blockUpdateTaskHandle);
|
||||
break;
|
||||
}
|
||||
case SCREEN_MARKET_CAP:
|
||||
case SCREEN_MSCW_TIME:
|
||||
case SCREEN_BTC_TICKER: {
|
||||
WorkItem priceUpdate = {TASK_PRICE_UPDATE, 0};
|
||||
xQueueSend(workQueue, &priceUpdate, portMAX_DELAY);
|
||||
// xTaskNotifyGive(priceUpdateTaskHandle);
|
||||
break;
|
||||
}
|
||||
case SCREEN_TIME: {
|
||||
WorkItem timeUpdate = {TASK_TIME_UPDATE, 0};
|
||||
xQueueSend(workQueue, &timeUpdate, portMAX_DELAY);
|
||||
// xTaskNotifyGive(timeUpdateTaskHandle);
|
||||
break;
|
||||
}
|
||||
case SCREEN_HALVING_COUNTDOWN:
|
||||
case SCREEN_BLOCK_HEIGHT: {
|
||||
WorkItem blockUpdate = {TASK_BLOCK_UPDATE, 0};
|
||||
xQueueSend(workQueue, &blockUpdate, portMAX_DELAY);
|
||||
// xTaskNotifyGive(blockUpdateTaskHandle);
|
||||
break;
|
||||
}
|
||||
case SCREEN_MARKET_CAP:
|
||||
case SCREEN_MSCW_TIME:
|
||||
case SCREEN_BTC_TICKER: {
|
||||
WorkItem priceUpdate = {TASK_PRICE_UPDATE, 0};
|
||||
xQueueSend(workQueue, &priceUpdate, portMAX_DELAY);
|
||||
// xTaskNotifyGive(priceUpdateTaskHandle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
||||
@ -232,7 +230,7 @@ void onApiShowText(AsyncWebServerRequest *request) {
|
||||
if (request->hasParam("t")) {
|
||||
AsyncWebParameter *p = request->getParam("t");
|
||||
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;
|
||||
for (uint i = 0; i < NUM_SCREENS; i++) {
|
||||
@ -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);
|
||||
|
||||
@ -474,7 +471,7 @@ void onApiSettingsPost(AsyncWebServerRequest *request) {
|
||||
int params = request->params();
|
||||
for (int i = 0; i < params; 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(),
|
||||
p->value().c_str(), p->size());
|
||||
} else if (p->isPost()) {
|
||||
@ -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>();
|
||||
|
@ -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;
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
OneParamRewrite::OneParamRewrite(const char *from, const char *to)
|
||||
: AsyncWebRewrite(from, to) {
|
||||
|
||||
_paramIndex = _from.indexOf('{');
|
||||
|
||||
if (_paramIndex >= 0 && _from.endsWith("}")) {
|
||||
|
@ -3,12 +3,12 @@
|
||||
#include "ESPAsyncWebServer.h"
|
||||
|
||||
class OneParamRewrite : public AsyncWebRewrite {
|
||||
protected:
|
||||
protected:
|
||||
String _urlPrefix;
|
||||
int _paramIndex;
|
||||
String _paramsBackup;
|
||||
|
||||
public:
|
||||
public:
|
||||
OneParamRewrite(const char *from, const char *to);
|
||||
bool match(AsyncWebServerRequest *request) override;
|
||||
};
|
Loading…
Reference in New Issue
Block a user