Skip to content

Commit 2777637

Browse files
committed
Improve Nostr Zap functionality, BitAxe integration bugfix
1 parent e39a0cc commit 2777637

File tree

9 files changed

+431
-117
lines changed

9 files changed

+431
-117
lines changed

data

Submodule data updated from 876f3b0 to 21a7192

lib/btclock/nostrdisplay_handler.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "nostrdisplay_handler.hpp"
2+
3+
std::array<std::string, NUM_SCREENS> parseZapNotify(std::uint16_t amount, bool withSatsSymbol)
4+
{
5+
std::string text = std::to_string(amount);
6+
std::size_t textLength = text.length();
7+
std::size_t startIndex = NUM_SCREENS - textLength;
8+
9+
std::array<std::string, NUM_SCREENS> textEpdContent = {"ZAP", "mdi-lnbolt", "", "", "", "", ""};
10+
11+
// Insert the sats symbol just before the digits
12+
if (startIndex > 0 && withSatsSymbol)
13+
{
14+
textEpdContent[startIndex - 1] = "STS";
15+
}
16+
17+
// Place the digits
18+
for (std::size_t i = 0; i < textLength; i++)
19+
{
20+
textEpdContent[startIndex + i] = text.substr(i, 1);
21+
}
22+
23+
return textEpdContent;
24+
}

lib/btclock/nostrdisplay_handler.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <array>
2+
#include <string>
3+
#include "utils.hpp"
4+
5+
std::array<std::string, NUM_SCREENS> parseZapNotify(std::uint16_t amount, bool withSatsSymbol);

src/icons/icons.cpp

+257-2
Large diffs are not rendered by default.

src/lib/config.cpp

+30-20
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ std::vector<ScreenMapping> screenMappings;
1818
std::mutex mcpMutex;
1919
uint lastTimeSync;
2020

21-
void addScreenMapping(int value, const char* name) {
22-
screenMappings.push_back({value, name});
21+
void addScreenMapping(int value, const char *name)
22+
{
23+
screenMappings.push_back({value, name});
2324
}
2425

2526
void setup()
@@ -74,16 +75,21 @@ void setup()
7475

7576
if (preferences.getBool("useNostr", DEFAULT_USE_NOSTR) || preferences.getBool("nostrZapNotify", DEFAULT_ZAP_NOTIFY_ENABLED))
7677
{
77-
setupNostrNotify();
78+
setupNostrNotify(preferences.getBool("useNostr", DEFAULT_USE_NOSTR), preferences.getBool("nostrZapNotify", DEFAULT_ZAP_NOTIFY_ENABLED));
7879
setupNostrTask();
7980
}
80-
81+
8182
if (!preferences.getBool("useNostr", DEFAULT_USE_NOSTR))
8283
{
8384
xTaskCreate(setupWebsocketClients, "setupWebsocketClients", 8192, NULL,
8485
tskIDLE_PRIORITY, NULL);
8586
}
8687

88+
if (preferences.getBool("bitaxeEnabled", DEFAULT_BITAXE_ENABLED))
89+
{
90+
setupBitaxeFetchTask();
91+
}
92+
8793
setupButtonTask();
8894
setupOTA();
8995

@@ -255,7 +261,6 @@ void syncTime()
255261
lastTimeSync = esp_timer_get_time() / 1000000;
256262
}
257263

258-
259264
void setupPreferences()
260265
{
261266
preferences.begin("btclock", false);
@@ -281,9 +286,10 @@ void setupPreferences()
281286
// screenNameMap[SCREEN_HALVING_COUNTDOWN] = "Halving countdown";
282287
// screenNameMap[SCREEN_MARKET_CAP] = "Market Cap";
283288

284-
if (preferences.getBool("bitaxeEnabled", DEFAULT_BITAXE_ENABLED)) {
285-
addScreenMapping(SCREEN_BITAXE_HASHRATE, "BitAxe Hashrate");
286-
addScreenMapping(SCREEN_BITAXE_BESTDIFF, "BitAxe Best Difficulty");
289+
if (preferences.getBool("bitaxeEnabled", DEFAULT_BITAXE_ENABLED))
290+
{
291+
addScreenMapping(SCREEN_BITAXE_HASHRATE, "BitAxe Hashrate");
292+
addScreenMapping(SCREEN_BITAXE_BESTDIFF, "BitAxe Best Difficulty");
287293
}
288294
}
289295

@@ -300,11 +306,6 @@ void setupWebsocketClients(void *pvParameters)
300306
setupPriceNotify();
301307
}
302308

303-
if (preferences.getBool("bitaxeEnabled", DEFAULT_BITAXE_ENABLED))
304-
{
305-
setupBitaxeFetchTask();
306-
}
307-
308309
vTaskDelete(NULL);
309310
}
310311

@@ -443,13 +444,17 @@ void setupHardware()
443444
Serial.println(F("Found BH1750"));
444445
hasLuxSensor = true;
445446
bh1750.begin(BH1750::CONTINUOUS_LOW_RES_MODE, 0x5C);
446-
} else {
447+
}
448+
else
449+
{
447450
Serial.println(F("BH1750 Not found"));
448451
hasLuxSensor = false;
449452
}
450453
#endif
451454
}
452455

456+
457+
#ifdef IMPROV_ENABLED
453458
void improvGetAvailableWifiNetworks()
454459
{
455460
int networkNum = WiFi.scanNetworks();
@@ -658,6 +663,8 @@ void improv_set_error(improv::Error error)
658663
Serial.write(data.data(), data.size());
659664
}
660665

666+
#endif
667+
661668
void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info)
662669
{
663670
static bool first_connect = true;
@@ -824,11 +831,14 @@ String getFsRev()
824831
return ret;
825832
}
826833

827-
int findScreenIndexByValue(int value) {
828-
for (int i = 0; i < screenMappings.size(); i++) {
829-
if (screenMappings[i].value == value) {
830-
return i;
831-
}
834+
int findScreenIndexByValue(int value)
835+
{
836+
for (int i = 0; i < screenMappings.size(); i++)
837+
{
838+
if (screenMappings[i].value == value)
839+
{
840+
return i;
832841
}
833-
return -1; // Return -1 if value is not found
842+
}
843+
return -1; // Return -1 if value is not found
834844
}

src/lib/config.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "lib/block_notify.hpp"
1414
#include "lib/button_handler.hpp"
1515
#include "lib/epd.hpp"
16-
#include "lib/improv.hpp"
16+
// #include "lib/improv.hpp"
1717
#include "lib/led_handler.hpp"
1818
#include "lib/ota.hpp"
1919
#include "lib/nostr_notify.hpp"
@@ -57,13 +57,13 @@ String getMyHostname();
5757
std::vector<ScreenMapping> getScreenNameMap();
5858

5959
std::vector<std::string> getLocalUrl();
60-
bool improv_connectWifi(std::string ssid, std::string password);
61-
void improvGetAvailableWifiNetworks();
62-
bool onImprovCommandCallback(improv::ImprovCommand cmd);
63-
void onImprovErrorCallback(improv::Error err);
64-
void improv_set_state(improv::State state);
65-
void improv_send_response(std::vector<uint8_t> &response);
66-
void improv_set_error(improv::Error error);
60+
// bool improv_connectWifi(std::string ssid, std::string password);
61+
// void improvGetAvailableWifiNetworks();
62+
// bool onImprovCommandCallback(improv::ImprovCommand cmd);
63+
// void onImprovErrorCallback(improv::Error err);
64+
// void improv_set_state(improv::State state);
65+
// void improv_send_response(std::vector<uint8_t> &response);
66+
// void improv_set_error(improv::Error error);
6767

6868
void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info);
6969
String getHwRev();

src/lib/epd.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ void renderIcon(const uint dispNum, const String &text, bool partial)
532532
}
533533

534534
if (text.endsWith("lnbolt")) {
535-
iconIndex = 2;
535+
iconIndex = 3;
536536
}
537537

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

0 commit comments

Comments
 (0)