| 78 | // --------------------------------------------------------------------------- |
| 79 | |
| 80 | static 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 | |
| 107 | static void writeKey() { |
| 108 | uint8_t pin = bruceConfigPins.iButton; |
no test coverage detected