Compare commits

13 Commits

Author SHA1 Message Date
96d120f8ca Document 2.8 vs 3.5 hardware differences in README.
Link CYD_PROJECT_GUIDE section A for expansion pins and touch/backlight.
2026-10-25 10:40:26 +08:00
80b43b8f0a Link CYD_PROJECT_GUIDE for 3.5" touch/backlight/LVGL pitfalls.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-25 10:38:37 +08:00
83b1bdc5f7 Fix 3.5" black screen: drive backlight on GPIO27, not GPIO21.
GPIO21 is GT911 INT on 3248S035C; PWM on the wrong pin left the panel dark.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-25 10:34:00 +08:00
0a1b612cc9 Fix 3.5" gauge readout centering so value+unit stay aligned as digits change.
Also finish cyd_35r touch path (GT911) and refresh archived 35r firmware bins.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-25 10:30:24 +08:00
de177b281b Add optional cyd_35r (ESP32-3248S035) with 480x320 UI; default remains 2.8. 2026-10-23 16:24:19 +08:00
39081d2a2f Fix preview.html to native 320x240 without internal scale.
Card host now scales the iframe; remove broken transform that clipped UI to the corner.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-19 22:14:21 +08:00
23d1ce2ac6 Add HTML on-device UI preview for flasher catalog.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-19 22:10:13 +08:00
d78a9f91cd Archive flashable cyd_28r firmware bins for offline reflash.
Add flash scripts and export helper so the board can be programmed without rebuilding from source.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-17 17:24:38 +08:00
3173b5fffe Keep header uptime on a single row above the gauge panels.
Previous second-line up text sat under the opaque panels and got covered.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-17 16:38:14 +08:00
b9f2d83277 Fix dashboard layout so labels no longer cover the chart.
Carve exclusive regions for gauges, info, and trend; tighten spacing and polish arc/bar animation plus tap/long-press feedback.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-17 16:35:43 +08:00
482be39c01 Document stable tag v1.1-case-snaps for easy rollback.
Keep branch keep/v1.1-case-snaps alongside the prior v1.0-case-closed snapshot.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-17 15:21:39 +08:00
892e9d04c6 Optimize case v1.1 with rounded corners and FDM cantilever snaps.
Adds catch windows, locating pegs, and a snap coupon for print tuning; keep lip alignment and rear DHT bay.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-17 15:20:09 +08:00
c7d4b5a0c5 Document stable tag v1.0-case-closed for easy rollback.
Keep a named branch pointing at the closed-case snapshot.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-17 15:16:12 +08:00
32 changed files with 1407 additions and 246 deletions

View File

@@ -1,24 +1,27 @@
# CYD 温湿度仪表盘
ESP32 Cheap Yellow Display(ESP32-2432S028R)+ DHT11 + LVGL 温湿度仪表盘。
ESP32 Cheap Yellow Display(默认 2.8" ESP32-2432S028R;可选 3.5" `cyd_35r`)+ DHT11 + LVGL 温湿度仪表盘。
跨板对照与避坑:上级目录 [`../CYD_PROJECT_GUIDE.md`](../CYD_PROJECT_GUIDE.md) **§A**(2.8 vs 3.5:触控 / 背光 / 外设脚)。
## 硬件
| 项目 | 说明 |
|------|------|
| 板子 | CYD ESP32-2432S028R(2.8" ILI9341) |
| 传感器 | DHT11 |
| DATA | **GPIO22**(CN1 / P3) |
| 供电 | USB 5V;电池需外接充电管理(板载 JST 多为供电口) |
| 项目 | 2.8"(默认 `cyd_28r`) | 3.5C(`cyd_35r`) |
|------|------------------------|-------------------|
| 板子 | ESP32-2432S028R · ILI9341 | ESP32-3248S035C · ST7796 |
| 触控 | XPT2046 SoftSPI | GT911 I2C |
| 背光 | GPIO21 | GPIO27 |
| DHT11 DATA | **GPIO22**(CN1 空闲脚之一;2.8 另一常用空闲脚为 **27**) | **GPIO22**(3.5 上 27=背光,勿接 DHT) |
| 供电 | USB 5V | 同左 |
接线:`VCC→3.3V`,`GND→GND`,`DATA→GPIO22`。
接线(两板 DHT):`VCC→3.3V`,`GND→GND`,`DATA→GPIO22`。
## 功能
- 横屏温湿度圆弧仪表 + 数字读数
- EMA 平滑、min/max、舒适度、体感温度 / 露点
- 温湿度趋势折线
- 点按屏幕切换背光亮度(4 档)
- 横屏网格布局:双圆弧仪表 + 底部左信息 / 右趋势图(分区不重叠)
- EMA 平滑、min/max、舒适度条、体感 / 露点分行显示
- 圆弧与舒适度条缓动动画;趋势折线 SHIFT 更新
- 短按切换背光(4 档,顶部提示);长按 ≥0.7s 重置 min/max
- 偶发 DHT 读失败容错(连续失败才报错)
- 常亮运行(无自动熄屏 / 休眠)
@@ -31,6 +34,18 @@ pio run -e cyd_28r -t upload
pio device monitor -b 115200
```
### 预编译固件(随时刷,不必编译)
已归档到 [`firmware/cyd_28r/`](firmware/cyd_28r/)(含 bootloader / partitions / app):
```powershell
cd firmware\cyd_28r
.\flash.ps1
# 或 .\flash.ps1 -Port COM3
```
说明见 [`firmware/README.md`](firmware/README.md)。源码更新后重新打包:`.\firmware\export_from_build.ps1`。
### 环境选择
| 环境 | 适用 |
@@ -38,14 +53,15 @@ pio device monitor -b 115200
| `cyd_28r` | 标准 ILI9341 CYD(默认) |
| `cyd_28r_inv` | 颜色反相 / 发白 |
| `cyd_28_st7789` | USB-C 双口 / ST7789 变体 |
| `cyd_35r` | 3.5" ESP32-3248S035(ST7796 + GT911) |
## 3D 外壳
桌面斜立分体壳(前框 + 后盖支架 + DHT11 通风仓),可直接打印:
v1.1 圆角分体壳(前框 + 后盖 + 四侧悬臂卡扣 + 后盖 DHT 卡位),可直接打印:
- STL:[`cad/export/front.stl`](cad/export/front.stl)、[`cad/export/back.stl`](cad/export/back.stl)
- STL:[`cad/export/front.stl`](cad/export/front.stl)、[`cad/export/back.stl`](cad/export/back.stl)、[`cad/export/snap_coupon.stl`](cad/export/snap_coupon.stl)(试打卡扣)
- 浏览器预览:[`cad/viewer.html`](cad/viewer.html)(需本地 HTTP,见下)
- 参数源 / 说明:[`cad/README.md`](cad/README.md)
- 参数与打印建议:[`cad/README.md`](cad/README.md)
```bash
# 浏览器查看
@@ -53,11 +69,11 @@ python -m http.server 8765 --directory cad
# 打开 http://localhost:8765/viewer.html
# 重新导出 STL
pip install trimesh manifold3d numpy
pip install trimesh manifold3d numpy shapely
python cad/generate_stl.py
```
固定用 `4 × M3×10`;DHT11 装后盖通风仓,线接 CN1。
合盖以卡扣为主、止口对齐;四角 `M3×10` 可选。建议 PETG;DHT11 装后盖背面卡位,线接 CN1。
## 项目结构
@@ -66,6 +82,7 @@ platformio.ini # 板级与库依赖
include/lv_conf.h # LVGL 配置
src/main.cpp # 仪表盘主程序
scripts/exclude_lvgl_asm.py # 排除 ESP32 不兼容的 LVGL ASM
firmware/ # 预编译固件(可离线刷写)
cad/ # 3D 外壳(OpenSCAD + STL)
.cursor/rules/ # Cursor 协作规则
README.md # 本文档
@@ -80,6 +97,32 @@ README.md # 本文档
详见 `.cursor/rules/git-and-docs.mdc`。
## 稳定版快照(可随时切回)
| 标签 | 提交 | 内容 |
|------|------|------|
| **`v1.1-case-snaps`**(当前推荐) | `892e9d0` | 圆角 R3.5、四侧悬臂卡扣、定位柱、后盖 DHT 卡位、`snap_coupon` |
| `v1.0-case-closed` | `646cf45` | 仅止口合盖 + DHT 后盖微突出,无卡扣、无旁侧格子 |
本地分支备份:`keep/v1.1-case-snaps`、`keep/v1.0-case-closed`。
```bash
# 查看标签
git tag -l
# 临时查看当前稳定版(只读)
git switch --detach v1.1-case-snaps
# 基于该版开新分支继续改
git switch -c restore/v1.1-case-snaps v1.1-case-snaps
# 切回旧无卡扣版
git switch --detach v1.0-case-closed
# 整库硬切回(会丢弃之后未提交改动,慎用)
git reset --hard v1.1-case-snaps
```
## 变更记录
| 日期 | 说明 |
@@ -92,3 +135,12 @@ README.md # 本文档
| 2026-10-17 | 预览增强:合盖/开盖、分解、装配动画、剖切/线框等 |
| 2026-10-17 | 外壳改定:DHT11 后盖卡位微突出;前后盖止口合盖 |
| 2026-10-17 | 去掉旁侧多余凸块;修复合盖对齐;DHT 改为后盖平面卡位 |
| 2026-10-17 | 打标签 `v1.0-case-closed` 作为可回滚稳定版 |
| 2026-10-17 | 外壳 v1.1:外圆角 R3.5、四侧悬臂卡扣、定位柱、卡扣试打样件 |
| 2026-10-17 | 打标签 `v1.1-case-snaps`(及分支 `keep/v1.1-case-snaps`)作为可回滚稳定版 |
| 2026-10-17 | UI 重排:修文字压图表;表盘/底栏分区;动画与短按/长按交互 |
| 2026-10-17 | 顶栏改单行,避免 up 文案被表盘面板盖住 |
| 2026-10-17 | 归档预编译固件到 `firmware/cyd_28r/`,附一键刷写脚本 |
| 2026-10-25 | 3.5" 表盘读数:数值+单位整体居中,数值变宽后不再盖住单位 |
| 2026-10-25 | 修复 3.5" 黑屏:背光改回 GPIO27(GPIO21 为 GT911 INT) |
| 2026-10-25 | README 链到上级 `CYD_PROJECT_GUIDE.md` §A(2.8/3.5 对照) |

View File

@@ -1,21 +1,39 @@
# CYD 温湿度仪表盘 3D 外壳
# CYD 温湿度仪表盘 3D 外壳(v1.1)
## 结构说明(当前版)
## 结构说明
只有两件:**前框** + **后盖**。
只有两件:**前框** + **后盖**。外轮廓圆角 R=3.5mm,主要靠 **4 处悬臂卡扣** 合盖(止口仍保留对齐;四角 M3 可选)。
| 部位 | 作用 |
|------|------|
| 前框 | 屏窗;公止口,合盖时插入后盖 |
| 后盖 | 装板子;母止口;**背面中心 DHT11 卡位通风口**(探头微突出约 1.6mm) |
| DHT 示意 | 预览里蓝色/灰块,表示传感器装在后盖背面卡位里 |
| 前框 | 屏窗;公止口;长边各 2 根悬臂卡扣(钩朝外) |
| 后盖 | 装板子;母止口;卡扣窗口 + 卡台;**背面中心 DHT11 卡位通风口**(探头微突出约 1.6mm) |
| 定位柱 | 四角短 peg / 孔,合盖防错位 |
| `snap_coupon.stl` | 单独试打卡扣样件,调间隙后再打整壳 |
**没有**外壳旁边的大“格子”。旧版里那两块是:侧向支脚块、外挂 DHT 仓——已删除,避免误解。
**没有**外壳旁边的大“格子”(旧支脚块 / 外挂仓已删)。
## 卡扣参数(按 FDM 常见经验)
参考悬臂卡扣实践(应变控制、根部过渡、配合间隙、PETG 反复开合更稳):
| 参数 | 本壳取值 | 说明 |
|------|----------|------|
| 自由臂长 L | 11 mm | 偏短可再加长降低应变 |
| 根厚 / 尖厚 | 1.7 → 0.95 mm | 锥形臂,应力分散 |
| 钩深 undercut | 0.75 mm | 含 lead-in 斜面 |
| 侧向间隙 | 0.45 mm | FDM 合盖/卡扣常用约 0.4–0.5 |
| 止口间隙 | 0.45 mm | 同左 |
| 材料建议 | **PETG** | PLA 可试装,反复开合易脆 |
打印:卡扣臂尽量落在 **XY 弯曲平面**(不要让弯曲撕开层层)。先打 `snap_coupon.stl`,太紧就略加大间隙或减钩深。
## 合盖
前框止口落入后盖槽;预览默认合盖(开合度 0%)。
对齐数据在 `export/mate.json`。
前框止口落入后盖槽,卡扣钩入后盖窗口卡台;预览默认合盖(开合度 0%)。
对齐数据在 `export/mate.json`(`version: 1.1-snaps`)。
稳定标签:当前 **`v1.1-case-snaps`**;旧无卡扣版 **`v1.0-case-closed`**(见仓库根 README)。
## 浏览器预览
@@ -31,11 +49,13 @@ python -m http.server 8765 --directory cad
## 导出 STL
```bash
pip install trimesh manifold3d numpy
pip install trimesh manifold3d numpy shapely
python cad/generate_stl.py
```
输出:`export/front.stl`、`back.stl`、`snap_coupon.stl`、`mate.json`。
## 装配
1. DHT11 从**后盖背面**按入中心卡位,探头朝外略突出,线进腔内接 CN1/GPIO22
2. CYD 放入后盖,前框合盖,四角 M3×10 可选固定
2. CYD 放入后盖,前框对准止口/定位柱合盖,听四侧卡扣入位;四角 M3×10 可选

Binary file not shown.

Binary file not shown.

View File

@@ -1,8 +1,14 @@
{
"outer_l": 91.5,
"outer_w": 55.5,
"outer_l": 91.6,
"outer_w": 55.599999999999994,
"front_body_h": 7.2,
"back_body_h": 10.4,
"lip_h": 2.2,
"dht_proud": 1.6
"lip_h": 2.0,
"dht_proud": 1.6,
"corner_r": 3.5,
"snap_w": 6.5,
"snap_l": 11.0,
"snap_hook": 0.75,
"lip_clear": 0.45,
"version": "1.1-snaps"
}

BIN
cad/export/snap_coupon.stl Normal file

Binary file not shown.

View File

@@ -1,31 +1,59 @@
#!/usr/bin/env python3
"""
CYD climate case — clean clamshell.
CYD climate case v1.1 — rounded clamshell + FDM snap clips.
- Front: screen bezel + male lip
- Back: cavity + female groove + DHT11 snap pocket flush in back wall (tip proud ~1.6mm)
- No side “boxes”: removed bulky stand block and external DHT hang-on bay
Design refs (FDM snap-fit best practice):
- Cantilever L≈12–16mm, root t≈1.6–2.0mm, width≥5mm
- Undercut ≈0.7mm, lead-in ≈35°, root fillet ≥0.5·t
- Mating clearance ≈0.4–0.5mm (FDM)
- Prefer PETG for repeated open/close; print snap arms in XY bend plane
Features:
- Outer R=3.5mm / inner R≈2.0mm rounded shell
- 4 side cantilever snaps (front) + catch windows (back)
- Corner locating pegs / sockets for 合盖对齐
- DHT11 flush rear pocket with slight proud grill
- Optional M3 bosses kept as backup
"""
from __future__ import annotations
import json
from pathlib import Path
import numpy as np
import trimesh
from trimesh.creation import box, cylinder
from shapely.geometry import Point, box
from trimesh.creation import cylinder, extrude_polygon
# ---- board ----
PCB_L, PCB_W = 86.0, 50.0
MH_INSET = 4.0
DISP_X, DISP_L, DISP_W, DISP_H = 8.0, 69.0, 50.0, 4.0
VIEW_L, VIEW_W, VIEW_IX, VIEW_IY = 59.5, 45.0, 7.0, 2.5
WALL, GAP = 2.4, 0.35
# ---- shell ----
WALL, GAP = 2.4, 0.40
CORNER_R = 3.5
INNER_R = 2.0
BEZEL_T = 2.2
CAVITY = 8.0
LIP_H, LIP_CLEAR = 2.2, 0.2
LIP_H = 2.0
LIP_CLEAR = 0.45 # FDM clearance around lip
USB_W, USB_H, USB_Y = 15.0, 9.0, 30.5
SCREW, BOSS_OD, BOSS_ID = 3.3, 7.0, 2.5
# DHT11 module pocket (from OUTSIDE of back face z=0)
# ---- snap (cantilever) ----
SNAP_W = 6.5
SNAP_L = 11.0 # free length
SNAP_T_ROOT = 1.7
SNAP_T_TIP = 0.95
SNAP_HOOK = 0.75 # undercut
SNAP_LEAD = 0.9 # lead-in ramp height along arm
SNAP_CLEAR = 0.45 # side gap around moving arm
SNAP_Z_ROOT = 1.2 # root starts below front rim into skirt
# ---- DHT ----
DHT_L, DHT_W, DHT_H = 16.0, 12.5, 7.5
DHT_PROUD = 1.6
@@ -34,8 +62,7 @@ INNER_W = PCB_W + 2 * GAP
OUTER_L = INNER_L + 2 * WALL
OUTER_W = INNER_W + 2 * WALL
SKIRT = DISP_H + 1.0
# Back total height to mating plane (top of female groove floor)
BACK_BODY_H = WALL + CAVITY # rim starts here
BACK_BODY_H = WALL + CAVITY
FRONT_BODY_H = BEZEL_T + SKIRT
MH = [
@@ -45,6 +72,17 @@ MH = [
(MH_INSET, PCB_W - MH_INSET),
]
# snap centers along long sides (x), inset from ends
SNAP_XS = [OUTER_L * 0.28, OUTER_L * 0.72]
def rounded_prism(l: float, w: float, h: float, r: float, z0: float = 0.0) -> trimesh.Trimesh:
r = min(r, l / 2 - 0.05, w / 2 - 0.05)
poly = box(r, r, l - r, w - r).buffer(r, resolution=8)
mesh = extrude_polygon(poly, height=h)
mesh.apply_translation([0, 0, z0])
return mesh
def aabb(x0, y0, z0, x1, y1, z1) -> trimesh.Trimesh:
xa, xb = sorted((float(x0), float(x1)))
@@ -52,8 +90,8 @@ def aabb(x0, y0, z0, x1, y1, z1) -> trimesh.Trimesh:
za, zb = sorted((float(z0), float(z1)))
dx, dy, dz = xb - xa, yb - ya, zb - za
if min(dx, dy, dz) < 1e-6:
raise ValueError(f"degenerate {[xa, ya, za, xb, yb, zb]}")
m = box(extents=[dx, dy, dz])
raise ValueError(f"degenerate box {xa,ya,za,xb,yb,zb}")
m = trimesh.creation.box(extents=[dx, dy, dz])
m.apply_translation([xa + dx / 2, ya + dy / 2, za + dz / 2])
return m
@@ -65,168 +103,295 @@ def U(*ms: trimesh.Trimesh) -> trimesh.Trimesh:
return r
def D(a: trimesh.Trimesh, *ss: trimesh.Trimesh) -> trimesh.Trimesh:
def Diff(a: trimesh.Trimesh, *ss: trimesh.Trimesh) -> trimesh.Trimesh:
r = a
for s in ss:
r = r.difference(s, engine="manifold")
return r
def make_front() -> trimesh.Trimesh:
def cantilever_snap(x_center: float, y_wall: float, outward_sign: int) -> trimesh.Trimesh:
"""
Z=0: outer screen face
Z=FRONT_BODY_H: open rim with male lip extending to FRONT_BODY_H+LIP_H
Snap arm on front: root near FRONT_BODY_H, extends +Z (into back when closed).
Hook faces outward (+/- Y).
outward_sign: +1 for +Y wall (hook +Y), -1 for -Y wall.
"""
body = aabb(0, 0, 0, OUTER_L, OUTER_W, FRONT_BODY_H)
hollow = aabb(WALL, WALL, BEZEL_T, OUTER_L - WALL, OUTER_W - WALL, FRONT_BODY_H + 1)
# Build in local: arm along +Z, thickness in Y, width in X
# Root fillet approximated by stepped thickening
pieces = []
n = 6
for i in range(n):
t = i / (n - 1)
# taper thickness root -> tip
th = SNAP_T_ROOT * (1 - t) + SNAP_T_TIP * t
z0 = FRONT_BODY_H - SNAP_Z_ROOT + t * (SNAP_L + SNAP_Z_ROOT)
z1 = FRONT_BODY_H - SNAP_Z_ROOT + (t + 1 / n) * (SNAP_L + SNAP_Z_ROOT) + 0.05
# arm sits inside wall face, hook later
if outward_sign > 0:
y0 = y_wall - WALL + SNAP_CLEAR
y1 = y0 + th
else:
y1 = y_wall + WALL - SNAP_CLEAR
y0 = y1 - th
pieces.append(aabb(x_center - SNAP_W / 2, y0, z0, x_center + SNAP_W / 2, y1, z1))
arm = U(*pieces)
# hook wedge at tip (lead-in ramp) — min thickness keeps manifold volumes valid
tip_z = FRONT_BODY_H - SNAP_Z_ROOT + SNAP_L + SNAP_Z_ROOT
hook_steps = []
for i in range(5):
t = (i + 1) / 5 # start above 0 so h>0
h = max(0.25, SNAP_HOOK * min(1.0, t / 0.55))
z0 = tip_z - SNAP_LEAD + (i / 5) * SNAP_LEAD
z1 = tip_z - SNAP_LEAD + ((i + 1) / 5) * SNAP_LEAD + 0.08
if outward_sign > 0:
y0 = y_wall - WALL + SNAP_CLEAR + SNAP_T_TIP
y1 = y0 + h
else:
y1 = y_wall + WALL - SNAP_CLEAR - SNAP_T_TIP
y0 = y1 - h
hook_steps.append(aabb(x_center - SNAP_W / 2 + 0.4, y0, z0, x_center + SNAP_W / 2 - 0.4, y1, z1))
return U(arm, *hook_steps)
def catch_window(x_center: float, y_wall: float, outward_sign: int) -> trimesh.Trimesh:
"""Opening / ledge cut in back wall for snap hook."""
# Window through wall where hook passes, then a ledge below for catch
win_h = SNAP_L + 2.5
z0 = BACK_BODY_H - 1.0
z1 = z0 + win_h
if outward_sign > 0:
return aabb(
x_center - SNAP_W / 2 - SNAP_CLEAR,
y_wall - WALL - 0.2,
z0,
x_center + SNAP_W / 2 + SNAP_CLEAR,
y_wall + 0.6,
z1,
)
return aabb(
x_center - SNAP_W / 2 - SNAP_CLEAR,
y_wall - 0.6,
z0,
x_center + SNAP_W / 2 + SNAP_CLEAR,
y_wall + WALL + 0.2,
z1,
)
def catch_ledge(x_center: float, y_wall: float, outward_sign: int) -> trimesh.Trimesh:
"""Internal ledge the hook seats under (retention)."""
z0 = BACK_BODY_H + 0.3
z1 = z0 + 1.4
if outward_sign > 0:
return aabb(
x_center - SNAP_W / 2 + 0.3,
OUTER_W - WALL - 0.2,
z0,
x_center + SNAP_W / 2 - 0.3,
OUTER_W - WALL + SNAP_HOOK + 0.3,
z1,
)
return aabb(
x_center - SNAP_W / 2 + 0.3,
WALL - SNAP_HOOK - 0.3,
z0,
x_center + SNAP_W / 2 - 0.3,
WALL + 0.2,
z1,
)
def make_front() -> trimesh.Trimesh:
body = rounded_prism(OUTER_L, OUTER_W, FRONT_BODY_H, CORNER_R, 0)
hollow = rounded_prism(INNER_L, INNER_W, FRONT_BODY_H + 1, INNER_R, BEZEL_T)
hollow.apply_translation([WALL, WALL, 0])
out = Diff(body, hollow)
# view + pocket
vx = WALL + GAP + DISP_X + VIEW_IX
vy = WALL + GAP + VIEW_IY
view = aabb(vx - 0.2, vy - 0.2, -0.5, vx + VIEW_L + 0.2, vy + VIEW_W + 0.2, BEZEL_T + 0.5)
out = Diff(out, aabb(vx - 0.2, vy - 0.2, -0.5, vx + VIEW_L + 0.2, vy + VIEW_W + 0.2, BEZEL_T + 0.5))
sx = WALL + GAP + DISP_X - 0.2
pocket = aabb(
sx, WALL + GAP - 0.1, BEZEL_T - 0.05,
sx + DISP_L + 0.4, WALL + GAP + DISP_W + 0.1, BEZEL_T + DISP_H + 0.6,
out = Diff(
out,
aabb(sx, WALL + GAP - 0.1, BEZEL_T - 0.05, sx + DISP_L + 0.4, WALL + GAP + DISP_W + 0.1, BEZEL_T + DISP_H + 0.6),
)
out = D(body, hollow, view, pocket)
# male lip: thin wall ring protruding past rim
lip_out = aabb(
WALL - 1.0, WALL - 1.0, FRONT_BODY_H - 0.05,
OUTER_L - (WALL - 1.0), OUTER_W - (WALL - 1.0), FRONT_BODY_H + LIP_H,
)
lip_in = aabb(
WALL + LIP_CLEAR, WALL + LIP_CLEAR, FRONT_BODY_H - 0.2,
OUTER_L - WALL - LIP_CLEAR, OUTER_W - WALL - LIP_CLEAR, FRONT_BODY_H + LIP_H + 0.5,
)
out = U(out, D(lip_out, lip_in))
# male lip (rounded ring approx via outer-inner)
lip_out = rounded_prism(OUTER_L - 1.2, OUTER_W - 1.2, LIP_H, CORNER_R - 0.6, FRONT_BODY_H - 0.05)
lip_out.apply_translation([0.6, 0.6, 0])
lip_in = rounded_prism(INNER_L + LIP_CLEAR * 2, INNER_W + LIP_CLEAR * 2, LIP_H + 0.6, INNER_R, FRONT_BODY_H - 0.2)
lip_in.apply_translation([WALL - LIP_CLEAR, WALL - LIP_CLEAR, 0])
out = U(out, Diff(lip_out, lip_in))
# locating pegs (导柱) near corners — stick into back sockets
pegs = []
for px, py in [(8.0, 8.0), (OUTER_L - 8.0, 8.0), (OUTER_L - 8.0, OUTER_W - 8.0), (8.0, OUTER_W - 8.0)]:
peg = cylinder(radius=1.4, height=LIP_H + 2.2, sections=20)
peg.apply_translation([px, py, FRONT_BODY_H + (LIP_H + 2.2) / 2 - 0.3])
pegs.append(peg)
out = U(out, *pegs)
# 4 snaps on long sides
snaps = []
for x in SNAP_XS:
snaps.append(cantilever_snap(x, OUTER_W, +1))
snaps.append(cantilever_snap(x, 0.0, -1))
out = U(out, *snaps)
# optional screw holes (backup)
for px, py in MH:
hole = cylinder(radius=SCREW / 2 + 0.1, height=FRONT_BODY_H + LIP_H + 4, sections=28)
hole = cylinder(radius=SCREW / 2 + 0.1, height=FRONT_BODY_H + LIP_H + 6, sections=24)
hole.apply_translation([WALL + GAP + px, WALL + GAP + py, FRONT_BODY_H / 2])
out = D(out, hole)
out = Diff(out, hole)
out.merge_vertices()
return out
def make_back() -> trimesh.Trimesh:
"""
Z=0: exterior back face (DHT grill here, slightly proud)
Z=BACK_BODY_H: mating plane; female groove from BACK_BODY_H to BACK_BODY_H+LIP_H
"""
total_h = BACK_BODY_H + LIP_H
body = aabb(0, 0, 0, OUTER_L, OUTER_W, total_h)
cavity = aabb(WALL, WALL, WALL, OUTER_L - WALL, OUTER_W - WALL, total_h + 1)
out = D(body, cavity)
body = rounded_prism(OUTER_L, OUTER_W, total_h, CORNER_R, 0)
cavity = rounded_prism(INNER_L, INNER_W, total_h + 1, INNER_R, WALL)
cavity.apply_translation([WALL, WALL, 0])
out = Diff(body, cavity)
# female groove: cut a channel in the top rim for the male lip
# outer wall of groove
groove = aabb(
WALL - 1.0 - LIP_CLEAR, WALL - 1.0 - LIP_CLEAR, BACK_BODY_H + 0.1,
OUTER_L - (WALL - 1.0 - LIP_CLEAR), OUTER_W - (WALL - 1.0 - LIP_CLEAR), total_h + 0.2,
)
groove_keep = aabb(
WALL + 0.05, WALL + 0.05, BACK_BODY_H - 0.1,
OUTER_L - WALL - 0.05, OUTER_W - WALL - 0.05, total_h + 0.3,
)
out = D(out, D(groove, groove_keep))
# female groove for lip
groove = rounded_prism(OUTER_L - 0.8, OUTER_W - 0.8, LIP_H + 0.3, CORNER_R - 0.4, BACK_BODY_H + 0.1)
groove.apply_translation([0.4, 0.4, 0])
keep = rounded_prism(INNER_L + 0.2, INNER_W + 0.2, LIP_H + 0.6, INNER_R, BACK_BODY_H - 0.1)
keep.apply_translation([WALL - 0.1, WALL - 0.1, 0])
out = Diff(out, Diff(groove, keep))
# locating sockets
for px, py in [(8.0, 8.0), (OUTER_L - 8.0, 8.0), (OUTER_L - 8.0, OUTER_W - 8.0), (8.0, OUTER_W - 8.0)]:
sock = cylinder(radius=1.55, height=3.2, sections=20)
sock.apply_translation([px, py, BACK_BODY_H + 1.4])
out = Diff(out, sock)
# snap catch windows + ledges
for x in SNAP_XS:
out = Diff(out, catch_window(x, OUTER_W, +1))
out = Diff(out, catch_window(x, 0.0, -1))
out = U(out, catch_ledge(x, OUTER_W, +1))
out = U(out, catch_ledge(x, 0.0, -1))
# USB
uy0 = WALL + GAP + USB_Y - USB_W / 2
out = D(out, aabb(-0.5, uy0, WALL + 1.0, WALL + 1.0, uy0 + USB_W, WALL + 1.0 + USB_H))
out = Diff(out, aabb(-0.5, uy0, WALL + 1.0, WALL + 1.0, uy0 + USB_W, WALL + 1.0 + USB_H))
# button holes
# buttons
for y in (12.0, 22.0):
btn = cylinder(radius=2.2, height=WALL + 2, sections=20)
btn = cylinder(radius=2.2, height=WALL + 2, sections=18)
btn.apply_translation([WALL + GAP + 10, WALL + GAP + y, WALL / 2])
out = D(out, btn)
out = Diff(out, btn)
# screw bosses
# M3 bosses backup
bosses = []
for px, py in MH:
x, y = WALL + GAP + px, WALL + GAP + py
boss = cylinder(radius=BOSS_OD / 2, height=CAVITY - 0.5, sections=28)
boss = cylinder(radius=BOSS_OD / 2, height=CAVITY - 0.5, sections=24)
boss.apply_translation([x, y, WALL + (CAVITY - 0.5) / 2])
hole = cylinder(radius=BOSS_ID / 2, height=CAVITY + 1, sections=20)
hole = cylinder(radius=BOSS_ID / 2, height=CAVITY + 1, sections=18)
hole.apply_translation([x, y, WALL + CAVITY / 2])
bosses.append(D(boss, hole))
bosses.append(Diff(boss, hole))
out = U(out, *bosses)
# ---- DHT11 flush pocket in back wall (NOT a side box) ----
# Center on back face
cx = OUTER_L * 0.5
cy = OUTER_W * 0.5
# Pocket carved from outside into wall+cavity enough for module
pocket = aabb(
cx - DHT_L / 2 - 0.3, cy - DHT_W / 2 - 0.3, -0.05,
cx + DHT_L / 2 + 0.3, cy + DHT_W / 2 + 0.3, WALL + DHT_H - 1.0,
# DHT pocket + proud rounded grill
cx, cy = OUTER_L / 2, OUTER_W / 2
out = Diff(
out,
aabb(cx - DHT_L / 2 - 0.3, cy - DHT_W / 2 - 0.3, -0.05, cx + DHT_L / 2 + 0.3, cy + DHT_W / 2 + 0.3, WALL + DHT_H - 1.0),
)
out = D(out, pocket)
# Snap rails (卡位) left/right inside pocket — thin ledges
rail_z0, rail_z1 = 1.2, 1.2 + 2.2
left = aabb(cx - DHT_L / 2 - 0.3, cy - 3.2, rail_z0, cx - DHT_L / 2 + 1.0, cy + 3.2, rail_z1)
right = aabb(cx + DHT_L / 2 - 1.0, cy - 3.2, rail_z0, cx + DHT_L / 2 + 0.3, cy + 3.2, rail_z1)
# bottom stop (prevents falling inward)
stop = aabb(cx - 5, cy - DHT_W / 2 + 0.5, WALL + DHT_H - 2.2, cx + 5, cy + DHT_W / 2 - 0.5, WALL + DHT_H - 1.0)
out = U(out, left, right, stop)
# Proud grill ring on exterior (the only intentional protrusion)
grill_ring = aabb(
cx - DHT_L / 2 - 1.0, cy - DHT_W / 2 - 1.0, -DHT_PROUD,
cx + DHT_L / 2 + 1.0, cy + DHT_W / 2 + 1.0, 0.05,
out = U(
out,
aabb(cx - DHT_L / 2 - 0.3, cy - 3.2, 1.2, cx - DHT_L / 2 + 1.0, cy + 3.2, 3.4),
aabb(cx + DHT_L / 2 - 1.0, cy - 3.2, 1.2, cx + DHT_L / 2 + 0.3, cy + 3.2, 3.4),
aabb(cx - 5, cy - DHT_W / 2 + 0.5, WALL + DHT_H - 2.2, cx + 5, cy + DHT_W / 2 - 0.5, WALL + DHT_H - 1.0),
)
grill_hole = aabb(
cx - DHT_L / 2 + 1.5, cy - DHT_W / 2 + 1.5, -DHT_PROUD - 0.2,
cx + DHT_L / 2 - 1.5, cy + DHT_W / 2 - 1.5, 0.2,
# rounded proud grill via buffered square
grill_poly = box(cx - DHT_L / 2 - 0.8, cy - DHT_W / 2 - 0.8, cx + DHT_L / 2 + 0.8, cy + DHT_W / 2 + 0.8).buffer(
1.2, resolution=6
)
# slot vents in proud face
grill = extrude_polygon(grill_poly, height=DHT_PROUD + 0.1)
grill.apply_translation([0, 0, -DHT_PROUD])
hole_poly = box(cx - DHT_L / 2 + 1.6, cy - DHT_W / 2 + 1.6, cx + DHT_L / 2 - 1.6, cy + DHT_W / 2 - 1.6).buffer(
0.8, resolution=5
)
ghole = extrude_polygon(hole_poly, height=DHT_PROUD + 0.4)
ghole.apply_translation([0, 0, -DHT_PROUD - 0.2])
slots = []
for i in range(4):
slots.append(aabb(
cx - 5 + i * 2.8, cy - 4.5, -DHT_PROUD - 0.2,
cx - 5 + i * 2.8 + 1.2, cy + 4.5, 0.2,
))
out = U(out, D(grill_ring, grill_hole, *slots))
# tiny wire path already open via pocket into cavity
# Simple thin kickstand rib (not a hollow “格子”) — optional small triangle
# Skip bulky stand entirely per user feedback.
slots.append(
aabb(cx - 5 + i * 2.8, cy - 4.2, -DHT_PROUD - 0.2, cx - 5 + i * 2.8 + 1.2, cy + 4.2, 0.15)
)
out = U(out, Diff(grill, ghole, *slots))
out.merge_vertices()
return out
def make_snap_coupon() -> trimesh.Trimesh:
"""Small test piece: one snap + one catch for tuning before full print."""
base = aabb(0, 0, 0, 40, 28, 3)
# fake front strip with one snap
strip = aabb(5, 20, 3, 35, 28, 3 + FRONT_BODY_H * 0.35)
snap = cantilever_snap(20, 28, +1)
# shift snap down a bit for coupon
front = U(strip, snap)
# fake back catch wall
wall = aabb(5, 0, 0, 35, 3.2, 18)
win = catch_window(20, 3.2, +1)
# remap catch to coupon coords roughly
catch = aabb(20 - SNAP_W / 2 - 0.5, -0.2, 8, 20 + SNAP_W / 2 + 0.5, 3.5, 18)
ledge = aabb(20 - SNAP_W / 2 + 0.3, 2.5, 10, 20 + SNAP_W / 2 - 0.3, 2.5 + SNAP_HOOK + 0.4, 11.4)
back = U(Diff(wall, catch), ledge)
# place back beside front
back.apply_translation([0, -8, 0])
label = aabb(2, 12, 3, 3.2, 18, 4.5) # marker nub
return U(base, front, back, label)
def main() -> None:
out = Path(__file__).resolve().parent / "export"
out.mkdir(parents=True, exist_ok=True)
print("front…")
print("front (rounded + snaps)…")
front = make_front()
print("back…")
print("back (rounded + catches)…")
back = make_back()
print("snap coupon…")
coupon = make_snap_coupon()
front.export(out / "front.stl")
back.export(out / "back.stl")
coupon.export(out / "snap_coupon.stl")
# write mate info for viewer
meta = out / "mate.json"
meta.write_text(
"{\n"
f' "outer_l": {OUTER_L},\n'
f' "outer_w": {OUTER_W},\n'
f' "front_body_h": {FRONT_BODY_H},\n'
f' "back_body_h": {BACK_BODY_H},\n'
f' "lip_h": {LIP_H},\n'
f' "dht_proud": {DHT_PROUD}\n'
"}\n",
meta = {
"outer_l": OUTER_L,
"outer_w": OUTER_W,
"front_body_h": FRONT_BODY_H,
"back_body_h": BACK_BODY_H,
"lip_h": LIP_H,
"dht_proud": DHT_PROUD,
"corner_r": CORNER_R,
"snap_w": SNAP_W,
"snap_l": SNAP_L,
"snap_hook": SNAP_HOOK,
"lip_clear": LIP_CLEAR,
"version": "1.1-snaps",
}
(out / "mate.json").write_text(
json.dumps(meta, indent=2) + "\n",
encoding="utf-8",
)
print(f"front {front.extents} watertight={front.is_watertight}")
print(f"back {back.extents} watertight={back.is_watertight}")
print("closed stack height ≈", BACK_BODY_H + FRONT_BODY_H, "mm (lips nest, not add full)")
print("Wrote STLs + mate.json")
print(f"front {front.extents} wt={front.is_watertight}")
print(f"back {back.extents} wt={back.is_watertight}")
print(f"coupon {coupon.extents} wt={coupon.is_watertight}")
print("Wrote front/back/snap_coupon + mate.json")
if __name__ == "__main__":

View File

@@ -62,8 +62,8 @@
</div>
<p class="faq">
后盖中心微凸的是 <b>DHT11 卡位通风口</b>(传感器按入后盖背面,探头略突出)。<br/>
已去掉旁边多余的大“格子”(旧版支脚块 / 外挂仓)。
v1.1:外轮廓圆角 + 长边四侧悬臂卡扣合盖;后盖中心微凸是 <b>DHT11 卡位通风口</b>。<br/>
已去掉旁边多余的大“格子”。稳定版标签 <code>v1.1-case-snaps</code>;旧无卡扣版 <code>v1.0-case-closed</code>。
</p>
<div id="status">加载中…</div>
</div>
@@ -231,7 +231,8 @@
root.add(backG); root.add(frontG); root.add(dhtG);
setLid(0); setExp(0); fit();
msg(`合盖对齐已按 mate.json · 外壳 ${mate.outer_l}×${mate.outer_w} mm · DHT 突出 ${mate.dht_proud} mm`);
const ver = mate.version ? ` · ${mate.version}` : "";
msg(`合盖对齐已按 mate.json${ver} · 外壳 ${mate.outer_l}×${mate.outer_w} mm · R${mate.corner_r ?? "?"} · DHT 突出 ${mate.dht_proud} mm`);
} catch (e) {
console.error(e);
msg("加载失败:请用 python -m http.server 8765 --directory cad", true);

50
firmware/README.md Normal file
View File

@@ -0,0 +1,50 @@
# 预编译固件(可随时刷写)
| 目录 | 板子 |
|------|------|
| [`cyd_28r/`](cyd_28r/) | CYD ESP32-2432S028R(2.8" ILI9341),DHT11 → GPIO22 |
| [`cyd_35r/`](cyd_35r/) | CYD ESP32-3248S035(3.5" ST7796 + GT911),DHT11 → GPIO22 |
版本信息见各目录 `VERSION.txt`。
## 直接刷写(无需重新编译)
1. USB 连接板子
2. 进入对应目录执行:
```powershell
cd firmware\cyd_28r # 或 cyd_35r
.\flash.ps1
# 或指定端口
.\flash.ps1 -Port COM3
```
也可双击 / 运行 `flash.bat`。
依赖其一即可:
- 已安装 PlatformIO(`pio`,自带 esptool)
- 或 `pip install esptool`
## 手动 esptool
```bash
esptool.py --chip esp32 --port COM3 --baud 921600 write_flash -z ^
--flash_mode dio --flash_freq 40m --flash_size 4MB ^
0x1000 bootloader.bin ^
0x8000 partitions.bin ^
0xe000 boot_app0.bin ^
0x10000 firmware.bin
```
## 从源码重新打包进本目录
在仓库根目录:
```powershell
.\firmware\export_from_build.ps1
.\firmware\export_from_build.ps1 -Env cyd_35r
# 仅复制、不编译:
.\firmware\export_from_build.ps1 -SkipBuild
.\firmware\export_from_build.ps1 -Env cyd_35r -SkipBuild
```

View File

@@ -0,0 +1,16 @@
name: CYD climate dashboard (cyd_28r)
git: 3173b5f
date: 2026-10-17
board: ESP32-2432S028R (ILI9341)
dht: GPIO22
flash_size: 4MB
offsets:
0x1000 bootloader.bin
0x8000 partitions.bin
0xe000 boot_app0.bin
0x10000 firmware.bin
sha256:
bootloader.bin 3D234A7471F67B013686DABD4DEE7C1FA915C9928463616A94BC9297ACF1ABF8
partitions.bin 0A8B5720E7B77FF11F1462458C3A509DEE79224E5279898F26D6A2E3AE0517B7
boot_app0.bin F94C5D786A7A8FAB06AC5D10E33BF37711A6697636DC037559EA19CC410A17F0
firmware.bin 136CDB0949D3B74DF14ACBB8A2ED100C6F6934BEBE6290639E9C4CD1E68582F4

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,5 @@
@echo off
setlocal
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0flash.ps1" %*
exit /b %ERRORLEVEL%

View File

@@ -0,0 +1,84 @@
# Flash archived CYD climate firmware (no rebuild needed)
# Usage:
# .\flash.ps1
# .\flash.ps1 -Port COM5
# .\flash.ps1 -Port COM5 -Baud 460800
param(
[string]$Port = "",
[int]$Baud = 921600
)
$ErrorActionPreference = "Stop"
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $here
function Find-Esptool {
$pio = Get-Command pio -ErrorAction SilentlyContinue
if ($pio) {
$pkg = Join-Path $env:USERPROFILE ".platformio\packages\tool-esptoolpy\esptool.py"
if (Test-Path $pkg) { return @{ Kind = "py"; Path = $pkg } }
}
$py = Get-Command python -ErrorAction SilentlyContinue
if ($py) {
try {
& python -c "import esptool" 2>$null
if ($LASTEXITCODE -eq 0) { return @{ Kind = "mod"; Path = "esptool" } }
} catch {}
}
$esp = Get-Command esptool.py -ErrorAction SilentlyContinue
if ($esp) { return @{ Kind = "py"; Path = $esp.Source } }
return $null
}
if (-not $Port) {
$ports = @()
try {
Add-Type -AssemblyName System.IO.Ports -ErrorAction SilentlyContinue | Out-Null
$ports = [System.IO.Ports.SerialPort]::GetPortNames() | Sort-Object
} catch {}
if (-not $ports -or $ports.Count -eq 0) {
$ports = Get-CimInstance Win32_SerialPort -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty DeviceID | Sort-Object
}
if (-not $ports -or $ports.Count -eq 0) {
Write-Error "No serial ports found. Plug in the CYD USB cable, then retry with -Port COMx"
}
if ($ports.Count -eq 1) {
$Port = $ports[0]
} else {
Write-Host "Available ports: $($ports -join ', ')"
$Port = $ports[-1]
Write-Host "Using last port: $Port (override with -Port)"
}
}
$tool = Find-Esptool
if (-not $tool) {
Write-Error "esptool not found. Install PlatformIO (`pio`) or: pip install esptool"
}
$argsCommon = @(
"--chip", "esp32",
"--port", $Port,
"--baud", "$Baud",
"--before", "default_reset",
"--after", "hard_reset",
"write_flash", "-z",
"--flash_mode", "dio",
"--flash_freq", "40m",
"--flash_size", "4MB",
"0x1000", "bootloader.bin",
"0x8000", "partitions.bin",
"0xe000", "boot_app0.bin",
"0x10000", "firmware.bin"
)
Write-Host "Flashing $here -> $Port @ $Baud"
if ($tool.Kind -eq "mod") {
& python -m esptool @argsCommon
} else {
& python $tool.Path @argsCommon
}
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Write-Host "Done. Open serial monitor at 115200 if needed."

View File

@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=320" />
<title>CLIMATE</title>
<style>
*{box-sizing:border-box;margin:0;padding:0}
html,body{width:320px;height:240px;overflow:hidden;background:#000;margin:0}
.bezel{width:320px;height:240px;background:#1a1408}
.screen{
width:320px;height:240px;background:#0A1018;color:#F2F5FA;
font:12px/1.2 system-ui,sans-serif;position:relative;overflow:hidden;
}
.hdr{display:flex;align-items:center;gap:8px;padding:4px 8px;height:24px}
.hdr b{font-size:14px;font-weight:700}
.hdr .up{color:#7E90A8}
.hdr .sp{margin-left:auto;display:flex;align-items:center;gap:6px;color:#7E90A8}
.led{width:9px;height:9px;border-radius:50%;background:#4CAF7A}
.row{display:flex;gap:6px;padding:0 8px}
.panel{
flex:1;height:118px;background:#121C2A;border:1px solid #1E2C40;
border-radius:6px;padding:6px 8px;position:relative;
}
.cap{color:#7E90A8;font-size:11px}
.gauge{
width:90px;height:90px;margin:4px auto 0;border-radius:50%;
background:conic-gradient(#3DBF8C 0 70%, #243247 0);
mask:radial-gradient(farthest-side,transparent 62%,#000 63%);
-webkit-mask:radial-gradient(farthest-side,transparent 62%,#000 63%);
}
.panel.hum .gauge{background:conic-gradient(#3DB8A8 0 55%, #243247 0)}
.val{position:absolute;left:0;right:0;top:48px;text-align:center;font-size:24px;font-weight:700}
.panel.hum .val{color:#3DB8A8}
.panel.temp .val{color:#3DBF8C}
.unit{font-size:11px;color:#7E90A8;font-weight:500}
.rng{position:absolute;left:0;right:0;bottom:6px;text-align:center;color:#7E90A8;font-size:11px}
.bot{
margin:6px 8px 0;height:78px;background:#121C2A;border:1px solid #1E2C40;
border-radius:6px;display:flex;gap:8px;padding:8px;
}
.info{width:88px}
.ok{color:#E6B84D;font-size:14px;font-weight:700}
.bar{margin-top:8px;height:8px;background:#243247;border-radius:4px;overflow:hidden}
.bar>i{display:block;height:100%;width:62%;background:#E6B84D}
.meta{margin-top:10px;color:#7E90A8;font-size:11px}
.chart{flex:1;background:#0E1622;border-radius:4px;position:relative;overflow:hidden}
.chart svg{width:100%;height:100%}
</style>
</head>
<body>
<div class="bezel"><div class="screen" id="s">
<div class="hdr"><b>CLIMATE</b><span class="up">up 01:24</span>
<span class="sp"><span>OK</span><span class="led"></span></span></div>
<div class="row">
<div class="panel temp"><div class="cap">TEMP</div><div class="gauge"></div>
<div class="val">24.6<span class="unit">C</span></div><div class="rng">22.1 / 26.0</div></div>
<div class="panel hum"><div class="cap">HUM</div><div class="gauge"></div>
<div class="val">48<span class="unit">%</span></div><div class="rng">41 / 55</div></div>
</div>
<div class="bot">
<div class="info"><div class="ok">COMFORT</div><div class="bar"><i></i></div>
<div class="meta">DHT11 · GPIO22</div></div>
<div class="chart"><svg viewBox="0 0 180 60" preserveAspectRatio="none">
<polyline fill="none" stroke="#3DBF8C" stroke-width="2"
points="0,40 20,35 40,38 60,28 80,30 100,22 120,26 140,18 160,24 180,20"/>
<polyline fill="none" stroke="#3DB8A8" stroke-width="2"
points="0,45 20,42 40,44 60,40 80,38 100,36 120,39 140,34 160,37 180,35"/>
</svg></div>
</div>
</div></div>
</body>
</html>

View File

@@ -0,0 +1,10 @@
{
"boardId": "esp32-2432s028",
"name": "CYD climate dashboard",
"summary": "Temperature & humidity gauges with comfort bar and chart",
"description": "DHT11 on GPIO22. Dual arcs for TEMP/HUM, comfort status, live sparkline.",
"tags": ["climate", "dht11", "gauge"],
"media": {
"preview": "media/preview.html"
}
}

Binary file not shown.

View File

@@ -0,0 +1,11 @@
name: CYD temperature (cyd_35r)
git: 0a1b612
date: 2026-10-25
board: ESP32-3248S035 (ST7796 + GT911)
flash_size: 4MB
offsets:
0x1000 bootloader.bin
0x8000 partitions.bin
0xe000 boot_app0.bin
0x10000 firmware.bin
note: TFT_BL=GPIO27

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,5 @@
@echo off
setlocal
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0flash.ps1" %*
exit /b %ERRORLEVEL%

View File

@@ -0,0 +1,84 @@
# Flash archived CYD climate firmware (no rebuild needed)
# Usage:
# .\flash.ps1
# .\flash.ps1 -Port COM5
# .\flash.ps1 -Port COM5 -Baud 460800
param(
[string]$Port = "",
[int]$Baud = 921600
)
$ErrorActionPreference = "Stop"
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $here
function Find-Esptool {
$pio = Get-Command pio -ErrorAction SilentlyContinue
if ($pio) {
$pkg = Join-Path $env:USERPROFILE ".platformio\packages\tool-esptoolpy\esptool.py"
if (Test-Path $pkg) { return @{ Kind = "py"; Path = $pkg } }
}
$py = Get-Command python -ErrorAction SilentlyContinue
if ($py) {
try {
& python -c "import esptool" 2>$null
if ($LASTEXITCODE -eq 0) { return @{ Kind = "mod"; Path = "esptool" } }
} catch {}
}
$esp = Get-Command esptool.py -ErrorAction SilentlyContinue
if ($esp) { return @{ Kind = "py"; Path = $esp.Source } }
return $null
}
if (-not $Port) {
$ports = @()
try {
Add-Type -AssemblyName System.IO.Ports -ErrorAction SilentlyContinue | Out-Null
$ports = [System.IO.Ports.SerialPort]::GetPortNames() | Sort-Object
} catch {}
if (-not $ports -or $ports.Count -eq 0) {
$ports = Get-CimInstance Win32_SerialPort -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty DeviceID | Sort-Object
}
if (-not $ports -or $ports.Count -eq 0) {
Write-Error "No serial ports found. Plug in the CYD USB cable, then retry with -Port COMx"
}
if ($ports.Count -eq 1) {
$Port = $ports[0]
} else {
Write-Host "Available ports: $($ports -join ', ')"
$Port = $ports[-1]
Write-Host "Using last port: $Port (override with -Port)"
}
}
$tool = Find-Esptool
if (-not $tool) {
Write-Error "esptool not found. Install PlatformIO (`pio`) or: pip install esptool"
}
$argsCommon = @(
"--chip", "esp32",
"--port", $Port,
"--baud", "$Baud",
"--before", "default_reset",
"--after", "hard_reset",
"write_flash", "-z",
"--flash_mode", "dio",
"--flash_freq", "40m",
"--flash_size", "4MB",
"0x1000", "bootloader.bin",
"0x8000", "partitions.bin",
"0xe000", "boot_app0.bin",
"0x10000", "firmware.bin"
)
Write-Host "Flashing $here -> $Port @ $Baud"
if ($tool.Kind -eq "mod") {
& python -m esptool @argsCommon
} else {
& python $tool.Path @argsCommon
}
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Write-Host "Done. Open serial monitor at 115200 if needed."

View File

@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=320" />
<title>CLIMATE</title>
<style>
*{box-sizing:border-box;margin:0;padding:0}
html,body{width:320px;height:240px;overflow:hidden;background:#000;margin:0}
.bezel{width:320px;height:240px;background:#1a1408}
.screen{
width:320px;height:240px;background:#0A1018;color:#F2F5FA;
font:12px/1.2 system-ui,sans-serif;position:relative;overflow:hidden;
}
.hdr{display:flex;align-items:center;gap:8px;padding:4px 8px;height:24px}
.hdr b{font-size:14px;font-weight:700}
.hdr .up{color:#7E90A8}
.hdr .sp{margin-left:auto;display:flex;align-items:center;gap:6px;color:#7E90A8}
.led{width:9px;height:9px;border-radius:50%;background:#4CAF7A}
.row{display:flex;gap:6px;padding:0 8px}
.panel{
flex:1;height:118px;background:#121C2A;border:1px solid #1E2C40;
border-radius:6px;padding:6px 8px;position:relative;
}
.cap{color:#7E90A8;font-size:11px}
.gauge{
width:90px;height:90px;margin:4px auto 0;border-radius:50%;
background:conic-gradient(#3DBF8C 0 70%, #243247 0);
mask:radial-gradient(farthest-side,transparent 62%,#000 63%);
-webkit-mask:radial-gradient(farthest-side,transparent 62%,#000 63%);
}
.panel.hum .gauge{background:conic-gradient(#3DB8A8 0 55%, #243247 0)}
.val{position:absolute;left:0;right:0;top:48px;text-align:center;font-size:24px;font-weight:700}
.panel.hum .val{color:#3DB8A8}
.panel.temp .val{color:#3DBF8C}
.unit{font-size:11px;color:#7E90A8;font-weight:500}
.rng{position:absolute;left:0;right:0;bottom:6px;text-align:center;color:#7E90A8;font-size:11px}
.bot{
margin:6px 8px 0;height:78px;background:#121C2A;border:1px solid #1E2C40;
border-radius:6px;display:flex;gap:8px;padding:8px;
}
.info{width:88px}
.ok{color:#E6B84D;font-size:14px;font-weight:700}
.bar{margin-top:8px;height:8px;background:#243247;border-radius:4px;overflow:hidden}
.bar>i{display:block;height:100%;width:62%;background:#E6B84D}
.meta{margin-top:10px;color:#7E90A8;font-size:11px}
.chart{flex:1;background:#0E1622;border-radius:4px;position:relative;overflow:hidden}
.chart svg{width:100%;height:100%}
/* CYD 3.5" full-bleed: non-uniform scale matches firmware UX()/UY(). */
html,body{width:480px!important;height:320px!important;overflow:hidden!important;background:#000!important;margin:0!important;padding:0!important}
.cyd35-scale{width:320px;height:240px;transform:scale(1.5,1.3333333333);transform-origin:0 0;overflow:hidden}
</style>
</head>
<body>
<div class="cyd35-scale">
<div class="bezel"><div class="screen" id="s">
<div class="hdr"><b>CLIMATE</b><span class="up">up 01:24</span>
<span class="sp"><span>OK</span><span class="led"></span></span></div>
<div class="row">
<div class="panel temp"><div class="cap">TEMP</div><div class="gauge"></div>
<div class="val">24.6<span class="unit">C</span></div><div class="rng">22.1 / 26.0</div></div>
<div class="panel hum"><div class="cap">HUM</div><div class="gauge"></div>
<div class="val">48<span class="unit">%</span></div><div class="rng">41 / 55</div></div>
</div>
<div class="bot">
<div class="info"><div class="ok">COMFORT</div><div class="bar"><i></i></div>
<div class="meta">DHT11 · GPIO22</div></div>
<div class="chart"><svg viewBox="0 0 180 60" preserveAspectRatio="none">
<polyline fill="none" stroke="#3DBF8C" stroke-width="2"
points="0,40 20,35 40,38 60,28 80,30 100,22 120,26 140,18 160,24 180,20"/>
<polyline fill="none" stroke="#3DB8A8" stroke-width="2"
points="0,45 20,42 40,44 60,40 80,38 100,36 120,39 140,34 160,37 180,35"/>
</svg></div>
</div>
</div></div>
</div>
</body>
</html>

View File

@@ -0,0 +1,14 @@
{
"boardId": "esp32-3248s035",
"name": "CYD climate dashboard (3.5\")",
"summary": "Temperature & humidity gauges with comfort bar and chart",
"description": "DHT11 on GPIO22. Dual arcs for TEMP/HUM, comfort status, live sparkline.",
"tags": [
"climate",
"dht11",
"gauge"
],
"media": {
"preview": "media/preview.html"
}
}

Binary file not shown.

View File

@@ -0,0 +1,87 @@
# Export firmware bins from PlatformIO build.
# Default: 2.8" (cyd_28r -> firmware/cyd_28r)
# 3.5": .\firmware\export_from_build.ps1 -Env cyd_35r
# (only after: pio run -e cyd_35r)
param(
[switch]$SkipBuild,
[ValidateSet("cyd_28r", "cyd_35r")]
[string]$Env = "cyd_28r"
)
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
Set-Location $root
$env:Path = "C:\Users\dsx2016\AppData\Local\Programs\Python\Python312\Scripts;" + $env:Path
if (-not $SkipBuild) {
pio run -e $Env
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
$src = Join-Path $root (".pio\build\" + $Env)
if ($Env -eq "cyd_35r") {
$dstName = "cyd_35r"
$boardLine = "board: ESP32-3248S035 (ST7796)"
$boardIdHint = "esp32-3248s035"
} else {
$dstName = "cyd_28r"
$boardLine = "board: ESP32-2432S028R (ILI9341)"
$boardIdHint = "esp32-2432s028"
}
$dst = Join-Path $root ("firmware\" + $dstName)
New-Item -ItemType Directory -Force -Path $dst | Out-Null
foreach ($f in @("bootloader.bin", "partitions.bin", "firmware.bin")) {
$p = Join-Path $src $f
if (-not (Test-Path $p)) { Write-Error "Missing build artifact: $p — build with: pio run -e $Env" }
Copy-Item $p $dst -Force
}
$bootApp = Join-Path $env:USERPROFILE ".platformio\packages\framework-arduinoespressif32\tools\partitions\boot_app0.bin"
if (-not (Test-Path $bootApp)) {
Write-Error "boot_app0.bin not found under PlatformIO packages"
}
Copy-Item $bootApp (Join-Path $dst "boot_app0.bin") -Force
$git = ""
try { $git = (git -C $root rev-parse --short HEAD).Trim() } catch { $git = "unknown" }
$date = Get-Date -Format "yyyy-MM-dd"
$hashes = Get-ChildItem (Join-Path $dst "*.bin") | Get-FileHash -Algorithm SHA256
$lines = @(
"name: CYD temperature ($dstName)",
"git: $git",
"date: $date",
$boardLine,
"flash_size: 4MB",
"offsets:",
" 0x1000 bootloader.bin",
" 0x8000 partitions.bin",
" 0xe000 boot_app0.bin",
" 0x10000 firmware.bin",
"sha256:"
)
foreach ($h in $hashes) {
$lines += (" {0,-15} {1}" -f (Split-Path $h.Path -Leaf), $h.Hash)
}
$lines | Set-Content -Encoding utf8 (Join-Path $dst "VERSION.txt")
# Keep / refresh meta.json boardId for catalog filtering
$metaPath = Join-Path $dst "meta.json"
if (Test-Path $metaPath) {
try {
$meta = Get-Content $metaPath -Raw | ConvertFrom-Json
$meta.boardId = $boardIdHint
if ($Env -eq "cyd_35r" -and $meta.name -notmatch '3\.5') {
$meta.name = ($meta.name -replace '\s*$','') + ' (3.5")'
}
$meta | ConvertTo-Json -Depth 8 | Set-Content -Encoding utf8 $metaPath
} catch {
Write-Host "meta.json update skipped: $_"
}
} elseif ($Env -eq "cyd_35r") {
Write-Host "Note: add firmware/cyd_35r/meta.json with boardId=$boardIdHint for the web catalog"
}
Write-Host "Exported -> $dst (env=$Env git=$git)"

6
include/touch.h Normal file
View File

@@ -0,0 +1,6 @@
#pragma once
#include <lvgl.h>
void touch_init();
void touch_read_cb(lv_indev_t *indev, lv_indev_data_t *data);

View File

@@ -1,4 +1,4 @@
; CYD ESP32-2432S028R — LVGL 温湿度仪表盘
; CYD ESP32-2432S028R <EFBFBD>?LVGL 温湿度仪表盘
; DHT11 DATA -> GPIO22
[platformio]
@@ -46,12 +46,12 @@ build_flags =
-D LV_CONF_INCLUDE_SIMPLE=1
-I include
; 标准 CYD 2.8" 电阻屏 (ILI9341)
; 标准 CYD 2.8" 电阻<EFBFBD>?(ILI9341)
[env:cyd_28r]
build_flags =
${env.build_flags}
; 颜色反相版本(若画面色偏/发白可改用此环境)
; 颜色反相版本(若画面色偏/发白可改用此环境<EFBFBD>?
[env:cyd_28r_inv]
build_flags =
${env.build_flags}
@@ -65,3 +65,29 @@ build_flags =
-D ST7789_DRIVER=1
-D TFT_RGB_ORDER=TFT_BGR
-D TFT_INVERSION_ON=1
; Optional 3.5" CYD ESP32-3248S035C (ST7796 + GT911 capacitive). Default remains cyd_28r.
; Build: pio run -e cyd_35r
; Keep TOUCH_CS=-1 — GPIO33 is GT911 SDA, not resistive touch CS.
; TFT_BL=GPIO27 (not 21 — 21 is GT911 INT on C boards).
[env:cyd_35r]
lib_deps =
lvgl/lvgl@9.2.2
bodmer/TFT_eSPI@2.5.43
beegee-tokyo/DHT sensor library for ESPx@^1.19
build_flags =
${env.build_flags}
-UILI9341_2_DRIVER
-DST7796_DRIVER=1
-UTFT_WIDTH
-UTFT_HEIGHT
-DTFT_WIDTH=320
-DTFT_HEIGHT=480
-UTFT_BL
-DTFT_BL=27
-DCYD_BOARD_3248S035=1
-DSUPPORT_TRANSACTIONS
-DTFT_RGB_ORDER=TFT_BGR
-ULV_MEM_SIZE
-DLV_MEM_SIZE=32768

View File

@@ -1,31 +1,65 @@
/**
* CYD ESP32-2432S028R — LVGL 温湿度仪表盘
* DHT11 DATA -> GPIO22
* Backlight: 2.8" GPIO21, 3.5" GPIO27 (GT911 INT is GPIO21 — not BL)
*/
#include <Arduino.h>
#include <lvgl.h>
#include <TFT_eSPI.h>
#include <XPT2046_Touchscreen.h>
#include <DHTesp.h>
#include <math.h>
#include "touch.h"
#define DHT_PIN 22
#if defined(CYD_BOARD_3248S035)
#define TFT_BL_PIN 27
#else
#define TFT_BL_PIN 21
#endif
#define XPT2046_IRQ 36
#define XPT2046_MOSI 32
#define XPT2046_MISO 39
#define XPT2046_CLK 25
#define XPT2046_CS 33
#if defined(CYD_BOARD_3248S035)
#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 320
#else
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#endif
#define DHT_READ_MS 2500
#define DHT_FAIL_TOLERANCE 3
#define EMA_ALPHA 0.35f
#define HISTORY_LEN 48
#if defined(CYD_BOARD_3248S035)
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 20 * (LV_COLOR_DEPTH / 8))
#else
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
#endif
/* Layout grid — every region has exclusive space, no overlaps */
#if defined(CYD_BOARD_3248S035)
#define UI_M 10
#define UI_G 10
#define UI_HDR_H 32
#define UI_GAUGE_H 168
#define UI_GAUGE_W 225
#define UI_ARC 120
#else
#define UI_M 6
#define UI_G 6
#define UI_HDR_H 22
#define UI_GAUGE_H 124
#define UI_GAUGE_W 151
#define UI_ARC 90
#endif
#define UI_BOT_Y (UI_HDR_H + UI_G + UI_GAUGE_H + UI_G) /* 158 */
#define UI_BOT_H (SCREEN_HEIGHT - UI_BOT_Y - UI_M) /* 76 */
#define UI_BOT_W (SCREEN_WIDTH - 2 * UI_M) /* 308 */
#if defined(CYD_BOARD_3248S035)
#define UI_INFO_W 180
#else
#define UI_INFO_W 124
#endif
#define UI_CHART_W (UI_BOT_W - 12 - UI_INFO_W - UI_G) /* ~160 */
static const lv_color_t COL_BG = lv_color_hex(0x0A1018);
static const lv_color_t COL_PANEL = lv_color_hex(0x121C2A);
@@ -41,9 +75,8 @@ static const lv_color_t COL_OK = lv_color_hex(0x4CAF7A);
static const lv_color_t COL_WARN = lv_color_hex(0xE6B84D);
static const lv_color_t COL_BAD = lv_color_hex(0xE05A5A);
static const lv_color_t COL_ARC_BG = lv_color_hex(0x243247);
static const lv_color_t COL_CHART_BG = lv_color_hex(0x0E1622);
SPIClass touchscreenSPI = SPIClass(VSPI);
XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);
DHTesp dht;
static uint32_t draw_buf[DRAW_BUF_SIZE / 4];
@@ -52,12 +85,16 @@ static lv_obj_t *arc_temp;
static lv_obj_t *arc_hum;
static lv_obj_t *lbl_temp_val;
static lv_obj_t *lbl_hum_val;
static lv_obj_t *lbl_temp_unit;
static lv_obj_t *lbl_hum_unit;
static lv_obj_t *lbl_temp_range;
static lv_obj_t *lbl_hum_range;
static lv_obj_t *lbl_comfort;
static lv_obj_t *lbl_feels;
static lv_obj_t *lbl_dew;
static lv_obj_t *lbl_status;
static lv_obj_t *lbl_uptime;
static lv_obj_t *lbl_hint;
static lv_obj_t *led_status;
static lv_obj_t *bar_comfort;
static lv_obj_t *chart;
@@ -76,6 +113,7 @@ static uint8_t fail_streak = 0;
static bool sensor_ok = false;
static uint8_t bright_level = 2;
static const uint8_t BRIGHT_PWM[4] = {40, 90, 160, 255};
static uint32_t hint_until_ms = 0;
static void set_backlight(uint8_t level) {
bright_level = level & 0x03;
@@ -116,9 +154,9 @@ static lv_color_t temp_color(float t) {
static const char *comfort_text(float t, float h) {
if (isnan(t) || isnan(h)) return "NO DATA";
if (t < 16 || t > 30 || h < 30 || h > 75) return "UNCOMFORTABLE";
if (t >= 20 && t <= 26 && h >= 40 && h <= 60) return "COMFORTABLE";
return "ACCEPTABLE";
if (t < 16 || t > 30 || h < 30 || h > 75) return "UNCOMFY";
if (t >= 20 && t <= 26 && h >= 40 && h <= 60) return "COMFY";
return "OK";
}
static lv_color_t comfort_color(float t, float h) {
@@ -136,27 +174,48 @@ static int comfort_score(float t, float h) {
return constrain(score, 0, 100);
}
static void show_hint(const char *text, uint32_t ms) {
lv_label_set_text(lbl_hint, text);
lv_obj_remove_flag(lbl_hint, LV_OBJ_FLAG_HIDDEN);
lv_obj_move_foreground(lbl_hint);
hint_until_ms = millis() + ms;
}
static void reset_minmax(void) {
if (!isnan(disp_temp)) {
min_temp = max_temp = disp_temp;
} else {
min_temp = max_temp = NAN;
}
if (!isnan(disp_hum)) {
min_hum = max_hum = disp_hum;
} else {
min_hum = max_hum = NAN;
}
show_hint("min/max reset", 1200);
}
static void touchscreen_read(lv_indev_t *indev, lv_indev_data_t *data) {
LV_UNUSED(indev);
static bool was_pressed = false;
static uint32_t press_ms = 0;
if (touchscreen.tirqTouched() && touchscreen.touched()) {
TS_Point p = touchscreen.getPoint();
data->point.x = map(p.y, 240, 3800, 1, SCREEN_WIDTH);
data->point.y = map(p.x, 200, 3700, SCREEN_HEIGHT, 1);
data->state = LV_INDEV_STATE_PRESSED;
touch_read_cb(indev, data);
if (data->state == LV_INDEV_STATE_PRESSED) {
if (!was_pressed) {
was_pressed = true;
press_ms = millis();
}
} else {
data->state = LV_INDEV_STATE_RELEASED;
if (was_pressed) {
was_pressed = false;
if (millis() - press_ms < 400) {
set_backlight((bright_level + 1) & 0x03);
}
} else if (was_pressed) {
was_pressed = false;
uint32_t held = millis() - press_ms;
if (held >= 700) {
reset_minmax();
} else if (held < 400) {
set_backlight((bright_level + 1) & 0x03);
char buf[20];
lv_snprintf(buf, sizeof(buf), "brightness %u/3", (unsigned)bright_level);
show_hint(buf, 900);
}
}
}
@@ -172,12 +231,29 @@ static void anim_arc(lv_obj_t *arc, int32_t value) {
lv_anim_init(&a);
lv_anim_set_var(&a, arc);
lv_anim_set_values(&a, cur, value);
lv_anim_set_duration(&a, 450);
lv_anim_set_duration(&a, 520);
lv_anim_set_exec_cb(&a, arc_anim_exec);
lv_anim_set_path_cb(&a, lv_anim_path_ease_out);
lv_anim_start(&a);
}
static void bar_anim_exec(void *obj, int32_t v) {
lv_bar_set_value((lv_obj_t *)obj, v, LV_ANIM_OFF);
}
static void anim_bar(lv_obj_t *bar, int32_t value) {
int32_t cur = lv_bar_get_value(bar);
if (cur == value) return;
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, bar);
lv_anim_set_values(&a, cur, value);
lv_anim_set_duration(&a, 400);
lv_anim_set_exec_cb(&a, bar_anim_exec);
lv_anim_set_path_cb(&a, lv_anim_path_ease_out);
lv_anim_start(&a);
}
static lv_obj_t *make_panel(lv_obj_t *parent, int x, int y, int w, int h) {
lv_obj_t *p = lv_obj_create(parent);
lv_obj_set_pos(p, x, y);
@@ -186,16 +262,20 @@ static lv_obj_t *make_panel(lv_obj_t *parent, int x, int y, int w, int h) {
lv_obj_set_style_bg_opa(p, LV_OPA_COVER, 0);
lv_obj_set_style_border_color(p, COL_EDGE, 0);
lv_obj_set_style_border_width(p, 1, 0);
lv_obj_set_style_radius(p, 14, 0);
lv_obj_set_style_radius(p, 12, 0);
lv_obj_set_style_pad_all(p, 6, 0);
lv_obj_set_style_pad_row(p, 0, 0);
lv_obj_set_style_pad_column(p, 0, 0);
lv_obj_clear_flag(p, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_remove_flag(p, LV_OBJ_FLAG_SCROLLABLE);
return p;
}
static lv_obj_t *make_gauge(lv_obj_t *parent, lv_color_t accent, int max_val) {
lv_obj_t *arc = lv_arc_create(parent);
lv_obj_set_size(arc, 112, 112);
lv_obj_align(arc, LV_ALIGN_TOP_MID, 0, 14);
lv_obj_set_size(arc, UI_ARC, UI_ARC);
/* Leave room under arc for min/max line (~16px) */
lv_obj_align(arc, LV_ALIGN_TOP_MID, 0, 2);
lv_arc_set_rotation(arc, 135);
lv_arc_set_bg_angles(arc, 0, 270);
lv_arc_set_range(arc, 0, max_val);
@@ -203,35 +283,66 @@ static lv_obj_t *make_gauge(lv_obj_t *parent, lv_color_t accent, int max_val) {
lv_obj_remove_style(arc, NULL, LV_PART_KNOB);
lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_style_arc_color(arc, COL_ARC_BG, LV_PART_MAIN);
lv_obj_set_style_arc_width(arc, 12, LV_PART_MAIN);
lv_obj_set_style_arc_width(arc, 10, LV_PART_MAIN);
lv_obj_set_style_arc_color(arc, accent, LV_PART_INDICATOR);
lv_obj_set_style_arc_width(arc, 12, LV_PART_INDICATOR);
lv_obj_set_style_arc_width(arc, 10, LV_PART_INDICATOR);
lv_obj_set_style_arc_rounded(arc, true, LV_PART_MAIN);
lv_obj_set_style_arc_rounded(arc, true, LV_PART_INDICATOR);
return arc;
}
/* Center value+unit as a group on the arc (re-run after text changes). */
static void layout_gauge_readout(lv_obj_t *arc, lv_obj_t *val, lv_obj_t *unit) {
const int gap = 3;
const int lift = 4; /* open-bottom arc: nudge readout slightly up */
lv_obj_update_layout(lv_obj_get_parent(arc));
lv_obj_update_layout(arc);
lv_obj_update_layout(val);
lv_obj_update_layout(unit);
const int32_t vw = lv_obj_get_width(val);
const int32_t vh = lv_obj_get_height(val);
const int32_t uw = lv_obj_get_width(unit);
const int32_t uh = lv_obj_get_height(unit);
const int32_t pair_w = vw + gap + uw;
const int32_t ax = lv_obj_get_x(arc);
const int32_t ay = lv_obj_get_y(arc);
const int32_t aw = lv_obj_get_width(arc);
const int32_t ah = lv_obj_get_height(arc);
const int32_t cx = ax + aw / 2;
const int32_t cy = ay + ah / 2 - lift;
const int32_t vx = cx - pair_w / 2;
const int32_t vy = cy - vh / 2;
lv_obj_set_pos(val, vx, vy);
/* Unit sits on the baseline of the value, to the right */
lv_obj_set_pos(unit, vx + vw + gap, vy + vh - uh - 1);
}
static void create_ui(void) {
lv_obj_t *scr = lv_screen_active();
lv_obj_set_style_bg_color(scr, COL_BG, 0);
lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, 0);
lv_obj_clear_flag(scr, LV_OBJ_FLAG_SCROLLABLE);
/* ---- header single row (0 .. UI_HDR_H), never under panels ---- */
lv_obj_t *title = lv_label_create(scr);
lv_label_set_text(title, "ROOM CLIMATE");
lv_obj_set_style_text_font(title, &lv_font_montserrat_16, 0);
lv_label_set_text(title, "CLIMATE");
lv_obj_set_style_text_font(title, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(title, COL_TEXT, 0);
lv_obj_align(title, LV_ALIGN_TOP_LEFT, 10, 6);
lv_obj_set_pos(title, UI_M, 4);
lbl_uptime = lv_label_create(scr);
lv_label_set_text(lbl_uptime, "tap: brightness");
lv_label_set_text(lbl_uptime, "up 00:00");
lv_obj_set_style_text_font(lbl_uptime, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_uptime, COL_MUTED, 0);
lv_obj_align(lbl_uptime, LV_ALIGN_TOP_LEFT, 10, 24);
lv_obj_align_to(lbl_uptime, title, LV_ALIGN_OUT_RIGHT_MID, 8, 1);
led_status = lv_led_create(scr);
lv_obj_set_size(led_status, 10, 10);
lv_obj_align(led_status, LV_ALIGN_TOP_RIGHT, -10, 10);
lv_obj_set_size(led_status, 9, 9);
lv_obj_align(led_status, LV_ALIGN_TOP_RIGHT, -UI_M, 6);
lv_led_set_color(led_status, COL_WARN);
lv_led_on(led_status);
@@ -239,106 +350,158 @@ static void create_ui(void) {
lv_label_set_text(lbl_status, "INIT");
lv_obj_set_style_text_font(lbl_status, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_status, COL_MUTED, 0);
lv_obj_align(lbl_status, LV_ALIGN_TOP_RIGHT, -26, 8);
lv_obj_align(lbl_status, LV_ALIGN_TOP_RIGHT, -(UI_M + 16), 4);
lv_obj_t *p_temp = make_panel(scr, 6, 40, 152, 132);
lbl_hint = lv_label_create(scr);
lv_label_set_text(lbl_hint, "");
lv_obj_set_style_text_font(lbl_hint, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_hint, COL_TEMP_WARM, 0);
lv_obj_set_style_bg_color(lbl_hint, COL_BG, 0);
lv_obj_set_style_bg_opa(lbl_hint, LV_OPA_COVER, 0);
lv_obj_set_style_pad_hor(lbl_hint, 6, 0);
lv_obj_align(lbl_hint, LV_ALIGN_TOP_MID, 0, 4);
lv_obj_add_flag(lbl_hint, LV_OBJ_FLAG_HIDDEN);
/* ---- gauge panels (start strictly below header) ---- */
const int gy = UI_HDR_H + UI_G; /* 28 */
lv_obj_t *p_temp = make_panel(scr, UI_M, gy, UI_GAUGE_W, UI_GAUGE_H);
lv_obj_t *t_cap = lv_label_create(p_temp);
lv_label_set_text(t_cap, "TEMP");
lv_obj_set_style_text_font(t_cap, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(t_cap, COL_MUTED, 0);
lv_obj_align(t_cap, LV_ALIGN_TOP_LEFT, 2, 0);
lv_obj_align(t_cap, LV_ALIGN_TOP_LEFT, 0, -2);
arc_temp = make_gauge(p_temp, COL_TEMP_OK, 50);
lbl_temp_val = lv_label_create(p_temp);
lv_label_set_text(lbl_temp_val, "--.-");
lv_obj_set_style_text_font(lbl_temp_val, &lv_font_montserrat_28, 0);
lv_obj_set_style_text_font(lbl_temp_val, &lv_font_montserrat_24, 0);
lv_obj_set_style_text_color(lbl_temp_val, COL_TEMP_OK, 0);
lv_obj_align(lbl_temp_val, LV_ALIGN_CENTER, 0, 6);
lv_obj_t *t_unit = lv_label_create(p_temp);
lv_label_set_text(t_unit, "C");
lv_obj_set_style_text_font(t_unit, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(t_unit, COL_MUTED, 0);
lv_obj_align(t_unit, LV_ALIGN_CENTER, 36, 10);
lbl_temp_unit = lv_label_create(p_temp);
lv_label_set_text(lbl_temp_unit, "C");
lv_obj_set_style_text_font(lbl_temp_unit, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_temp_unit, COL_MUTED, 0);
layout_gauge_readout(arc_temp, lbl_temp_val, lbl_temp_unit);
lbl_temp_range = lv_label_create(p_temp);
lv_label_set_text(lbl_temp_range, "min -- max --");
lv_label_set_text(lbl_temp_range, "-- / --");
lv_obj_set_style_text_font(lbl_temp_range, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_temp_range, COL_MUTED, 0);
lv_obj_align(lbl_temp_range, LV_ALIGN_BOTTOM_MID, 0, 0);
lv_obj_align(lbl_temp_range, LV_ALIGN_BOTTOM_MID, 0, 2);
lv_obj_t *p_hum = make_panel(scr, 162, 40, 152, 132);
lv_obj_t *p_hum = make_panel(scr, UI_M + UI_GAUGE_W + UI_G, gy, UI_GAUGE_W, UI_GAUGE_H);
lv_obj_t *h_cap = lv_label_create(p_hum);
lv_label_set_text(h_cap, "HUM");
lv_obj_set_style_text_font(h_cap, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(h_cap, COL_MUTED, 0);
lv_obj_align(h_cap, LV_ALIGN_TOP_LEFT, 2, 0);
lv_obj_align(h_cap, LV_ALIGN_TOP_LEFT, 0, -2);
arc_hum = make_gauge(p_hum, COL_HUM, 100);
lbl_hum_val = lv_label_create(p_hum);
lv_label_set_text(lbl_hum_val, "--.-");
lv_obj_set_style_text_font(lbl_hum_val, &lv_font_montserrat_28, 0);
lv_label_set_text(lbl_hum_val, "--");
lv_obj_set_style_text_font(lbl_hum_val, &lv_font_montserrat_24, 0);
lv_obj_set_style_text_color(lbl_hum_val, COL_HUM, 0);
lv_obj_align(lbl_hum_val, LV_ALIGN_CENTER, 0, 6);
lv_obj_t *h_unit = lv_label_create(p_hum);
lv_label_set_text(h_unit, "%");
lv_obj_set_style_text_font(h_unit, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(h_unit, COL_MUTED, 0);
lv_obj_align(h_unit, LV_ALIGN_CENTER, 36, 10);
lbl_hum_unit = lv_label_create(p_hum);
lv_label_set_text(lbl_hum_unit, "%");
lv_obj_set_style_text_font(lbl_hum_unit, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_hum_unit, COL_MUTED, 0);
layout_gauge_readout(arc_hum, lbl_hum_val, lbl_hum_unit);
lbl_hum_range = lv_label_create(p_hum);
lv_label_set_text(lbl_hum_range, "min -- max --");
lv_label_set_text(lbl_hum_range, "-- / --");
lv_obj_set_style_text_font(lbl_hum_range, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_hum_range, COL_MUTED, 0);
lv_obj_align(lbl_hum_range, LV_ALIGN_BOTTOM_MID, 0, 0);
lv_obj_align(lbl_hum_range, LV_ALIGN_BOTTOM_MID, 0, 2);
lv_obj_t *p_bot = make_panel(scr, 6, 176, 308, 58);
lbl_comfort = lv_label_create(p_bot);
lv_label_set_text(lbl_comfort, "WAITING");
/* ---- bottom: left info | right chart (no shared space) ---- */
lv_obj_t *p_bot = make_panel(scr, UI_M, UI_BOT_Y, UI_BOT_W, UI_BOT_H);
lv_obj_t *info = lv_obj_create(p_bot);
lv_obj_set_size(info, UI_INFO_W, UI_BOT_H - 12);
lv_obj_align(info, LV_ALIGN_LEFT_MID, 0, 0);
lv_obj_set_style_bg_opa(info, LV_OPA_TRANSP, 0);
lv_obj_set_style_border_width(info, 0, 0);
lv_obj_set_style_pad_all(info, 0, 0);
lv_obj_clear_flag(info, LV_OBJ_FLAG_SCROLLABLE);
lbl_comfort = lv_label_create(info);
lv_label_set_text(lbl_comfort, "WAIT");
lv_obj_set_style_text_font(lbl_comfort, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(lbl_comfort, COL_WARN, 0);
lv_obj_align(lbl_comfort, LV_ALIGN_TOP_LEFT, 4, 0);
lv_obj_set_width(lbl_comfort, UI_INFO_W);
lv_label_set_long_mode(lbl_comfort, LV_LABEL_LONG_CLIP);
lv_obj_align(lbl_comfort, LV_ALIGN_TOP_LEFT, 0, 0);
lbl_feels = lv_label_create(p_bot);
lv_label_set_text(lbl_feels, "FEELS -- DEW --");
lv_obj_set_style_text_font(lbl_feels, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_feels, COL_MUTED, 0);
lv_obj_align(lbl_feels, LV_ALIGN_TOP_RIGHT, -4, 2);
bar_comfort = lv_bar_create(p_bot);
lv_obj_set_size(bar_comfort, 120, 10);
lv_obj_align(bar_comfort, LV_ALIGN_TOP_LEFT, 4, 20);
bar_comfort = lv_bar_create(info);
lv_obj_set_size(bar_comfort, UI_INFO_W - 4, 8);
lv_obj_align(bar_comfort, LV_ALIGN_TOP_LEFT, 0, 20);
lv_bar_set_range(bar_comfort, 0, 100);
lv_bar_set_value(bar_comfort, 0, LV_ANIM_OFF);
lv_obj_set_style_bg_color(bar_comfort, COL_ARC_BG, LV_PART_MAIN);
lv_obj_set_style_bg_opa(bar_comfort, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_set_style_radius(bar_comfort, 5, LV_PART_MAIN);
lv_obj_set_style_radius(bar_comfort, 4, LV_PART_MAIN);
lv_obj_set_style_bg_color(bar_comfort, COL_WARN, LV_PART_INDICATOR);
lv_obj_set_style_radius(bar_comfort, 5, LV_PART_INDICATOR);
lv_obj_set_style_radius(bar_comfort, 4, LV_PART_INDICATOR);
lbl_feels = lv_label_create(info);
lv_label_set_text(lbl_feels, "Feel --.-");
lv_obj_set_style_text_font(lbl_feels, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_feels, COL_MUTED, 0);
lv_obj_set_width(lbl_feels, UI_INFO_W);
lv_label_set_long_mode(lbl_feels, LV_LABEL_LONG_CLIP);
lv_obj_align(lbl_feels, LV_ALIGN_TOP_LEFT, 0, 34);
lbl_dew = lv_label_create(info);
lv_label_set_text(lbl_dew, "Dew --.-");
lv_obj_set_style_text_font(lbl_dew, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_dew, COL_MUTED, 0);
lv_obj_set_width(lbl_dew, UI_INFO_W);
lv_label_set_long_mode(lbl_dew, LV_LABEL_LONG_CLIP);
lv_obj_align(lbl_dew, LV_ALIGN_TOP_LEFT, 0, 48);
chart = lv_chart_create(p_bot);
lv_obj_set_size(chart, 168, 28);
lv_obj_align(chart, LV_ALIGN_BOTTOM_RIGHT, -2, -2);
lv_obj_set_size(chart, UI_CHART_W, UI_BOT_H - 16);
lv_obj_align(chart, LV_ALIGN_RIGHT_MID, 0, 0);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE);
lv_chart_set_point_count(chart, HISTORY_LEN);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 10, 40);
lv_chart_set_range(chart, LV_CHART_AXIS_SECONDARY_Y, 0, 100);
lv_obj_set_style_bg_opa(chart, LV_OPA_TRANSP, 0);
lv_obj_set_style_border_width(chart, 0, 0);
lv_obj_set_style_pad_all(chart, 0, 0);
lv_chart_set_div_line_count(chart, 0, 0);
lv_chart_set_update_mode(chart, LV_CHART_UPDATE_MODE_SHIFT);
lv_obj_set_style_bg_color(chart, COL_CHART_BG, 0);
lv_obj_set_style_bg_opa(chart, LV_OPA_COVER, 0);
lv_obj_set_style_border_color(chart, COL_EDGE, 0);
lv_obj_set_style_border_width(chart, 1, 0);
lv_obj_set_style_radius(chart, 8, 0);
lv_obj_set_style_pad_all(chart, 4, 0);
lv_obj_set_style_line_width(chart, 2, LV_PART_ITEMS);
lv_chart_set_div_line_count(chart, 2, 4);
lv_obj_set_style_line_color(chart, COL_EDGE, LV_PART_MAIN);
lv_obj_set_style_line_opa(chart, LV_OPA_40, LV_PART_MAIN);
ser_temp = lv_chart_add_series(chart, COL_TEMP_WARM, LV_CHART_AXIS_PRIMARY_Y);
ser_hum = lv_chart_add_series(chart, COL_HUM, LV_CHART_AXIS_SECONDARY_Y);
/* Keep header above any later siblings if layout drifts */
lv_obj_move_foreground(title);
lv_obj_move_foreground(lbl_uptime);
lv_obj_move_foreground(lbl_status);
lv_obj_move_foreground(led_status);
lv_obj_move_foreground(lbl_hint);
}
static void refresh_meta(void) {
char buf[40];
uint32_t up = millis() / 1000;
lv_snprintf(buf, sizeof(buf), "up %02lu:%02lu bl %u/3",
lv_snprintf(buf, sizeof(buf), "up %02lu:%02lu bl%u",
(unsigned long)(up / 60), (unsigned long)(up % 60), (unsigned)bright_level);
lv_label_set_text(lbl_uptime, buf);
if (hint_until_ms && (int32_t)(millis() - hint_until_ms) >= 0) {
hint_until_ms = 0;
lv_obj_add_flag(lbl_hint, LV_OBJ_FLAG_HIDDEN);
}
if (sensor_ok) {
uint32_t age = (millis() - last_ok_ms) / 1000;
lv_snprintf(buf, sizeof(buf), "LIVE %lus", (unsigned long)age);
@@ -348,7 +511,7 @@ static void refresh_meta(void) {
}
static void update_ui(bool ok) {
char buf[40];
char buf[32];
if (ok && !isnan(disp_temp) && !isnan(disp_hum)) {
lv_color_t tc = temp_color(disp_temp);
@@ -356,34 +519,38 @@ static void update_ui(bool ok) {
lv_snprintf(buf, sizeof(buf), "%.1f", disp_temp);
lv_label_set_text(lbl_temp_val, buf);
lv_obj_set_style_text_color(lbl_temp_val, tc, 0);
layout_gauge_readout(arc_temp, lbl_temp_val, lbl_temp_unit);
lv_obj_set_style_arc_color(arc_temp, tc, LV_PART_INDICATOR);
anim_arc(arc_temp, (int)lroundf(constrain(disp_temp, 0.0f, 50.0f)));
lv_snprintf(buf, sizeof(buf), "%.0f", disp_hum);
lv_label_set_text(lbl_hum_val, buf);
layout_gauge_readout(arc_hum, lbl_hum_val, lbl_hum_unit);
anim_arc(arc_hum, (int)lroundf(constrain(disp_hum, 0.0f, 100.0f)));
lv_snprintf(buf, sizeof(buf), "min %.0f max %.0f", min_temp, max_temp);
lv_snprintf(buf, sizeof(buf), "%.0f / %.0f", min_temp, max_temp);
lv_label_set_text(lbl_temp_range, buf);
lv_snprintf(buf, sizeof(buf), "min %.0f max %.0f", min_hum, max_hum);
lv_snprintf(buf, sizeof(buf), "%.0f / %.0f", min_hum, max_hum);
lv_label_set_text(lbl_hum_range, buf);
float feels = heat_index_c(disp_temp, disp_hum);
float dew = dew_point_c(disp_temp, disp_hum);
lv_snprintf(buf, sizeof(buf), "FEELS %.1f DEW %.1f", feels, dew);
lv_snprintf(buf, sizeof(buf), "Feel %.1f", feels);
lv_label_set_text(lbl_feels, buf);
lv_snprintf(buf, sizeof(buf), "Dew %.1f", dew);
lv_label_set_text(lbl_dew, buf);
lv_color_t cc = comfort_color(disp_temp, disp_hum);
lv_label_set_text(lbl_comfort, comfort_text(disp_temp, disp_hum));
lv_obj_set_style_text_color(lbl_comfort, cc, 0);
lv_bar_set_value(bar_comfort, comfort_score(disp_temp, disp_hum), LV_ANIM_ON);
anim_bar(bar_comfort, comfort_score(disp_temp, disp_hum));
lv_obj_set_style_bg_color(bar_comfort, cc, LV_PART_INDICATOR);
lv_chart_set_next_value(chart, ser_temp, (int32_t)lroundf(disp_temp));
lv_chart_set_next_value(chart, ser_hum, (int32_t)lroundf(disp_hum));
refresh_meta();
} else {
lv_label_set_text(lbl_comfort, "SENSOR ERROR");
lv_label_set_text(lbl_comfort, "ERROR");
lv_obj_set_style_text_color(lbl_comfort, COL_BAD, 0);
lv_label_set_text(lbl_status, "ERR");
lv_led_set_color(led_status, COL_BAD);
@@ -439,16 +606,19 @@ void setup() {
lv_init();
touchscreenSPI.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
touchscreen.begin(touchscreenSPI);
touchscreen.setRotation(2);
touch_init();
#if defined(CYD_BOARD_3248S035)
lv_display_t *disp = lv_tft_espi_create(320, 480, draw_buf, sizeof(draw_buf));
#else
lv_display_t *disp = lv_tft_espi_create(240, 320, draw_buf, sizeof(draw_buf));
#endif
lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270);
lv_indev_t *indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev, touchscreen_read);
lv_indev_set_display(indev, disp);
create_ui();
delay(1500);

193
src/touch.cpp Normal file
View File

@@ -0,0 +1,193 @@
#include "touch.h"
#include <Arduino.h>
/**
* 2.8": XPT2046 resistive SoftSPI bus (CS33).
* 3.5C (3248S035C): GT911 capacitive on I2C Wire SDA33/SCL32/INT21/RST25.
* Feed coords are always native panel 320x480 for LVGL ROTATION_270.
* (DHT11 is 1-wire on GPIO22 — Wire is free for GT911.)
*/
static int16_t clampi(int32_t v, int32_t lo, int32_t hi) {
if (v < lo) return (int16_t)lo;
if (v > hi) return (int16_t)hi;
return (int16_t)v;
}
#if defined(CYD_BOARD_3248S035)
#include <Wire.h>
/* Native panel size — not UI landscape SCREEN_* (480x320). */
static constexpr int16_t PANEL_W = 320;
static constexpr int16_t PANEL_H = 480;
#define CYD_GT911_SDA 33
#define CYD_GT911_SCL 32
#define CYD_GT911_INT 21
#define CYD_GT911_RST 25
/* Minimal GT911 — no config rewrite (TAMC setResolution can hang Wire). */
static uint8_t s_gt_addr = 0x5D;
static constexpr uint16_t GT_POINT_INFO = 0x814E;
static constexpr uint16_t GT_POINT_1 = 0x814F;
static bool gt_write8(uint16_t reg, uint8_t val) {
Wire.beginTransmission(s_gt_addr);
Wire.write((uint8_t)(reg >> 8));
Wire.write((uint8_t)(reg & 0xFF));
Wire.write(val);
return Wire.endTransmission() == 0;
}
static bool gt_read(uint16_t reg, uint8_t *buf, uint8_t len) {
Wire.beginTransmission(s_gt_addr);
Wire.write((uint8_t)(reg >> 8));
Wire.write((uint8_t)(reg & 0xFF));
if (Wire.endTransmission(false) != 0) {
return false;
}
const uint8_t n = Wire.requestFrom(s_gt_addr, len);
if (n != len) {
return false;
}
for (uint8_t i = 0; i < len; i++) {
buf[i] = Wire.read();
}
return true;
}
static bool gt_probe(uint8_t addr) {
Wire.beginTransmission(addr);
return Wire.endTransmission() == 0;
}
/* TAMC-compatible address select: INT low => 0x5D, INT high => 0x14 */
static void gt_hw_reset(bool addr_0x14) {
pinMode(CYD_GT911_INT, OUTPUT);
pinMode(CYD_GT911_RST, OUTPUT);
digitalWrite(CYD_GT911_INT, LOW);
digitalWrite(CYD_GT911_RST, LOW);
delay(10);
digitalWrite(CYD_GT911_INT, addr_0x14 ? HIGH : LOW);
delay(1);
digitalWrite(CYD_GT911_RST, HIGH);
delay(5);
digitalWrite(CYD_GT911_INT, LOW);
delay(50);
/* Backlight is GPIO27 — leave INT as input for polling / optional IRQ. */
pinMode(CYD_GT911_INT, INPUT);
delay(50);
}
static bool gt_find_addr() {
for (uint8_t a : {uint8_t(0x5D), uint8_t(0x14)}) {
if (gt_probe(a)) {
s_gt_addr = a;
return true;
}
}
return false;
}
void touch_init() {
Serial.println("Touch: GT911 I2C capacitive (3.5C) minimal");
Wire.begin(CYD_GT911_SDA, CYD_GT911_SCL);
Wire.setClock(100000);
#if defined(WIRE_HAS_TIMEOUT) || defined(ESP32)
Wire.setTimeOut(50);
#endif
if (!gt_find_addr()) {
Serial.println("GT911 not found — hw reset 0x5D");
gt_hw_reset(false);
if (!gt_find_addr()) {
Serial.println("GT911 not found — hw reset 0x14");
gt_hw_reset(true);
gt_find_addr();
}
}
Serial.printf("GT911 probe 0x5D=%s 0x14=%s using=0x%02X\n",
gt_probe(0x5D) ? "OK" : "no", gt_probe(0x14) ? "OK" : "no",
s_gt_addr);
Serial.printf("GT911 SDA=%d SCL=%d INT=%d RST=%d\n", CYD_GT911_SDA,
CYD_GT911_SCL, CYD_GT911_INT, CYD_GT911_RST);
}
void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) {
uint8_t info = 0;
if (!gt_read(GT_POINT_INFO, &info, 1)) {
data->state = LV_INDEV_STATE_RELEASED;
return;
}
const uint8_t touches = info & 0x0F;
const bool buffered = (info & 0x80) != 0;
if (!buffered || touches == 0) {
if (buffered) {
gt_write8(GT_POINT_INFO, 0);
}
data->state = LV_INDEV_STATE_RELEASED;
return;
}
uint8_t pt[7];
if (!gt_read(GT_POINT_1, pt, 7)) {
gt_write8(GT_POINT_INFO, 0);
data->state = LV_INDEV_STATE_RELEASED;
return;
}
gt_write8(GT_POINT_INFO, 0);
const int16_t raw_x = (int16_t)(pt[1] | (pt[2] << 8));
const int16_t raw_y = (int16_t)(pt[3] | (pt[4] << 8));
/* Native 320x480 → LVGL 270. UI ≈ (H-1-raw_y, raw_x). */
const int16_t nx = clampi(raw_x, 0, PANEL_W - 1);
const int16_t ny = clampi(raw_y, 0, PANEL_H - 1);
data->point.x = (int16_t)((PANEL_W - 1) - nx);
data->point.y = (int16_t)((PANEL_H - 1) - ny);
data->state = LV_INDEV_STATE_PRESSED;
}
#else
#include <SPI.h>
#include <XPT2046_Touchscreen.h>
#define XPT2046_IRQ 36
#define XPT2046_MOSI 32
#define XPT2046_MISO 39
#define XPT2046_CLK 25
#define XPT2046_CS 33
/* 2.8 UI landscape feed (unchanged from prior main.cpp). */
static constexpr int16_t UI_W = 320;
static constexpr int16_t UI_H = 240;
static SPIClass touchscreenSPI = SPIClass(VSPI);
static XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);
void touch_init() {
touchscreenSPI.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
touchscreen.begin(touchscreenSPI);
touchscreen.setRotation(2);
Serial.println("Touch: XPT2046 resistive (2.8)");
}
void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) {
if (touchscreen.tirqTouched() && touchscreen.touched()) {
TS_Point p = touchscreen.getPoint();
data->point.x = map(p.y, 240, 3800, 1, UI_W);
data->point.y = map(p.x, 200, 3700, UI_H, 1);
data->state = LV_INDEV_STATE_PRESSED;
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
}
#endif