add the function to close the tool menu

main
kirbylife 2023-04-27 15:34:48 -06:00
parent f83638bfae
commit c8f14b7b19
2 changed files with 21 additions and 7 deletions

View File

@ -77,7 +77,6 @@ fn main() -> ! {
let cmd = block!(serial.read()).unwrap_or(u8::MAX); let cmd = block!(serial.read()).unwrap_or(u8::MAX);
match cmd { match cmd {
EXIT => {}
HANDSHAKE => serial.write(OK).unwrap(), HANDSHAKE => serial.write(OK).unwrap(),
SET_TIMESTAMP => { SET_TIMESTAMP => {
serial.write(OK).unwrap(); serial.write(OK).unwrap();

View File

@ -13,8 +13,9 @@ SET_TIMESTAMP = bytes([10])
ADD_TOKEN = bytes([20]) ADD_TOKEN = bytes([20])
DELETE_TOKEN = bytes([30]) DELETE_TOKEN = bytes([30])
GET_TOKENS = bytes([40]) GET_TOKENS = bytes([40])
WIPE_TOKENS = bytes([50]) SOFT_WIPE_TOKENS = bytes([50])
EXIT = bytes([254]) HARD_WIPE_TOKENS = bytes([60])
EXIT = bytes([255])
def loop_input(msg: str, valid_values: Any) -> str: def loop_input(msg: str, valid_values: Any) -> str:
valid_values = list(map(str, valid_values)) valid_values = list(map(str, valid_values))
@ -71,10 +72,11 @@ def main(argv: list[str]):
print("1) Update timestamp") print("1) Update timestamp")
print("2) Add a new token") print("2) Add a new token")
print("3) Remove a token") print("3) Remove a token")
print("4) WIPE ALL THE TOKENS") print("4) SOFT wipe all tokens")
print("5) EXIT") print("5) HARD WIPE ALL THE TOKENS")
print("6) EXIT")
opt = loop_input(">>> ", range(1, 6)) opt = loop_input(">>> ", range(1, 7))
# Update Timestamp # Update Timestamp
if opt == "1": if opt == "1":
@ -125,13 +127,26 @@ def main(argv: list[str]):
print("Token added successfully!") print("Token added successfully!")
# Wipe tokens # Wipe tokens
elif opt == "4": elif opt == "4":
conn.write(WIPE_TOKENS) conn.write(SOFT_WIPE_TOKENS)
sleep(0.1) sleep(0.1)
_ = conn.read() _ = conn.read()
resp = conn.read() resp = conn.read()
if resp == OK: if resp == OK:
print("All the tokens wipped successfully!") print("All the tokens wipped successfully!")
else:
print("Error!!")
elif opt == "5": elif opt == "5":
resp = loop_input("This will erase all the EEPROM, do you want to continue? [Y/N]", ["y", "Y", "n", "N"]).upper()
if resp == "Y":
conn.write(HARD_WIPE_TOKENS)
sleep(0.1)
resp = conn.read()
if resp == OK:
print("All the Eeprom erased successfully!")
else:
print("Error!!")
elif opt == "6":
conn.write(EXIT)
return 0 return 0
if __name__ == "__main__": if __name__ == "__main__":