65 lines
2.5 KiB
Python
65 lines
2.5 KiB
Python
import re
|
|
|
|
with open('esp32_serial_backend/esp32_serial_backend.ino', 'r', encoding='utf8') as f:
|
|
content = f.read()
|
|
|
|
# 1. Add gLastTapInfo at the top
|
|
if 'String gLastTapInfo = "";' not in content:
|
|
content = content.replace('bool gIsWebJob = false;', 'bool gIsWebJob = false;\nString gLastTapInfo = "";')
|
|
|
|
# 2. In handleCommand for RFID, set gLastTapInfo and draw it instantly
|
|
old_rfid_handler = ''' String resolved = jsonGetString(lookResp, "name");
|
|
resolved.trim();
|
|
bool registered = jsonGetBool(lookResp, "registered", false);
|
|
|
|
Serial.println(String("RFID: registered=") + (registered ? "true" : "false") + " name=" + resolved);
|
|
|
|
// ===== KARTU TIDAK TERDAFTAR ====='''
|
|
new_rfid_handler = ''' String resolved = jsonGetString(lookResp, "name");
|
|
resolved.trim();
|
|
bool registered = jsonGetBool(lookResp, "registered", false);
|
|
|
|
Serial.println(String("RFID: registered=") + (registered ? "true" : "false") + " name=" + resolved);
|
|
|
|
// Simpan info person untuk ditampilkan di bawah menu
|
|
gLastTapInfo = uid + (resolved.length() ? " (" + resolved + ")" : "");
|
|
|
|
// Langsung gambar ke layar agar terlihat secara instan
|
|
tft.fillRect(0, 205, tft.width(), 35, TFT_BLACK);
|
|
tft.setTextSize(1);
|
|
tft.setTextColor(0x07FF, TFT_BLACK); // CYAN
|
|
tft.setCursor(15, 210);
|
|
tft.print("Tap: " + gLastTapInfo);
|
|
|
|
// ===== KARTU TIDAK TERDAFTAR ====='''
|
|
content = content.replace(old_rfid_handler, new_rfid_handler)
|
|
|
|
# 3. In loop() menu redraw, preserve gLastTapInfo
|
|
old_menu_redraw = ''' tft.setTextColor(0xFD20, TFT_BLACK); // orange
|
|
tft.setCursor(15, 190);
|
|
tft.print("BELUM DAFTAR -> Ditolak");
|
|
|
|
drawIPAddress();
|
|
|
|
gMenuDrawn = true;'''
|
|
new_menu_redraw = ''' tft.setTextColor(0xFD20, TFT_BLACK); // orange
|
|
tft.setCursor(15, 190);
|
|
tft.print("BELUM DAFTAR -> Ditolak");
|
|
|
|
if (gLastTapInfo.length() > 0) {
|
|
tft.setTextSize(1);
|
|
tft.setTextColor(0x07FF, TFT_BLACK); // CYAN
|
|
tft.setCursor(15, 210);
|
|
tft.print("Tap: " + gLastTapInfo);
|
|
}
|
|
|
|
drawIPAddress();
|
|
|
|
gMenuDrawn = true;'''
|
|
content = content.replace(old_menu_redraw, new_menu_redraw)
|
|
|
|
with open('esp32_serial_backend/esp32_serial_backend.ino', 'w', encoding='utf8') as f:
|
|
f.write(content)
|
|
|
|
print("Update complete")
|