MCPcopy Create free account
hub / github.com/BruceDevices/firmware / readKey

Function readKey

src/modules/others/ibutton.cpp:80–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78// ---------------------------------------------------------------------------
79
80static bool readKey(int maxRetries = 20) {
81 for (int attempt = 0; attempt < maxRetries; attempt++) {
82 if (check(EscPress)) return false;
83 if (oneWire->reset() == 0) return false;
84
85 oneWire->write(0x33);
86 oneWire->read_bytes(keyBuffer, 8);
87
88 if (bufferCrcValid()) {
89 keyLoaded = true;
90 return true;
91 }
92
93 tft.fillScreen(bruceConfig.bgColor);
94 drawMainBorderWithTitle("iButton");
95 padprintln("Reading... attempt " + String(attempt + 2));
96 padprintln("CRC mismatch, retrying...");
97 padprintln("");
98 padprintln("Keep key on the contact!");
99 delay(100);
100 }
101
102 // Retries exhausted — still store what we got
103 keyLoaded = true;
104 return false;
105}
106
107static void writeKey() {
108 uint8_t pin = bruceConfigPins.iButton;

Callers 1

setup_ibuttonFunction · 0.85

Calls 7

checkFunction · 0.85
bufferCrcValidFunction · 0.85
drawMainBorderWithTitleFunction · 0.85
padprintlnFunction · 0.85
resetMethod · 0.45
writeMethod · 0.45
fillScreenMethod · 0.45

Tested by

no test coverage detected