2个版本
使用旧Rust 2015
0.0.2 | 2018年6月18日 |
---|---|
0.0.1 | 2018年6月8日 |
#1402 在 嵌入式开发
22KB
298 行
恒温器
此库为控制集中式HVAC系统或其他加热和/或冷却设备的恒温器提供有限状态机。
警告:此库正在积极开发中。目前不打算用于生产。
许可协议
许可协议为以下之一
- MIT许可证(《LICENSE》或 http://opensource.org/licenses/MIT》)
- Apache许可证,版本2.0(《LICENSE-APACHE》或 https://apache.ac.cn/licenses/LICENSE-2.0》)
任选其一。
贡献
除非您明确说明,否则您有意提交以包含在作品中并由您定义的Apache-2.0许可证所定义的任何贡献,均将按上述方式双重许可,而无需任何额外的条款或条件。
lib.rs
:
此crate提供用于控制集中式HVAC系统或其他加热和/或冷却设备的恒温器的有限状态机。
此组件的目标是提供一个抽象的恒温器,可以嵌入任何需要控制温度和/或湿度的设备中(例如,家庭、办公室、冰箱、啤酒机)。库从使用温度和湿度测量的简单滞环控制算法开始。在此基础上,此库将考虑各种策略,以不断优化针对节能、系统寿命或预测需求等目标。
此crate目前不适用于多阶段或其他受控变量负载应用。它基于大多数HVAC系统和制冷压缩机的简单开/关加热和冷却设备模型进行设计。
恒温器使用双精度浮点格式表示摄氏度温度和百分比相对湿度。
使用示例
extern crate thermostat;
use thermostat::{OperatingMode, Thermostat, Error as ThermostatError, ThermostatInterface};
struct MyThermostatInterface {}
impl ThermostatInterface for MyThermostatInterface {
fn calling_for_heat(&self) -> Result<bool, ThermostatError> {
Ok(true) // return if we are currently calling for heat
}
fn call_for_heat(&self) -> Result<(), ThermostatError> {
Ok(())
}
fn stop_call_for_heat(&self) -> Result<(), ThermostatError> {
Ok(())
}
fn calling_for_cool(&self) -> Result<bool, ThermostatError> {
Ok(true) // return if we are currently calling for cool
}
fn call_for_cool(&self) -> Result<(), ThermostatError> {
Ok(())
}
fn stop_call_for_cool(&self) -> Result<(), ThermostatError> {
Ok(())
}
fn calling_for_fan(&self) -> Result<bool, ThermostatError> {
Ok(true) // return if we are currently calling for fan
}
fn call_for_fan(&self) -> Result<(), ThermostatError> {
Ok(())
}
fn stop_call_for_fan(&self) -> Result<(), ThermostatError> {
Ok(())
}
fn get_seconds(&self) -> Result<u64, ThermostatError> {
Ok(0) // actually return seconds elapsed here
}
}
fn main() {
// create a new physical interface for the thermostat
let interface = MyThermostatInterface {};
// create a new thermostat with our physical interface
let mut thermostat = Thermostat::new(&interface);
// once the thermostat has been provided with a measure routine
// it will begin polling for new measurements and calling for
// heat, cool, and/or fan -- depending on which methods have
// been registered.
// set max temp thermostat will allow before calling for cool
thermostat.set_maximum_set_temperature(22.5).unwrap();
// set min temp thermostat will allow before calling for heat
thermostat.set_minimum_set_temperature(18.0).unwrap();
// maintain temperatures between min and max set points
thermostat.set_operating_mode(OperatingMode::MaintainRange).unwrap();
}