#ifndef GLBLDATA_H
#define GLBLDATA_H
#include <Arduino.h>
#define OPEN true
#define CLOSE false

#define V1_SET 0
#define V2_SET 1
#define V3_SET 2
#define V4_SET 3
#define V5_SET 4
#define V6_SET 5
#define V7_SET 6

#define V1_RES 8
#define V2_RES 9
#define V3_RES 10
#define V4_RES 11
#define V5_RES 12
#define V6_RES 13
#define V7_RES 14

#define LED1 16
#define LED2 17
#define LED3 18
#define LED4 19
#define LED5 20
#define LED6 21
#define LED7 22


#define RST_V(x) {ios.setBitOn(x+8);ios.setBitOff(x);ios.setBitOff(x+16);}
#define SET_V(x) {ios.setBitOff(x+8);ios.setBitOn(x);ios.setBitOn(x+16);}
#define KEEP_V(x) {ios.setBitOff(x);ios.setBitOff(x+8);}
#define MOTOR_POWER_TIME 15*2 //15secs scaled to 500msec timing
#define POWER_VALVES ios.setBitOff(1);ios.setBitOn(9)
#define UNPOWER_VALVES ios.setBitOff(9);ios.setBitOn(1)

#define NUM_VALVES 7




typedef enum valvestate_e{
    VALVE_CLOSED = 0,
    VALVE_CLOSED_MOTORIZED,
    VALVE_CLOSED_COILPWR,
    VALVE_OPENING_POWER_COILPWR,
    VALVE_OPENING_POWER,
    VALVE_CLOSING_POWER_COILPWR,
    VALVE_CLOSING_POWER,
    VALVE_CLOSING_COILPWR,
    VALVE_CLOSING,
    VALVE_OPENING_COILPWR,
    VALVE_OPENING,
    VALVE_OPEN_MOTORIZED,
    VALVE_OPEN_COILPWR,
    VALVE_OPEN,
    VALVE_NUM_STATES
  }valvestate_t;


typedef struct dataset_s{
    bool setValveState[NUM_VALVES] = {CLOSE};
    valvestate_t valveState[NUM_VALVES] = {VALVE_CLOSED};
    uint32_t timers[NUM_VALVES] = {0};
    bool statusChange = true;
    bool timerChange = false;
}dataset_t;

extern dataset_t glblData;
static const char* valveStateStrings[VALVE_NUM_STATES] = {
    "VALVE_CLOSED",
    "VALVE_CLOSED_MOTORIZED",
    "VALVE_CLOSED_COILPWR",
    "VALVE_OPENING_POWER_COILPWR",
    "VALVE_OPENING_POWER",
    "VALVE_CLOSING_POWER_COILPWR",
    "VALVE_CLOSING_POWER",
    "VALVE_CLOSING_COILPWR",
    "VALVE_CLOSING",
    "VALVE_OPENING_COILPWR",
    "VALVE_OPENING",
    "VALVE_OPEN_MOTORIZED",
    "VALVE_OPEN_COILPWR",
    "VALVE_OPEN",
};

#endif