c
module main
{
  type state_t = enum { HEATING, COOLING };

  var state : state_t;
  input temperature : real;
  output heatOn : boolean;
  output heatOff : boolean;

  const setpoint : real = 20.0;
  const upperThreshold : real = 22.0;
  const lowerThreshold : real = 18.0;

  init {
    state = HEATING; // Initial state
    heatOn = false;
    heatOff = false;
  }

  next {
    if (state == HEATING) {
      if (temperature >= upperThreshold) {
        heatOn = false;
      } else if (temperature <= setpoint) {
        heatOn = true;
      } else {
        heatOn = false;
      }
    } else {
      if (temperature <= lowerThreshold) {
        heatOff = false;
      } else if (temperature >= setpoint) {
        heatOff = true;
      } else {
        heatOff = false;
      }
    }

    if (heatOn) {
      state = HEATING;
    } else if (heatOff) {
      state = COOLING;
    }
  }
}
