-//TODO:
-// have a minimun time for each state to protect on-off on the fan and the heating element
-
 //The MIT License (MIT)
 //Copyright (c) 2016 Gustavo Gonnet
 //

// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#include "application.h"
#include "elapsedMillis.h"
#include "PietteTech_DHT.h"
#include "FiniteStateMachine.h"

#define APP_NAME "Thermostat"
// IO mapping
// D0 : relay: fan
// D1 : relay: heat
// D2 : relay: cold
// D3 : relay:
// D4 : DHT22
// D5 : unused
// D6 : unused
// D7 : unused
// A0~A7 : unused

//initialize states with proper enter, update and exit functions
State initState = State( initEnterFunction, initUpdateFunction, initExitFunction );
State idleState = State( idleEnterFunction, idleUpdateFunction, idleExitFunction );
State heatingState = State( heatingEnterFunction, heatingUpdateFunction, heatingExitFunction );

void dht_wrapper() { DHT.isrCallback(); }


/*******************************************************************************
 * Function Name  : loop
 * Description    : this function runs continuously while the project is running
 *******************************************************************************/
void loop() {

  //this function reads the temperature of the DHT sensor
  readTemperature();

  //this function updates the FSM
  // the FSM is the heart of the thermostat - all actions are defined by its states
  thermostatStateMachine.update();

}

/*******************************************************************************
