Central Heating controller using the real time clock, PHY module for internet, 1-wire interface for temperature sensors, a system log and a configuration file

Dependencies:   net 1-wire lpc1768 crypto clock web fram log

/media/uploads/andrewboyson/heating.sch

/media/uploads/andrewboyson/heating.brd

/media/uploads/andrewboyson/eagle.epf

Revision:
96:18a3813bb4b5
Parent:
95:97621bfbedfa
Child:
97:84d58bf7a835
diff -r 97621bfbedfa -r 18a3813bb4b5 heating/radiator.c
--- a/heating/radiator.c	Fri Oct 02 15:40:53 2020 +0000
+++ b/heating/radiator.c	Sat Oct 03 14:29:33 2020 +0000
@@ -20,21 +20,24 @@
 static char      htgWinter;            static int iWinter;
 static char      htgOverride;          static int iOverride;
 static char*     hallRom;              static int iHallRom;
-static uint16_t  overrideCancelMinute; static int iOverrideCancelMinute;
+static uint8_t  overrideCancelHour;    static int iOverrideCancelHour;
+static uint8_t  overrideCancelMinute;  static int iOverrideCancelMinute;
 static  int16_t  nightTemperature;     static int iNightTemperature;
 static  int16_t  frostTemperature;     static int iFrostTemperature;
 
 bool     RadiatorGetWinter              () { return (bool)htgWinter;              } 
 bool     RadiatorGetOverride            () { return (bool)htgOverride;            } 
 uint16_t RadiatorGetHallDS18B20Value    () { return DS18B20ValueFromRom(hallRom); }
-int      RadiatorGetOverrideCancelMinute() { return (int)overrideCancelMinute;    }
+int      RadiatorGetOverrideCancelHour  () { return  (int)overrideCancelHour;     }
+int      RadiatorGetOverrideCancelMinute() { return  (int)overrideCancelMinute;   }
 int      RadiatorGetNightTemperature    () { return  (int)nightTemperature;       } 
 int      RadiatorGetFrostTemperature    () { return  (int)frostTemperature;       } 
 
 static void  setWinter              ( bool  value) { htgWinter            =     (char)value; FramWrite(iWinter,               1, &htgWinter           ); }
 static void  setOverride            ( bool  value) { htgOverride          =     (char)value; FramWrite(iOverride,             1, &htgOverride         ); }
 static void  setHallRom             ( char* value) { memcpy(hallRom,  value, 8);             FramWrite(iHallRom,              8,  hallRom             ); }
-void RadiatorSetOverrideCancelMinute( int   value) { overrideCancelMinute = (uint16_t)value, FramWrite(iOverrideCancelMinute, 2, &overrideCancelMinute); }
+void RadiatorSetOverrideCancelHour  ( int   value) { overrideCancelHour   =  (uint8_t)value, FramWrite(iOverrideCancelHour,   1, &overrideCancelHour  ); }
+void RadiatorSetOverrideCancelMinute( int   value) { overrideCancelMinute =  (uint8_t)value, FramWrite(iOverrideCancelMinute, 1, &overrideCancelMinute); }
 void RadiatorSetNightTemperature    ( int   value) { nightTemperature     =  (int16_t)value; FramWrite(iNightTemperature,     2, &nightTemperature    ); }
 void RadiatorSetFrostTemperature    ( int   value) { frostTemperature     =  (int16_t)value; FramWrite(iFrostTemperature,     2, &frostTemperature    ); }
 
@@ -55,23 +58,23 @@
     
     outputBeforeOverride = (htgWinter && ProgramTimerOutput) || tooCold;
 }
-static void adjustOverride()
+static void autoCancelOverride()
 {
     
     //Remove override at 11pm
-    if (!ClkTimeIsSet())
+    if (ClkTimeIsSet())
     {
         struct tm tm;
         ClkNowTmLocal(&tm);
-        static bool timeWasAfter11pm = false;
-        bool timeIsAfter11pm = tm.tm_hour >= 23;
-        if (timeIsAfter11pm && !timeWasAfter11pm && htgOverride) setOverride(false);
-        timeWasAfter11pm = timeIsAfter11pm;
+        static bool cancelWasDue = false;
+        bool cancelIsDue = tm.tm_hour == overrideCancelHour && tm.tm_min == overrideCancelMinute;
+        if (cancelIsDue && !cancelWasDue && htgOverride) setOverride(false);
+        cancelWasDue = cancelIsDue;
     }
     
     //Remove override if no longer required
     static bool previousOutput = false;
-    if (previousOutput != outputBeforeOverride) setOverride(false);
+    if (previousOutput != outputBeforeOverride && htgOverride) setOverride(false);
     previousOutput = outputBeforeOverride;
 }
 bool RadiatorPump = false;
@@ -119,15 +122,16 @@
     DS18B20RomCount++;
 
     int  address;
-    char    def1;
+    int8_t  def1;
     int16_t def2;
-    def1 =  0;    address = FramLoad( 1, &htgWinter,            &def1); if (address < 0) return -1; iWinter               = address; 
-    def1 =  0;    address = FramLoad( 1, &htgOverride,          &def1); if (address < 0) return -1; iOverride             = address; 
-                  address = FramLoad( 8,  hallRom,                  0); if (address < 0) return -1; iHallRom              = address;
-    def2 = 23*60; address = FramLoad( 2, &overrideCancelMinute, &def2); if (address < 0) return -1; iOverrideCancelMinute = address;
+    def1 =  0; address = FramLoad( 1, &htgWinter,            &def1); if (address < 0) return -1; iWinter               = address; 
+    def1 =  0; address = FramLoad( 1, &htgOverride,          &def1); if (address < 0) return -1; iOverride             = address; 
+               address = FramLoad( 8,  hallRom,                  0); if (address < 0) return -1; iHallRom              = address;
+    def1 = 23; address = FramLoad( 1, &overrideCancelHour,   &def1); if (address < 0) return -1; iOverrideCancelHour   = address;
+    def1 =  0; address = FramLoad( 1, &overrideCancelMinute, &def1); if (address < 0) return -1; iOverrideCancelMinute = address;
                             FramAllocate(2); //Spare two bytes
-    def2 = 15;    address = FramLoad( 2, &nightTemperature,     &def2); if (address < 0) return -1; iNightTemperature     = address; 
-    def2 =  8;    address = FramLoad( 2, &frostTemperature,     &def2); if (address < 0) return -1; iFrostTemperature     = address; 
+    def2 = 15; address = FramLoad( 2, &nightTemperature,     &def2); if (address < 0) return -1; iNightTemperature     = address; 
+    def2 =  8; address = FramLoad( 2, &frostTemperature,     &def2); if (address < 0) return -1; iFrostTemperature     = address; 
     
     RADIATOR_PUMP_DIR = 1; //Set the direction to 1 == output
     
@@ -137,7 +141,7 @@
 {
     //Make the radiator output
     makeOutputBeforeOverride();
-    adjustOverride();
+    autoCancelOverride(); //Do this after making the outputt as it uses that information
     makeOutputWithOverride();
     
     //Pump output