Skip to content

Commit 80b58e0

Browse files
committed
reproducible build, fixed qr
1 parent fa0c51c commit 80b58e0

4 files changed

Lines changed: 99 additions & 75 deletions

File tree

build.sh

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,53 @@
11
#!/bin/sh
2+
set -e
3+
4+
# ---- desired toolchain (matches your working local) ----
5+
REQUIRED_CORE="esp32:esp32@2.0.17"
6+
# Optional: warn if CLI differs from your local (1.2.2). Comment out if not needed.
7+
REQUIRED_CLI_VER="1.2.2"
8+
9+
# ---- sanity: arduino-cli present ----
210
command -v arduino-cli >/dev/null 2>&1 || { echo >&2 "arduino-cli not found. Aborting."; exit 1; }
3-
arduino-cli config --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json init --overwrite
11+
12+
# ---- (optional) warn if CLI version differs, but don't fail ----
13+
CLI_VER="$(arduino-cli version | awk '{print $3}')"
14+
[ "$CLI_VER" = "$REQUIRED_CLI_VER" ] || echo "WARN: arduino-cli $CLI_VER != $REQUIRED_CLI_VER (ok if CI pins it)."
15+
16+
# ---- make sure Espressif index is configured (idempotent) ----
17+
if ! arduino-cli config dump | grep -q 'package_esp32_index.json'; then
18+
arduino-cli config init --overwrite
19+
arduino-cli config set board_manager.additional_urls \
20+
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
21+
fi
22+
423
arduino-cli core update-index
5-
arduino-cli upgrade
6-
# uBitcoin is broken on esp32 3.x.x
7-
arduino-cli core install esp32:esp32@2.0.17
8-
arduino-cli lib install TFT_eSPI ArduinoJson uBitcoin JC_Button EspSoftwareSerial "Adafruit Thermal Printer Library"
924

25+
# ---- ensure the exact core version is installed (idempotent) ----
26+
arduino-cli core install "$REQUIRED_CORE"
27+
28+
# NOTE: DO NOT run `arduino-cli upgrade` here; it can pull newer tool bundles and change behavior.
29+
30+
# ---- ensure the exact library versions you used locally (idempotent) ----
31+
# If already present at that version, this is a no-op.
32+
while IFS= read -r lib; do
33+
[ -n "$lib" ] || continue
34+
arduino-cli lib install "$lib"
35+
done <<'EOF'
36+
TFT_eSPI@2.5.43
37+
ArduinoJson@7.2.0
38+
uBitcoin@0.2.0
39+
JC_Button@2.1.4
40+
EspSoftwareSerial@8.1.0
41+
Adafruit Thermal Printer Library@1.4.1
42+
EOF
43+
44+
# ---- your existing flags & compile (unchanged) ----
1045
tft_config=$(sh ./tft_config_build_flags.sh)
1146
arduino-cli compile \
12-
--build-property "build.partitions=min_spiffs" \
13-
--build-property "upload.maximum_size=1966080" \
14-
--build-property "build.extra_flags.esp32=${tft_config}" \
15-
--library ./libraries/QRCode \
16-
--build-path build --fqbn esp32:esp32:ttgo-lora32 fossa
47+
--build-property "build.partitions=min_spiffs" \
48+
--build-property "upload.maximum_size=1966080" \
49+
--build-property "build.extra_flags.esp32=${tft_config}" \
50+
--library ./libraries/QRCode \
51+
--build-path build \
52+
--fqbn esp32:esp32:ttgo-lora32 \
53+
fossa

fossa/104_printer.ino

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,39 @@
11

2-
3-
// define a list of quote Strings that can be used to print on the receipt
4-
const char* quotes[13] = {
5-
"It's very attractive to the libertarian viewpoint if we can explain it properly. I'm better with code than with words though.\r\nSatoshi Nakamoto, Dec 14, 2008",
6-
"In a few decades when the reward gets too small, the transaction fee will become the main compensation for nodes.\r\nSatoshi Nakamoto, Feb 14, 2010",
7-
"I'm sure that in 20 years there will either be very large transaction volume or no volume.\r\nSatoshi Nakamoto, Feb 14, 2010",
8-
"Imagine if gold turned to lead when stolen. If the thief gives it back, it turns to gold again.\r\nSatoshi Nakamoto, Aug 11, 2010",
9-
"If you don't believe me or don't get it, I don't have time to try to convince you, sorry.\r\nSatoshi Nakamoto, Jul 29, 2010",
10-
"The Times 03/Jan/2009 Chancellor on brink of second bailout for banks.",
11-
"It would have been nice to get this attention in any other context. WikiLeaks has kicked the hornet's nest, and the swarm is headed towards us.\r\nSatoshi Nakamoto, Dec 11, 2010",
12-
"Lost coins only make everyone else's coins worth slightly more. Think of it as a donation to everyone.\r\nSatoshi Nakamoto, Jul 21, 2010",
13-
"Sigh... why delete a wallet instead of moving it aside and keeping the old copy just in case? You should never delete a wallet.\r\nSatoshi Nakamoto, October 3rd, 2010",
14-
"It's very attractive to the libertarian viewpoint if we can explain it properly. I'm better with code than with words though.\r\nSatoshi Nakamoto, Nov 14 2008",
15-
"It's time we had the same thing for money. With e-currency based on cryptographic proof, without the need to trust a third party middleman, money can be secure and transactions effortless.\r\nSatoshi Nakamoto, Jan 11 2009",
16-
"Sorry to be a wet blanket. Writing a description for this thing for general audiences is bloody hard. There's nothing to relate it to.\r\nSatoshi Nakamoto, 05 Jul 2010",
17-
"Yes, but we can win a major battle in the arms race and gain a new territory of freedom for several years.\r\nSatoshi Nakamoto, 6 Nov 2008"
18-
};
19-
20-
// function that returns a random quote from the list of quotes
21-
const char* getRandomQuote() {
22-
return quotes[random(0, 13)];
2+
void printQRcode(const String& qrData, uint8_t moduleSize = 6, bool isMainQR = true) {
3+
uint8_t ms = isMainQR ? moduleSize : (moduleSize > 1 ? moduleSize - 1 : 1);
4+
if (ms < 1) ms = 1;
5+
if (ms > 16) ms = 16;
6+
7+
Stream& out = printerSerial; // or your HardwareSerial if you swapped
8+
const uint8_t ecc = '1'; // M is a good default for receipts
9+
10+
// Some units like an init/reset
11+
const uint8_t init[] = { 0x1B, 0x40 }; // ESC @
12+
const uint8_t model2[] = { 0x1D,0x28,0x6B, 0x04,0x00, 0x31,0x41, 0x32,0x00 }; // GS ( k ... 1 A '2' 0
13+
const uint8_t sizeCmd[] = { 0x1D,0x28,0x6B, 0x03,0x00, 0x31,0x43, ms }; // module size
14+
const uint8_t eccCmd[] = { 0x1D,0x28,0x6B, 0x03,0x00, 0x31,0x45, ecc }; // ECC
15+
16+
out.write(init, sizeof(init));
17+
out.write(model2, sizeof(model2));
18+
out.write(sizeCmd, sizeof(sizeCmd));
19+
out.write(eccCmd, sizeof(eccCmd));
20+
21+
// Store data: pL/pH = (len + 3), little-endian
22+
const uint16_t k = (uint16_t)qrData.length(); // your ~170 fits easily
23+
const uint16_t len = k + 3;
24+
const uint8_t storeHdr[] = { 0x1D,0x28,0x6B, (uint8_t)(len & 0xFF), (uint8_t)(len >> 8), 0x31,0x50,0x30 };
25+
out.write(storeHdr, sizeof(storeHdr));
26+
out.print(qrData);
27+
28+
// Print symbol
29+
const uint8_t printCmd[] = { 0x1D,0x28,0x6B, 0x03,0x00, 0x31,0x51,0x30 };
30+
out.write(printCmd, sizeof(printCmd));
31+
32+
out.flush();
33+
delay(50);
34+
printer.feed(1); // ensure it renders out of the head
2335
}
2436

25-
void printQRcode(String qrData, byte size = 2, bool isMainQR = true) {
26-
// Using a smaller size or adjusting based on isMainQR
27-
byte adjustedSize = isMainQR ? size : max(1, size - 10); // Ensure minimum size of 1
28-
29-
// Adjust error correction: L (0x31), M (0x32), Q (0x33), H (0x34)
30-
byte eccLevel = 0x31; // Start with low and increase if errors persist
31-
32-
// Commands setup
33-
const byte modelCommand[] = { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x43, adjustedSize };
34-
const byte eccCommand[] = { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x45, eccLevel };
35-
const byte printCommand[] = { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x51, 0x30 };
36-
37-
printerSerial.write(modelCommand, sizeof(modelCommand));
38-
printerSerial.write(eccCommand, sizeof(eccCommand));
39-
40-
int len = qrData.length() + 3;
41-
if (len > 255) {
42-
// Simple error handling for data that is too large
43-
Serial.println("Data too long for a single QR code!");
44-
return;
45-
}
46-
byte dataCommand[] = { 0x1D, 0x28, 0x6B, (byte)len, 0x00, 0x31, 0x50, 0x30 };
47-
printerSerial.write(dataCommand, sizeof(dataCommand));
48-
printerSerial.print(qrData);
49-
printerSerial.write(printCommand, sizeof(printCommand));
50-
}
5137

5238
void printReceipt() {
5339
printer.wake();
@@ -67,9 +53,6 @@ void printReceipt() {
6753
printer.feed(1);
6854
printQRcode(qrData);
6955
printer.boldOff();
70-
printer.feed(1);
71-
printer.justify('L');
72-
printer.println(getRandomQuote());
7356
printer.feed(3);
7457
printer.sleep();
7558
}

fossa/105_display.ino

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ void feedmefiatloop() {
3333
delay(100);
3434
}
3535
void qrShowCodeLNURL(String message) {
36-
Serial.println("poo");
37-
if (printerBool == true) {
38-
printMessage(printingT, waitT, "", TFT_WHITE, TFT_BLACK);
39-
printReceipt();
40-
delay(3000);
41-
}
42-
Serial.println("poo");
4336
Serial.println(qrData);
4437
tft.fillScreen(TFT_WHITE);
4538
const char *qrDataChar = qrData.c_str();
@@ -61,6 +54,8 @@ void qrShowCodeLNURL(String message) {
6154
tft.setTextSize(2);
6255
tft.setTextColor(TFT_BLACK, TFT_WHITE);
6356
tft.println(message);
57+
Serial.println("Printing if printer exists");
58+
printReceipt();
6459
delay(2000);
6560
waitForTap = true;
6661
while (waitForTap) {

fossa/fossa.ino

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,31 @@ void setup() {
117117
SerialPort1.begin(300, SERIAL_8N2, BILL_TX, BILL_RX);
118118
SerialPort2.begin(4800, SERIAL_8N1, COIN_TX);
119119
printerSerial.begin(9600);
120-
pinMode(COIN_INHIBIT, OUTPUT);
120+
printer.begin();
121+
printer.wake();
122+
printer.setDefault();
123+
printer.justify('C');
124+
printer.feed(3);
125+
printer.boldOn();
126+
printer.setSize('L');
127+
printer.println("Printer Connected :)");
128+
printer.println("");
129+
printer.println("");
130+
printer.println("");
131+
printer.println("");
132+
printer.println("");
133+
printer.sleep();
121134

122-
// initialize printer
123-
if (printerSerial.available()) {
124-
printerBool = true;
125-
printer.begin();
126-
}
135+
pinMode(COIN_INHIBIT, OUTPUT);
127136
}
128137

129138
void loop() {
130139
if (maxBeforeResetTally >= maxBeforeReset) {
131140
printMessage("", tooMuchFiatT, contactOwnerT, TFT_WHITE, TFT_BLACK);
132141
delay(100000000);
133142
} else {
143+
// initialize printer
144+
134145
SerialPort1.write(184);
135146
digitalWrite(COIN_INHIBIT, HIGH);
136147
tft.fillScreen(TFT_BLACK);
@@ -146,9 +157,7 @@ void loop() {
146157
Serial.println(maxBeforeResetTally);
147158
maxBeforeResetTally = maxBeforeResetTally + (total / 100);
148159
Serial.println(maxBeforeResetTally);
149-
Serial.println("poo");
150160
makeLNURL();
151-
Serial.println("poo");
152161
qrShowCodeLNURL(scanMeT);
153162
}
154163
}

0 commit comments

Comments
 (0)