Compare commits

...

37 commits

Author SHA1 Message Date
fa705e45e8 add mqtt module 2024-12-20 12:00:18 +01:00
Djuri Baars
e8a7b221cb Update WebUI for new mining pools 2024-12-20 04:07:46 +01:00
Djuri Baars
aeee5238b3 Improve mining pool interface, added GoBrrr pool, Public Pool and Satoshi Radio pool 2024-12-20 04:00:09 +01:00
Djuri Baars
f613c7e9a1 Update WebUI 2024-12-20 01:33:10 +01:00
c7ea2f3e4d Merge pull request '[Feature] Adds mining pool screens' (#5) from kdmukai/btclock_v3:mining_stats_v2 into main
Reviewed-on: btclock/btclock_v3#5
2024-12-20 00:11:01 +00:00
Djuri Baars
814cd234a9 Big refactor of mining pool support, optimization of existing icons 2024-12-20 01:08:03 +01:00
f9aa593f0b Removed pool name consts; reduce Preferences hits 2024-12-19 13:54:28 -06:00
01ef6daf9f Update screen id consts 2024-12-19 13:53:16 -06:00
8f9307d1e4 Remove whitespace 2024-12-18 21:34:52 -06:00
e758659a4a Remove platformio edit 2024-12-18 21:31:05 -06:00
be224d1f91 Restoring .gitmodule link to main webui repo 2024-12-18 21:17:19 -06:00
72e5ee6580 README update 2024-12-18 21:17:19 -06:00
c3af0b4d36 Docs update; info on mining pool stats config 2024-12-18 21:17:19 -06:00
fabc6c1d28 bugfix for long preferences key 2024-12-18 21:17:19 -06:00
e175b5f2f5 syncing to my forked webui submodule 2024-12-18 21:17:19 -06:00
2bc5984f6f Add mining pool daily/expected earnings 2024-12-18 21:17:19 -06:00
1bd465b33a rebuilt with larger partitions 2024-12-18 21:17:19 -06:00
Djuri Baars
ae2e6656df Fix LittleFS sha256 generation 2024-12-18 22:52:50 +01:00
Djuri Baars
c989169ff4 Fix workflow and auto updater webui filenames 2024-12-18 22:20:40 +01:00
Djuri Baars
1a4bc9b711 Merge branch 'main' of https://git.btclock.dev/btclock/btclock_v3 2024-12-18 21:40:53 +01:00
Djuri Baars
0dcde59fb4 Fix workflow 2024-12-18 21:40:18 +01:00
Djuri Baars
de8fe2e26e Fix preaction script 2024-12-18 20:41:42 +01:00
Djuri Baars
af4c466659 Switch to leaner MCP23017 library, create new aligned partition tables 2024-12-18 19:47:03 +01:00
Djuri Baars
83d293c58e Add bitaxe logo to WebUI 2024-12-18 01:32:11 +01:00
Djuri Baars
da25c7de90 Merge remote-tracking branch 'keith/bitaxe_logo' 2024-12-18 01:27:05 +01:00
Djuri Baars
4a52fc0bf2 Add vertical screen description option 2024-12-18 00:50:20 +01:00
db0ec01c86 Add bitaxe logo 2024-12-17 08:53:00 -06:00
Djuri Baars
34b77ea105 Update WebUI 2024-12-12 23:12:59 +01:00
Djuri Baars
dbf2c53083 Adapted tests for Mow Units 2024-12-10 15:18:04 +01:00
Djuri Baars
2a116d97ed Add frontlight off when dark setting 2024-12-10 15:13:17 +01:00
3b6f1db3c5 Merge pull request 'Mow Units: No rounding' (#3) from kdmukai/btclock_v3:mow_units_no_rounding into main
Reviewed-on: btclock/btclock_v3#3
2024-12-10 13:26:23 +00:00
9ada991ab1 Update utils.cpp 2024-12-09 16:05:55 -06:00
132aa835cd Mow Units no rounding! 2024-12-09 15:58:39 -06:00
Djuri Baars
d6604d28d6 Update some initial values 2024-12-05 18:28:46 +01:00
Djuri Baars
33c06c86a1 Prepare sats per dollar for 1B amounts 2024-12-05 18:22:59 +01:00
Djuri Baars
f0f591a16f Make better use of the screens in compact suffix mode 2024-12-05 05:21:14 +01:00
Djuri Baars
41b5fcf1c1 Bugfix for suffix compact mode 2024-12-05 04:32:32 +01:00
55 changed files with 2286 additions and 954 deletions

View file

@ -1,4 +1,4 @@
name: 'BTClock CI'
name: "BTClock CI"
on:
push:
@ -22,7 +22,7 @@ jobs:
with:
node-version: lts/*
cache: yarn
cache-dependency-path: '**/yarn.lock'
cache-dependency-path: "**/yarn.lock"
- uses: actions/cache@v4
with:
path: |
@ -34,8 +34,8 @@ jobs:
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v5
with:
python-version: '3.9'
cache: 'pip'
python-version: "3.9"
cache: "pip"
- name: Get current date
id: dateAndTime
shell: bash
@ -81,9 +81,9 @@ jobs:
version: esp32s3
epd_variant: [213epd, 29epd]
exclude:
- chip: {name: btclock_rev_b, version: esp32s3}
- chip: { name: btclock_rev_b, version: esp32s3 }
epd_variant: 29epd
- chip: {name: btclock_v8, version: esp32s3}
- chip: { name: btclock_v8, version: esp32s3 }
epd_variant: 29epd
steps:
- uses: https://code.forgejo.org/forgejo/download-artifact@v4
@ -93,9 +93,10 @@ jobs:
- name: Install esptools.py
run: pip install --upgrade esptool
- name: Create merged firmware binary
shell: bash
run: |
mkdir -p ${{ matrix.chip.name }}_${{ matrix.epd_variant }}
if [ "${{ matrix.chip.name }}" == "btclock_v8" ]; then
mkdir -p ${{ matrix.chip.name }}_${{ matrix.epd_variant }} && \
esptool.py --chip ${{ matrix.chip.version }} merge_bin \
-o ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${{ matrix.chip.name }}_${{ matrix.epd_variant }}.bin \
--flash_mode dio \
@ -105,10 +106,19 @@ jobs:
0x8000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/partitions.bin \
0xe000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/ota_data_initial.bin \
0x10000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/firmware.bin \
0x810000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs.bin;
0xDF0000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs_16MB.bin
elif [ "${{ matrix.chip.name }}" == "btclock_rev_b" ]; then
esptool.py --chip ${{ matrix.chip.version }} merge_bin \
-o ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${{ matrix.chip.name }}_${{ matrix.epd_variant }}.bin \
--flash_mode dio \
--flash_freq 80m \
--flash_size 8MB \
0x0000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/bootloader.bin \
0x8000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/partitions.bin \
0xe000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/ota_data_initial.bin \
0x10000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/firmware.bin \
0x6F0000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs_8MB.bin;
else
# Original command for other cases
mkdir -p ${{ matrix.chip.name }}_${{ matrix.epd_variant }} && \
esptool.py --chip ${{ matrix.chip.version }} merge_bin \
-o ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${{ matrix.chip.name }}_${{ matrix.epd_variant }}.bin \
--flash_mode dio \
@ -116,19 +126,26 @@ jobs:
0x8000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/partitions.bin \
0xe000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/ota_data_initial.bin \
0x10000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/firmware.bin \
0x370000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs.bin
0x380000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs_4MB.bin
# Adjust the offset for littlefs or other files as needed for the original case
fi
- name: Create checksum for firmware
shell: bash
run: shasum -a 256 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/firmware.bin | awk '{print $1}' > ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${{ matrix.chip.name }}_${{ matrix.epd_variant }}_firmware.bin.sha256
- name: Create checksum for merged binary
shell: bash
run: shasum -a 256 ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${{ matrix.chip.name }}_${{ matrix.epd_variant }}.bin | awk '{print $1}' > ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${{ matrix.chip.name }}_${{ matrix.epd_variant }}.bin.sha256
- name: Create checksum for littlefs partition
run: shasum -a 256 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs.bin | awk '{print $1}' > ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs.bin.sha256
shell: bash
run: |
fs_file=$(find .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }} -name "littlefs*.bin")
echo $fs_file
fs_name=$(basename "$fs_file")
shasum -a 256 "$fs_file" | awk '{print $1}' > "${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${fs_name}.sha256"
cat "${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${fs_name}.sha256"
- name: Copy all artifacts to output folder
run: cp .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/*.bin .pio/boot_app0.bin ${{ matrix.chip.name }}_${{ matrix.epd_variant }}
@ -161,11 +178,11 @@ jobs:
- name: Create release
uses: https://code.forgejo.org/actions/forgejo-release@v2.4.0
with:
url: 'https://git.btclock.dev'
repo: '${{ github.repository }}'
url: "https://git.btclock.dev"
repo: "${{ github.repository }}"
direction: upload
tag: '${{ github.ref_name }}'
sha: '${{ github.sha }}'
tag: "${{ github.ref_name }}"
sha: "${{ github.sha }}"
release-dir: release
token: ${{ secrets.TOKEN }}
override: ${{ github.ref_type != 'tag' && github.ref_name != 'main' }}

View file

@ -17,7 +17,7 @@ Biggest differences with v2 are:
New features:
- BitAxe integration
- Zap notifier
-
- Braiins Pool and Ocean mining stats integration
"Steal focus on new block" means that when a new block is mined, the display will switch to the block height screen if it's not on it already.
@ -28,3 +28,30 @@ Most [information](https://github.com/btclock/btclock_v2/wiki) about BTClock v2
## Building
Use PlatformIO to build it yourself. Make sure you fetch the [WebUI](https://github.com/btclock/webui) submodule.
## Braiins Pool and Ocean integration
Enable mining pool stats by accessing your btclock's web UI (point a web browser at the device's IP address).
Under Settings -> Extra Features: toggle Enable Mining Pool Stats.
New options will appear. Select your mining pool and enter your pool username (Ocean) or api key (Braiins).
The Mining Pool Earnings screen displays:
* Braiins: Today's mining reward thus far
* Ocean: Your estimated earnings if the pool were to find a block right now
### Braiins Pool integration
Create an API key based on the steps [here](https://academy.braiins.com/en/braiins-pool/monitoring/#api-configuration).
The key's permissions should be:
* Web Access: no
* API Access: yes
* Access Permissions: Read-only
Copy the token that is created for the new key. Enter this as your "Mining Pool username or api key" in the btclock web UI.
### Ocean integration
Your "Mining Pool username" is just the onchain withdrawal address that you specify when pointing your miners at Ocean.

2
data

@ -1 +1 @@
Subproject commit f0fa58b5ea60f695aeaae9ddd7138cbb3686e96a
Subproject commit fd328d4f05345eaa73cf27d05bb542eaa6915cdb

View file

@ -24,7 +24,7 @@ std::array<std::string, NUM_SCREENS> parseBitaxeHashRate(std::string text)
}
ret[NUM_SCREENS - 1] = "GH/S";
ret[0] = "BIT/AXE";
ret[0] = "mdi:bitaxe";
return ret;
}
@ -37,7 +37,7 @@ std::array<std::string, NUM_SCREENS> parseBitaxeBestDiff(std::string text)
if (text.length() < NUM_SCREENS)
{
text.insert(text.begin(), NUM_SCREENS - text.length(), ' ');
ret[0] = "BIT/AXE";
ret[0] = "mdi:bitaxe";
ret[1] = "mdi:rocket";
firstIndex = 2;
}

View file

@ -73,7 +73,8 @@ std::array<std::string, NUM_SCREENS> parsePriceData(std::uint32_t price, char cu
std::string priceString;
if (std::to_string(price).length() >= NUM_SCREENS || useSuffixFormat)
{
priceString = getCurrencySymbol(currencySymbol) + formatNumberWithSuffix(price, NUM_SCREENS - 2, mowMode);
int numScreens = shareDot || mowMode ? NUM_SCREENS - 1 : NUM_SCREENS - 2;
priceString = getCurrencySymbol(currencySymbol) + formatNumberWithSuffix(price, numScreens, mowMode);
}
else
{
@ -84,16 +85,24 @@ std::array<std::string, NUM_SCREENS> parsePriceData(std::uint32_t price, char cu
{
priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' ');
if (mowMode)
{
ret[0] = "MOW/UNITS";
}
else
{
ret[0] = "BTC/" + getCurrencyCode(currencySymbol);
}
firstIndex = 1;
}
if (shareDot)
size_t dotPosition = priceString.find('.');
if (shareDot && dotPosition != std::string::npos && dotPosition > 0)
{
std::vector<std::string> tempArray;
size_t dotPosition = priceString.find('.');
if (dotPosition != std::string::npos && dotPosition > 0)
{
for (size_t i = 0; i < priceString.length(); ++i)
@ -137,9 +146,26 @@ std::array<std::string, NUM_SCREENS> parseSatsPerCurrency(std::uint32_t price,ch
if (priceString.length() < (NUM_SCREENS))
{
priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' ');
// Check if price is greater than 1 billion
if (price >= 100000000)
{
double satsPerCurrency = (1.0 / static_cast<double>(price)) * 1e8; // Calculate satoshis
std::ostringstream oss;
oss << std::fixed << std::setprecision(3) << satsPerCurrency; // Format with 3 decimal places
priceString = oss.str();
}
else
{
priceString = std::to_string(static_cast<int>(round(1.0 / static_cast<double>(price) * 1e8))); // Default formatting
}
if (currencySymbol != CURRENCY_USD)
// Pad the string with spaces if necessary
if (priceString.length() < NUM_SCREENS)
{
priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' ');
}
if (currencySymbol != CURRENCY_USD || price >= 100000000) // no time anymore when earlier than 1
ret[0] = "SATS/" + getCurrencyCode(currencySymbol);
else
ret[0] = "MSCW/TIME";
@ -322,9 +348,9 @@ emscripten::val parseBlockHeightArray(std::uint32_t blockHeight)
return arrayToStringArray(parseBlockHeight(blockHeight));
}
emscripten::val parsePriceDataArray(std::uint32_t price, const std::string &currencySymbol, bool useSuffixFormat = false)
emscripten::val parsePriceDataArray(std::uint32_t price, const std::string &currencySymbol, bool useSuffixFormat = false, bool mowMode = false, bool shareDot = false)
{
return arrayToStringArray(parsePriceData(price, currencySymbol[0], useSuffixFormat));
return arrayToStringArray(parsePriceData(price, currencySymbol[0], useSuffixFormat, mowMode, shareDot));
}
emscripten::val parseHalvingCountdownArray(std::uint32_t blockHeight, bool asBlocks)

View file

@ -83,15 +83,32 @@ std::string formatNumberWithSuffix(std::uint64_t num, int numCharacters, bool mo
}
// Add suffix
int len = snprintf(result, sizeof(result), "%.0f%c", numDouble, suffix);
int len;
// Mow Mode always uses string truncation to avoid rounding
std::string mowAsString = std::to_string(numDouble);
if (mowMode) {
// Default to one decimal place
len = snprintf(result, sizeof(result), "%s%c", mowAsString.substr(0, mowAsString.find(".") + 2).c_str(), suffix);
}
else
{
len = snprintf(result, sizeof(result), "%.0f%c", numDouble, suffix);
}
// If there's room, add more decimal places
if (len < numCharacters)
{
int restLen = mowMode ? numCharacters - len : numCharacters - len - 1;
if (mowMode) {
snprintf(result, sizeof(result), "%s%c", mowAsString.substr(0, mowAsString.find(".") + 2 + restLen).c_str(), suffix);
}
else
{
snprintf(result, sizeof(result), "%.*f%c", restLen, numDouble, suffix);
}
}
return result;
}

20
maintainers.yaml Normal file
View file

@ -0,0 +1,20 @@
identifier: BTClock
maintainers:
- npub1k5f85zx0xdskyayqpfpc0zq6n7vwqjuuxugkayk72fgynp34cs3qfcvqg2
relays:
- wss://relay.noderunners.network/
- wss://nostr.sathoarder.com/
- wss://offchain.pub/
- wss://nostr3.daedaluslabs.io/
- wss://nostr4.daedaluslabs.io/
- wss://nostr.dbtc.link/
- wss://purplepag.es/
- wss://nos.lol/
- wss://nostr1.daedaluslabs.io/
- wss://nostr.noderunners.network/
- wss://nostr.lnbitcoin.cz/
- wss://relay.primal.net/
- wss://relay.damus.io
- wss://nostr-relay.derekross.me/
- wss://nostr2.azzamo.net/
- wss://nostr2.daedaluslabs.io/

View file

@ -3,5 +3,5 @@ nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x1b8000,
app1, app, ota_1, , 0x1b8000,
spiffs, data, spiffs, , 0x66800,
spiffs, data, spiffs, , 0x66C00,
coredump, data, coredump,, 0x10000,
1 # Name Type SubType Offset Size Flags
3 otadata data ota 0xe000 0x2000
4 app0 app ota_0 0x10000 0x1b8000
5 app1 app ota_1 0x1b8000
6 spiffs data spiffs 0x66800 0x66C00
7 coredump data coredump 0x10000

View file

@ -1,7 +1,7 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 36K, 20K,
otadata, data, ota, 56K, 8K,
app0, app, ota_0, 64K, 4096K,
app1, app, ota_1, , 4096K,
spiffs, data, spiffs, , 410K,
coredump, data, coredump,, 64K,
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x6F0000,
app1, app, ota_1, , 0x6F0000,
spiffs, data, spiffs, , 0x200000,
coredump, data, coredump,, 0x10000,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 36K 0x9000 20K 0x5000
3 otadata data ota 56K 0xe000 8K 0x2000
4 app0 app ota_0 64K 0x10000 4096K 0x6F0000
5 app1 app ota_1 4096K 0x6F0000
6 spiffs data spiffs 410K 0x200000
7 coredump data coredump 64K 0x10000

View file

@ -1,7 +1,7 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 36K, 20K,
otadata, data, ota, 56K, 8K,
app0, app, ota_0, 64K, 1760K,
app1, app, ota_1, , 1760K,
spiffs, data, spiffs, , 410K,
coredump, data, coredump,, 64K,
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x370000,
app1, app, ota_1, , 0x370000,
spiffs, data, spiffs, , 0xCD000,
coredump, data, coredump,, 0x10000,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 36K 0x9000 20K 0x5000
3 otadata data ota 56K 0xe000 8K 0x2000
4 app0 app ota_0 64K 0x10000 1760K 0x370000
5 app1 app ota_1 1760K 0x370000
6 spiffs data spiffs 410K 0xCD000
7 coredump data coredump 64K 0x10000

View file

@ -20,8 +20,9 @@ framework = arduino, espidf
monitor_speed = 115200
monitor_filters = esp32_exception_decoder, colorize
board_build.filesystem = littlefs
extra_scripts = post:scripts/extra_script.py
board_build.embed_files = x509_crt_bundle
extra_scripts = pre:scripts/pre_script.py, post:scripts/extra_script.py
board_build.embed_files =
x509_crt_bundle
build_flags =
!python scripts/git_rev.py
-DLAST_BUILD_TIME=$UNIX_TIME
@ -35,13 +36,13 @@ lib_deps =
https://github.com/joltwallet/esp_littlefs.git
bblanchon/ArduinoJson@^7.2.1
mathieucarbou/ESPAsyncWebServer @ 3.3.23
adafruit/Adafruit BusIO@^1.16.2
adafruit/Adafruit MCP23017 Arduino Library@^2.3.2
robtillaart/MCP23017@^0.8.0
adafruit/Adafruit NeoPixel@^1.12.3
https://github.com/dsbaars/universal_pin
https://github.com/dsbaars/universal_pin#feature/mcp23017_rt
https://github.com/dsbaars/GxEPD2#universal_pin
https://github.com/tzapu/WiFiManager.git#v2.0.17
rblb/Nostrduino@1.2.8
elims/PsychicMqttClient@^0.2.0
[env:lolin_s3_mini]
extends = btclock_base
@ -64,7 +65,7 @@ build_unflags =
[env:btclock_rev_b]
extends = btclock_base
board = btclock_rev_b
board_build.partitions = partition.csv
board_build.partitions = partition_8mb.csv
build_flags =
${btclock_base.build_flags}
-D MCP_INT_PIN=8

View file

@ -5,6 +5,9 @@ from shutil import copyfileobj, rmtree
from pathlib import Path
import subprocess
revision = (
subprocess.check_output(["git", "rev-parse", "HEAD"])
.strip()
@ -43,5 +46,15 @@ def before_buildfs(source, target, env):
output_directory = 'data/build_gz'
process_directory(input_directory, output_directory)
flash_size = env.BoardConfig().get("upload.flash_size", "4MB")
fs_image_name = f"littlefs_{flash_size}"
env.Replace(ESP32_FS_IMAGE_NAME=fs_image_name)
env.Replace(ESP8266_FS_IMAGE_NAME=fs_image_name)
os.environ["PUBLIC_BASE_URL"] = ""
env.AddPreAction("$BUILD_DIR/littlefs.bin", before_buildfs)
fs_name = env.get("ESP32_FS_IMAGE_NAME", "littlefs.bin")
# Or alternatively:
# fs_name = env.get("FSTOOLNAME", "littlefs.bin")
# Use the variable in the pre-action
env.AddPreAction(f"$BUILD_DIR/{fs_name}.bin", before_buildfs)

7
scripts/pre_script.py Normal file
View file

@ -0,0 +1,7 @@
Import("env")
flash_size = env.BoardConfig().get("upload.flash_size", "4MB")
fs_image_name = f"littlefs_{flash_size}"
env.Replace(ESP32_FS_IMAGE_NAME=fs_image_name)
env.Replace(ESP8266_FS_IMAGE_NAME=fs_image_name)

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@
char *wsServer;
esp_websocket_client_handle_t blockNotifyClient = NULL;
uint currentBlockHeight = 860000;
uint currentBlockHeight = 873400;
uint blockMedianFee = 1;
bool blockNotifyInit = false;
unsigned long int lastBlockUpdate;

View file

@ -5,15 +5,15 @@ const TickType_t debounceDelay = pdMS_TO_TICKS(50);
TickType_t lastDebounceTime = 0;
#ifdef IS_BTCLOCK_V8
#define BTN_1 0
#define BTN_2 1
#define BTN_3 2
#define BTN_4 3
#define BTN_1 256
#define BTN_2 512
#define BTN_3 1024
#define BTN_4 2048
#else
#define BTN_1 3
#define BTN_2 2
#define BTN_3 1
#define BTN_4 0
#define BTN_1 2048
#define BTN_2 1024
#define BTN_3 512
#define BTN_4 256
#endif
void buttonTask(void *parameter) {
@ -22,11 +22,12 @@ void buttonTask(void *parameter) {
std::lock_guard<std::mutex> lock(mcpMutex);
TickType_t currentTime = xTaskGetTickCount();
if ((currentTime - lastDebounceTime) >= debounceDelay) {
lastDebounceTime = currentTime;
if (!digitalRead(MCP_INT_PIN)) {
uint pin = mcp1.getLastInterruptPin();
uint pin = mcp1.getInterruptFlagRegister();
switch (pin) {
case BTN_1:
@ -43,12 +44,12 @@ void buttonTask(void *parameter) {
break;
}
}
mcp1.clearInterrupts();
mcp1.getInterruptCaptureRegister();
} else {
}
// Very ugly, but for some reason this is necessary
while (!digitalRead(MCP_INT_PIN)) {
mcp1.clearInterrupts();
mcp1.getInterruptCaptureRegister();
}
}
}

View file

@ -2,10 +2,12 @@
#define MAX_ATTEMPTS_WIFI_CONNECTION 20
// zlib_turbo zt;
Preferences preferences;
Adafruit_MCP23X17 mcp1;
MCP23017 mcp1(0x20);
#ifdef IS_BTCLOCK_V8
Adafruit_MCP23X17 mcp2;
MCP23017 mcp2(0x21);
#endif
#ifdef HAS_FRONTLIGHT
@ -35,7 +37,7 @@ void setup()
}
{
std::lock_guard<std::mutex> lockMcp(mcpMutex);
if (mcp1.digitalRead(3) == LOW)
if (mcp1.read1(3) == LOW)
{
preferences.putBool("wifiConfigured", false);
preferences.remove("txPower");
@ -46,7 +48,7 @@ void setup()
}
{
if (mcp1.digitalRead(0) == LOW)
if (mcp1.read1(0) == LOW)
{
// Then loop forever to prevent anything else from writing to the screen
while (true)
@ -54,7 +56,7 @@ void setup()
delay(1000);
}
}
else if (mcp1.digitalRead(1) == LOW)
else if (mcp1.read1(1) == LOW)
{
preferences.clear();
queueLedEffect(LED_EFFECT_WIFI_ERASE_SETTINGS);
@ -66,6 +68,7 @@ void setup()
}
setupWifi();
// loadIcons();
setupWebserver();
@ -92,6 +95,17 @@ void setup()
setupBitaxeFetchTask();
}
if (preferences.getBool("miningPoolStats", DEFAULT_MINING_POOL_STATS_ENABLED))
{
setupMiningPoolStatsFetchTask();
}
if (preferences.getBool("mqttEnabled", DEFAULT_MQTT_ENABLED))
{
if (setupMqtt())
setupMqttTask();
}
setupButtonTask();
setupOTA();
@ -106,6 +120,7 @@ void setup()
#endif
forceFullRefresh();
}
void setupWifi()
@ -132,7 +147,7 @@ void setupWifi()
bool buttonPress = false;
{
std::lock_guard<std::mutex> lockMcp(mcpMutex);
buttonPress = (mcp1.digitalRead(2) == LOW);
buttonPress = (mcp1.read1(2) == LOW);
}
{
@ -327,6 +342,14 @@ void setupPreferences()
addScreenMapping(SCREEN_BITAXE_HASHRATE, "BitAxe Hashrate");
addScreenMapping(SCREEN_BITAXE_BESTDIFF, "BitAxe Best Difficulty");
}
if (preferences.getBool("miningPoolStats", DEFAULT_MINING_POOL_STATS_ENABLED))
{
addScreenMapping(SCREEN_MINING_POOL_STATS_HASHRATE, "Mining Pool Hashrate");
if (getMiningPool()->supportsDailyEarnings()) {
addScreenMapping(SCREEN_MINING_POOL_STATS_EARNINGS, "Mining Pool Earnings");
}
}
}
String replaceAmbiguousChars(String input)
@ -507,7 +530,7 @@ void setupHardware()
Wire.begin(I2C_SDA_PIN, I2C_SCK_PIN, 400000);
if (!mcp1.begin_I2C(0x20))
if (!mcp1.begin())
{
Serial.println(F("Error MCP23017 1"));
@ -517,17 +540,20 @@ void setupHardware()
else
{
pinMode(MCP_INT_PIN, INPUT_PULLUP);
mcp1.setupInterrupts(false, false, LOW);
// mcp1.setupInterrupts(false, false, LOW);
mcp1.enableControlRegister(MCP23x17_IOCR_ODR);
mcp1.mirrorInterrupts(true);
for (int i = 0; i < 4; i++)
{
mcp1.pinMode(i, INPUT_PULLUP);
mcp1.setupInterruptPin(i, LOW);
mcp1.pinMode1(i, INPUT_PULLUP);
mcp1.enableInterrupt(i, LOW);
}
#ifndef IS_BTCLOCK_V8
for (int i = 8; i <= 14; i++)
{
mcp1.pinMode(i, OUTPUT);
mcp1.pinMode1(i, OUTPUT);
}
#endif
}
@ -538,7 +564,7 @@ void setupHardware()
#endif
#ifdef IS_BTCLOCK_V8
if (!mcp2.begin_I2C(0x21))
if (!mcp2.begin())
{
Serial.println(F("Error MCP23017 2"));
@ -791,3 +817,31 @@ const char* getFirmwareFilename() {
return "";
}
}
const char* getWebUiFilename() {
if (HW_REV == "REV_B_EPD_2_13") {
return "littlefs_8MB.bin";
} else if (HW_REV == "REV_A_EPD_2_13") {
return "littlefs_4MB.bin";
} else if (HW_REV == "REV_A_EPD_2_9") {
return "littlefs_4MB.bin";
} else {
return "littlefs_4MB.bin";
}
}
// void loadIcons() {
// size_t ocean_logo_size = 886;
// int iUncompSize = zt.gzip_info((uint8_t *)epd_compress_bitaxe, ocean_logo_size);
// Serial.printf("uncompressed size = %d\n", iUncompSize);
// uint8_t *pUncompressed;
// pUncompressed = (uint8_t *)malloc(iUncompSize+4);
// int rc = zt.gunzip((uint8_t *)epd_compress_bitaxe, ocean_logo_size, pUncompressed);
// if (rc == ZT_SUCCESS) {
// Serial.println("Decode success");
// }
// }

View file

@ -1,6 +1,6 @@
#pragma once
#include <Adafruit_MCP23X17.h>
#include <MCP23017.h>
#include <Arduino.h>
#include <Preferences.h>
#include <WiFiClientSecure.h>
@ -18,6 +18,7 @@
#include "lib/ota.hpp"
#include "lib/nostr_notify.hpp"
#include "lib/bitaxe_fetch.hpp"
#include "lib/mining_pool_stats_fetch.hpp"
#include "lib/v2_notify.hpp"
@ -29,6 +30,7 @@
#include "PCA9685.h"
#include "BH1750.h"
#endif
#include "lib/mqtt.hpp"
#define NTP_SERVER "pool.ntp.org"
#define DEFAULT_TIME_OFFSET_SECONDS 3600
@ -84,3 +86,5 @@ void addScreenMapping(int value, const char* name);
int findScreenIndexByValue(int value);
String replaceAmbiguousChars(String input);
const char* getFirmwareFilename();
const char* getWebUiFilename();
// void loadIcons();

View file

@ -45,6 +45,8 @@
#define DEFAULT_FL_EFFECT_DELAY 15
#define DEFAULT_LUX_LIGHT_TOGGLE 128
#define DEFAULT_FL_OFF_WHEN_DARK true
#define DEFAULT_FL_ALWAYS_ON false
#define DEFAULT_FL_FLASH_ON_UPDATE false
@ -56,6 +58,14 @@
#define DEFAULT_BITAXE_ENABLED false
#define DEFAULT_BITAXE_HOSTNAME "bitaxe1"
#define DEFAULT_MINING_POOL_STATS_ENABLED false
#define DEFAULT_MINING_POOL_NAME "ocean"
#define DEFAULT_MINING_POOL_USER "38Qkkei3SuF1Eo45BaYmRHUneRD54yyTFy" // Random actual Ocean hasher
#define DEFAULT_MQTT_ENABLED false
#define DEFAULT_MQTT_URL ""
#define DEFAULT_MQTT_ROOTTOPIC "home/"
#define DEFAULT_ZAP_NOTIFY_ENABLED false
#define DEFAULT_ZAP_NOTIFY_PUBKEY "b5127a08cf33616274800a4387881a9f98e04b9c37116e92de5250498635c422"
#define DEFAULT_LED_FLASH_ON_ZAP true
@ -68,3 +78,4 @@
#define DEFAULT_ACTIVE_CURRENCIES "USD,EUR,JPY"
#define DEFAULT_GIT_RELEASE_URL "https://git.btclock.dev/api/v1/repos/btclock/btclock_v3/releases/latest"
#define DEFAULT_VERTICAL_DESC true

View file

@ -191,7 +191,7 @@ void setupDisplays()
}
// Hold lower button to enable "storage mode" (prevents burn-in of ePaper displays)
if (mcp1.digitalRead(0) == LOW)
if (mcp1.read1(0) == LOW)
{
setFgColor(GxEPD_BLACK);
setBgColor(GxEPD_WHITE);
@ -373,7 +373,11 @@ extern "C" void updateDisplay(void *pvParameters) noexcept
void splitText(const uint dispNum, const String &top, const String &bottom,
bool partial)
{
if(preferences.getBool("verticalDesc", DEFAULT_VERTICAL_DESC) && dispNum == 0) {
displays[dispNum].setRotation(1);
} else {
displays[dispNum].setRotation(2);
}
displays[dispNum].setFont(&FONT_SMALL);
displays[dispNum].setTextColor(getFgColor());
@ -600,18 +604,46 @@ void renderIcon(const uint dispNum, const String &text, bool partial)
displays[dispNum].setTextColor(getFgColor());
uint iconIndex = 0;
uint width = 122;
uint height = 122;
if (text.endsWith("rocket")) {
iconIndex = 1;
}
if (text.endsWith("lnbolt")) {
else if (text.endsWith("lnbolt")) {
iconIndex = 2;
}
else if (text.endsWith("bitaxe")) {
width = 122;
height = 250;
iconIndex = 3;
}
else if (text.endsWith("miningpool")) {
LogoData logo = getMiningPoolLogo();
int x_offset = (displays[dispNum].width() - logo.width) / 2;
int y_offset = (displays[dispNum].height() - logo.height) / 2;
// Close the file
displays[dispNum].drawInvertedBitmap(x_offset,y_offset, logo.data, logo.width, logo.height, getFgColor());
return;
}
int x_offset = (displays[dispNum].width() - width) / 2;
int y_offset = (displays[dispNum].height() - height) / 2;
displays[dispNum].drawInvertedBitmap(x_offset,y_offset, epd_icons_allArray[iconIndex], width, height, getFgColor());
// displays[dispNum].drawInvertedBitmap(0,0, getOceanIcon(), 122, 250, getFgColor());
displays[dispNum].drawInvertedBitmap(0,0, epd_icons_allArray[iconIndex], 122, 250, getFgColor());
}
void renderQr(const uint dispNum, const String &text, bool partial)
{
#ifdef USE_QR

View file

@ -4,6 +4,7 @@
#include <Fonts/FreeSansBold9pt7b.h>
#include <GxEPD2_BW.h>
#include <mcp23x17_pin.hpp>
#include <mutex>
#include <native_pin.hpp>
@ -13,6 +14,7 @@
#include "lib/config.hpp"
#include "lib/shared.hpp"
#include "icons/icons.h"
#include "mining_pool_stats_fetch.hpp"
#ifdef USE_QR
#include "qrcodegen.h"

View file

@ -0,0 +1,32 @@
#include "brains_pool.hpp"
void BraiinsPool::prepareRequest(HTTPClient& http) const {
http.addHeader("Pool-Auth-Token", poolUser.c_str());
}
std::string BraiinsPool::getApiUrl() const {
return "https://pool.braiins.com/accounts/profile/json/btc/";
}
PoolStats BraiinsPool::parseResponse(const JsonDocument &doc) const
{
std::string unit = doc["btc"]["hash_rate_unit"].as<std::string>();
static const std::unordered_map<std::string, int> multipliers = {
{"Zh/s", 21}, {"Eh/s", 18}, {"Ph/s", 15}, {"Th/s", 12}, {"Gh/s", 9}, {"Mh/s", 6}, {"Kh/s", 3}};
int multiplier = multipliers.at(unit);
float hashValue = doc["btc"]["hash_rate_5m"].as<float>();
return PoolStats{
.hashrate = std::to_string(static_cast<int>(std::round(hashValue))) + std::string(multiplier, '0'),
.dailyEarnings = static_cast<int64_t>(doc["btc"]["today_reward"].as<float>() * 100000000)};
}
LogoData BraiinsPool::getLogo() const {
return LogoData{
.data = epd_icons_allArray[5],
.width = 122,
.height = 250
};
}

View file

@ -0,0 +1,20 @@
#pragma once
#include "lib/mining_pool/mining_pool_interface.hpp"
#include <icons/icons.h>
class BraiinsPool : public MiningPoolInterface
{
public:
void setPoolUser(const std::string &user) override { poolUser = user; }
void prepareRequest(HTTPClient &http) const override;
std::string getApiUrl() const override;
PoolStats parseResponse(const JsonDocument &doc) const override;
LogoData getLogo() const override;
bool supportsDailyEarnings() const override { return true; }
bool hasLogo() const override { return true; }
std::string getDisplayLabel() const override { return "BRAIINS/POOL"; } // Fallback if needed
std::string getDailyEarningsLabel() const override { return "sats/earned"; }
private:
static int getHashrateMultiplier(const std::string &unit);
};

View file

@ -0,0 +1,14 @@
// src/noderunners/noderunners_pool.cpp
#include "gobrrr_pool.hpp"
std::string GoBrrrPool::getApiUrl() const {
return "https://pool.gobrrr.me/api/client/" + poolUser;
}
LogoData GoBrrrPool::getLogo() const {
return LogoData {
.data = epd_icons_allArray[7],
.width = 122,
.height = 122
};
}

View file

@ -0,0 +1,15 @@
#pragma once
#include "lib/mining_pool/mining_pool_interface.hpp"
#include "lib/mining_pool/public_pool/public_pool.hpp"
#include <icons/icons.h>
class GoBrrrPool : public PublicPool {
public:
std::string getApiUrl() const override;
bool hasLogo() const override { return true; }
std::string getDisplayLabel() const override { return "GOBRRR/POOL"; }
LogoData getLogo() const override;
};

View file

@ -0,0 +1,10 @@
#pragma once
#include <cstdint>
#include <stddef.h>
struct LogoData {
const uint8_t* data;
size_t width;
size_t height;
};

View file

@ -0,0 +1,23 @@
#pragma once
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include "pool_stats.hpp"
#include "logo_data.hpp"
class MiningPoolInterface {
public:
virtual ~MiningPoolInterface() = default;
virtual void setPoolUser(const std::string& user) = 0;
virtual void prepareRequest(HTTPClient& http) const = 0;
virtual std::string getApiUrl() const = 0;
virtual PoolStats parseResponse(const JsonDocument& doc) const = 0;
virtual bool hasLogo() const = 0;
virtual LogoData getLogo() const = 0;
virtual std::string getDisplayLabel() const = 0;
virtual bool supportsDailyEarnings() const = 0;
virtual std::string getDailyEarningsLabel() const = 0;
protected:
std::string poolUser;
};

View file

@ -0,0 +1,122 @@
#include "mining_pool_stats_handler.hpp"
#include <iostream>
std::array<std::string, NUM_SCREENS> parseMiningPoolStatsHashRate(std::string text, const MiningPoolInterface& pool)
{
std::array<std::string, NUM_SCREENS> ret;
ret.fill(""); // Initialize all elements to empty strings
std::string hashrate;
std::string label;
if (text.length() > 21) {
// We are massively future-proof!!
label = "ZH/S";
hashrate = text.substr(0, text.length() - 21);
} else if (text.length() > 18) {
label = "EH/S";
hashrate = text.substr(0, text.length() - 18);
} else if (text.length() > 15) {
label = "PH/S";
hashrate = text.substr(0, text.length() - 15);
} else if (text.length() > 12) {
label = "TH/S";
hashrate = text.substr(0, text.length() - 12);
} else if (text.length() > 9) {
label = "GH/S";
hashrate = text.substr(0, text.length() - 9);
} else if (text.length() > 6) {
label = "MH/S";
hashrate = text.substr(0, text.length() - 6);
} else if (text.length() > 3) {
label = "KH/S";
hashrate = text.substr(0, text.length() - 3);
} else {
label = "H/S";
hashrate = text;
}
std::size_t textLength = hashrate.length();
// Calculate the position where the digits should start
// Account for the position of the mining pool logo and the hashrate label
std::size_t startIndex = NUM_SCREENS - 1 - textLength;
// Insert the pickaxe icon just before the digits
if (startIndex > 0)
{
ret[startIndex - 1] = "mdi:pickaxe";
}
// Place the digits
for (std::size_t i = 0; i < textLength; ++i)
{
ret[startIndex + i] = hashrate.substr(i, 1);
}
ret[NUM_SCREENS - 1] = label;
if (pool.hasLogo()) {
ret[0] = "mdi:miningpool";
} else {
ret[0] = pool.getDisplayLabel();
}
return ret;
}
std::array<std::string, NUM_SCREENS> parseMiningPoolStatsDailyEarnings(int sats, std::string label, const MiningPoolInterface& pool)
{
std::array<std::string, NUM_SCREENS> ret;
ret.fill(""); // Initialize all elements to empty strings
std::string satsDisplay = std::to_string(sats);
if (sats >= 100000000) {
// A whale mining 1+ BTC per day! No decimal points; whales scoff at such things.
label = "BTC" + label.substr(4);
satsDisplay = satsDisplay.substr(0, satsDisplay.length() - 8);
} else if (sats >= 10000000) {
// 10.0M to 99.9M you get one decimal point
satsDisplay = satsDisplay.substr(0, satsDisplay.length() - 6) + "." + satsDisplay[2] + "M";
} else if (sats >= 1000000) {
// 1.00M to 9.99M you get two decimal points
satsDisplay = satsDisplay.substr(0, satsDisplay.length() - 6) + "." + satsDisplay.substr(2, 2) + "M";
} else if (sats >= 100000) {
// 100K to 999K you get no extra precision
satsDisplay = satsDisplay.substr(0, satsDisplay.length() - 3) + "K";
} else if (sats >= 10000) {
// 10.0K to 99.9K you get one decimal point
satsDisplay = satsDisplay.substr(0, satsDisplay.length() - 3) + "." + satsDisplay[2] + "K";
} else {
// Pleb miner! 4 digit or fewer sats will fit as-is. no-op.
}
std::size_t textLength = satsDisplay.length();
// Calculate the position where the digits should start
// Account for the position of the mining pool logo
std::size_t startIndex = NUM_SCREENS - 1 - textLength;
// Insert the pickaxe icon just before the digits if there's room
if (startIndex > 0)
{
ret[startIndex - 1] = "mdi:pickaxe";
}
// Place the digits
for (std::size_t i = 0; i < textLength; ++i)
{
ret[startIndex + i] = satsDisplay.substr(i, 1);
}
ret[NUM_SCREENS - 1] = label;
if (pool.hasLogo()) {
ret[0] = "mdi:miningpool";
} else {
ret[0] = pool.getDisplayLabel();
}
return ret;
}

View file

@ -0,0 +1,8 @@
#include <array>
#include <string>
#ifndef UNITY_TEST
#include "lib/mining_pool/mining_pool_interface.hpp"
#endif
std::array<std::string, NUM_SCREENS> parseMiningPoolStatsHashRate(std::string text, const MiningPoolInterface& pool);
std::array<std::string, NUM_SCREENS> parseMiningPoolStatsDailyEarnings(int sats, std::string label, const MiningPoolInterface& pool);

View file

@ -0,0 +1,42 @@
// src/noderunners/noderunners_pool.cpp
#include "noderunners_pool.hpp"
void NoderunnersPool::prepareRequest(HTTPClient& http) const {
// Empty as NodeRunners doesn't need special headers
}
std::string NoderunnersPool::getApiUrl() const {
return "https://pool.noderunners.network/api/v1/users/" + poolUser;
}
PoolStats NoderunnersPool::parseResponse(const JsonDocument& doc) const {
std::string hashrateStr = doc["hashrate1m"].as<std::string>();
char unit = hashrateStr.back();
std::string value = hashrateStr.substr(0, hashrateStr.size() - 1);
int multiplier = getHashrateMultiplier(unit);
return PoolStats{
.hashrate = value + std::string(multiplier, '0'),
.dailyEarnings = std::nullopt
};
}
LogoData NoderunnersPool::getLogo() const {
return LogoData {
.data = epd_icons_allArray[6],
.width = 122,
.height = 122
};
}
int NoderunnersPool::getHashrateMultiplier(char unit) {
if (unit == '0')
return 0;
static const std::unordered_map<char, int> multipliers = {
{'Z', 21}, {'E', 18}, {'P', 15}, {'T', 12},
{'G', 9}, {'M', 6}, {'K', 3}
};
return multipliers.at(unit);
}

View file

@ -0,0 +1,22 @@
#pragma once
#include "lib/mining_pool/mining_pool_interface.hpp"
#include <icons/icons.h>
class NoderunnersPool : public MiningPoolInterface {
public:
void setPoolUser(const std::string& user) override { poolUser = user; }
void prepareRequest(HTTPClient& http) const override;
std::string getApiUrl() const override;
PoolStats parseResponse(const JsonDocument& doc) const override;
LogoData getLogo() const override;
bool supportsDailyEarnings() const override { return false; }
std::string getDailyEarningsLabel() const override { return ""; }
bool hasLogo() const override { return true; }
std::string getDisplayLabel() const override { return "NODE/RUNNERS"; } // Fallback if needed
protected:
static int getHashrateMultiplier(char unit);
};

View file

@ -0,0 +1,26 @@
#include "ocean_pool.hpp"
void OceanPool::prepareRequest(HTTPClient& http) const {
// Empty as Ocean doesn't need special headers
}
std::string OceanPool::getApiUrl() const {
return "https://api.ocean.xyz/v1/statsnap/" + poolUser;
}
PoolStats OceanPool::parseResponse(const JsonDocument& doc) const {
return PoolStats{
.hashrate = doc["result"]["hashrate_300s"].as<std::string>(),
.dailyEarnings = static_cast<int64_t>(
doc["result"]["estimated_earn_next_block"].as<float>() * 100000000
)
};
}
LogoData OceanPool::getLogo() const {
return LogoData{
.data = epd_icons_allArray[4],
.width = 122,
.height = 122
};
}

View file

@ -0,0 +1,18 @@
#pragma once
#include "lib/mining_pool/mining_pool_interface.hpp"
#include <icons/icons.h>
class OceanPool : public MiningPoolInterface {
public:
void setPoolUser(const std::string& user) override { poolUser = user; }
void prepareRequest(HTTPClient& http) const override;
std::string getApiUrl() const override;
PoolStats parseResponse(const JsonDocument& doc) const override;
LogoData getLogo() const override;
bool hasLogo() const override { return true; }
std::string getDisplayLabel() const override { return "OCEAN/POOL"; } // Fallback if needed
bool supportsDailyEarnings() const override { return true; }
std::string getDailyEarningsLabel() const override { return "sats/block"; }
};

View file

@ -0,0 +1,25 @@
#include "pool_factory.hpp"
const char* PoolFactory::MINING_POOL_NAME_OCEAN = "ocean";
const char* PoolFactory::MINING_POOL_NAME_NODERUNNERS = "noderunners";
const char* PoolFactory::MINING_POOL_NAME_BRAIINS = "braiins";
const char* PoolFactory::MINING_POOL_NAME_SATOSHI_RADIO = "satoshi_radio";
const char* PoolFactory::MINING_POOL_NAME_PUBLIC_POOL = "public_pool";
const char* PoolFactory::MINING_POOL_NAME_GOBRRR_POOL = "gobrrr_pool";
std::unique_ptr<MiningPoolInterface> PoolFactory::createPool(const std::string& poolName) {
static const std::unordered_map<std::string, std::function<std::unique_ptr<MiningPoolInterface>()>> poolFactories = {
{MINING_POOL_NAME_OCEAN, []() { return std::make_unique<OceanPool>(); }},
{MINING_POOL_NAME_NODERUNNERS, []() { return std::make_unique<NoderunnersPool>(); }},
{MINING_POOL_NAME_BRAIINS, []() { return std::make_unique<BraiinsPool>(); }},
{MINING_POOL_NAME_SATOSHI_RADIO, []() { return std::make_unique<SatoshiRadioPool>(); }},
{MINING_POOL_NAME_PUBLIC_POOL, []() { return std::make_unique<PublicPool>(); }},
{MINING_POOL_NAME_GOBRRR_POOL, []() { return std::make_unique<GoBrrrPool>(); }}
};
auto it = poolFactories.find(poolName);
if (it == poolFactories.end()) {
return nullptr;
}
return it->second();
}

View file

@ -0,0 +1,44 @@
#pragma once
#include "mining_pool_interface.hpp"
#include <memory>
#include <string>
#include "noderunners/noderunners_pool.hpp"
#include "braiins/brains_pool.hpp"
#include "ocean/ocean_pool.hpp"
#include "satoshi_radio/satoshi_radio_pool.hpp"
#include "public_pool/public_pool.hpp"
#include "gobrrr_pool/gobrrr_pool.hpp"
class PoolFactory {
public:
static std::unique_ptr<MiningPoolInterface> createPool(const std::string& poolName);
static std::vector<std::string> getAvailablePools() {
return {
MINING_POOL_NAME_OCEAN,
MINING_POOL_NAME_NODERUNNERS,
MINING_POOL_NAME_SATOSHI_RADIO,
MINING_POOL_NAME_BRAIINS,
MINING_POOL_NAME_PUBLIC_POOL,
MINING_POOL_NAME_GOBRRR_POOL
};
}
static std::string getAvailablePoolsAsString() {
const auto pools = getAvailablePools();
std::string result;
for (size_t i = 0; i < pools.size(); ++i) {
result += pools[i];
if (i < pools.size() - 1) {
result += ", ";
}
}
return result;
}
private:
static const char* MINING_POOL_NAME_OCEAN;
static const char* MINING_POOL_NAME_NODERUNNERS;
static const char* MINING_POOL_NAME_BRAIINS;
static const char* MINING_POOL_NAME_SATOSHI_RADIO;
static const char* MINING_POOL_NAME_PUBLIC_POOL;
static const char* MINING_POOL_NAME_GOBRRR_POOL;
};

View file

@ -0,0 +1,10 @@
#pragma once
#include <string>
#include <optional>
struct PoolStats {
std::string hashrate;
std::optional<int64_t> dailyEarnings;
};

View file

@ -0,0 +1,21 @@
// src/noderunners/noderunners_pool.cpp
#include "public_pool.hpp"
std::string PublicPool::getApiUrl() const {
return "https://public-pool.io:40557/api/client/" + poolUser;
}
PoolStats PublicPool::parseResponse(const JsonDocument& doc) const {
uint64_t totalHashrate = 0;
for (JsonVariantConst worker : doc["workers"].as<JsonArrayConst>()) {
totalHashrate += static_cast<uint64_t>(std::llround(worker["hashRate"].as<double>()));
}
return PoolStats{
.hashrate = std::to_string(totalHashrate),
.dailyEarnings = std::nullopt // Public Pool doesn't support daily earnings
};
}

View file

@ -0,0 +1,15 @@
#pragma once
#include "lib/mining_pool/mining_pool_interface.hpp"
#include "lib/mining_pool/noderunners/noderunners_pool.hpp"
#include <icons/icons.h>
class PublicPool : public NoderunnersPool {
public:
std::string getApiUrl() const override;
bool hasLogo() const override { return false; }
std::string getDisplayLabel() const override { return "PUBLIC/POOL"; }
PoolStats parseResponse(const JsonDocument& doc) const override;
};

View file

@ -0,0 +1,6 @@
// src/noderunners/noderunners_pool.cpp
#include "satoshi_radio_pool.hpp"
std::string SatoshiRadioPool::getApiUrl() const {
return "https://pool.satoshiradio.nl/api/v1/users/" + poolUser;
}

View file

@ -0,0 +1,14 @@
#pragma once
#include "lib/mining_pool/mining_pool_interface.hpp"
#include "lib/mining_pool/noderunners/noderunners_pool.hpp"
#include <icons/icons.h>
class SatoshiRadioPool : public NoderunnersPool {
public:
std::string getApiUrl() const override;
bool hasLogo() const override { return false; }
std::string getDisplayLabel() const override { return "SATOSHI/RADIO"; } // Fallback if needed
};

View file

@ -0,0 +1,99 @@
#include "mining_pool_stats_fetch.hpp"
TaskHandle_t miningPoolStatsFetchTaskHandle;
std::string miningPoolName;
std::string miningPoolStatsHashrate;
int miningPoolStatsDailyEarnings;
std::string getMiningPoolStatsHashRate()
{
return miningPoolStatsHashrate;
}
int getMiningPoolStatsDailyEarnings()
{
return miningPoolStatsDailyEarnings;
}
void taskMiningPoolStatsFetch(void *pvParameters)
{
for (;;)
{
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
HTTPClient http;
http.setUserAgent(USER_AGENT);
std::string poolName = preferences.getString("miningPoolName", DEFAULT_MINING_POOL_NAME).c_str();
std::string poolUser = preferences.getString("miningPoolUser", DEFAULT_MINING_POOL_USER).c_str();
auto poolInterface = PoolFactory::createPool(poolName);
if (!poolInterface)
{
Serial.println("Unknown mining pool: \"" + String(poolName.c_str()) + "\"");
continue;
}
poolInterface->setPoolUser(poolUser);
std::string apiUrl = poolInterface->getApiUrl();
http.begin(apiUrl.c_str());
poolInterface->prepareRequest(http);
int httpCode = http.GET();
if (httpCode == 200)
{
String payload = http.getString();
JsonDocument doc;
deserializeJson(doc, payload);
PoolStats stats = poolInterface->parseResponse(doc);
miningPoolStatsHashrate = stats.hashrate;
if (stats.dailyEarnings)
{
miningPoolStatsDailyEarnings = *stats.dailyEarnings;
}
else
{
miningPoolStatsDailyEarnings = 0; // or any other default value
}
if (workQueue != nullptr && (getCurrentScreen() == SCREEN_MINING_POOL_STATS_HASHRATE || getCurrentScreen() == SCREEN_MINING_POOL_STATS_EARNINGS))
{
WorkItem priceUpdate = {TASK_MINING_POOL_STATS_UPDATE, 0};
xQueueSend(workQueue, &priceUpdate, portMAX_DELAY);
}
}
else
{
Serial.print(
F("Error retrieving mining pool data. HTTP status code: "));
Serial.println(httpCode);
}
}
}
void setupMiningPoolStatsFetchTask()
{
xTaskCreate(taskMiningPoolStatsFetch, "miningPoolStatsFetch", (6 * 1024), NULL, tskIDLE_PRIORITY,
&miningPoolStatsFetchTaskHandle);
xTaskNotifyGive(miningPoolStatsFetchTaskHandle);
}
std::unique_ptr<MiningPoolInterface>& getMiningPool()
{
static std::unique_ptr<MiningPoolInterface> currentMiningPool;
if (!currentMiningPool) {
std::string poolName = preferences.getString("miningPoolName", DEFAULT_MINING_POOL_NAME).c_str();
currentMiningPool = PoolFactory::createPool(poolName);
}
return currentMiningPool;
}
LogoData getMiningPoolLogo()
{
return getMiningPool()->getLogo();
}

View file

@ -0,0 +1,19 @@
#pragma once
#include <Arduino.h>
#include <HTTPClient.h>
#include "mining_pool/pool_factory.hpp"
#include "lib/config.hpp"
#include "lib/shared.hpp"
extern TaskHandle_t miningPoolStatsFetchTaskHandle;
void setupMiningPoolStatsFetchTask();
void taskMiningPoolStatsFetch(void *pvParameters);
std::string getMiningPoolStatsHashRate();
int getMiningPoolStatsDailyEarnings();
std::unique_ptr<MiningPoolInterface>& getMiningPool();
LogoData getMiningPoolLogo();

131
src/lib/mqtt.cpp Normal file
View file

@ -0,0 +1,131 @@
#include "mqtt.hpp"
TaskHandle_t mqttTaskHandle = NULL;
// WiFiClient wifiClient;
//PubSubClient client(wifiClient);
PsychicMqttClient mqttClient;
// avoid circular deps, just forward declare externs used here.
#ifdef HAS_FRONTLIGHT
bool hasLightLevel();
float getLightLevel();
#endif
String getMyHostname();
void onMqttCallback(char* topic, byte* payload, unsigned int length)
{
Serial.println("MQTT message arrived");
}
const String getDeviceTopic()
{
const String hostname = getMyHostname();
const String rootTopic = preferences.getString("mqttRootTopic", DEFAULT_MQTT_ROOTTOPIC);
String fullTopic = rootTopic;
if (!rootTopic.endsWith("/") && rootTopic != "")
{
fullTopic += "/";
}
fullTopic += hostname + "/";
return String(fullTopic);
}
// boolean connectMqtt()
// {
// const String willTopic = getDeviceTopic() + "status";
// mqttClient.connect()
// boolean result = client.connect("btclockClient", willTopic.c_str(), 0, true, "offline");
// if (!result)
// {
// Serial.println("[MQTT] could not connect");
// return result;
// }
// publish("status", "online", true);
// return result;
// }
boolean setupMqtt()
{
const String url = preferences.getString("mqttUrl", DEFAULT_MQTT_URL);
if (url == "")
{
Serial.println("[MQTT] url not set");
return false;
}
Serial.print("[MQTT] url: ");
Serial.println(url.c_str());
mqttClient.setClientId(getMyHostname().c_str());
mqttClient.setServer(url.c_str());
// if (url.startsWith("mqtts:") || url.startsWith("wss:"))
// mqttClient.attachArduinoCACertBundle();
mqttClient.connect();
const String willTopic = getDeviceTopic() + "status";
mqttClient.setWill(willTopic.c_str(), 0, 1, "offline");
publish("status", "online", true);
return true;
}
void mqttTask(void *pvParameters)
{
int t=0;
while (1)
{
// client.loop();
vTaskDelay(pdMS_TO_TICKS(1000));
if (t++ % 10 == 0)
{
#ifdef HAS_FRONTLIGHT
if (hasLightLevel())
{
std::string lux_s = std::to_string(static_cast<int>(std::round(getLightLevel())));
publish("sensors/lux", lux_s.c_str());
}
#endif
if (WiFi.isConnected())
{
int8_t rssi = WiFi.RSSI();
std::string rssi_s = std::to_string(static_cast<int>(rssi));
publish("wifi/rssi", rssi_s.c_str());
publish("wifi/bssid", WiFi.BSSIDstr().c_str());
}
std::string heap_free_s = std::to_string(static_cast<int>(ESP.getFreeHeap()));
publish("mem/heap_free", heap_free_s.c_str());
std::string heap_size_s = std::to_string(static_cast<int>(ESP.getHeapSize()));
publish("mem/heap_size", heap_size_s.c_str());
}
}
}
void setupMqttTask()
{
xTaskCreate(mqttTask, "mqttTask", 8192, NULL, 10, &mqttTaskHandle);
}
void publishForDevice(const char *topic, const char *payload)
{
publishForDevice(topic, payload, false);
}
void publishForDevice(const char *topic, const char *payload, boolean retain)
{
const String fullTopic = getDeviceTopic() + topic;
publish(fullTopic.c_str(), payload, retain);
}
void publish(const char *topic, const char *payload)
{
publish(topic, payload, false);
}
void publish(const char *topic, const char *payload, boolean retain)
{
if (!mqttClient.publish(topic, 0, retain, payload))
{
Serial.println("[MQTT] could not write");
}
}

13
src/lib/mqtt.hpp Normal file
View file

@ -0,0 +1,13 @@
#pragma once
#include <Arduino.h>
#include <WiFiClientSecure.h>
#include <PsychicMqttClient.h>
#include "lib/shared.hpp"
boolean setupMqtt();
void setupMqttTask();
void publishForDevice(const char *topic, const char *payload);
void publishForDevice(const char *topic, const char *payload, boolean retain);
void publish(const char *topic, const char *payload);
void publish(const char *topic, const char *payload, boolean retain);

View file

@ -171,14 +171,13 @@ int downloadUpdateHandler(char updateType)
break;
case UPDATE_WEBUI:
{
latestRelease = getLatestRelease("littlefs.bin");
latestRelease = getLatestRelease(getWebUiFilename());
// updateWebUi(latestRelease.fileUrl, U_SPIFFS);
// return 0;
}
break;
}
// First, download the expected SHA256
String expectedSHA256 = downloadSHA256(latestRelease.checksumUrl);
if (expectedSHA256.isEmpty())

View file

@ -8,7 +8,7 @@ const char *wsServerPrice = "wss://ws.coincap.io/prices?assets=bitcoin";
// WebsocketsClient client;
esp_websocket_client_handle_t clientPrice = NULL;
esp_websocket_client_config_t config;
uint currentPrice = 50000;
uint currentPrice = 90000;
unsigned long int lastPriceUpdate;
bool priceNotifyInit = false;
std::map<char, std::uint64_t> currencyMap;

View file

@ -33,9 +33,19 @@ void workerTask(void *pvParameters) {
parseBitaxeBestDiff(getBitaxeBestDiff());
}
setEpdContent(taskEpdContent);
}
break;
}
case TASK_MINING_POOL_STATS_UPDATE: {
if (getCurrentScreen() == SCREEN_MINING_POOL_STATS_HASHRATE) {
taskEpdContent =
parseMiningPoolStatsHashRate(getMiningPoolStatsHashRate(), *getMiningPool());
} else if (getCurrentScreen() == SCREEN_MINING_POOL_STATS_EARNINGS) {
taskEpdContent =
parseMiningPoolStatsDailyEarnings(getMiningPoolStatsDailyEarnings(), getMiningPool()->getDailyEarningsLabel(), *getMiningPool());
}
setEpdContent(taskEpdContent);
break;
}
case TASK_PRICE_UPDATE: {
uint currency = getCurrentCurrency();
uint price = getPrice(currency);
@ -179,6 +189,17 @@ void setCurrentScreen(uint newScreen) {
return;
}
break;
}
case SCREEN_MINING_POOL_STATS_HASHRATE:
case SCREEN_MINING_POOL_STATS_EARNINGS: {
if (preferences.getBool("miningPoolStats", DEFAULT_MINING_POOL_STATS_ENABLED)) {
WorkItem miningPoolStatsUpdate = {TASK_MINING_POOL_STATS_UPDATE, 0};
xQueueSend(workQueue, &miningPoolStatsUpdate, portMAX_DELAY);
} else {
setCurrentScreen(SCREEN_BLOCK_HEIGHT);
return;
}
break;
}
}

View file

@ -6,6 +6,7 @@
#include <data_handler.hpp>
#include <bitaxe_handler.hpp>
#include "lib/mining_pool/mining_pool_stats_handler.hpp"
#include "lib/epd.hpp"
#include "lib/shared.hpp"
@ -23,7 +24,8 @@ typedef enum {
TASK_BLOCK_UPDATE,
TASK_FEE_UPDATE,
TASK_TIME_UPDATE,
TASK_BITAXE_UPDATE
TASK_BITAXE_UPDATE,
TASK_MINING_POOL_STATS_UPDATE
} TaskType;
typedef struct {

View file

@ -144,3 +144,11 @@ String calculateSHA256(WiFiClient *stream, size_t contentLength) {
return result;
}
// uint8_t* getOceanIcon() {
// zlib_turbo zt;
// int iUncompSize = zt.gzip_info((uint8_t *)ocean_logo_comp, ocean_logo_size);
// uint8_t *pUncompressed;
// pUncompressed = (uint8_t *)malloc(iUncompSize+4);
// zt.gunzip((uint8_t *)ocean_logo_comp, ocean_logo_size, pUncompressed);
// }

View file

@ -1,6 +1,7 @@
#pragma once
#include <Adafruit_MCP23X17.h>
#include "MCP23017.h"
// #include <zlib_turbo.h>
#include <ArduinoJson.h>
#include <WiFiClientSecure.h>
#include <Preferences.h>
@ -17,9 +18,9 @@
#include "defaults.hpp"
extern Adafruit_MCP23X17 mcp1;
extern MCP23017 mcp1;
#ifdef IS_BTCLOCK_V8
extern Adafruit_MCP23X17 mcp2;
extern MCP23017 mcp2;
#endif
extern Preferences preferences;
extern std::mutex mcpMutex;
@ -41,24 +42,16 @@ 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_BTC_TICKER_USD = 20;
// const PROGMEM int SCREEN_BTC_TICKER_EUR = 21;
// const PROGMEM int SCREEN_BTC_TICKER_GBP = 22;
// const PROGMEM int SCREEN_BTC_TICKER_JPY = 23;
// const PROGMEM int SCREEN_BTC_TICKER_AUD = 24;
// const PROGMEM int SCREEN_BTC_TICKER_CAD = 25;
const PROGMEM int SCREEN_MARKET_CAP = 30;
// const PROGMEM int SCREEN_MARKET_CAP_USD = 30;
// const PROGMEM int SCREEN_MARKET_CAP_EUR = 31;
// const PROGMEM int SCREEN_MARKET_CAP_GBP = 32;
// const PROGMEM int SCREEN_MARKET_CAP_JPY = 33;
// const PROGMEM int SCREEN_MARKET_CAP_AUD = 34;
// const PROGMEM int SCREEN_MARKET_CAP_CAD = 35;
const PROGMEM int SCREEN_MINING_POOL_STATS_HASHRATE = 70;
const PROGMEM int SCREEN_MINING_POOL_STATS_EARNINGS = 71;
const PROGMEM int SCREEN_BITAXE_HASHRATE = 80;
const PROGMEM int SCREEN_BITAXE_BESTDIFF = 81;
const PROGMEM int SCREEN_COUNTDOWN = 98;
const PROGMEM int SCREEN_CUSTOM = 99;
const int SCREEN_COUNT = 7;
@ -73,7 +66,12 @@ const int usPerMinute = 60 * usPerSecond;
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;
@ -86,3 +84,14 @@ struct ScreenMapping {
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);
}
};
}

View file

@ -72,6 +72,10 @@ void IRAM_ATTR minuteTimerISR(void *arg) {
vTaskNotifyGiveFromISR(bitaxeFetchTaskHandle, &xHigherPriorityTaskWoken);
}
if (miningPoolStatsFetchTaskHandle != NULL) {
vTaskNotifyGiveFromISR(miningPoolStatsFetchTaskHandle, &xHigherPriorityTaskWoken);
}
if (xHigherPriorityTaskWoken == pdTRUE) {
portYIELD_FROM_ISR();
}

View file

@ -510,7 +510,10 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json)
settings["timePerScreen"].as<uint>() * 60);
}
String strSettings[] = {"hostnamePrefix", "mempoolInstance", "nostrPubKey", "nostrRelay", "bitaxeHostname", "nostrZapPubkey", "httpAuthUser", "httpAuthPass", "gitReleaseUrl"};
String strSettings[] = {"hostnamePrefix", "mempoolInstance", "nostrPubKey",
"nostrRelay", "bitaxeHostname", "nostrZapPubkey",
"httpAuthUser", "httpAuthPass", "gitReleaseUrl",
"mqttUrl", "mqttRootTopic"};
for (String setting : strSettings)
{
@ -546,9 +549,10 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json)
"mdnsEnabled", "otaEnabled", "stealFocus",
"mcapBigChar", "useSatsSymbol", "useBlkCountdown",
"suffixPrice", "disableLeds", "ownDataSource",
"mowMode", "suffixShareDot",
"mowMode", "suffixShareDot", "flOffWhenDark",
"flAlwaysOn", "flDisable", "flFlashOnUpd",
"mempoolSecure", "useNostr", "bitaxeEnabled",
"miningPoolStats", "verticalDesc", "mqttEnabled",
"nostrZapNotify", "stagingSource", "httpAuthEnabled"};
for (String setting : boolSettings)
@ -689,6 +693,8 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
root["suffixPrice"] = preferences.getBool("suffixPrice", DEFAULT_SUFFIX_PRICE);
root["disableLeds"] = preferences.getBool("disableLeds", DEFAULT_DISABLE_LEDS);
root["mowMode"] = preferences.getBool("mowMode", DEFAULT_MOW_MODE);
root["verticalDesc"] = preferences.getBool("verticalDesc", DEFAULT_VERTICAL_DESC);
root["suffixShareDot"] = preferences.getBool("suffixShareDot", DEFAULT_SUFFIX_SHARE_DOT);
root["hostnamePrefix"] = preferences.getString("hostnamePrefix", DEFAULT_HOSTNAME_PREFIX);
@ -711,10 +717,18 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
root["bitaxeEnabled"] = preferences.getBool("bitaxeEnabled", DEFAULT_BITAXE_ENABLED);
root["bitaxeHostname"] = preferences.getString("bitaxeHostname", DEFAULT_BITAXE_HOSTNAME);
root["miningPoolStats"] = preferences.getBool("miningPoolStats", DEFAULT_MINING_POOL_STATS_ENABLED);
root["miningPoolName"] = preferences.getString("miningPoolName", DEFAULT_MINING_POOL_NAME);
root["miningPoolUser"] = preferences.getString("miningPoolUser", DEFAULT_MINING_POOL_USER);
root["availablePools"] = PoolFactory::getAvailablePools();
root["mqttEnabled"] = preferences.getBool("mqttEnabled", DEFAULT_MQTT_ENABLED);
root["mqttUrl"] = preferences.getString("mqttUrl", DEFAULT_MQTT_URL);
root["mqttRootTopic"] = preferences.getString("mqttRootTopic", DEFAULT_MQTT_ROOTTOPIC);
root["httpAuthEnabled"] = preferences.getBool("httpAuthEnabled", DEFAULT_HTTP_AUTH_ENABLED);
root["httpAuthUser"] = preferences.getString("httpAuthUser", DEFAULT_HTTP_AUTH_USERNAME);
root["httpAuthPass"] = preferences.getString("httpAuthPass", DEFAULT_HTTP_AUTH_PASSWORD);
#ifdef HAS_FRONTLIGHT
root["hasFrontlight"] = true;
root["flDisable"] = preferences.getBool("flDisable");
@ -726,6 +740,8 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
root["hasLightLevel"] = hasLightLevel();
root["luxLightToggle"] = preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE);
root["flOffWhenDark"] = preferences.getBool("flOffWhenDark", DEFAULT_FL_OFF_WHEN_DARK);
#else
root["hasFrontlight"] = false;
root["hasLightLevel"] = false;
@ -746,17 +762,8 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
#endif
JsonArray screens = root["screens"].to<JsonArray>();
JsonArray actCurrencies = root["actCurrencies"].to<JsonArray>();
for (const auto &str : getActiveCurrencies())
{
actCurrencies.add(str);
}
JsonArray availableCurrencies = root["availableCurrencies"].to<JsonArray>();
for (const auto &str : getAvailableCurrencies())
{
availableCurrencies.add(str);
}
root["actCurrencies"] = getActiveCurrencies();
root["availableCurrencies"] = getAvailableCurrencies();
std::vector<ScreenMapping> screenNameMap = getScreenNameMap();

View file

@ -14,6 +14,7 @@
#include "lib/price_notify.hpp"
#include "lib/screen_handler.hpp"
#include "webserver/OneParamRewrite.hpp"
#include "lib/mining_pool/pool_factory.hpp"
extern TaskHandle_t eventSourceTaskHandle;

View file

@ -51,7 +51,7 @@ extern "C" void app_main()
if (hasLightLevel()) {
if (preferences.getUInt("luxLightToggle", DEFAULT_LUX_LIGHT_TOGGLE) != 0)
{
if (hasLightLevel() && getLightLevel() <= 2)
if (hasLightLevel() && getLightLevel() <= 1 && preferences.getBool("flOffWhenDark", DEFAULT_FL_OFF_WHEN_DARK))
{
if (frontlightIsOn()) {
frontlightFadeOutAll();

View file

@ -33,6 +33,17 @@ void test_CorrectSatsPerDollarConversion(void)
TEST_ASSERT_EQUAL_STRING("4", output[NUM_SCREENS - 1].c_str());
}
void test_SatsPerDollarAfter1B(void)
{
std::array<std::string, NUM_SCREENS> output = parseSatsPerCurrency(120000000, CURRENCY_USD, false);
TEST_ASSERT_EQUAL_STRING("SATS/USD", output[0].c_str());
TEST_ASSERT_EQUAL_STRING("0", output[NUM_SCREENS - 5].c_str());
TEST_ASSERT_EQUAL_STRING(".", output[NUM_SCREENS - 4].c_str());
TEST_ASSERT_EQUAL_STRING("8", output[NUM_SCREENS - 3].c_str());
TEST_ASSERT_EQUAL_STRING("3", output[NUM_SCREENS - 2].c_str());
TEST_ASSERT_EQUAL_STRING("3", output[NUM_SCREENS - 1].c_str());
}
void test_CorrectSatsPerPoundConversion(void)
{
std::array<std::string, NUM_SCREENS> output = parseSatsPerCurrency(37253, CURRENCY_GBP, false);
@ -98,9 +109,41 @@ void test_PriceSuffixMode(void)
TEST_ASSERT_EQUAL_STRING("K", output[NUM_SCREENS - 1].c_str());
}
void test_PriceSuffixModeCompact1(void)
{
std::array<std::string, NUM_SCREENS> output = parsePriceData(100000, '$', true, false, true);
std::string joined = joinArrayWithBrackets(output);
TEST_ASSERT_EQUAL_STRING_MESSAGE("BTC/USD", output[0].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("$", output[NUM_SCREENS - 6].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("1", output[NUM_SCREENS - 5].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("0", output[NUM_SCREENS - 4].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("0.", output[NUM_SCREENS - 3].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("0", output[NUM_SCREENS - 2].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("K", output[NUM_SCREENS - 1].c_str(), joined.c_str());
}
void test_PriceSuffixModeCompact2(void)
{
std::array<std::string, NUM_SCREENS> output = parsePriceData(1000000, '$', true, false, true);
std::string joined = joinArrayWithBrackets(output);
TEST_ASSERT_EQUAL_STRING_MESSAGE("BTC/USD", output[0].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("$", output[NUM_SCREENS - 6].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("1.", output[NUM_SCREENS - 5].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("0", output[NUM_SCREENS - 4].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("0", output[NUM_SCREENS - 3].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("0", output[NUM_SCREENS - 2].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("M", output[NUM_SCREENS - 1].c_str(), joined.c_str());
}
void test_PriceSuffixModeMow(void)
{
std::array<std::string, NUM_SCREENS> output = parsePriceData(93000, '$', true, true);
std::array<std::string, NUM_SCREENS> output = parsePriceData(93600, '$', true, true);
std::string joined = joinArrayWithBrackets(output);
@ -115,11 +158,12 @@ void test_PriceSuffixModeMow(void)
void test_PriceSuffixModeMowCompact(void)
{
std::array<std::string, NUM_SCREENS> output = parsePriceData(93000, '$', true, true, true);
std::array<std::string, NUM_SCREENS> output = parsePriceData(93600, '$', true, true, true);
std::string joined = joinArrayWithBrackets(output);
TEST_ASSERT_EQUAL_STRING("BTC/USD", output[0].c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("MOW/UNITS", output[0].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("$", output[NUM_SCREENS - 6].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("0.", output[NUM_SCREENS - 5].c_str(), joined.c_str());
TEST_ASSERT_EQUAL_STRING_MESSAGE("0", output[NUM_SCREENS - 4].c_str(), joined.c_str());
@ -234,6 +278,7 @@ int runUnityTests(void)
UNITY_BEGIN();
RUN_TEST(test_CorrectSatsPerDollarConversion);
RUN_TEST(test_CorrectSatsPerPoundConversion);
RUN_TEST(test_SatsPerDollarAfter1B);
RUN_TEST(test_SixCharacterBlockHeight);
RUN_TEST(test_SevenCharacterBlockHeight);
RUN_TEST(test_FeeRateDisplay);
@ -246,6 +291,8 @@ int runUnityTests(void)
RUN_TEST(test_Mcap1TrillionJpy);
RUN_TEST(test_Mcap1TrillionJpySmallChars);
RUN_TEST(test_PriceSuffixMode);
RUN_TEST(test_PriceSuffixModeCompact1);
RUN_TEST(test_PriceSuffixModeCompact2);
RUN_TEST(test_PriceSuffixModeMow);
RUN_TEST(test_PriceSuffixModeMowCompact);