Skip to content

Commit

Permalink
FIXUP - improve output
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Oct 29, 2024
1 parent 30c45f4 commit 5064f8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
22 changes: 1 addition & 21 deletions tools/modules/flash_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,8 @@ def erase_flash():
"""
print("Erasing flash...")
cmd_erase = "st-flash --connect-under-reset --reset erase"
ret = subprocess.run(cmd_erase, shell=True)
ret = subprocess.run(cmd_erase, capture_output=True, text=True)
if ret.returncode != 0:
print(f"Erasing flash... {Fore.RED}{Style.RESET_ALL}")
sys.exit(1)
print(f"Erasing flash... {Fore.GREEN}{Style.RESET_ALL}")


def print_end_success(message: str):
"""
Print a success message in cyan with a checkmark.
Args:
message (str): The message to print.
"""
print(f"{Fore.CYAN}{message}... ✅{Style.RESET_ALL}")


def print_end_failure(message: str):
"""
Print a failure message in red with a cross mark.
Args:
message (str): The message to print.
"""
print(f"{Fore.RED}{message}... ❌{Style.RESET_ALL}")
17 changes: 9 additions & 8 deletions tools/modules/serial_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


import glob
import logging
import sys
from time import sleep
from typing import List, Optional
Expand All @@ -35,13 +36,12 @@ def connect_serial(port_pattern: str) -> serial.Serial:
serial_port = ports[0] if ports else port_pattern

try:
logging.info(f"Connecting to {serial_port} ...")
com = serial.Serial(serial_port, 115200, timeout=SERIAL_TIMEOUT)
print(f"Connected to {com.name}... {Fore.GREEN}{Style.RESET_ALL}")
logging.info(f"Connecting to {serial_port} ... ")
return com
except serial.serialutil.SerialException as error:
print(
f"Error connecting to {serial_port}: {error}... {Fore.RED}{Style.RESET_ALL}"
)
logging.exception(f"Connecting to {serial_port} ... 💥️\n{error}")
sys.exit(1)


Expand All @@ -54,13 +54,14 @@ def reset_buffer(com: serial.Serial):
"""
print("Resetting COM buffer...")
try:
logging.info(f"Resetting serial port {com.name} ...")
com.reset_input_buffer()
com.reset_output_buffer()
com.send_break(duration=1)
sleep(1)
print(f"Resetting COM buffer... {Fore.GREEN}{Style.RESET_ALL}")
except serial.SerialException as e:
print(f"Error resetting COM buffer: {e}... {Fore.RED}{Style.RESET_ALL}")
logging.info(f"Resetting serial port {com.name} ... ✅")
except serial.SerialException as error:
logging.exception(f"Resetting serial port {com.name} ... 💥️\n{error}")
sys.exit(1)


Expand All @@ -78,7 +79,7 @@ def read_output_serial(com: serial.Serial) -> str:
data = com.readline().decode("utf-8").strip()
return data
except serial.SerialException as e:
print(f"Serial read error: {e}")
logging.exception(f"Serial read error: {e}")
return ""


Expand Down

0 comments on commit 5064f8c

Please sign in to comment.