Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
my_xihale
Time
提交
26cd0c85
T
Time
项目概览
my_xihale
/
Time
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Time
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
26cd0c85
编写于
11月 11, 2015
作者:
P
PaulStoffregen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix for includes with Arduino 1.6.6
上级
a7cc3261
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
158 addition
and
156 deletion
+158
-156
Time.h
Time.h
+1
-144
TimeLib.h
TimeLib.h
+144
-0
examples/TimeArduinoDue/TimeArduinoDue.ino
examples/TimeArduinoDue/TimeArduinoDue.ino
+1
-1
examples/TimeGPS/TimeGPS.ino
examples/TimeGPS/TimeGPS.ino
+1
-1
examples/TimeNTP/TimeNTP.ino
examples/TimeNTP/TimeNTP.ino
+1
-1
examples/TimeRTC/TimeRTC.ino
examples/TimeRTC/TimeRTC.ino
+2
-2
examples/TimeRTCLog/TimeRTCLog.ino
examples/TimeRTCLog/TimeRTCLog.ino
+2
-2
examples/TimeRTCSet/TimeRTCSet.ino
examples/TimeRTCSet/TimeRTCSet.ino
+2
-2
examples/TimeSerial/TimeSerial.ino
examples/TimeSerial/TimeSerial.ino
+1
-1
examples/TimeSerialDateStrings/TimeSerialDateStrings.ino
examples/TimeSerialDateStrings/TimeSerialDateStrings.ino
+1
-1
examples/TimeTeensy3/TimeTeensy3.ino
examples/TimeTeensy3/TimeTeensy3.ino
+1
-1
keywords.txt
keywords.txt
+1
-0
未找到文件。
Time.h
浏览文件 @
26cd0c85
/*
time.h - low level time and date functions
*/
/*
July 3 2011 - fixed elapsedSecsThisWeek macro (thanks Vincent Valdy for this)
- fixed daysToTime_t macro (thanks maniacbug)
*/
#ifndef _Time_h
#ifdef __cplusplus
#define _Time_h
#include <inttypes.h>
#ifndef __AVR__
#include <sys/types.h> // for __time_t_defined, but avr libc lacks sys/types.h
#endif
#if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc
typedef
unsigned
long
time_t
;
#endif
// This ugly hack allows us to define C++ overloaded functions, when included
// from within an extern "C", as newlib's sys/stat.h does. Actually it is
// intended to include "time.h" from the C library (on ARM, but AVR does not
// have that file at all). On Mac and Windows, the compiler will find this
// "Time.h" instead of the C library "time.h", so we may cause other weird
// and unpredictable effects by conflicting with the C library header "time.h",
// but at least this hack lets us define C++ functions as intended. Hopefully
// nothing too terrible will result from overriding the C library header?!
extern
"C++"
{
typedef
enum
{
timeNotSet
,
timeNeedsSync
,
timeSet
}
timeStatus_t
;
typedef
enum
{
dowInvalid
,
dowSunday
,
dowMonday
,
dowTuesday
,
dowWednesday
,
dowThursday
,
dowFriday
,
dowSaturday
}
timeDayOfWeek_t
;
typedef
enum
{
tmSecond
,
tmMinute
,
tmHour
,
tmWday
,
tmDay
,
tmMonth
,
tmYear
,
tmNbrFields
}
tmByteFields
;
typedef
struct
{
uint8_t
Second
;
uint8_t
Minute
;
uint8_t
Hour
;
uint8_t
Wday
;
// day of week, sunday is day 1
uint8_t
Day
;
uint8_t
Month
;
uint8_t
Year
;
// offset from 1970;
}
tmElements_t
,
TimeElements
,
*
tmElementsPtr_t
;
//convenience macros to convert to and from tm years
#define tmYearToCalendar(Y) ((Y) + 1970) // full four digit year
#define CalendarYrToTm(Y) ((Y) - 1970)
#define tmYearToY2k(Y) ((Y) - 30) // offset is from 2000
#define y2kYearToTm(Y) ((Y) + 30)
typedef
time_t
(
*
getExternalTime
)();
//typedef void (*setExternalTime)(const time_t); // not used in this version
/*==============================================================================*/
/* Useful Constants */
#define SECS_PER_MIN (60UL)
#define SECS_PER_HOUR (3600UL)
#define SECS_PER_DAY (SECS_PER_HOUR * 24UL)
#define DAYS_PER_WEEK (7UL)
#define SECS_PER_WEEK (SECS_PER_DAY * DAYS_PER_WEEK)
#define SECS_PER_YEAR (SECS_PER_WEEK * 52UL)
#define SECS_YR_2000 (946684800UL) // the time at the start of y2k
/* Useful Macros for getting elapsed time */
#define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN)
#define numberOfMinutes(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN)
#define numberOfHours(_time_) (( _time_% SECS_PER_DAY) / SECS_PER_HOUR)
#define dayOfWeek(_time_) ((( _time_ / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday
#define elapsedDays(_time_) ( _time_ / SECS_PER_DAY) // this is number of days since Jan 1 1970
#define elapsedSecsToday(_time_) (_time_ % SECS_PER_DAY) // the number of seconds since last midnight
// The following macros are used in calculating alarms and assume the clock is set to a date later than Jan 1 1971
// Always set the correct time before settting alarms
#define previousMidnight(_time_) (( _time_ / SECS_PER_DAY) * SECS_PER_DAY) // time at the start of the given day
#define nextMidnight(_time_) ( previousMidnight(_time_) + SECS_PER_DAY ) // time at the end of the given day
#define elapsedSecsThisWeek(_time_) (elapsedSecsToday(_time_) + ((dayOfWeek(_time_)-1) * SECS_PER_DAY) ) // note that week starts on day 1
#define previousSunday(_time_) (_time_ - elapsedSecsThisWeek(_time_)) // time at the start of the week for the given time
#define nextSunday(_time_) ( previousSunday(_time_)+SECS_PER_WEEK) // time at the end of the week for the given time
/* Useful Macros for converting elapsed time to a time_t */
#define minutesToTime_t ((M)) ( (M) * SECS_PER_MIN)
#define hoursToTime_t ((H)) ( (H) * SECS_PER_HOUR)
#define daysToTime_t ((D)) ( (D) * SECS_PER_DAY) // fixed on Jul 22 2011
#define weeksToTime_t ((W)) ( (W) * SECS_PER_WEEK)
/*============================================================================*/
/* time and date functions */
int
hour
();
// the hour now
int
hour
(
time_t
t
);
// the hour for the given time
int
hourFormat12
();
// the hour now in 12 hour format
int
hourFormat12
(
time_t
t
);
// the hour for the given time in 12 hour format
uint8_t
isAM
();
// returns true if time now is AM
uint8_t
isAM
(
time_t
t
);
// returns true the given time is AM
uint8_t
isPM
();
// returns true if time now is PM
uint8_t
isPM
(
time_t
t
);
// returns true the given time is PM
int
minute
();
// the minute now
int
minute
(
time_t
t
);
// the minute for the given time
int
second
();
// the second now
int
second
(
time_t
t
);
// the second for the given time
int
day
();
// the day now
int
day
(
time_t
t
);
// the day for the given time
int
weekday
();
// the weekday now (Sunday is day 1)
int
weekday
(
time_t
t
);
// the weekday for the given time
int
month
();
// the month now (Jan is month 1)
int
month
(
time_t
t
);
// the month for the given time
int
year
();
// the full four digit year: (2009, 2010 etc)
int
year
(
time_t
t
);
// the year for the given time
time_t
now
();
// return the current time as seconds since Jan 1 1970
void
setTime
(
time_t
t
);
void
setTime
(
int
hr
,
int
min
,
int
sec
,
int
day
,
int
month
,
int
yr
);
void
adjustTime
(
long
adjustment
);
/* date strings */
#define dt_MAX_STRING_LEN 9 // length of longest date string (excluding terminating null)
char
*
monthStr
(
uint8_t
month
);
char
*
dayStr
(
uint8_t
day
);
char
*
monthShortStr
(
uint8_t
month
);
char
*
dayShortStr
(
uint8_t
day
);
/* time sync functions */
timeStatus_t
timeStatus
();
// indicates if time has been set and recently synchronized
void
setSyncProvider
(
getExternalTime
getTimeFunction
);
// identify the external time provider
void
setSyncInterval
(
time_t
interval
);
// set the number of seconds between re-sync
/* low level functions to convert to and from system time */
void
breakTime
(
time_t
time
,
tmElements_t
&
tm
);
// break time_t into elements
time_t
makeTime
(
tmElements_t
&
tm
);
// convert time elements into time_t
}
// extern "C++"
#endif // __cplusplus
#endif
/* _Time_h */
#include "TimeLib.h"
TimeLib.h
0 → 100644
浏览文件 @
26cd0c85
/*
time.h - low level time and date functions
*/
/*
July 3 2011 - fixed elapsedSecsThisWeek macro (thanks Vincent Valdy for this)
- fixed daysToTime_t macro (thanks maniacbug)
*/
#ifndef _Time_h
#ifdef __cplusplus
#define _Time_h
#include <inttypes.h>
#ifndef __AVR__
#include <sys/types.h> // for __time_t_defined, but avr libc lacks sys/types.h
#endif
#if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc
typedef
unsigned
long
time_t
;
#endif
// This ugly hack allows us to define C++ overloaded functions, when included
// from within an extern "C", as newlib's sys/stat.h does. Actually it is
// intended to include "time.h" from the C library (on ARM, but AVR does not
// have that file at all). On Mac and Windows, the compiler will find this
// "Time.h" instead of the C library "time.h", so we may cause other weird
// and unpredictable effects by conflicting with the C library header "time.h",
// but at least this hack lets us define C++ functions as intended. Hopefully
// nothing too terrible will result from overriding the C library header?!
extern
"C++"
{
typedef
enum
{
timeNotSet
,
timeNeedsSync
,
timeSet
}
timeStatus_t
;
typedef
enum
{
dowInvalid
,
dowSunday
,
dowMonday
,
dowTuesday
,
dowWednesday
,
dowThursday
,
dowFriday
,
dowSaturday
}
timeDayOfWeek_t
;
typedef
enum
{
tmSecond
,
tmMinute
,
tmHour
,
tmWday
,
tmDay
,
tmMonth
,
tmYear
,
tmNbrFields
}
tmByteFields
;
typedef
struct
{
uint8_t
Second
;
uint8_t
Minute
;
uint8_t
Hour
;
uint8_t
Wday
;
// day of week, sunday is day 1
uint8_t
Day
;
uint8_t
Month
;
uint8_t
Year
;
// offset from 1970;
}
tmElements_t
,
TimeElements
,
*
tmElementsPtr_t
;
//convenience macros to convert to and from tm years
#define tmYearToCalendar(Y) ((Y) + 1970) // full four digit year
#define CalendarYrToTm(Y) ((Y) - 1970)
#define tmYearToY2k(Y) ((Y) - 30) // offset is from 2000
#define y2kYearToTm(Y) ((Y) + 30)
typedef
time_t
(
*
getExternalTime
)();
//typedef void (*setExternalTime)(const time_t); // not used in this version
/*==============================================================================*/
/* Useful Constants */
#define SECS_PER_MIN (60UL)
#define SECS_PER_HOUR (3600UL)
#define SECS_PER_DAY (SECS_PER_HOUR * 24UL)
#define DAYS_PER_WEEK (7UL)
#define SECS_PER_WEEK (SECS_PER_DAY * DAYS_PER_WEEK)
#define SECS_PER_YEAR (SECS_PER_WEEK * 52UL)
#define SECS_YR_2000 (946684800UL) // the time at the start of y2k
/* Useful Macros for getting elapsed time */
#define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN)
#define numberOfMinutes(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN)
#define numberOfHours(_time_) (( _time_% SECS_PER_DAY) / SECS_PER_HOUR)
#define dayOfWeek(_time_) ((( _time_ / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday
#define elapsedDays(_time_) ( _time_ / SECS_PER_DAY) // this is number of days since Jan 1 1970
#define elapsedSecsToday(_time_) (_time_ % SECS_PER_DAY) // the number of seconds since last midnight
// The following macros are used in calculating alarms and assume the clock is set to a date later than Jan 1 1971
// Always set the correct time before settting alarms
#define previousMidnight(_time_) (( _time_ / SECS_PER_DAY) * SECS_PER_DAY) // time at the start of the given day
#define nextMidnight(_time_) ( previousMidnight(_time_) + SECS_PER_DAY ) // time at the end of the given day
#define elapsedSecsThisWeek(_time_) (elapsedSecsToday(_time_) + ((dayOfWeek(_time_)-1) * SECS_PER_DAY) ) // note that week starts on day 1
#define previousSunday(_time_) (_time_ - elapsedSecsThisWeek(_time_)) // time at the start of the week for the given time
#define nextSunday(_time_) ( previousSunday(_time_)+SECS_PER_WEEK) // time at the end of the week for the given time
/* Useful Macros for converting elapsed time to a time_t */
#define minutesToTime_t ((M)) ( (M) * SECS_PER_MIN)
#define hoursToTime_t ((H)) ( (H) * SECS_PER_HOUR)
#define daysToTime_t ((D)) ( (D) * SECS_PER_DAY) // fixed on Jul 22 2011
#define weeksToTime_t ((W)) ( (W) * SECS_PER_WEEK)
/*============================================================================*/
/* time and date functions */
int
hour
();
// the hour now
int
hour
(
time_t
t
);
// the hour for the given time
int
hourFormat12
();
// the hour now in 12 hour format
int
hourFormat12
(
time_t
t
);
// the hour for the given time in 12 hour format
uint8_t
isAM
();
// returns true if time now is AM
uint8_t
isAM
(
time_t
t
);
// returns true the given time is AM
uint8_t
isPM
();
// returns true if time now is PM
uint8_t
isPM
(
time_t
t
);
// returns true the given time is PM
int
minute
();
// the minute now
int
minute
(
time_t
t
);
// the minute for the given time
int
second
();
// the second now
int
second
(
time_t
t
);
// the second for the given time
int
day
();
// the day now
int
day
(
time_t
t
);
// the day for the given time
int
weekday
();
// the weekday now (Sunday is day 1)
int
weekday
(
time_t
t
);
// the weekday for the given time
int
month
();
// the month now (Jan is month 1)
int
month
(
time_t
t
);
// the month for the given time
int
year
();
// the full four digit year: (2009, 2010 etc)
int
year
(
time_t
t
);
// the year for the given time
time_t
now
();
// return the current time as seconds since Jan 1 1970
void
setTime
(
time_t
t
);
void
setTime
(
int
hr
,
int
min
,
int
sec
,
int
day
,
int
month
,
int
yr
);
void
adjustTime
(
long
adjustment
);
/* date strings */
#define dt_MAX_STRING_LEN 9 // length of longest date string (excluding terminating null)
char
*
monthStr
(
uint8_t
month
);
char
*
dayStr
(
uint8_t
day
);
char
*
monthShortStr
(
uint8_t
month
);
char
*
dayShortStr
(
uint8_t
day
);
/* time sync functions */
timeStatus_t
timeStatus
();
// indicates if time has been set and recently synchronized
void
setSyncProvider
(
getExternalTime
getTimeFunction
);
// identify the external time provider
void
setSyncInterval
(
time_t
interval
);
// set the number of seconds between re-sync
/* low level functions to convert to and from system time */
void
breakTime
(
time_t
time
,
tmElements_t
&
tm
);
// break time_t into elements
time_t
makeTime
(
tmElements_t
&
tm
);
// convert time elements into time_t
}
// extern "C++"
#endif // __cplusplus
#endif
/* _Time_h */
examples/TimeArduinoDue/TimeArduinoDue.ino
浏览文件 @
26cd0c85
...
...
@@ -6,7 +6,7 @@
* https://github.com/MarkusLange/Arduino-Due-RTC-Library
*/
#include <Time.h>
#include <Time
Lib
.h>
#include <rtc_clock.h>
// Select the Slowclock source
...
...
examples/TimeGPS/TimeGPS.ino
浏览文件 @
26cd0c85
...
...
@@ -4,7 +4,7 @@
*
*/
#include <Time.h>
#include <Time
Lib
.h>
#include <TinyGPS.h> // http://arduiniana.org/libraries/TinyGPS/
#include <SoftwareSerial.h>
// TinyGPS and SoftwareSerial libraries are the work of Mikal Hart
...
...
examples/TimeNTP/TimeNTP.ino
浏览文件 @
26cd0c85
...
...
@@ -5,7 +5,7 @@
* This sketch uses the Ethernet library
*/
#include <Time
.h>
#include <Time
Lib.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
...
...
examples/TimeRTC/TimeRTC.
pde
→
examples/TimeRTC/TimeRTC.
ino
浏览文件 @
26cd0c85
...
...
@@ -4,8 +4,8 @@
*
*/
#include <Time
.h>
#include <Wire.h>
#include <Time
Lib.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
void
setup
()
{
...
...
examples/TimeRTCLog/TimeRTCLog.
pde
→
examples/TimeRTCLog/TimeRTCLog.
ino
浏览文件 @
26cd0c85
...
...
@@ -6,8 +6,8 @@
* the time of the event and time since the previous event is calculated and sent to the serial port.
*/
#include <Time
.h>
#include <Wire.h>
#include <Time
Lib.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
const
int
nbrInputPins
=
6
;
// monitor 6 digital pins
...
...
examples/TimeRTCSet/TimeRTCSet.ino
浏览文件 @
26cd0c85
...
...
@@ -7,8 +7,8 @@
* On Linux, you can use "date +T%s > /dev/ttyACM0" (UTC time zone)
*/
#include <Time
.h>
#include <Wire.h>
#include <Time
Lib.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
...
...
examples/TimeSerial/TimeSerial.ino
浏览文件 @
26cd0c85
...
...
@@ -10,7 +10,7 @@
* On Linux, you can use "date +T%s\n > /dev/ttyACM0" (UTC time zone)
*/
#include <Time
.h>
#include <Time
Lib.h>
#define TIME_HEADER "T" // Header tag for serial time sync message
#define TIME_REQUEST 7 // ASCII bell character requests a time sync message
...
...
examples/TimeSerialDateStrings/TimeSerialDateStrings.ino
浏览文件 @
26cd0c85
...
...
@@ -15,7 +15,7 @@
* send: Fl\n for long date format
*/
#include <Time
.h>
#include <Time
Lib.h>
// single character message tags
#define TIME_HEADER 'T' // Header tag for serial time sync message
...
...
examples/TimeTeensy3/TimeTeensy3.ino
浏览文件 @
26cd0c85
...
...
@@ -4,7 +4,7 @@
*
*/
#include <Time
.h>
#include <Time
Lib.h>
void
setup
()
{
// set the Time library to use Teensy 3.0's RTC to keep time
...
...
keywords.txt
浏览文件 @
26cd0c85
...
...
@@ -24,6 +24,7 @@ adjustTime KEYWORD2
setSyncProvider KEYWORD2
setSyncInterval KEYWORD2
timeStatus KEYWORD2
TimeLib KEYWORD2
#######################################
# Instances (KEYWORD2)
#######################################
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录