From ca2f473e244c22119e49700fa7ddf489b42ad6ab Mon Sep 17 00:00:00 2001 From: Thomas Mohaupt Date: Wed, 28 Dec 2016 16:49:36 +0100 Subject: [PATCH 1/4] add method to set split time --- DCF77.cpp | 9 ++++++++- DCF77.h | 2 ++ README.md | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/DCF77.cpp b/DCF77.cpp index 2c252db..17f9ff6 100644 --- a/DCF77.cpp +++ b/DCF77.cpp @@ -37,6 +37,7 @@ DCF77::DCF77(int DCF77Pin, int DCFinterrupt, bool OnRisingFlank) dCF77Pin = DCF77Pin; dCFinterrupt = DCFinterrupt; pulseStart = OnRisingFlank ? HIGH : LOW; + dCFsplitTime = DCFSplitTime; if (!initialized) { pinMode(dCF77Pin, INPUT); @@ -64,6 +65,11 @@ void DCF77::initialize(void) CEST = 0; } +void DCF77::setSplitTime(int shortPulseLength, int longPulseLength) +{ + dCFsplitTime = (shortPulseLength+longPulseLength)/2; +} + /** * Start receiving DCF77 information */ @@ -127,7 +133,7 @@ void DCF77::int0handler() { } PreviousLeadingEdge = leadingEdge; // Distinguish between long and short pulses - if (difference < DCFSplitTime) { appendSignal(0); } else { appendSignal(1); } + if (difference < dCFsplitTime) { appendSignal(0); } else { appendSignal(1); } Up = false; } } @@ -333,6 +339,7 @@ time_t DCF77::getUTCTime(void) */ int DCF77::dCF77Pin=0; int DCF77::dCFinterrupt=0; +int DCF77::dCFsplitTime=DCFSplitTime; byte DCF77::pulseStart=HIGH; // Parameters shared between interupt loop and main loop diff --git a/DCF77.h b/DCF77.h index 6ab3372..b88fff0 100644 --- a/DCF77.h +++ b/DCF77.h @@ -23,6 +23,7 @@ class DCF77 { bool initialized; static int dCF77Pin; static int dCFinterrupt; + static int dCFsplitTime; static byte pulseStart; // DCF77 and internal timestamps @@ -87,6 +88,7 @@ class DCF77 { public: // Public Functions DCF77(int DCF77Pin, int DCFinterrupt, bool OnRisingFlank=true); + static void setSplitTime(int shortPulseLength, int longPulseLength); static time_t getTime(void); static time_t getUTCTime(void); diff --git a/README.md b/README.md index cefd671..d9808a9 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,8 @@ The DCFF77 directory contains the DCFF77 library and some example sketches coming from the DCF decoder. While the DCF specification says that pulses should be either 100 or 200 ms, you will probably see longer pulse lengths. For optimal distinction between long and short pulses use the output of this - sketch to set the parameter #define DCFSplitTime in DCF77.h to (Tshort+Tlong)/2. + sketch to set the pulse length with + DCF.setSplitTime(short_pulse_length, long_pulse_length); - DCFBinaryStream.pde @@ -151,6 +152,7 @@ can be found here: void setup() { Serial.begin(9600); DCF.Start(); + // DCF.setSplitTime(80, 180); Serial.println("Waiting for DCF77 time ... "); Serial.println("It will take at least 2 minutes before a first time update."); } From b3676ac3c7b2c7b80fdee70058823525d2bf3e66 Mon Sep 17 00:00:00 2001 From: Thomas Mohaupt Date: Thu, 29 Dec 2016 09:47:24 +0100 Subject: [PATCH 2/4] use TimeLib.h, for compatibility with >=Arduino 1.6.10 - newer avr-libc --- DCF77.cpp | 112 ++++++++--------- DCF77.h | 31 +++-- README.md | 119 +++++++++--------- examples/DCFBinaryStream/DCFBinaryStream.pde | 34 ++--- .../InternalClockSync/InternalClockSync.pde | 30 ++--- examples/SyncProvider/SyncProvider.pde | 38 +++--- examples/TimeZones/TimeZones.pde | 34 ++--- utility/Utils.h | 10 +- 8 files changed, 202 insertions(+), 206 deletions(-) diff --git a/DCF77.cpp b/DCF77.cpp index 17f9ff6..9129e58 100644 --- a/DCF77.cpp +++ b/DCF77.cpp @@ -1,5 +1,5 @@ /* - DCF77.c - DCF77 library + DCF77.c - DCF77 library Copyright (c) Thijs Elenbaas 2012 This library is free software; you can redistribute it and/or @@ -15,14 +15,14 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - 11 Apr 2012 - initial release + + 11 Apr 2012 - initial release 23 Apr 2012 - added UTC support 2 Jul 2012 - minor bugfix and additional noise rejection */ #include //https://github.com/thijse/Arduino-Libraries/downloads -#include //http://playground.arduino.cc/code/time +#include //http://playground.arduino.cc/code/time #include #define _DCF77_VERSION 1_0_0 // software version of this library @@ -32,15 +32,15 @@ using namespace Utils; /** * Constructor */ -DCF77::DCF77(int DCF77Pin, int DCFinterrupt, bool OnRisingFlank) +DCF77::DCF77(int DCF77Pin, int DCFinterrupt, bool OnRisingFlank) { dCF77Pin = DCF77Pin; - dCFinterrupt = DCFinterrupt; + dCFinterrupt = DCFinterrupt; pulseStart = OnRisingFlank ? HIGH : LOW; dCFsplitTime = DCFSplitTime; - - if (!initialized) { - pinMode(dCF77Pin, INPUT); + + if (!initialized) { + pinMode(dCF77Pin, INPUT); initialize(); } initialized = true; @@ -49,8 +49,8 @@ DCF77::DCF77(int DCF77Pin, int DCFinterrupt, bool OnRisingFlank) /** * Initialize parameters */ -void DCF77::initialize(void) -{ +void DCF77::initialize(void) +{ leadingEdge = 0; trailingEdge = 0; PreviousLeadingEdge = 0; @@ -73,7 +73,7 @@ void DCF77::setSplitTime(int shortPulseLength, int longPulseLength) /** * Start receiving DCF77 information */ -void DCF77::Start(void) +void DCF77::Start(void) { attachInterrupt(dCFinterrupt, int0handler, CHANGE); } @@ -81,15 +81,15 @@ void DCF77::Start(void) /** * Stop receiving DCF77 information */ -void DCF77::Stop(void) +void DCF77::Stop(void) { - detachInterrupt(dCFinterrupt); + detachInterrupt(dCFinterrupt); } /** * Initialize buffer for next time update */ -inline void DCF77::bufferinit(void) +inline void DCF77::bufferinit(void) { runningBuffer = 0; bufferPosition = 0; @@ -108,35 +108,35 @@ void DCF77::int0handler() { LogLn("rCT"); return; } - + // If the detected pulse is too short it will be an // incorrect pulse that we shall reject as well if ((flankTime-leadingEdge) DCFSyncTime) { finalizeBuffer(); - } - PreviousLeadingEdge = leadingEdge; + } + PreviousLeadingEdge = leadingEdge; // Distinguish between long and short pulses if (difference < dCFsplitTime) { appendSignal(0); } else { appendSignal(1); } - Up = false; + Up = false; } - } + } } /** @@ -144,10 +144,10 @@ void DCF77::int0handler() { */ inline void DCF77::appendSignal(unsigned char signal) { Log(signal, DEC); - runningBuffer = runningBuffer | ((unsigned long long) signal << bufferPosition); + runningBuffer = runningBuffer | ((unsigned long long) signal << bufferPosition); bufferPosition++; if (bufferPosition > 59) { - // Buffer is full before at end of time-sequence + // Buffer is full before at end of time-sequence // this may be due to noise giving additional peaks LogLn("EoB"); finalizeBuffer(); @@ -166,12 +166,12 @@ inline void DCF77::finalizeBuffer(void) { filledTimestamp = now(); // Reset running buffer bufferinit(); - FilledBufferAvailable = true; + FilledBufferAvailable = true; } else { // Buffer is not yet full at end of time-sequence LogLn("EoM"); // Reset running buffer - bufferinit(); + bufferinit(); } } @@ -189,8 +189,8 @@ bool DCF77::receivedTimeUpdate(void) { LogLn("Invalid parity"); return false; } - - // Since the received signal is error-prone, and the parity check is not very strong, + + // Since the received signal is error-prone, and the parity check is not very strong, // we will do some sanity checks on the time time_t processedTime = latestupdatedTime + (now() - processingTimestamp); if (processedTimeMAX_TIME) { @@ -209,23 +209,23 @@ bool DCF77::receivedTimeUpdate(void) { // Time can be further from internal clock for several reasons // We will check if lag from internal clock is consistent time_t shiftPrevious = (previousUpdatedTime - previousProcessingTimestamp); - time_t shiftCurrent = (latestupdatedTime - processingTimestamp); + time_t shiftCurrent = (latestupdatedTime - processingTimestamp); time_t shiftDifference = abs(shiftCurrent-shiftPrevious); storePreviousTime(); if(shiftDifference < 2*SECS_PER_MIN) { - LogLn("time lag consistent"); + LogLn("time lag consistent"); return true; } else { LogLn("time lag inconsistent"); } - - // If lag is inconsistent, this may be because of no previous stored date + + // If lag is inconsistent, this may be because of no previous stored date // This would be resolved in a second run. return false; } /** - * Store previous time. Needed for consistency + * Store previous time. Needed for consistency */ void DCF77::storePreviousTime(void) { previousUpdatedTime = latestupdatedTime; @@ -233,14 +233,14 @@ void DCF77::storePreviousTime(void) { } /** - * Calculate the parity of the time and date. + * Calculate the parity of the time and date. */ -void DCF77::calculateBufferParities(void) { - // Calculate Parity - flags.parityFlag = 0; +void DCF77::calculateBufferParities(void) { + // Calculate Parity + flags.parityFlag = 0; for(int pos=0;pos<59;pos++) { - bool s = (processingBuffer >> pos) & 1; - + bool s = (processingBuffer >> pos) & 1; + // Update the parity bits. First: Reset when minute, hour or date starts. if (pos == 21 || pos == 29 || pos == 36) { flags.parityFlag = 0; @@ -258,18 +258,18 @@ void DCF77::calculateBufferParities(void) { /** * Evaluates the information stored in the buffer. This is where the DCF77 - * signal is decoded + * signal is decoded */ -bool DCF77::processBuffer(void) { - +bool DCF77::processBuffer(void) { + ///// Start interaction with interrupt driven loop ///// - + // Copy filled buffer and timestamp from interrupt driven loop processingBuffer = filledBuffer; processingTimestamp = filledTimestamp; // Indicate that there is no filled, unprocessed buffer anymore - FilledBufferAvailable = false; - + FilledBufferAvailable = false; + ///// End interaction with interrupt driven loop ///// // Calculate parities for checking buffer @@ -284,16 +284,16 @@ bool DCF77::processBuffer(void) { if (flags.parityMin == rx_buffer->P1 && flags.parityHour == rx_buffer->P2 && flags.parityDate == rx_buffer->P3 && - rx_buffer->CEST != rx_buffer->CET) - { - //convert the received buffer into time + rx_buffer->CEST != rx_buffer->CET) + { + //convert the received buffer into time time.Second = 0; time.Minute = rx_buffer->Min-((rx_buffer->Min/16)*6); time.Hour = rx_buffer->Hour-((rx_buffer->Hour/16)*6); - time.Day = rx_buffer->Day-((rx_buffer->Day/16)*6); + time.Day = rx_buffer->Day-((rx_buffer->Day/16)*6); time.Month = rx_buffer->Month-((rx_buffer->Month/16)*6); time.Year = 2000 + rx_buffer->Year-((rx_buffer->Year/16)*6) -1970; - latestupdatedTime = makeTime(time); + latestupdatedTime = makeTime(time); CEST = rx_buffer->CEST; //Parity correct return true; @@ -304,7 +304,7 @@ bool DCF77::processBuffer(void) { } /** - * Get most recently received time + * Get most recently received time * Note, this only returns an time once, until the next update */ time_t DCF77::getTime(void) @@ -319,7 +319,7 @@ time_t DCF77::getTime(void) } /** - * Get most recently received time in UTC + * Get most recently received time in UTC * Note, this only returns an time once, until the next update */ time_t DCF77::getUTCTime(void) @@ -366,5 +366,3 @@ time_t DCF77::processingTimestamp= 0; time_t DCF77::previousProcessingTimestamp=0; unsigned char DCF77::CEST=0; DCF77::ParityFlags DCF77::flags = {0,0,0,0}; - - diff --git a/DCF77.h b/DCF77.h index b88fff0..bcf4472 100644 --- a/DCF77.h +++ b/DCF77.h @@ -2,16 +2,16 @@ #define DCF77_h #if ARDUINO >= 100 -#include +#include #else -#include +#include #endif -#include +#include #define MIN_TIME 1334102400 // Date: 11-4-2012 #define MAX_TIME 4102444800 // Date: 1-1-2100 -#define DCFRejectionTime 700 // Pulse-to-Pulse rejection time. +#define DCFRejectionTime 700 // Pulse-to-Pulse rejection time. #define DCFRejectPulseWidth 50 // Minimal pulse width #define DCFSplitTime 180 // Specifications distinguishes pulse width 100 ms and 200 ms. In practice we see 130 ms and 230 #define DCFSyncTime 1500 // Specifications defines 2000 ms pulse for end of sequence @@ -20,7 +20,7 @@ class DCF77 { private: //Private variables - bool initialized; + bool initialized; static int dCF77Pin; static int dCFinterrupt; static int dCFsplitTime; @@ -28,16 +28,16 @@ class DCF77 { // DCF77 and internal timestamps static time_t previousUpdatedTime; - static time_t latestupdatedTime; + static time_t latestupdatedTime; static time_t processingTimestamp; - static time_t previousProcessingTimestamp; + static time_t previousProcessingTimestamp; static unsigned char CEST; // DCF time format structure struct DCF77Buffer { //unsigned long long prefix :21; unsigned long long prefix :17; - unsigned long long CEST :1; // CEST - unsigned long long CET :1; // CET + unsigned long long CEST :1; // CEST + unsigned long long CET :1; // CET unsigned long long unused :2; // unused bits unsigned long long Min :7; // minutes unsigned long long P1 :1; // parity minutes @@ -49,8 +49,8 @@ class DCF77 { unsigned long long Year :8; // year (5 -> 2005) unsigned long long P3 :1; // parity }; - - + + // DCF Parity format structure struct ParityFlags{ unsigned char parityFlag :1; @@ -74,7 +74,7 @@ class DCF77 { static int trailingEdge; static int PreviousLeadingEdge; static bool Up; - + //Private functions void static initialize(void); void static bufferinit(void); @@ -85,11 +85,11 @@ class DCF77 { bool static processBuffer(void); void static appendSignal(unsigned char signal); -public: +public: // Public Functions - DCF77(int DCF77Pin, int DCFinterrupt, bool OnRisingFlank=true); + DCF77(int DCF77Pin, int DCFinterrupt, bool OnRisingFlank=true); static void setSplitTime(int shortPulseLength, int longPulseLength); - + static time_t getTime(void); static time_t getUTCTime(void); static void Start(void); @@ -98,4 +98,3 @@ class DCF77 { }; #endif - diff --git a/README.md b/README.md index d9808a9..e320b84 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,33 @@ # Arduino DCF77 library -The DCF77 library adds the ability to read and decode the atomic time broadcasted by the -DCF77 radiostation. It has been designed to work in conjunction with the Arduino Time +The DCF77 library adds the ability to read and decode the atomic time broadcasted by the +DCF77 radiostation. It has been designed to work in conjunction with the Arduino Time library and allows a sketch to get the precise CET time and date as a standard C time_t. The DCF77 Library download. Example sketches have been added to -1. illustrate and debug the incoming signal -2. use the library, using the setSyncProvider callback and converting to different - time zones. In order to exploit all features in the library, Both the Time and +1. illustrate and debug the incoming signal +2. use the library, using the setSyncProvider callback and converting to different + time zones. In order to exploit all features in the library, Both the Time and TimeZone library are included. -Additional documentation and full explanations of the samples can be found in these blog +Additional documentation and full explanations of the samples can be found in these blog posts on DCF Hardware, DCF Signal can be found here: [http://thijs.elenbaas.net/2012/04/arduino-dcf77-radio-clock-receiver-library/](http://thijs.elenbaas.net/2012/04/arduino-dcf77-radio-clock-receiver-library/) ## Downloading -This package can be downloaded in different manners +This package can be downloaded in different manners - The Arduino Library Manager: [see here how to use it](http://www.arduino.cc/en/guide/libraries#toc3). - The PlatformIO Library Manager: [see here how to use it](http://docs.platformio.org/en/latest/ide/arduino.html). -- By directly loading fetching the Archive from GitHub: +- By directly loading fetching the Archive from GitHub: 1. Go to [https://github.com/thijse/Arduino-DCF77](https://github.com/thijse/Arduino-DCF77) 2. Click the DOWNLOAD ZIP button in the panel on the 3. Rename the uncompressed folder **Arduino-DCF77-master** to **DCF77**. 4. You may need to create the libraries subfolder if its your first library. - 5. Place the **DCF77** library folder in your **arduinosketchfolder/libraries/** folder. + 5. Place the **DCF77** library folder in your **arduinosketchfolder/libraries/** folder. 5. Restart the IDE. 6. For more information, [read this extended manual](http://thijs.elenbaas.net/2012/07/installing-an-arduino-library/) - If you want to have a package that includes all referenced libraries, use the pre-packaged library @@ -37,118 +37,118 @@ This package can be downloaded in different manners 3. For more information, [read this extended manual](http://thijs.elenbaas.net/2012/07/installing-an-arduino-library/) ##Samples - + The DCF77 directory contains some examples: ### DCFSignal.pde - This is the most basic example: it shows the raw signal coming from the - DCF decoder. It will show Pulse-to-Pulse times of approximately 1000 ms and + This is the most basic example: it shows the raw signal coming from the + DCF decoder. It will show Pulse-to-Pulse times of approximately 1000 ms and pulse widths of approx 100ms and 200ms. ### DCFPulseLength - This example illustrates the pulse-to-pulse time and pulse lengths - coming from the DCF decoder. While the DCF specification says that pulses - should be either 100 or 200 ms, you will probably see longer pulse lengths. - For optimal distinction between long and short pulses use the output of this + This example illustrates the pulse-to-pulse time and pulse lengths + coming from the DCF decoder. While the DCF specification says that pulses + should be either 100 or 200 ms, you will probably see longer pulse lengths. + For optimal distinction between long and short pulses use the output of this sketch to set the parameter #define DCFSplitTime in DCF77.h to (Tshort+Tlong)/2. ### DCFBinaryStream - This example shows the binary stream generated by the pulse train coming + This example shows the binary stream generated by the pulse train coming from the DCF decoder and the resulting CET time. ### InternalClockSync - This is the probably the most important example: It shows how to fetch a - DCF77 time and synchronize the internal Arduino clock. + This is the probably the most important example: It shows how to fetch a + DCF77 time and synchronize the internal Arduino clock. ### SyncProvider - This sketch shows how to fetch a DCF77 time and synchronize the internal clock - using the setSyncProvider function. Note that the loop code does not require any - logic to maintain time sync. The Time library will monitor DC77 and sync the - time as necessary. + This sketch shows how to fetch a DCF77 time and synchronize the internal clock + using the setSyncProvider function. Note that the loop code does not require any + logic to maintain time sync. The Time library will monitor DC77 and sync the + time as necessary. ### TimeZones - This example shows how to convert the DCF77 time to a different timezone. It uses - the UTC time to ensure that no ambiguities can exist. For timezone conversion it + This example shows how to convert the DCF77 time to a different timezone. It uses + the UTC time to ensure that no ambiguities can exist. For timezone conversion it employs the TimeZone library. *** Using the Library *** -To use the library, first download the DCF77 library here: +To use the library, first download the DCF77 library here: https://github.com/thijse/Arduino-Libraries/downloads -and install it in the Arduino Library folder. -For a tutorial on how to install new libraries for use with the Arduino development +and install it in the Arduino Library folder. +For a tutorial on how to install new libraries for use with the Arduino development environment please refer to http://www.arduino.cc/en/Reference/Libraries or follow this step-by-step how-to article on installing Arduino libraries: http://thijs.elenbaas.net/2012/07/installing-an-arduino-library -If the library is installed at the correct location, you can find the examples discussed -in this and the previous post under Examples > DCF77. I also added the time library to +If the library is installed at the correct location, you can find the examples discussed +in this and the previous post under Examples > DCF77. I also added the time library to the archive for convenience. The DCFF77 directory contains the DCFF77 library and some example sketches - DCFSignal.pde - This is the most basic example: it shows the raw signal coming from the - DCF decoder. It will show Pulse-to-Pulse times of approximately 1000 ms and + This is the most basic example: it shows the raw signal coming from the + DCF decoder. It will show Pulse-to-Pulse times of approximately 1000 ms and pulse widths of approx 100ms and 200ms. - DCFPulseLength.pde - This example illustrates the pulse-to-pulse time and pulse lengths - coming from the DCF decoder. While the DCF specification says that pulses - should be either 100 or 200 ms, you will probably see longer pulse lengths. - For optimal distinction between long and short pulses use the output of this - sketch to set the pulse length with + This example illustrates the pulse-to-pulse time and pulse lengths + coming from the DCF decoder. While the DCF specification says that pulses + should be either 100 or 200 ms, you will probably see longer pulse lengths. + For optimal distinction between long and short pulses use the output of this + sketch to set the pulse length with DCF.setSplitTime(short_pulse_length, long_pulse_length); - DCFBinaryStream.pde - This example shows the binary stream generated by the pulse train coming + This example shows the binary stream generated by the pulse train coming from the DCF decoder and the resulting CET time. - InternalClockSync.pde - This is the probably the most important example: It shows how to fetch a - DCF77 time and synchronize the internal Arduino clock. + This is the probably the most important example: It shows how to fetch a + DCF77 time and synchronize the internal Arduino clock. - SyncProvider.pde - This sketch shows how to fetch a DCF77 time and synchronize the internal clock - using the setSyncProvider function. Note that the loop code does not require any - logic to maintain time sync. The Time library will monitor DC77 and sync the - time as necessary. + This sketch shows how to fetch a DCF77 time and synchronize the internal clock + using the setSyncProvider function. Note that the loop code does not require any + logic to maintain time sync. The Time library will monitor DC77 and sync the + time as necessary. - TimeZones.pde - This example shows how to convert the DCF77 time to a different timezone. It uses - the UTC time to ensure that no ambiguities can exist. For timezone conversion it + This example shows how to convert the DCF77 time to a different timezone. It uses + the UTC time to ensure that no ambiguities can exist. For timezone conversion it employs the TimeZone library. -### Example sketch -The sketch below implements the most DCF77 basic functionality. It reads the signal from -pin 2, and 2-3 minutes it will update the internal clock. More information on this example -can be found here: +### Example sketch +The sketch below implements the most DCF77 basic functionality. It reads the signal from +pin 2, and 2-3 minutes it will update the internal clock. More information on this example +can be found here: [http://thijs.elenbaas.net/2012/04/arduino-dcf77-radio-clock-receiver-library/ ](http://thijs.elenbaas.net/2012/04/arduino-dcf77-radio-clock-receiver-library/) - + #include "DCF77.h" - #include "Time.h" - + #include "TimeLib.h" + #define DCF_PIN 2// Connection pin to DCF 77 device #define DCF_INTERRUPT 0 // Interrupt number associated with pin - + time_t time; DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT); - + void setup() { Serial.begin(9600); DCF.Start(); @@ -156,7 +156,7 @@ can be found here: Serial.println("Waiting for DCF77 time ... "); Serial.println("It will take at least 2 minutes before a first time update."); } - + void loop() { delay(1000); time_t DCFtime = DCF.getTime(); // Check if new DCF77 time is available @@ -167,7 +167,7 @@ can be found here: } digitalClockDisplay(); } - + void digitalClockDisplay(){ // digital clock display of the time Serial.print(hour()); @@ -181,7 +181,7 @@ can be found here: Serial.print(year()); Serial.println(); } - + void printDigits(int digits){ // utility function for digital clock display: prints preceding colon and leading 0 Serial.print(":"); @@ -193,9 +193,8 @@ can be found here: ## On using and modifying libraries - [http://www.arduino.cc/en/Main/Libraries](http://www.arduino.cc/en/Main/Libraries) -- [http://www.arduino.cc/en/Reference/Libraries](http://www.arduino.cc/en/Reference/Libraries) +- [http://www.arduino.cc/en/Reference/Libraries](http://www.arduino.cc/en/Reference/Libraries) ## Copyright DCF77 is provided Copyright © 2013,2014,2015 under LGPL License. - diff --git a/examples/DCFBinaryStream/DCFBinaryStream.pde b/examples/DCFBinaryStream/DCFBinaryStream.pde index 69cf6b1..b05cbac 100644 --- a/examples/DCFBinaryStream/DCFBinaryStream.pde +++ b/examples/DCFBinaryStream/DCFBinaryStream.pde @@ -3,36 +3,36 @@ * example code illustrating time synced from a DCF77 receiver * Thijs Elenbaas, 2012 * This example code is in the public domain. - - This example shows the binary stream generated by the + + This example shows the binary stream generated by the pulse train coming from the DCF decoder and the resulting time In order for this example to give output from the DCF library, - make sure that logging is turned on in the DCF library. You can - do this by adding the #define VERBOSE_DEBUG 1 in Utils.cpp. - - NOTE: If you used a package manager to download the DCF77 library, + make sure that logging is turned on in the DCF library. You can + do this by adding the #define VERBOSE_DEBUG 1 in Utils.cpp. + + NOTE: If you used a package manager to download the DCF77 library, make sure have also fetched these libraries: - * Time + * Time A package that includes all referenced libraries can be found at: - https://github.com/thijse/Zipballs/blob/master/DCF77/DCF77.zip?raw=true - + https://github.com/thijse/Zipballs/blob/master/DCF77/DCF77.zip?raw=true + */ -#include //https://github.com/thijse/Arduino-Libraries/downloads -#include //http://www.arduino.cc/playground/Code/Time +#include //https://github.com/thijse/Arduino-Libraries/downloads +#include //http://www.arduino.cc/playground/Code/Time -#define DCF_PIN 2 // Connection pin to DCF 77 device -#define DCF_INTERRUPT 0 // Interrupt number associated with pin +#define DCF_PIN 2 // Connection pin to DCF 77 device +#define DCF_INTERRUPT 0 // Interrupt number associated with pin time_t time; DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT); void setup() { - Serial.begin(9600); + Serial.begin(9600); Serial.println("1 - binary 1 corresponding to long pulse"); Serial.println("0 - binary 0 corresponding to short pulse"); Serial.println("BF - Buffer is full at end of time-sequence. This is good"); @@ -46,11 +46,11 @@ void loop() { time_t DCFtime = DCF.getTime(); if (DCFtime!=0) { digitalClockDisplay(DCFtime); - } + } } void digitalClockDisplay(time_t _time){ - tmElements_t tm; + tmElements_t tm; breakTime(_time, tm); Serial.println(""); @@ -74,4 +74,4 @@ void printDigits(int digits){ if(digits < 10) Serial.print('0'); Serial.print(digits); -} \ No newline at end of file +} diff --git a/examples/InternalClockSync/InternalClockSync.pde b/examples/InternalClockSync/InternalClockSync.pde index 6cfa860..2f126d9 100644 --- a/examples/InternalClockSync/InternalClockSync.pde +++ b/examples/InternalClockSync/InternalClockSync.pde @@ -3,24 +3,24 @@ * example code illustrating time synced from a DCF77 receiver * Thijs Elenbaas, 2012 * This example code is in the public domain. - + This example shows how to fetch a DCF77 time and synchronize the internal clock. In order for this example to give clear output, - make sure that you disable logging from the DCF library. You can - do this by commenting out #define VERBOSE_DEBUG 1 in Utils.cpp. - - NOTE: If you used a package manager to download the DCF77 library, + make sure that you disable logging from the DCF library. You can + do this by commenting out #define VERBOSE_DEBUG 1 in Utils.cpp. + + NOTE: If you used a package manager to download the DCF77 library, make sure have also fetched these libraries: - * Time + * Time A package that includes all referenced libraries can be found at: - https://github.com/thijse/Zipballs/blob/master/DCF77/DCF77.zip?raw=true - + https://github.com/thijse/Zipballs/blob/master/DCF77/DCF77.zip?raw=true + */ #include "DCF77.h" -#include "Time.h" +#include "TimeLib.h" #define DCF_PIN 2 // Connection pin to DCF 77 device #define DCF_INTERRUPT 0 // Interrupt number associated with pin @@ -30,7 +30,7 @@ DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT); void setup() { - Serial.begin(9600); + Serial.begin(9600); DCF.Start(); Serial.println("Waiting for DCF77 time ... "); Serial.println("It will take at least 2 minutes until a first update can be processed."); @@ -43,8 +43,8 @@ void loop() { { Serial.println("Time is updated"); setTime(DCFtime); - } - digitalClockDisplay(); + } + digitalClockDisplay(); } void digitalClockDisplay(){ @@ -57,8 +57,8 @@ void digitalClockDisplay(){ Serial.print(" "); Serial.print(month()); Serial.print(" "); - Serial.print(year()); - Serial.println(); + Serial.print(year()); + Serial.println(); } void printDigits(int digits){ @@ -67,4 +67,4 @@ void printDigits(int digits){ if(digits < 10) Serial.print('0'); Serial.print(digits); -} \ No newline at end of file +} diff --git a/examples/SyncProvider/SyncProvider.pde b/examples/SyncProvider/SyncProvider.pde index 12b5c7c..2b8bada 100644 --- a/examples/SyncProvider/SyncProvider.pde +++ b/examples/SyncProvider/SyncProvider.pde @@ -6,24 +6,24 @@ This example shows how to fetch a DCF77 time and synchronize the internal clock. In order for this example to give clear output, - make sure that you disable logging from the DCF library. You can - do this by commenting out #define VERBOSE_DEBUG 1 in Utils.cpp. - - NOTE: If you used a package manager to download the DCF77 library, + make sure that you disable logging from the DCF library. You can + do this by commenting out #define VERBOSE_DEBUG 1 in Utils.cpp. + + NOTE: If you used a package manager to download the DCF77 library, make sure have also fetched these libraries: - * Time + * Time A package that includes all referenced libraries can be found at: https://github.com/thijse/Zipballs/blob/master/DCF77/DCF77.zip?raw=true - + */ -#include //https://github.com/thijse/Arduino-Libraries/downloads -#include //http://www.arduino.cc/playground/Code/Time +#include //https://github.com/thijse/Arduino-Libraries/downloads +#include //http://www.arduino.cc/playground/Code/Time -#define DCF_PIN 2 // Connection pin to DCF 77 device -#define DCF_INTERRUPT 0 // Interrupt number associated with pin +#define DCF_PIN 2 // Connection pin to DCF 77 device +#define DCF_INTERRUPT 0 // Interrupt number associated with pin time_t prevDisplay = 0; // when the digital clock was displayed time_t time; @@ -31,7 +31,7 @@ DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT); void setup() { - Serial.begin(9600); + Serial.begin(9600); DCF.Start(); setSyncInterval(30); setSyncProvider(getDCFTime); @@ -40,8 +40,8 @@ void setup() { Serial.println("Waiting for DCF77 time ... "); Serial.println("It will take at least 2 minutes until a first update can be processed."); - while(timeStatus()== timeNotSet) { - // wait until the time is set by the sync provider + while(timeStatus()== timeNotSet) { + // wait until the time is set by the sync provider Serial.print("."); delay(2000); } @@ -49,11 +49,11 @@ void setup() { void loop() -{ +{ if( now() != prevDisplay) //update the display only if the time has changed { prevDisplay = now(); - digitalClockDisplay(); + digitalClockDisplay(); } } @@ -68,8 +68,8 @@ void digitalClockDisplay(){ Serial.print(" "); Serial.print(month()); Serial.print(" "); - Serial.print(year()); - Serial.println(); + Serial.print(year()); + Serial.println(); } void printDigits(int digits){ @@ -81,11 +81,11 @@ void printDigits(int digits){ } unsigned long getDCFTime() -{ +{ time_t DCFtime = DCF.getTime(); // Indicator that a time check is done if (DCFtime!=0) { - Serial.print("X"); + Serial.print("X"); } return DCFtime; } diff --git a/examples/TimeZones/TimeZones.pde b/examples/TimeZones/TimeZones.pde index 0884efa..e12efa6 100644 --- a/examples/TimeZones/TimeZones.pde +++ b/examples/TimeZones/TimeZones.pde @@ -6,24 +6,24 @@ This example shows how to fetch a DCF77 time and synchronize the internal clock. In order for this example to give clear output, - make sure that you disable logging from the DCF library. You can - do this by commenting out #define VERBOSE_DEBUG 1 in Utils.cpp. - - NOTE: If you used a package manager to download the DCF77 library, + make sure that you disable logging from the DCF library. You can + do this by commenting out #define VERBOSE_DEBUG 1 in Utils.cpp. + + NOTE: If you used a package manager to download the DCF77 library, make sure have also fetched these libraries: - * Time + * Time * Timezone A package that includes all referenced libraries can be found at: https://github.com/thijse/Zipballs/blob/master/DCF77/DCF77.zip?raw=true - - + + */ #include //https://github.com/thijse/Arduino-Libraries/downloads -#include //http://www.arduino.cc/playground/Code/Time +#include //http://www.arduino.cc/playground/Code/Time #include //https://github.com/JChristensen/Timezone #define DCF_PIN 2 // Connection pin to DCF 77 device @@ -47,7 +47,7 @@ DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT); void setup() { - Serial.begin(9600); + Serial.begin(9600); DCF.Start(); setSyncInterval(30); setSyncProvider(getDCFTime); @@ -56,8 +56,8 @@ void setup() { Serial.println("Waiting for DCF77 UK local time ... "); Serial.println("It will take at least 2 minutes until a first update can be processed."); - while(timeStatus()== timeNotSet) { - // wait until the time is set by the sync provider + while(timeStatus()== timeNotSet) { + // wait until the time is set by the sync provider Serial.print("."); delay(2000); } @@ -65,11 +65,11 @@ void setup() { void loop() -{ +{ if( now() != prevDisplay) //update the display only if the time has changed { prevDisplay = now(); - digitalClockDisplay(); + digitalClockDisplay(); } } @@ -84,8 +84,8 @@ void digitalClockDisplay(){ Serial.print(" "); Serial.print(month()); Serial.print(" "); - Serial.print(year()); - Serial.println(); + Serial.print(year()); + Serial.println(); } void printDigits(int digits){ @@ -97,9 +97,9 @@ void printDigits(int digits){ } unsigned long getDCFTime() -{ +{ time_t DCFtime = DCF.getUTCTime(); // Convert from UTC - + if (DCFtime!=0) { Serial.print("X"); // Indicator that a time check is done time_t LocalTime = UK.toLocal(DCFtime); diff --git a/utility/Utils.h b/utility/Utils.h index 1d6fb75..f761099 100644 --- a/utility/Utils.h +++ b/utility/Utils.h @@ -2,16 +2,16 @@ #define Utils_h #if ARDUINO >= 100 -#include +#include #else -#include +#include #endif -#include +#include #define intDisable() ({ uint8_t sreg = SREG; cli(); sreg; }) -#define intRestore(sreg) SREG = sreg +#define intRestore(sreg) SREG = sreg -namespace Utils { +namespace Utils { void Log(char*s); void LogLn(char*s); void Log(int i,char format); From 3f985857799c91077d38b6fa833d7a5b2ee85992 Mon Sep 17 00:00:00 2001 From: Thomas Mohaupt Date: Thu, 29 Dec 2016 10:08:35 +0100 Subject: [PATCH 3/4] change log parameter to const char * --- utility/Utils.cpp | 14 +++++++------- utility/Utils.h | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/utility/Utils.cpp b/utility/Utils.cpp index 5b32bad..cb9c483 100644 --- a/utility/Utils.cpp +++ b/utility/Utils.cpp @@ -1,31 +1,31 @@ #include "Utils.h" namespace Utils { - + #define DEBUG_BLINK_PIN 13 // Connected to debug led //#define VERBOSE_DEBUG 1 // Verbose - void LogLn(char*s) + void LogLn(const char*s) { #ifdef VERBOSE_DEBUG Serial.println(s); #endif } - void Log(char*s) + void Log(const char*s) { #ifdef VERBOSE_DEBUG Serial.print(s); #endif } - void Log(int i,char format) + void Log(int i,const char format) { #ifdef VERBOSE_DEBUG Serial.print(i, format); #endif } - void LogLn(int i,char format) + void LogLn(int i,const char format) { #ifdef VERBOSE_DEBUG Serial.println(i, format); @@ -45,11 +45,11 @@ namespace Utils { Serial.println(i); #endif } - + void BlinkDebug(uint8_t state) { #ifdef DEBUG_BLINK_PIN digitalWrite(DEBUG_BLINK_PIN, state); #endif } - + } diff --git a/utility/Utils.h b/utility/Utils.h index f761099..3f7cc71 100644 --- a/utility/Utils.h +++ b/utility/Utils.h @@ -12,10 +12,10 @@ #define intRestore(sreg) SREG = sreg namespace Utils { - void Log(char*s); - void LogLn(char*s); - void Log(int i,char format); - void LogLn(int i,char format); + void Log(const char*s); + void LogLn(const char*s); + void Log(int i,const char format); + void LogLn(int i,const char format); void Log(int i); void LogLn(int i); void BlinkDebug(uint8_t state); From fd8cb09bd575f01d709b0887e10b2bc6fb772e4d Mon Sep 17 00:00:00 2001 From: Thomas Mohaupt Date: Thu, 29 Dec 2016 11:17:22 +0100 Subject: [PATCH 4/4] fix indentation and tailing spaces --- examples/DCFPulseLength/DCFPulseLength.pde | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/examples/DCFPulseLength/DCFPulseLength.pde b/examples/DCFPulseLength/DCFPulseLength.pde index fdff68a..1535102 100644 --- a/examples/DCFPulseLength/DCFPulseLength.pde +++ b/examples/DCFPulseLength/DCFPulseLength.pde @@ -2,17 +2,17 @@ * DCFPulseLength.ino - DCF77 debug Example * Thijs Elenbaas, 2012 * This example code is in the public domain. - + This simple example shows the pulse-to-pulse time and pulse lengths coming from the DCF decoder. - + Notice that will the DCF specification says that pulses should be either 100 or 200 ms, we notice longer pulse lengths. This is likely due to to - the hardware of the decoder. For optimal distinction between long and - short pulses in the DCF library, set the parameter - #define DCFSplitTime in DCF77.h to (Tlongpulse+Tlongpulse)/2 + the hardware of the decoder. For optimal distinction between long and + short pulses in the DCF library, set the parameter + #define DCFSplitTime in DCF77.h to (Tlongpulse+Tlongpulse)/2 */ - + #define BLINKPIN 13 #define DCF77PIN 2 @@ -44,10 +44,8 @@ void loop() { Serial.println(flankDown - flankUp); PreviousflankUp = flankUp; Up = false; - digitalWrite(BLINKPIN, LOW); - } + digitalWrite(BLINKPIN, LOW); + } } - -} - +}