2 releases
Uses old Rust 2015
0.0.2 | Jun 18, 2018 |
---|---|
0.0.1 | Jun 8, 2018 |
#1345 in Embedded development
22KB
298 lines
thermostat
This library provides a finite state machine for a thermostat controlling a centralized HVAC system or other heating and/or cooling apparatus.
WARNING: This library is under active development. It is not currently intended for production use.
License
Licensed under either of:
- MIT license (LICENSE or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
This crate provides a finite state machine for a thermostat controlling a centralized HVAC system or other heating and/or cooling apparatus.
The goal of this component is to provide an abstracted thermostat that can be embedded in any device where temperature and/or humidity must be controlled (e.g., homes, offices, refigerators, kegerators). The library is starting out with a simple hysteretic control algorithm using temperature and humidity measurements. Progressing from there, this library will look at various stratgies to continually optimize in-situ for objectievs such as power conservation, system lifespan, or predicted demand.
This crate is not currently suitable for use with multi-stage or other controlled variable load applications. It was designed on a model of simple on-or-off heating and cooling devices found with in most HVAC systems and refigeration compressors.
The thermostat uses double-precision floating-point format for representing both temperature in degrees Celsius and percent relative humidity.
Usage Example
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();
}