1 个不稳定版本
0.1.0 | 2018年10月29日 |
---|
#867 在 嵌入式开发
20KB
262 行
hvac
本crate提供了一个HVAC控制器的状态机。
HVAC控制系统调节加热和/或空调系统的运行。本质上,它们根据其他系统的指令(通常是恒温器)打开或关闭加热、冷却和空气循环。
本crate目前仅支持单阶段HVAC实现,其中加热和冷却系统可以开启或关闭,没有操作的中继状态。支持对加热、冷却和风扇服务的最小运行和恢复时间的可选约束。
本crate不依赖于标准库或任何其他crate,使其易于在标准应用程序以及利用#![no_std]
的嵌入式目标中使用。
示例
use hvac::prelude::*;
// create a new hvac controller with the
// following constraints:
//
// heat:
// - no min run time
// - min recover of 1 minute (60 sec)
//
// cool:
// - min run time of 5 minutes (300 sec)
// - min recover of 5 minutes (300 sec)
//
// fan:
// - no min run time
// - no min recovery
let mut hvac_controller = Hvac::default()
.with_heat(None, Some(60))
.with_cool(Some(300), Some(300))
.with_fan(None, None);
// enable heat as soon as permissible
let state = hvac_controller.heat();
for i in 0..60 {
// advance state machine to `i`
// seconds elapsed
let state = hvac_controller.tick(i);
// even though we have called for
// heat, it will not be enabled
// until we have met our 60 second
// minimum recovery time
assert_eq!(state.service, None);
// and since the fan is set to auto
// by default, it remains disabled
assert_eq!(state.fan, false);
}
// once the state machine is at
// 60 seconds elappsed...
let state = hvac_controller.tick(60);
// we have now met our minimum recover
// time and heat is enabled
assert_eq!(state.service, Some(HvacService::Heat));
// along with the fan
assert_eq!(state.fan, true);
// we can now call for cool
let state = hvac_controller.cool();
// and heat will be immediately disabled
// since we gave it no min run time but
// cool is not immediately enabled due
// to its 300 second recovery time
assert_eq!(state.service, None);
// fan is still set to auto and has no
// minimum run time, it is also disabled
assert_eq!(state.fan, false);
// advancing to cool's minimum recovery
// time will result in cool starting
let state = hvac_controller.tick(300);
assert_eq!(state.service, Some(HvacService::Cool));
// fan also starts again
assert_eq!(state.fan, true);
// we idle the system calls
let state = hvac_controller.idle();
// which has no immediate effect because
// of cool's min run time
assert_eq!(state.service, Some(HvacService::Cool));
assert_eq!(state.fan, true);
// we disable auto mode for the fan
let state = hvac_controller.fan_auto(false);
// which still has no immediate effect
assert_eq!(state.service, Some(HvacService::Cool));
assert_eq!(state.fan, true);
// until we advance another 300 seconds
// elapsed to meet cool's min run time
let state = hvac_controller.tick(600);
// now cool has stopped but fan
// continues with auto mode disabled
assert_eq!(state.service, None);
assert_eq!(state.fan, true);
// without a minimum run time, fan will
// immediately shut down when put back
// into auto mode
let state = hvac_controller.fan_auto(true);
assert_eq!(state.fan, false);
许可证
以下两者中选择一项,由您决定
- Apache许可证版本2.0,(LICENSE-APACHE 或 http://www.apache.org/licenses/LICENSE-2.0)
- MIT许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
贡献
除非您明确表示,否则任何有意提交给作品以供包含的贡献,如Apache-2.0许可证所定义,应如上双许可,不附加任何额外条款或条件。