-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathwipe_epd.py
More file actions
67 lines (52 loc) · 1.81 KB
/
wipe_epd.py
File metadata and controls
67 lines (52 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
"""Utility to clear the Waveshare E-Paper display when Ragnar restarts."""
from __future__ import annotations
import json
import os
import sys
from pathlib import Path
try:
from shared import DEFAULT_EPD_TYPE # type: ignore
except Exception:
DEFAULT_EPD_TYPE = "epd2in13_V4"
from epd_helper import EPDHelper
REPO_ROOT = Path(__file__).resolve().parent
CONFIG_PATH = REPO_ROOT / "config" / "shared_config.json"
def _read_epd_type_from_config() -> str | None:
"""Return the epd_type persisted in shared_config.json, if available."""
try:
with CONFIG_PATH.open("r", encoding="utf-8") as handle:
data = json.load(handle)
except FileNotFoundError:
return None
except json.JSONDecodeError:
return None
return data.get("epd_type")
def resolve_epd_type() -> str | None:
"""Determine which EPD profile to use when clearing the screen."""
if env_override := os.getenv("EPD_TYPE"):
return env_override
config_value = _read_epd_type_from_config()
if config_value:
return config_value
return DEFAULT_EPD_TYPE
def wipe_display(epd_type: str) -> None:
"""Perform a full refresh + clear on the requested display profile."""
helper = EPDHelper(epd_type)
helper.init_full_update()
helper.clear()
helper.sleep()
def main() -> int:
epd_type = resolve_epd_type()
if not epd_type:
print("wipe_epd: no EPD type configured, skipping", file=sys.stderr)
return 0
try:
wipe_display(epd_type)
except Exception as exc: # pragma: no cover - hardware specific
print(f"wipe_epd: failed to clear display ({exc})", file=sys.stderr)
return 1
print(f"wipe_epd: cleared display using {epd_type}")
return 0
if __name__ == "__main__":
raise SystemExit(main())