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/values.c
- Revision:
- 11:fa01ea25b62d
- Parent:
- 1:ccc66fdf858d
- Child:
- 13:2ca12dd42e91
diff -r 93442e6f3de7 -r fa01ea25b62d heating/values.c --- a/heating/values.c Mon Nov 26 14:06:44 2018 +0000 +++ b/heating/values.c Sun Dec 02 19:17:40 2018 +0000 @@ -5,7 +5,9 @@ #include "tftp.h" #include "dns.h" #include "fram.h" -#include "tick.h" +#include "clock.h" +#include "mstimer.h" +#include "clktm.h" #include "ds18b20.h" #include "radiator.h" #include "boiler.h" @@ -23,12 +25,12 @@ static int32_t count; static int iCount; static int iData; -char* ValuesGetServerName ( ) { return serverName; } -char* ValuesGetFileName ( ) { return fileName; } -int ValuesGetWriteSize ( ) { return (int) writeSize; } +char* ValuesGetServerName ( ) { return serverName; } +char* ValuesGetFileName ( ) { return fileName; } +int ValuesGetWriteSize ( ) { return (int) writeSize; } int ValuesGetReadInterval ( ) { return (int) readInterval; } -void ValuesGetStartTm (struct tm* ptm) { TicksToTmUtc(startTime, ptm); } -int ValuesGetCount ( ) { return (int) count; } +void ValuesGetStartTm (struct tm* ptm) { TimeToTmUtc(startTime, ptm); } +int ValuesGetCount ( ) { return (int) count; } static void lblcpy(char* dst, char* src) { strncpy(dst, src, DNS_MAX_LABEL_LENGTH); dst[DNS_MAX_LABEL_LENGTH] = 0; } @@ -55,7 +57,7 @@ } -static uint32_t readElapsed; +static uint32_t readStartMs; static int writeIndex; @@ -74,10 +76,7 @@ } static void readValues() -{ - if (readElapsed == 0 ) return; - if (readElapsed < readInterval) return; //Do nothing if interval not expired - +{ uint64_t record = 0; uint16_t value; value = DS18B20ValueFromRom(RadiatorGetHallRom()); @@ -104,12 +103,10 @@ record |= BoilerCall << 4; record |= BoilerPump << 5; //AAAB BBCC CDDD 003F - if (count == 0) setStartTime(Ticks()); + if (count == 0) setStartTime(ClockTime()); FramWrite(iData + 8 * count, 8, &record); setCount(count + 1); - - readElapsed = 0; } static void writeValues() @@ -121,7 +118,7 @@ strcpy(TftpServerName, serverName); struct tm tm; - TicksToTmUtc(startTime, &tm); + TimeToTmUtc(startTime, &tm); strftime(TftpFileName, DNS_MAX_LABEL_LENGTH+1, fileName, &tm); if (ValuesTrace) @@ -136,19 +133,26 @@ void ValuesMain() { - if (Ticked()) + if (!readInterval) readStartMs = MsTimerCount; + if (writeSize && readInterval) { - if (readInterval) readElapsed++; - else readElapsed = 0; + if (MsTimerHasElapsed(readStartMs, readInterval * 1000)) + { + readValues(); //Only read values if they are going to be backed up + readStartMs = MsTimerCount; + } } - if (writeSize > 0) readValues(); //Only read values if they are going to be backed up + else + { + readStartMs = MsTimerCount; + } if (count >= writeSize) writeValues(); //Backup the values once the backup size is reached } int ValuesInit() { if (readValuesFromFram()) return -1; - readElapsed = 0; + readStartMs = MsTimerCount; TftpGetNextByteFunction = nextByteOfWriteStream; if (count > 0) writeValues(); //Backup the values if there are any return 0;