- tft.py: ILI9341 SPI 드라이버 + 320x240 대시보드(온도·습도·토양·릴레이 5칸·1시간 추세선), 바뀐 프레임만 전송 - oled.py: SSD1306/SH1106 I2C 상태 표시(smbus2+Pillow, 추가 설치 없음) - greenhouse.py: display 설정(목록)이 있을 때만 표시 스레드 시작. 표시 오류는 제어 루프에 영향 없음 - config.yaml: display 블록(TFT 기본, OLED 주석), 릴레이 짧은 이름(short) - oled_test.py / ili9341_test.py / display_demo.py: 배선 확인·시연용(MQTT·HA 전송 없음) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""표시 장치(TFT/OLED) 시연. 서비스·MQTT 없이 모의 값만 화면에 띄운다(HA 전송 없음).
|
|
|
|
python3 display_demo.py [config.yaml] [초] # 기본 900초 후 종료
|
|
"""
|
|
import math
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
import greenhouse
|
|
|
|
cfg_path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path(__file__).with_name("config.yaml")
|
|
duration = float(sys.argv[2]) if len(sys.argv) > 2 else 900
|
|
gh = greenhouse.Greenhouse(yaml.safe_load(cfg_path.read_text())) # MQTT 루프를 시작하지 않는다
|
|
for d in gh.displays:
|
|
if hasattr(d, "hist"):
|
|
d.hist.extend([20 + 4 * math.sin(i / 14) + i * 0.03 for i in range(90)])
|
|
d._last_hist = time.time()
|
|
d.start()
|
|
t0 = time.time()
|
|
try:
|
|
while time.time() - t0 < duration:
|
|
now = time.time(); k = now - t0
|
|
gh.values["air.temperature"] = (round(24.3 + 1.5 * math.sin(k / 40), 1), now)
|
|
gh.values["air.humidity"] = (round(61 + 6 * math.sin(k / 55)), now)
|
|
gh.values["soil.soil_moisture"] = (round(42 + 8 * math.sin(k / 90)), now)
|
|
gh.acts["fan"].relay.on = True
|
|
gh.acts["lamp2"].relay.on = int(k // 20) % 2 == 0
|
|
time.sleep(3)
|
|
finally:
|
|
for d in gh.displays:
|
|
d.stop()
|
|
d.join(3)
|