btclock_v3/src/lib/shared.hpp

125 lines
3.1 KiB
C++
Raw Normal View History

2023-11-07 01:11:12 +01:00
#pragma once
#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>
#include <mbedtls/md.h>
#include "esp_crt_bundle.h"
#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
#include "defaults.hpp"
2024-12-20 23:02:54 +01:00
#define USER_AGENT "BTClock/3.0"
extern MCP23017 mcp1;
2024-09-21 15:58:07 +02:00
#ifdef IS_BTCLOCK_V8
extern MCP23017 mcp2;
#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;
2023-11-07 21:26:15 +01:00
const PROGMEM int SCREEN_TIME = 3;
const PROGMEM int SCREEN_HALVING_COUNTDOWN = 4;
const PROGMEM int SCREEN_BLOCK_FEE_RATE = 6;
const PROGMEM int SCREEN_SATS_PER_CURRENCY = 10;
const PROGMEM int SCREEN_BTC_TICKER = 20;
const PROGMEM int SCREEN_MARKET_CAP = 30;
const PROGMEM int SCREEN_MINING_POOL_STATS_HASHRATE = 70;
const PROGMEM int SCREEN_MINING_POOL_STATS_EARNINGS = 71;
2024-07-29 20:49:46 +02:00
const PROGMEM int SCREEN_BITAXE_HASHRATE = 80;
const PROGMEM int SCREEN_BITAXE_BESTDIFF = 81;
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;
const int SCREEN_COUNT = 7;
2023-11-30 22:38:01 +01:00
const PROGMEM int screens[SCREEN_COUNT] = {
SCREEN_BLOCK_HEIGHT, SCREEN_SATS_PER_CURRENCY, SCREEN_BTC_TICKER,
SCREEN_TIME, SCREEN_HALVING_COUNTDOWN, SCREEN_MARKET_CAP,
SCREEN_BLOCK_FEE_RATE};
const int usPerSecond = 1000000;
const int usPerMinute = 60 * usPerSecond;
2023-11-07 21:26:15 +01:00
// extern const char *github_root_ca;
2025-01-06 01:27:13 +01:00
// extern const char *isrg_root_x1cert;
extern const uint8_t rootca_crt_bundle_start[] asm("_binary_x509_crt_bundle_start");
// 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");
// uint8_t* getOceanIcon();
// const size_t ocean_logo_size = ocean_logo_comp_end - ocean_logo_comp;
const PROGMEM char UPDATE_FIRMWARE = U_FLASH;
const PROGMEM char UPDATE_WEBUI = U_SPIFFS;
const PROGMEM char UPDATE_ALL = 99;
2024-07-29 20:49:46 +02:00
struct ScreenMapping {
int value;
const char* name;
};
String calculateSHA256(uint8_t* data, size_t len);
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);
}
};
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
};