Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
feat: added logging to login_system
Browse files Browse the repository at this point in the history
so that debugging is easier on rpi
  • Loading branch information
MitchellJC committed Oct 6, 2024
1 parent 016c5cf commit 4a034a2
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions client/drivers/login_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Login system
"""

import logging
from typing import Callable

import numpy as np
Expand All @@ -22,6 +23,8 @@

Action = Callable[[HardwareComponents], int]

logger = logging.getLogger(__name__)


def handle_authentication(hardware: HardwareComponents) -> int:
"""Run authentication loop until user either registers or logs in.
Expand All @@ -33,7 +36,7 @@ def handle_authentication(hardware: HardwareComponents) -> int:
id of logged in user.
"""
while True:
hardware.send_message("Left button to login\nRight button to register")
_log_and_send(hardware, "Left button to login\nRight button to register")
button = hardware.wait_for_button_press()

if button == RIGHT_BUTTON:
Expand Down Expand Up @@ -65,7 +68,8 @@ def _loop_action(hardware: HardwareComponents, action: Action) -> int:

def _attempt_login(hardware: HardwareComponents) -> int:
capturer = RaspCapturer()
hardware.send_message(f"Press left button to take photo\n{QUIT_INSTRUCTIONS}")
message = f"Press left button to take photo\n{QUIT_INSTRUCTIONS}"
_log_and_send(hardware, message)

button_pressed = hardware.wait_for_button_press()
if button_pressed == LEFT_BUTTON:
Expand All @@ -86,10 +90,11 @@ def _attempt_register(hardware: HardwareComponents) -> int:
# Capture NUM_FACES faces
faces: list[np.ndarray] = []
for i in range(NUM_FACES):
hardware.send_message(
message = (
f"Press left button to take photo {i + 1}/{NUM_FACES}\n"
f"{QUIT_INSTRUCTIONS}"
)
_log_and_send(hardware, message)

button_pressed = hardware.wait_for_button_press()
if button_pressed == RIGHT_BUTTON:
Expand All @@ -100,13 +105,13 @@ def _attempt_register(hardware: HardwareComponents) -> int:
faces.append(frame)

# Try register faces
hardware.send_message("Registering face...")
_log_and_send(hardware, "Registering...")
user_id = next_user_id()
status = register_faces(user_id, faces)

if status == Status.OK.value:
create_user()
hardware.send_message("Registration successful!")
_log_and_send(hardware, "Registration successful!")
return user_id

_handle_status_message(hardware, status)
Expand All @@ -120,4 +125,9 @@ def _is_status_id(status: int) -> bool:

def _handle_status_message(hardware: HardwareComponents, status: int) -> None:
if status in BAD_STATUS_MESSAGES:
hardware.send_message(BAD_STATUS_MESSAGES[status])
_log_and_send(hardware, BAD_STATUS_MESSAGES[status])


def _log_and_send(hardware: HardwareComponents, message: str) -> None:
logger.debug(message)
hardware.send_message(message)

0 comments on commit 4a034a2

Please sign in to comment.