diff --git a/apps/usr_app/app_th.c b/apps/usr_app/app_th.c index 74113a5..f30e558 100644 --- a/apps/usr_app/app_th.c +++ b/apps/usr_app/app_th.c @@ -2,9 +2,8 @@ * @file app_th.c * @brief CBR3 温湿度采集实现 * @author cyWu <1917507415@qq.com> - * @date 2026.08.31 - * @version V1.1.0,发令阶段 nack 也计入连续失败;fault_code 由上层映射为 1 - * (规格书 V3.0.0:fault 编号不变,DP 号随协议右移为 DP24) + * @date 2026.09.03 + * @version V1.3.0,对外温湿度与显示/上报绑死(T>=0.5℃ / H>=2%) ******************************************************************************/ #include "app_th.h" @@ -32,8 +31,8 @@ typedef struct { ThState_t state; uint16_t poll_ms; /**< 距上次采样的累计毫秒 */ uint32_t wait_t0; /**< 测量命令发出时刻 */ - int16_t temp_x10; /**< 最近有效温度 ×10 */ - uint8_t humi; /**< 最近有效湿度 % */ + int16_t temp_pub; /**< 对外温度 ×10(显示/上报/联动,|ΔT|>=0.5℃ 才改) */ + uint8_t humi_pub; /**< 对外湿度 %(显示/上报/联动,|ΔH|>=2 才改) */ uint8_t valid; /**< 1=有有效采样 */ uint8_t fail_cnt; /**< 连续失败次数 */ uint8_t last_ok; /**< 最近一次采样是否成功(app_linkage 8.4 用) */ @@ -125,17 +124,39 @@ void app_th_poll(uint16_t dt) /* IO 分离后无总线竞争,finish 不会返回 -2;0=成功,-1=通讯失败 */ s_th.state = TH_ST_IDLE; if (ret == 0) { - s_th.temp_x10 = t; - s_th.humi = h; + int16_t dt_x10; + uint8_t dh; + + /* 首次成功直接跟上;之后相对对外值达到阈值才改显示/上报/联动 */ + if (!s_th.valid) { + s_th.temp_pub = t; + s_th.humi_pub = h; + } else { + dt_x10 = (int16_t)(t - s_th.temp_pub); + if (dt_x10 < 0) { + dt_x10 = (int16_t)(-dt_x10); + } + if (dt_x10 >= BOARD_TH_TEMP_PUB_DELTA_X10) { + s_th.temp_pub = t; + } + dh = (h > s_th.humi_pub) ? (uint8_t)(h - s_th.humi_pub) + : (uint8_t)(s_th.humi_pub - h); + if (dh >= BOARD_TH_HUMI_PUB_DELTA) { + s_th.humi_pub = h; + } + } s_th.fail_cnt = 0; s_th.valid = 1; s_th.last_ok = 1; /* 先填值再置 pending:消费者关中断取,生产者是中断,顺序无歧义 */ - s_th_pending_t = t; - s_th_pending_h = h; + s_th_pending_t = s_th.temp_pub; + s_th_pending_h = s_th.humi_pub; s_th_pending = 1; - log_info("th %d.%dC %d%%\n", - (int)(t / 10), (int)((t < 0) ? (-t % 10) : (t % 10)), h); + log_info("th raw=%d.%dC/%d%% pub=%d.%dC/%d%%\n", + (int)(t / 10), (int)((t < 0) ? (-t % 10) : (t % 10)), (int)h, + (int)(s_th.temp_pub / 10), + (int)((s_th.temp_pub < 0) ? (-s_th.temp_pub % 10) : (s_th.temp_pub % 10)), + (int)s_th.humi_pub); } else { th_on_fail(); } @@ -153,21 +174,21 @@ uint8_t app_th_get_valid(void) } /** - * @brief 最近一次有效温度 + * @brief 对外温度(数码管 + DP3 + 联动) * @return 温度 ×10 */ int16_t app_th_get_temp_x10(void) { - return s_th.temp_x10; + return s_th.temp_pub; } /** - * @brief 最近一次有效湿度 + * @brief 对外湿度(数码管 + DP4 + 联动) * @return 湿度 0~100 整数 % */ uint8_t app_th_get_humi(void) { - return s_th.humi; + return s_th.humi_pub; } /** diff --git a/apps/usr_app/app_th.h b/apps/usr_app/app_th.h index 0a4be63..9c5e264 100644 --- a/apps/usr_app/app_th.h +++ b/apps/usr_app/app_th.h @@ -2,13 +2,14 @@ * @file app_th.h * @brief CBR3 温湿度采集:2s 周期、失败计数、最近有效值 * @author cyWu <1917507415@qq.com> - * @date 2026.08.31 - * @version V1.1.0,发令阶段 nack 也计入连续失败 + * @date 2026.09.03 + * @version V1.3.0,对外温湿度与显示/上报绑死(T>=0.5℃ / H>=2%) * - * @note 规格书 8.4:联动只在本次采样成功时用新值比较;采样失败保持 - * 上一有效值继续判(与显示一致),直到连续 3 次失败显示 "--" - * (DP24 fault_code=1)。fault_code=2 预留,本模块只给出 - * is_fault,由 app_function 映射。 + * @note 规格书 8.4:联动、数码管、DP3/DP4 都用对外温湿度;采样失败保持 + * 上一对外值继续判,直到连续 3 次失败显示 "--"(DP24 + * fault_code=1)。对外值首次跟上,之后 + * |ΔT|>=BOARD_TH_TEMP_PUB_DELTA_X10、|ΔH|>=BOARD_TH_HUMI_PUB_DELTA + * 才改,避免小数抖动导致显示、APP、联动各跳。 ******************************************************************************/ #ifndef __APP_TH_H__ @@ -36,13 +37,13 @@ void app_th_poll(uint16_t dt); uint8_t app_th_get_valid(void); /** - * @brief 最近一次有效温度 + * @brief 对外温度(数码管 + DP3 + 联动) * @return 温度 ×10(如 25.3℃ → 253) */ int16_t app_th_get_temp_x10(void); /** - * @brief 最近一次有效湿度 + * @brief 对外湿度(数码管 + DP4 + 联动) * @return 湿度 0~100 整数 % */ uint8_t app_th_get_humi(void); @@ -72,9 +73,9 @@ uint8_t app_th_last_sample_ok(void); * 消费者(usr_ble_adv_updata,BLE 线程任务上下文)调本函数取走, * 内部 local_irq_disable 保护,取到即清。 * 只在真正采样成功(last_ok 那次)时产生,失败/fault 不产生, - * 取到的就是本次新值而不是历史有效值。 - * @param t_x10 出参:温度 ×10(可为 NULL) - * @param h 出参:湿度 %(可为 NULL) + * 温度、湿度都是对外值(与数码管/DP3/DP4 一致)。 + * @param t_x10 出参:对外温度 ×10(可为 NULL) + * @param h 出参:对外湿度 %(可为 NULL) * @return 1=取到一次新采样,0=无新采样 */ uint8_t app_th_take_sample(int16_t *t_x10, uint8_t *h); diff --git a/apps/usr_periph/board_pin.h b/apps/usr_periph/board_pin.h index 3a2fbeb..44a140b 100644 --- a/apps/usr_periph/board_pin.h +++ b/apps/usr_periph/board_pin.h @@ -146,6 +146,8 @@ #define BOARD_TH_PERIOD_MS 2000 /**< 采集周期 2s(手册要求 >1s,规格书第 2.3/18 章) */ #define BOARD_TH_FAIL_MAX 3 /**< 连续失败 3 次判传感器故障 */ +#define BOARD_TH_HUMI_PUB_DELTA 2 /**< 对外湿度:相对上次 |ΔH|>=2% 才更新显示/上报 */ +#define BOARD_TH_TEMP_PUB_DELTA_X10 5 /**< 对外温度:相对上次 |ΔT|>=0.5℃ 才更新显示/上报 */ #define BOARD_AHT20_WAIT_MS 80 /**< 测量等待时长 */ #define BOARD_AHT20_I2C_HZ 100000 /**< 软件 I2C 时钟 */