Skip to content

Commit

Permalink
Improve Nostr Zap functionality, BitAxe integration bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
dsbaars committed Aug 31, 2024
1 parent e39a0cc commit 2777637
Show file tree
Hide file tree
Showing 9 changed files with 431 additions and 117 deletions.
2 changes: 1 addition & 1 deletion data
24 changes: 24 additions & 0 deletions lib/btclock/nostrdisplay_handler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "nostrdisplay_handler.hpp"

std::array<std::string, NUM_SCREENS> parseZapNotify(std::uint16_t amount, bool withSatsSymbol)
{
std::string text = std::to_string(amount);
std::size_t textLength = text.length();
std::size_t startIndex = NUM_SCREENS - textLength;

std::array<std::string, NUM_SCREENS> textEpdContent = {"ZAP", "mdi-lnbolt", "", "", "", "", ""};

// Insert the sats symbol just before the digits
if (startIndex > 0 && withSatsSymbol)
{
textEpdContent[startIndex - 1] = "STS";
}

// Place the digits
for (std::size_t i = 0; i < textLength; i++)
{
textEpdContent[startIndex + i] = text.substr(i, 1);
}

return textEpdContent;
}
5 changes: 5 additions & 0 deletions lib/btclock/nostrdisplay_handler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <array>
#include <string>
#include "utils.hpp"

std::array<std::string, NUM_SCREENS> parseZapNotify(std::uint16_t amount, bool withSatsSymbol);
259 changes: 257 additions & 2 deletions src/icons/icons.cpp

Large diffs are not rendered by default.

50 changes: 30 additions & 20 deletions src/lib/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ std::vector<ScreenMapping> screenMappings;
std::mutex mcpMutex;
uint lastTimeSync;

void addScreenMapping(int value, const char* name) {
screenMappings.push_back({value, name});
void addScreenMapping(int value, const char *name)
{
screenMappings.push_back({value, name});
}

void setup()
Expand Down Expand Up @@ -74,16 +75,21 @@ void setup()

if (preferences.getBool("useNostr", DEFAULT_USE_NOSTR) || preferences.getBool("nostrZapNotify", DEFAULT_ZAP_NOTIFY_ENABLED))
{
setupNostrNotify();
setupNostrNotify(preferences.getBool("useNostr", DEFAULT_USE_NOSTR), preferences.getBool("nostrZapNotify", DEFAULT_ZAP_NOTIFY_ENABLED));
setupNostrTask();
}

if (!preferences.getBool("useNostr", DEFAULT_USE_NOSTR))
{
xTaskCreate(setupWebsocketClients, "setupWebsocketClients", 8192, NULL,
tskIDLE_PRIORITY, NULL);
}

if (preferences.getBool("bitaxeEnabled", DEFAULT_BITAXE_ENABLED))
{
setupBitaxeFetchTask();
}

setupButtonTask();
setupOTA();

Expand Down Expand Up @@ -255,7 +261,6 @@ void syncTime()
lastTimeSync = esp_timer_get_time() / 1000000;
}


void setupPreferences()
{
preferences.begin("btclock", false);
Expand All @@ -281,9 +286,10 @@ void setupPreferences()
// screenNameMap[SCREEN_HALVING_COUNTDOWN] = "Halving countdown";
// screenNameMap[SCREEN_MARKET_CAP] = "Market Cap";

if (preferences.getBool("bitaxeEnabled", DEFAULT_BITAXE_ENABLED)) {
addScreenMapping(SCREEN_BITAXE_HASHRATE, "BitAxe Hashrate");
addScreenMapping(SCREEN_BITAXE_BESTDIFF, "BitAxe Best Difficulty");
if (preferences.getBool("bitaxeEnabled", DEFAULT_BITAXE_ENABLED))
{
addScreenMapping(SCREEN_BITAXE_HASHRATE, "BitAxe Hashrate");
addScreenMapping(SCREEN_BITAXE_BESTDIFF, "BitAxe Best Difficulty");
}
}

Expand All @@ -300,11 +306,6 @@ void setupWebsocketClients(void *pvParameters)
setupPriceNotify();
}

if (preferences.getBool("bitaxeEnabled", DEFAULT_BITAXE_ENABLED))
{
setupBitaxeFetchTask();
}

vTaskDelete(NULL);
}

Expand Down Expand Up @@ -443,13 +444,17 @@ void setupHardware()
Serial.println(F("Found BH1750"));
hasLuxSensor = true;
bh1750.begin(BH1750::CONTINUOUS_LOW_RES_MODE, 0x5C);
} else {
}
else
{
Serial.println(F("BH1750 Not found"));
hasLuxSensor = false;
}
#endif
}


#ifdef IMPROV_ENABLED
void improvGetAvailableWifiNetworks()
{
int networkNum = WiFi.scanNetworks();
Expand Down Expand Up @@ -658,6 +663,8 @@ void improv_set_error(improv::Error error)
Serial.write(data.data(), data.size());
}

#endif

void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info)
{
static bool first_connect = true;
Expand Down Expand Up @@ -824,11 +831,14 @@ String getFsRev()
return ret;
}

int findScreenIndexByValue(int value) {
for (int i = 0; i < screenMappings.size(); i++) {
if (screenMappings[i].value == value) {
return i;
}
int findScreenIndexByValue(int value)
{
for (int i = 0; i < screenMappings.size(); i++)
{
if (screenMappings[i].value == value)
{
return i;
}
return -1; // Return -1 if value is not found
}
return -1; // Return -1 if value is not found
}
16 changes: 8 additions & 8 deletions src/lib/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "lib/block_notify.hpp"
#include "lib/button_handler.hpp"
#include "lib/epd.hpp"
#include "lib/improv.hpp"
// #include "lib/improv.hpp"
#include "lib/led_handler.hpp"
#include "lib/ota.hpp"
#include "lib/nostr_notify.hpp"
Expand Down Expand Up @@ -57,13 +57,13 @@ String getMyHostname();
std::vector<ScreenMapping> getScreenNameMap();

std::vector<std::string> getLocalUrl();
bool improv_connectWifi(std::string ssid, std::string password);
void improvGetAvailableWifiNetworks();
bool onImprovCommandCallback(improv::ImprovCommand cmd);
void onImprovErrorCallback(improv::Error err);
void improv_set_state(improv::State state);
void improv_send_response(std::vector<uint8_t> &response);
void improv_set_error(improv::Error error);
// bool improv_connectWifi(std::string ssid, std::string password);
// void improvGetAvailableWifiNetworks();
// bool onImprovCommandCallback(improv::ImprovCommand cmd);
// void onImprovErrorCallback(improv::Error err);
// void improv_set_state(improv::State state);
// void improv_send_response(std::vector<uint8_t> &response);
// void improv_set_error(improv::Error error);

void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info);
String getHwRev();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/epd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ void renderIcon(const uint dispNum, const String &text, bool partial)
}

if (text.endsWith("lnbolt")) {
iconIndex = 2;
iconIndex = 3;
}

displays[dispNum].drawInvertedBitmap(0,0, epd_icons_allArray[iconIndex], 122, 250, getFgColor());
Expand Down
Loading

0 comments on commit 2777637

Please sign in to comment.