#include <i2c_driver_wire.h>
        const float hectoPascalsPerInchHg   = 33.8639;
const unsigned long msOneSecond             = 1000;
const unsigned long msOneMinute             = 60 * msOneSecond;
const unsigned long msOneHour               = 60 * msOneMinute;
const unsigned char OSS                     = 3;  // Oversampling Setting
        const float pi                      = 3.1415926536;
          const int SillyInteger            = -9999;
const unsigned long usOneMinute             = 1000 * msOneMinute;
const unsigned long usOneSecond             = 1000 * msOneSecond;

const char AT           = '@';
const char BLANK        = ' ';
const char CR           = 13;
const char DOT          = '.';
const char DQUOTE       = '"';
const char EXCLAIM      = '!';
const char HYPHEN       = '-';
const char MINUS        = HYPHEN;
const char nullstring[] = "";
const char PERIOD       = DOT;
const char SQUOTE       = '\'';
const char TAB          = '\t';

elapsedMillis msSinceBlinkStarted;

enum tRelayMode {rmForced, rmNightlight, rmThermostat, rmWaterfall};

typedef struct
  { bool  ForceOn;
    bool  InstructionInProgress;
    float LightHigh;
    float LightLow;
    int   RelayMode;
    int   Sched_msmOffTime;
    int   Sched_msmOnTime;
    float TempHigh;
    float TempLow;
    float ThermHysteresisF;
  } tRelayInfo;

tRelayInfo RelayInfo;

class tInfrastructure
  { public:
       bool Debugging;                 // set in setup; used variously
       bool DoInactivityCheck;         // set in setup2; used in top.loop
       bool InIDE;                     // set in setup; used variously
       bool RelayTempDefined;          // set in XBee2.ProcessEndOfLine; used x2 in relay
      float RelayTempF;                // ..
       // bool OutsideTempDefined;        // set in XBee2.ProcessEndOfLine; used x2 in relay
      // float OutsideTempF;              // ..
       bool RecentLightDefined;        // ..
      float RecentLight;               // set in resistance.ReadTheSensor; used in relay.Dark
       bool RecentPressureDefined;     // set in XBee2.ProcessEndOfLine; used in hPaRecentPressure
      float RecentPressureInchesHg;    // ..
      float RecentWindSpeed;           // set in switch.ReadFrequency; used in Resistance.ReadWindVane
       bool Speedup;                   // set in XBee2.ProcessEndOfLine; used variously
       bool UsingTFT320x480;           // set in setup
       bool XBeeActive;                // set in XBee2.setup; used in top.XBeeCheck

       // bool FurnaceNewlyOn();               // called from switch.ReadEventCounter
       // void FurnaceNowOn(const bool NowOn); // called from ACDetector.UpdateState
       void Hang()
              { while (true); }
        int hPaRecentPressure()             // called from (SCD30, SCD40).ReadTheSensor
              { return (int)(hectoPascalsPerInchHg * RecentPressureInchesHg); }
       bool IsGrounded(const int ThePin);   // called from DS1307, setup, SpeedupCheck
       void SayInIDE(const char Message[]); // called widely
       void setup();                        // called from top.setup
  }; // tInfrastructure

bool tInfrastructure::IsGrounded(const int ThePin)
  { pinMode(ThePin, INPUT_PULLUP);
    int Value = digitalRead(ThePin);
    return(Value == LOW);
  } // tInfrastructure::IsGrounded

void tInfrastructure::SayInIDE(const char Message[])
  { if (InIDE)
      { Serial.println(Message); }
  } // tInfrastructure::SayInIDE

void tInfrastructure::setup()
  { pinMode(pinExtraLED,    OUTPUT);
    pinMode(pinuSDNonEmpty, OUTPUT);                         // used by standalone logger
    pinMode(pinEventBlink,  OUTPUT);                         // sensors.EndReport, top.setup

    InIDE                 = IsGrounded(pinGroundInIDE);      // global
    Debugging             = IsGrounded(pinGroundDebugging);  // ..
    UsingTFT320x480       = IsGrounded(pinGroundTFT320x480); // ..
    RecentLightDefined    = false;                           // ..
    RecentPressureDefined = false;                           // ..
    RecentWindSpeed       = 1.0;                             // .. default wind speed
    RelayTempDefined      = false;                           // ..
    SayInIDE            ("in IDE");
       RecentPressureDefined = true;   // ********************************************************
      RecentPressureInchesHg = 30;

    if (InIDE)                                               // Serial
      { Serial.begin(9600);                                  // ..
        delay(3 * msOneSecond);                              // ..
        Serial.setTimeout(30 * msOneSecond);                 // ..
      }                                                      // ..
  } // tInfrastructure::setup()

float DampedNonNeg(const float OldValue, const float NewValue, const float Damping)
  { // used in switch & resistance
    float Result = NewValue;
    if (OldValue >= 0)
      Result = Damping * OldValue + (1-Damping) * NewValue;
    return Result;
  } // used everywhere

void Hang() { while (true) {}; }
                                     

