2023-11-07 01:11:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
2024-12-18 19:47:03 +01:00
|
|
|
#include "MCP23017.h"
|
|
|
|
// #include <zlib_turbo.h>
|
2023-11-07 21:26:15 +01:00
|
|
|
#include <ArduinoJson.h>
|
2024-09-11 17:40:44 +02:00
|
|
|
#include <WiFiClientSecure.h>
|
2023-11-07 01:11:12 +01:00
|
|
|
#include <Preferences.h>
|
2023-11-30 22:38:01 +01:00
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
#include <freertos/task.h>
|
2024-03-18 19:32:34 +01:00
|
|
|
#include <GxEPD2.h>
|
|
|
|
#include <GxEPD2_BW.h>
|
2024-09-11 03:23:41 +02:00
|
|
|
#include <mbedtls/md.h>
|
2024-11-25 23:54:02 +01:00
|
|
|
#include "esp_crt_bundle.h"
|
2024-09-11 20:27:40 +02:00
|
|
|
#include <Update.h>
|
2024-12-20 23:02:54 +01:00
|
|
|
#include <HTTPClient.h>
|
2023-11-13 20:02:58 +01:00
|
|
|
|
2023-11-30 22:56:50 +01:00
|
|
|
#include <mutex>
|
2023-11-30 22:38:01 +01:00
|
|
|
#include <utils.hpp>
|
2025-01-05 22:11:53 +01:00
|
|
|
#include <array>
|
|
|
|
#include <string>
|
2023-11-07 01:11:12 +01:00
|
|
|
|
2024-07-11 14:08:37 +02:00
|
|
|
#include "defaults.hpp"
|
|
|
|
|
2024-12-20 23:02:54 +01:00
|
|
|
#define USER_AGENT "BTClock/3.0"
|
|
|
|
|
2024-12-18 19:47:03 +01:00
|
|
|
extern MCP23017 mcp1;
|
2024-09-21 15:58:07 +02:00
|
|
|
#ifdef IS_BTCLOCK_V8
|
2024-12-18 19:47:03 +01:00
|
|
|
extern MCP23017 mcp2;
|
2023-11-26 00:51:54 +01:00
|
|
|
#endif
|
2023-11-07 01:11:12 +01:00
|
|
|
extern Preferences preferences;
|
2023-11-13 20:02:58 +01:00
|
|
|
extern std::mutex mcpMutex;
|
2023-11-07 21:26:15 +01:00
|
|
|
|
2024-03-18 19:32:34 +01:00
|
|
|
#ifdef VERSION_EPD_2_13
|
|
|
|
#define EPD_CLASS GxEPD2_213_B74
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef VERSION_EPD_2_9
|
|
|
|
#define EPD_CLASS GxEPD2_290_T94
|
|
|
|
#endif
|
|
|
|
|
2023-11-07 21:26:15 +01:00
|
|
|
const PROGMEM int SCREEN_BLOCK_HEIGHT = 0;
|
2024-09-05 14:00:15 +02:00
|
|
|
|
2023-11-07 21:26:15 +01:00
|
|
|
const PROGMEM int SCREEN_TIME = 3;
|
|
|
|
const PROGMEM int SCREEN_HALVING_COUNTDOWN = 4;
|
2024-03-10 20:24:55 +01:00
|
|
|
const PROGMEM int SCREEN_BLOCK_FEE_RATE = 6;
|
2024-09-05 14:00:15 +02:00
|
|
|
|
|
|
|
const PROGMEM int SCREEN_SATS_PER_CURRENCY = 10;
|
|
|
|
|
|
|
|
const PROGMEM int SCREEN_BTC_TICKER = 20;
|
|
|
|
|
|
|
|
const PROGMEM int SCREEN_MARKET_CAP = 30;
|
2024-12-20 01:08:03 +01:00
|
|
|
|
|
|
|
const PROGMEM int SCREEN_MINING_POOL_STATS_HASHRATE = 70;
|
|
|
|
const PROGMEM int SCREEN_MINING_POOL_STATS_EARNINGS = 71;
|
2024-09-05 14:00:15 +02:00
|
|
|
|
2024-07-29 20:49:46 +02:00
|
|
|
const PROGMEM int SCREEN_BITAXE_HASHRATE = 80;
|
|
|
|
const PROGMEM int SCREEN_BITAXE_BESTDIFF = 81;
|
2023-11-10 19:52:06 +01:00
|
|
|
|
2024-12-17 20:17:21 -06:00
|
|
|
|
2023-11-07 21:26:15 +01:00
|
|
|
const PROGMEM int SCREEN_COUNTDOWN = 98;
|
|
|
|
const PROGMEM int SCREEN_CUSTOM = 99;
|
2024-03-10 20:24:55 +01:00
|
|
|
const int SCREEN_COUNT = 7;
|
2023-11-30 22:38:01 +01:00
|
|
|
const PROGMEM int screens[SCREEN_COUNT] = {
|
2024-09-05 14:00:15 +02:00
|
|
|
SCREEN_BLOCK_HEIGHT, SCREEN_SATS_PER_CURRENCY, SCREEN_BTC_TICKER,
|
2024-03-10 20:24:55 +01:00
|
|
|
SCREEN_TIME, SCREEN_HALVING_COUNTDOWN, SCREEN_MARKET_CAP,
|
|
|
|
SCREEN_BLOCK_FEE_RATE};
|
2023-11-13 12:27:34 +01:00
|
|
|
const int usPerSecond = 1000000;
|
|
|
|
const int usPerMinute = 60 * usPerSecond;
|
2023-11-07 21:26:15 +01:00
|
|
|
|
2024-11-25 23:54:02 +01:00
|
|
|
// extern const char *github_root_ca;
|
2025-01-06 01:27:13 +01:00
|
|
|
// extern const char *isrg_root_x1cert;
|
2024-11-25 23:54:02 +01:00
|
|
|
|
|
|
|
extern const uint8_t rootca_crt_bundle_start[] asm("_binary_x509_crt_bundle_start");
|
2024-12-18 19:47:03 +01:00
|
|
|
// extern const uint8_t ocean_logo_comp[] asm("_binary_ocean_gz_start");
|
|
|
|
// extern const uint8_t ocean_logo_comp_end[] asm("_binary_ocean_gz_end");
|
2024-11-25 23:54:02 +01:00
|
|
|
|
2024-12-18 19:47:03 +01:00
|
|
|
// uint8_t* getOceanIcon();
|
|
|
|
|
|
|
|
// const size_t ocean_logo_size = ocean_logo_comp_end - ocean_logo_comp;
|
2024-09-11 03:23:41 +02:00
|
|
|
|
2024-09-11 20:27:40 +02:00
|
|
|
const PROGMEM char UPDATE_FIRMWARE = U_FLASH;
|
|
|
|
const PROGMEM char UPDATE_WEBUI = U_SPIFFS;
|
|
|
|
const PROGMEM char UPDATE_ALL = 99;
|
2024-09-11 03:23:41 +02:00
|
|
|
|
2024-07-29 20:49:46 +02:00
|
|
|
struct ScreenMapping {
|
|
|
|
int value;
|
|
|
|
const char* name;
|
2024-09-11 03:23:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
String calculateSHA256(uint8_t* data, size_t len);
|
2024-12-20 01:08:03 +01:00
|
|
|
String calculateSHA256(WiFiClient *stream, size_t contentLength);
|
|
|
|
|
|
|
|
namespace ArduinoJson {
|
|
|
|
template <typename T>
|
|
|
|
struct Converter<std::vector<T>> {
|
|
|
|
static void toJson(const std::vector<T>& src, JsonVariant dst) {
|
|
|
|
JsonArray array = dst.to<JsonArray>();
|
|
|
|
for (T item : src)
|
|
|
|
array.add(item);
|
|
|
|
}
|
|
|
|
};
|
2024-12-30 00:53:50 +01:00
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
struct Converter<std::array<String, N>> {
|
|
|
|
static void toJson(const std::array<String, N>& src, JsonVariant dst) {
|
|
|
|
JsonArray array = dst.to<JsonArray>();
|
|
|
|
for (const String& item : src) {
|
|
|
|
array.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2024-12-20 23:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class HttpHelper {
|
|
|
|
public:
|
|
|
|
static HTTPClient* begin(const String& url);
|
|
|
|
static void end(HTTPClient* http);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static WiFiClientSecure secureClient;
|
|
|
|
static bool certBundleSet;
|
|
|
|
static WiFiClient insecureClient;
|
2025-01-05 22:11:53 +01:00
|
|
|
};
|
|
|
|
|