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

Commit

Permalink
fixing text displays
Browse files Browse the repository at this point in the history
Hopefully fixing newline nonsense for displaying the login text stuff
  • Loading branch information
polypies73 committed Oct 10, 2024
1 parent e4a0a4a commit 58ea5f1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 106 deletions.
97 changes: 6 additions & 91 deletions client/drivers/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,6 @@ def make_failed(cls) -> "ControlledData":

# SECTION: Getters/Setters

def DEBUG_get_next_posture_graph_value(self) -> int:
"""
Get next thing to put on the DEBUG graph.
Returns:
(int): Next thing to put on the DEBUG graph.
TODO: Remove this method
"""
return_me = self._DEBUG_current_graph_function(
self._DEBUG_current_graph_list_index
)
self._DEBUG_current_graph_list_index += 1
return return_me

def is_failed(self) -> bool:
"""
Returns:
Expand Down Expand Up @@ -216,80 +201,6 @@ def set_last_plant_time(self, time: datetime) -> None:
"""
self._last_plant_time = time

def get_last_sniff_time(self) -> datetime:
"""
Returns:
(datetime): The last time that the user was provided olfactory feedback.
"""
return self._last_cushion_time

def set_last_sniff_time(self, time: datetime) -> None:
"""
Args:
time : datetime
The last time that the user was provided olfactory feedback.
"""
self._last_sniff_time = time

def accept_new_posture_data(
self, posture_data: List[float]
) -> None: # TODO: Refine type signature
"""
Update the internal store of posture data for the OLED display.
Args:
posture_data : List[float]
New posture data to accept and merge with the current state of this object.
TODO: Implement me!
"""
# DEBUG:
print("<!> accept_new_posture_data()")
# :DEBUG
for datum in posture_data:
self._posture_data.put_nowait(datum)

# SECTION: Posture data mapping

def get_cushion_posture_data(
self,
) -> "CUSHION_POSTURE_DATA": # TODO: Decide what this type looks like
"""
Returns:
(CUSHION_POSTURE_DATA): Posture data necessary for cushion feedback.
TODO: Implement this.
"""
# DEBUG:
print("<!> WARNING: get_cushion_posture_data() not implemented!")
# :DEBUG
return None

def get_plant_posture_data(
self,
) -> "PLANT_POSTURE_DATA": # TODO: Decide what this type looks like
"""
Returns:
(PLANT_POSTURE_DATA) Posture data necessary for plant feedback.
TODO: Implement this.
"""
# DEBUG:
print("<!> WARNING: get_plant_posture_data() not implemented!")
# :DEBUG
return None

def get_sniff_posture_data(
self,
) -> "SNIFF_POSTURE_DATA": # TODO: Decide what this type looks like
"""
Returns:
(SNIFF_POSTURE_DATA): Posture data necessary for scent feedback.
TODO: Implement this.
"""
# DEBUG:
print("<!> WARNING: get_sniff_posture_data() not implemented!")
# :DEBUG
return None


## SECTION: Hardware packaged together

Expand Down Expand Up @@ -574,15 +485,19 @@ def oled_display_texts(self, texts: List[str], x: int, y: int, colour: int) -> i
)
return display_height_offset

def send_message(self, message: str, message_time: int = 1) -> None:
def send_message(self, messages: List[str], message_time: int = 1) -> None:
"""Clear the screen and display message
Args:
message: Message to send to the user
message_time: Time (seconds) to sleep for after displaying message.
"""
self.display.fill(0)
self.oled_display_text(message, 0, 0, 1)
display_height_offset = 0
for text in messages:
display_height_offset = self.oled_display_text(
text, 0, 0 + display_height_offset, 1
)
self.display.show()
time.sleep(message_time)

Expand Down
30 changes: 15 additions & 15 deletions client/drivers/login_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def handle_authentication(hardware: HardwareComponents) -> int:
while True:
_log_and_send(
hardware,
"Left button to login\n"
"Right button to register\n"
"Double press right button to reset data",
["Left button to login",
"Right button to register",
"Double press right button to reset data"]
)
button = hardware.wait_for_button_press()

Expand Down Expand Up @@ -82,8 +82,8 @@ def _loop_action(hardware: HardwareComponents, action: Action) -> int:

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

button_pressed = hardware.wait_for_button_press()
if button_pressed == LEFT_BUTTON:
Expand All @@ -92,7 +92,7 @@ def _attempt_login(hardware: HardwareComponents) -> int:
if button_pressed == RIGHT_BUTTON:
return QUIT

_log_and_send(hardware, "Trying login...", message_time=0)
_log_and_send(hardware, ["Trying login..."], message_time=0)
status = get_face_match(face)
_handle_status_message(hardware, status)

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

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

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

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

_handle_status_message(hardware, status)
Expand All @@ -144,7 +144,7 @@ def _handle_status_message(hardware: HardwareComponents, status: int) -> None:


def _log_and_send(
hardware: HardwareComponents, message: str, message_time: int = 1
hardware: HardwareComponents, messages: list[str], message_time: int = 1
) -> None:
logger.debug(message)
hardware.send_message(message, message_time=message_time)
logger.debug(messages)
hardware.send_message(messages, message_time=message_time)

0 comments on commit 58ea5f1

Please sign in to comment.