Skip to content

Commit 32c0587

Browse files
authored
Merge pull request mysensors#7 from petewill/master
Update Time library to latest version
2 parents 4a645c3 + 5793e99 commit 32c0587

File tree

30 files changed

+1060
-606
lines changed

30 files changed

+1060
-606
lines changed

examples/GPSSensor/GPSSensor.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static const uint32_t GPSBaud = 9600;
5050
const int offset = 1;
5151

5252
#include <SPI.h>
53-
#include <Time.h>
53+
#include <TimeLib.h>
5454
#include <MySensors.h>
5555
#include <TinyGPS++.h>
5656
#include <SoftwareSerial.h>

examples/IrrigationController/IrrigationController.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Contributed by Jim ([email protected]) with much contribution from Pete (p
9191
//#define MY_NODE_ID 1 // Set this to fix your Radio ID or use Auto
9292

9393
#include <Wire.h>
94-
#include <Time.h>
94+
#include <TimeLib.h>
9595
#include <SPI.h>
9696
#include <MySensors.h>
9797
#include <LiquidCrystal.h>

examples/RainGauge/RainGauge.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#include <SPI.h>
4848
#include <MySensors.h>
4949
#include <math.h>
50-
#include <Time.h>
50+
#include <TimeLib.h>
5151

5252
#define SKETCH_NAME "Rain Gauge"
5353
#define SKETCH_VERSION "1.4.1a"

examples/RealTimeClockDisplaySensor/RealTimeClockDisplaySensor.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
#include <SPI.h>
5050
#include <MySensors.h>
51-
#include <Time.h>
51+
#include <TimeLib.h>
5252
#include <DS3232RTC.h> // A DS3231/DS3232 library
5353
#include <Wire.h>
5454
#include <LiquidCrystal_I2C.h>

examples/TimeAwareSensor/TimeAwareSensor.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
#include <SPI.h>
3636
#include <MySensors.h>
37-
#include <Time.h>
37+
#include <TimeLib.h>
3838

3939
bool timeReceived = false;
4040
unsigned long lastUpdate=0, lastRequest=0;

examples/TouchDisplaySceneControllerSensor/TouchDisplaySceneControllerSensor.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
#define MY_RADIO_NRF24
6363
//#define MY_RADIO_RFM69
6464

65-
#include <Time.h>
65+
#include <TimeLib.h>
6666
#include <SPI.h>
6767
#include <MySensors.h>
6868
#include <stdarg.h>

libraries/Time/DateStrings.cpp

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
/* DateStrings.cpp
22
* Definitions for date strings for use with the Time library
33
*
4+
* Updated for Arduino 1.5.7 18 July 2014
5+
*
46
* No memory is consumed in the sketch if your code does not call any of the string methods
57
* You can change the text of the strings, make sure the short strings are each exactly 3 characters
6-
* the long strings can be any length up to the constant dt_MAX_STRING_LEN defined in Time.h
8+
* the long strings can be any length up to the constant dt_MAX_STRING_LEN defined in TimeLib.h
79
*
810
*/
9-
10-
#include <avr/pgmspace.h>
11-
#include "Time.h"
11+
12+
#if defined(__AVR__)
13+
#include <avr/pgmspace.h>
14+
#else
15+
// for compatiblity with Arduino Due and Teensy 3.0 and maybe others?
16+
#define PROGMEM
17+
#define PGM_P const char *
18+
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
19+
#define pgm_read_word(addr) (*(const unsigned char **)(addr))
20+
#define strcpy_P(dest, src) strcpy((dest), (src))
21+
#endif
22+
#include <string.h> // for strcpy_P or strcpy
23+
#include "TimeLib.h"
1224

1325
// the short strings for each day or month must be exactly dt_SHORT_STR_LEN
1426
#define dt_SHORT_STR_LEN 3 // the length of short strings
1527

1628
static char buffer[dt_MAX_STRING_LEN+1]; // must be big enough for longest string and the terminating null
1729

30+
const char monthStr0[] PROGMEM = "";
1831
const char monthStr1[] PROGMEM = "January";
1932
const char monthStr2[] PROGMEM = "February";
2033
const char monthStr3[] PROGMEM = "March";
@@ -28,10 +41,10 @@ const char monthStr10[] PROGMEM = "October";
2841
const char monthStr11[] PROGMEM = "November";
2942
const char monthStr12[] PROGMEM = "December";
3043

31-
PGM_P const monthNames_P[] PROGMEM =
44+
const PROGMEM char * const PROGMEM monthNames_P[] =
3245
{
33-
"",monthStr1,monthStr2,monthStr3,monthStr4,monthStr5,monthStr6,
34-
monthStr7,monthStr8,monthStr9,monthStr10,monthStr11,monthStr12
46+
monthStr0,monthStr1,monthStr2,monthStr3,monthStr4,monthStr5,monthStr6,
47+
monthStr7,monthStr8,monthStr9,monthStr10,monthStr11,monthStr12
3548
};
3649

3750
const char monthShortNames_P[] PROGMEM = "ErrJanFebMarAprMayJunJulAugSepOctNovDec";
@@ -45,15 +58,19 @@ const char dayStr5[] PROGMEM = "Thursday";
4558
const char dayStr6[] PROGMEM = "Friday";
4659
const char dayStr7[] PROGMEM = "Saturday";
4760

48-
PGM_P const dayNames_P[] PROGMEM = { dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7};
49-
const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThrFriSat";
61+
const PROGMEM char * const PROGMEM dayNames_P[] =
62+
{
63+
dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7
64+
};
65+
66+
const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThuFriSat";
5067

5168
/* functions to return date strings */
5269

5370
char* monthStr(uint8_t month)
5471
{
5572
strcpy_P(buffer, (PGM_P)pgm_read_word(&(monthNames_P[month])));
56-
return buffer;
73+
return buffer;
5774
}
5875

5976
char* monthShortStr(uint8_t month)

libraries/Time/Examples/Processing/SyncArduinoClock/SyncArduinoClock.pde

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212

1313

1414
import processing.serial.*;
15+
import java.util.Date;
16+
import java.util.Calendar;
17+
import java.util.GregorianCalendar;
1518

16-
public static final short portIndex = 1; // select the com port, 0 is the first port
17-
public static final char TIME_HEADER = 'T'; //header byte for arduino serial time message
19+
public static final short portIndex = 0; // select the com port, 0 is the first port
20+
public static final String TIME_HEADER = "T"; //header for arduino serial time message
1821
public static final char TIME_REQUEST = 7; // ASCII bell character
1922
public static final char LF = 10; // ASCII linefeed
2023
public static final char CR = 13; // ASCII linefeed
@@ -25,10 +28,15 @@ void setup() {
2528
println(Serial.list());
2629
println(" Connecting to -> " + Serial.list()[portIndex]);
2730
myPort = new Serial(this,Serial.list()[portIndex], 9600);
31+
println(getTimeNow());
2832
}
2933

3034
void draw()
3135
{
36+
textSize(20);
37+
textAlign(CENTER);
38+
fill(0);
39+
text("Click to send\nTime Sync", 0, 75, 200, 175);
3240
if ( myPort.available() > 0) { // If data is available,
3341
char val = char(myPort.read()); // read it and store it in val
3442
if(val == TIME_REQUEST){
@@ -52,19 +60,19 @@ void mousePressed() {
5260
}
5361

5462

55-
void sendTimeMessage(char header, long time) {
63+
void sendTimeMessage(String header, long time) {
5664
String timeStr = String.valueOf(time);
5765
myPort.write(header); // send header and time to arduino
58-
myPort.write(timeStr);
66+
myPort.write(timeStr);
67+
myPort.write('\n');
5968
}
6069

6170
long getTimeNow(){
6271
// java time is in ms, we want secs
63-
GregorianCalendar cal = new GregorianCalendar();
64-
cal.setTime(new Date());
65-
int tzo = cal.get(Calendar.ZONE_OFFSET);
66-
int dst = cal.get(Calendar.DST_OFFSET);
67-
long now = (cal.getTimeInMillis() / 1000) ;
68-
now = now + (tzo/1000) + (dst/1000);
69-
return now;
72+
Date d = new Date();
73+
Calendar cal = new GregorianCalendar();
74+
long current = d.getTime()/1000;
75+
long timezone = cal.get(cal.ZONE_OFFSET)/1000;
76+
long daylight = cal.get(cal.DST_OFFSET)/1000;
77+
return current + timezone + daylight;
7078
}

libraries/Time/Examples/Processing/SyncArduinoClock/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ The portIndex must be set the Serial port connected to Arduino.
66
Download TimeSerial.pde onto Arduino and you should see the time
77
message displayed when you run SyncArduinoClock in Processing.
88
The Arduino time is set from the time on your computer through the
9-
Processing sketch.
9+
Processing sketch.

libraries/Time/Examples/TimeGPS/TimeGPS.pde

Lines changed: 0 additions & 82 deletions
This file was deleted.

libraries/Time/Examples/TimeNTP/TimeNTP.pde

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)