This crate provides a state machine for an HVAC controller.
HVAC control systems regulate the operation of a heating and/or air conditioning system. Essentially, they turn on or off the heating, cooling, and air circulation as instructed by some other system–typically a thermostat.
This crate currently supports only single-stage HVAC implementations wherein the heating and cooling systems can be either on or off with no intermediate states of operation. Optional constraints on the minimum run and recovery time are supported for the heat, cool, and fan services.
This crate has no dependencies on the standard library or any other crates, making it
easily used in standard applications as well as embedded targets leveraging
#![no_std]
.
```rust 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 hvaccontroller = Hvac::default() .withheat(None, Some(60)) .withcool(Some(300), Some(300)) .withfan(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 = hvaccontroller.tick(i);
// even though we have called for
// heat, it will not be enabled
// until we have met our 60 second
// minimum recovery time
asserteq!(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 = hvaccontroller.tick(60); // we have now met our minimum recover // time and heat is enabled asserteq!(state.service, Some(HvacService::Heat)); // along with the fan assert_eq!(state.fan, true);
// we can now call for cool let state = hvaccontroller.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 asserteq!(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 = hvaccontroller.tick(300); asserteq!(state.service, Some(HvacService::Cool)); // fan also starts again assert_eq!(state.fan, true);
// we idle the system calls let state = hvaccontroller.idle(); // which has no immediate effect because // of cool's min run time asserteq!(state.service, Some(HvacService::Cool)); assert_eq!(state.fan, true);
// we disable auto mode for the fan let state = hvaccontroller.fanauto(false); // which still has no immediate effect asserteq!(state.service, Some(HvacService::Cool)); asserteq!(state.fan, true);
// until we advance another 300 seconds // elapsed to meet cool's min run time let state = hvaccontroller.tick(600); // now cool has stopped but fan // continues with auto mode disabled asserteq!(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 = hvaccontroller.fanauto(true); assert_eq!(state.fan, false); ```
Licensed under either of the following, at your option:
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.