Formatted and added bmi task
This commit is contained in:
37
plot.py
37
plot.py
@@ -30,36 +30,6 @@ TEXT = (230, 235, 240)
|
||||
ERROR = (255, 110, 110)
|
||||
LINE_RE = re.compile(r"\[<([^>]+)>\]:\s*(.*)")
|
||||
|
||||
DEFAULT_CONFIG = {
|
||||
"title": "IMU stream",
|
||||
"history_seconds": 10.0,
|
||||
"graphs": [
|
||||
{
|
||||
"title": "Accelerometer",
|
||||
"streams": [
|
||||
{"key": "acc_x", "label": "ACC X", "color": [90, 170, 255]},
|
||||
{"key": "acc_y", "label": "ACC Y", "color": [80, 220, 140]},
|
||||
{"key": "acc_z", "label": "ACC Z", "color": [255, 200, 60]},
|
||||
],
|
||||
},
|
||||
{
|
||||
"title": "Gyroscope",
|
||||
"streams": [
|
||||
{"key": "gyr_x", "label": "GYR X", "color": [240, 80, 80]},
|
||||
{"key": "gyr_y", "label": "GYR Y", "color": [220, 80, 220]},
|
||||
{"key": "gyr_z", "label": "GYR Z", "color": [240, 240, 240]},
|
||||
],
|
||||
},
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"tag": "IMU",
|
||||
"fields": ["acc_x", "acc_y", "acc_z", "gyr_x", "gyr_y", "gyr_z"],
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Read tagged serial values and draw them live from a JSON config."
|
||||
@@ -77,7 +47,7 @@ def parse_args() -> argparse.Namespace:
|
||||
"--config",
|
||||
type=Path,
|
||||
default=None,
|
||||
help="Path to JSON plot config (default: built-in IMU config)",
|
||||
help="Path to JSON plot config (default: ./plot_config.json)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--history-seconds",
|
||||
@@ -108,7 +78,10 @@ def parse_args() -> argparse.Namespace:
|
||||
|
||||
def load_config(config_path: Path | None) -> dict:
|
||||
if config_path is None:
|
||||
return DEFAULT_CONFIG
|
||||
config_path = Path("plot_config.json")
|
||||
|
||||
if not config_path.exists():
|
||||
raise SystemExit(f"Config file not found: {config_path}")
|
||||
|
||||
with config_path.open("r", encoding="utf-8") as handle:
|
||||
return json.load(handle)
|
||||
|
||||
Reference in New Issue
Block a user