Crate thermostat[][src]

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::{Measurement, OperatingMode, Thermostat, Error as ThermostatError};

enum HvacStatus {
    HeatOn,
    CoolOn,
    Off,
}

fn call_for_heat() -> Result<(), ThermostatError> {
    println!("calling for heat...");
    Ok(())
}

fn stop_call_for_heat() -> Result<(), ThermostatError> {
    println!("stopping call for heat...");
    Ok(())
}

fn call_for_cool() -> Result<(), ThermostatError> {
    println!("calling for cool...");
    Ok(())
}

fn stop_call_for_cool() -> Result<(), ThermostatError> {
    println!("stopping call for cool...");
    Ok(())
}

fn call_for_fan() -> Result<(), ThermostatError> {
    println!("calling for fan...");
    Ok(())
}

fn stop_call_for_fan() -> Result<(), ThermostatError> {
    println!("stopping call for fan...");
    Ok(())
}

fn measure_temp_and_humidity() -> Result<Measurement, ThermostatError> {
    Ok(Measurement {
        temperature: 15.0,
        humidity: 40.0,
    })
}

fn main() {
    // create a new thermostat with default settings
    let mut thermostat = Thermostat::default();

    // register interfaces with device native implementation
    thermostat.use_heat(call_for_heat, stop_call_for_heat);
    thermostat.use_cool(call_for_cool, stop_call_for_cool);
    thermostat.use_fan(call_for_fan, stop_call_for_fan);
    thermostat.use_measure(measure_temp_and_humidity);

    // 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.change_maximum_set_temperature(22.5).unwrap();
    // set min temp thermostat will allow before calling for heat
    thermostat.change_minimum_set_temperature(18.0).unwrap();
    // maintain temperatures between min and max set points
    thermostat.change_operating_mode(OperatingMode::MaintainRange).unwrap();
}

Structs

Measurement

Temperature and humidity measurement

Thermostat

Thermostat state machine

Enums

Error

Thermostat errors

OperatingMode

Various thermostat operating modes