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
Diff: heating/radiator.c
- Revision:
- 57:72c1c1357861
- Parent:
- 48:6eac12df3ad5
- Child:
- 76:3ef2a46c8b1e
diff -r 9536e7714d60 -r 72c1c1357861 heating/radiator.c --- a/heating/radiator.c Fri May 03 14:29:22 2019 +0000 +++ b/heating/radiator.c Mon May 06 07:55:09 2019 +0000 @@ -8,32 +8,27 @@ #include "ds18b20.h" #include "fram.h" #include "radiator.h" -#include "debounce.h" #include "led.h" -#define HALL_LED_DIR FIO0DIR(10) // P0.10 == p28; -#define HALL_LED_PIN FIO0PIN(10) -#define HALL_LED_SET FIO0SET(10) -#define HALL_LED_CLR FIO0CLR(10) #define RADIATOR_PUMP_DIR FIO2DIR(03) // P2.03 == p23; #define RADIATOR_PUMP_PIN FIO2PIN(03) #define RADIATOR_PUMP_SET FIO2SET(03) #define RADIATOR_PUMP_CLR FIO2CLR(03) -static char htgMode; static int iMode; +static char htgWinter; static int iWinter; static char htgOverride; static int iOverride; static char* hallRom; static int iHallRom; static int32_t nightTemperature; static int iNightTemperature; static int32_t frostTemperature; static int iFrostTemperature; -bool RadiatorGetMode (){ return (bool)htgMode; } +bool RadiatorGetWinter (){ return (bool)htgWinter; } bool RadiatorGetOverride (){ return (bool)htgOverride; } uint16_t RadiatorGetHallDS18B20Value(){ return DS18B20ValueFromRom(hallRom); } int RadiatorGetNightTemperature(){ return (int)nightTemperature; } int RadiatorGetFrostTemperature(){ return (int)frostTemperature; } -static void setMode ( bool value) { htgMode = (char)value; FramWrite(iMode, 1, &htgMode ); } +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 RadiatorSetNightTemperature ( int value) { nightTemperature = (int32_t)value; FramWrite(iNightTemperature, 4, &nightTemperature); } @@ -51,10 +46,10 @@ if (DS18B20IsValidValue(hallTemp16ths)) { tooCold = hallTemp16ths < frostTemp16ths; - if (htgMode) tooCold |= hallTemp16ths < nightTemp16ths; + if (htgWinter) tooCold |= hallTemp16ths < nightTemp16ths; } - outputBeforeOverride = htgMode && ProgramTimerOutput || tooCold; + outputBeforeOverride = htgWinter && ProgramTimerOutput || tooCold; } static void adjustOverride() { @@ -68,17 +63,17 @@ RadiatorPump = htgOverride ? !outputBeforeOverride : outputBeforeOverride ; } -void RadiatorSetMode(bool value) //Summer is false, Winter is true +void RadiatorSetWinter(bool value) //Summer is false, Winter is true { - if (htgMode == (char)value) return; //Ignore no change - setMode(value); //Change to the new value + if (htgWinter == (char)value) return; //Ignore no change + setWinter(value); //Change to the new value bool prevOutputBeforeOverride = outputBeforeOverride; makeOutputBeforeOverride(); if (htgOverride) //Only deal with an override that is already set; if it wasn't set don't change it { - if (htgMode) //Summer -> Winter + if (htgWinter) //Summer -> Winter { if (outputBeforeOverride != prevOutputBeforeOverride) setOverride(0); //Adjust the override to leave the heat as it was - off or on. } @@ -96,7 +91,7 @@ makeOutputBeforeOverride(); makeOutputWithOverride(); } -void RadiatorChgMode (){ RadiatorSetMode (!RadiatorGetMode ()); } +void RadiatorChgWinter (){ RadiatorSetWinter (!RadiatorGetWinter ()); } void RadiatorChgOverride(){ RadiatorSetOverride(!RadiatorGetOverride()); } int RadiatorInit() @@ -109,25 +104,18 @@ int address; char def1; int32_t def4; - def1 = 0; address = FramLoad( 1, &htgMode, &def1); if (address < 0) return -1; iMode = 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; def4 = 15; address = FramLoad( 4, &nightTemperature, &def4); if (address < 0) return -1; iNightTemperature = address; def4 = 8; address = FramLoad( 4, &frostTemperature, &def4); if (address < 0) return -1; iFrostTemperature = address; RADIATOR_PUMP_DIR = 1; //Set the direction to 1 == output - HALL_LED_DIR = 1; //Set the direction to 1 == output return 0; } void RadiatorMain() { - //deal with pushbutton - static bool prevOn = false; - bool thisOn = DebounceHallPbPressed(); - if (thisOn && !prevOn) RadiatorChgOverride(); - prevOn = thisOn; - //Make the radiator output makeOutputBeforeOverride(); adjustOverride(); @@ -137,7 +125,4 @@ if (RadiatorPump) RADIATOR_PUMP_SET; else RADIATOR_PUMP_CLR; - //Display the led - if (RadiatorPump) HALL_LED_SET; - else HALL_LED_CLR; } \ No newline at end of file