Skip to content

Commit

Permalink
Add a CPU Monitor (#455)
Browse files Browse the repository at this point in the history
* Added `CPUMonitor`. (#452)

* Using CPU monitor. (#453)

* Updated main controller case. (#443)
  • Loading branch information
ATATC authored Dec 11, 2024
1 parent e7c6a13 commit 2b25608
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
Binary file modified design/main_controller.c4d
Binary file not shown.
Binary file modified design/main_controller.stl
Binary file not shown.
1 change: 1 addition & 0 deletions leads_gpio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
if not _find_spec("serial"):
raise ImportError("Please install `pyserial` to run this module\n>>>pip install pyserial")

from leads_gpio.cpu_monitor import *
from leads_gpio.gps_receiver import *
from leads_gpio.led import *
from leads_gpio.led_group import *
15 changes: 15 additions & 0 deletions leads_gpio/cpu_monitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import override as _override

from gpiozero import CPUTemperature as _CPUTemperature

from leads import Device as _Device


class CPUMonitor(_Device):
def __init__(self) -> None:
super().__init__()
self._cpu_temp: _CPUTemperature = _CPUTemperature()

@_override
def read(self) -> dict[str, float]:
return {"temp": self._cpu_temp.temperature}
3 changes: 2 additions & 1 deletion leads_vec/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,10 @@ def switch_esc_mode(mode: str) -> None:
class IdleUpdate(FrequencyGenerator):
@_override
def do(self) -> None:
cpu_temp = get_device("cpu").read()["temp"] if has_device("cpu") else "?"
var_info.set(f"VeC {__version__.upper()}\n\n"
f"{_datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\n"
f"{format_duration(duration := _time() - w.runtime_data().start_time)}\n"
f"{format_duration(duration := _time() - w.runtime_data().start_time)} {cpu_temp} °C\n"
f"{(m := ctx.data().mileage):.1f} KM - {m * 3600 / duration:.1f} KM / H\n\n"
f"{cfg.refresh_rate} - {w.frame_rate():.2f} FPS - {w.net_delay() * 1000:.1f} MS\n"
f"{(["NOT FOUND"] + my_ip_addresses())[-1]}:{w.runtime_data().comm.port()}")
Expand Down
7 changes: 6 additions & 1 deletion leads_vec/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
SFT, read_device_marker, has_controller, POWER_CONTROLLER, WHEEL_SPEED_CONTROLLER, ACCELEROMETER
from leads_arduino import ArduinoMicro, WheelSpeedSensor, VoltageSensor, Accelerometer, Acceleration
from leads_comm_serial import SOBD
from leads_gpio import NMEAGPSReceiver, LEDGroup, LED, LEDGroupCommand, LEDCommand, Entire, Transition
from leads_gpio import NMEAGPSReceiver, LEDGroup, LED, LEDGroupCommand, LEDCommand, Entire, Transition, CPUMonitor
from leads_vec.config import Config
from leads_video import Base64Camera, get_camera

Expand Down Expand Up @@ -174,6 +174,11 @@ def initialize(self, *parent_tags: str) -> None:
super().initialize(*parent_tags)


@device("cpu", MAIN_CONTROLLER)
class CPU(CPUMonitor):
pass


class Indicator(LEDGroup):
@override
def initialize(self, *parent_tags: str) -> None:
Expand Down

0 comments on commit 2b25608

Please sign in to comment.