/*
 * thermostat.h
 *
 *  Created on: Jun 27, 2020
 *      Author: hoo2
 */

#ifndef THERMOSTAT_H_
#define THERMOSTAT_H_

#define  MEAS_WINDOW       (120)    // [sec]
#define  MEAS_INTERVAL     (5)      // [sec]
#define  MEASUREMENTS      (MEAS_WINDOW / MEAS_INTERVAL)    // keep this integer
#define  UI_AVERAGE_TIME   (10)     // [sec]
//#define  UI_USER_TIME      (10)

typedef float  float_t;
typedef int    int_t;

typedef enum {
   HEATING =0,
   COOLING
} mode_en;

typedef struct {
   float_t  T[MEASUREMENTS];
   float_t  Tav;
   uint32_t cur;
   uint8_t  flag_output;
   uint8_t  flag_init;
   uint8_t  flag_proximity;
   uint8_t  signal_cycle;
} app_data_t;


typedef struct {
   mode_en  mode;
   float_t  Tset;
   float_t  Thyst;
   float_t  Pset;
   float_t  Physt;
} settings_t;

typedef enum {
   ST_INIT =0,
   ST_COUNT,
   ST_AVERAGE,
   ST_USER
} state_en;

/*
 * globals
 */
extern app_data_t     app_data;
extern state_en       state;
extern settings_t     settings;

#define _Init_settings(s)  s = { \
      .mode = HEATING,           \
      .Tset = 21.0,              \
      .Thyst = 2.0,              \
      .Pset = 75.0,              \
      .Physt = 10.0              \
}
#endif /* THERMOSTAT_H_ */
