Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0ac12b9
Real Time Clock API - first draft
cmaglie Mar 18, 2016
dfe0136
Added motion interfaces
cmaglie Mar 24, 2016
0e1a28b
Fixed some typos
cmaglie Mar 24, 2016
67b8914
Added Rotation and Quaternion structures
cmaglie Mar 24, 2016
9924ebc
Renamed Motion.h -> MotionSense.h. Added some comments
cmaglie Mar 24, 2016
3eef53d
added Magnetometer class
cmaglie Mar 24, 2016
b66a1bb
Added some comments about units. Renamed Gyro -> Gyroscope
cmaglie Mar 25, 2016
4c1e94f
Correct quaternion order
cmaglie Mar 25, 2016
0a9804f
EulerAngles is a more appropriate name
cmaglie Mar 25, 2016
6e0ca14
Added Magnetometer.expectedMagneticFieldStrength() method
cmaglie Mar 25, 2016
0a96c9a
Added comment on EulerAngles units
cmaglie Mar 25, 2016
9be6359
No defaults FIFO methods for gyroscope.
cmaglie Mar 25, 2016
bde41a3
Added TimeProvider and related functions
cmaglie Apr 8, 2016
58dae9e
Added basic SoftwareRTC implementation.
cmaglie Apr 8, 2016
c400495
Add initial BLE API based on the BLEPeripheral library
sandeepmistry Apr 14, 2016
38424e2
Move BLE peripheral API into own folder
sandeepmistry Apr 26, 2016
49795df
Correct typo
sandeepmistry Apr 26, 2016
43c0daa
First draft of BLE central API
sandeepmistry Apr 26, 2016
4827027
Added a generic ArduinoAPI.h include folder with API version definitions
cmaglie Jun 9, 2016
4f8b4b2
Removed ARDUINO_REAL_TIME_CLOCK_API_VERSION
cmaglie Jun 9, 2016
e255e3d
Fixed return value on SoftwareRTC::setTime
cmaglie Jun 9, 2016
5bfc0cb
Add generic uint8_t RingBuffer class
facchinm Jul 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Real Time Clock API - first draft
  • Loading branch information
cmaglie committed Mar 18, 2016
commit 0ac12b9c85f94a3d94fb057b89d44929f893f33b
136 changes: 136 additions & 0 deletions api/RealTimeClock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
RealTimeClock API
Copyright (c) 2016 Arduino LLC. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

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
*/

#include "RealTimeClock.h"
#include <time.h>

#define YEAR_OFFSET 1900
#define MONTH_OFFSET 1

RealTimeClock *arduinoSystemRTC;

unsigned long now()
{
if (arduinoSystemRTC) {
return arduinoSystemRTC->getTime();
} else {
return 0;
}
}

static struct tm* toTm(unsigned long t)
{
time_t time = t;
return gmtime(&time);
}

int year(unsigned long t)
{
struct tm* tm = toTm(t);
return (tm->tm_year + YEAR_OFFSET);
}

int year()
{
return year(now());
}

int month(unsigned long t)
{
struct tm* tm = toTm(t);
return (tm->tm_mon + MONTH_OFFSET);
}

int month()
{
return month(now());
}

int day(unsigned long t)
{
struct tm* tm = toTm(t);
return tm->tm_mday;
}

int day()
{
return day(now());
}

int hour(unsigned long t)
{
struct tm* tm = toTm(t);
return tm->tm_hour;
}

int hour()
{
return hour(now());
}

int minute(unsigned long t)
{
struct tm* tm = toTm(t);
return tm->tm_min;
}

int minute()
{
return minute(now());
}

int second(unsigned long t)
{
struct tm* tm = toTm(t);
return tm->tm_sec;
}

int second()
{
return second(now());
}

void setTime(unsigned long t)
{
if (arduinoSystemRTC) {
arduinoSystemRTC->setTime(t);
}
}

unsigned long convertTime(int hour, int minute, int second, int day, int month, int year)
{
struct tm tm;

tm.tm_year = year - YEAR_OFFSET;
tm.tm_mon = month - MONTH_OFFSET;
tm.tm_mday = day;
tm.tm_hour = hour;
tm.tm_min = minute;
tm.tm_sec = second;
tm.tm_isdst = -1;

return mktime(&tm);
}

void setTime(int hour, int minute, int second, int day, int month, int year)
{
time_t t = convertTime(hour, minute, second, day, month, year);

setTime(t);
}
62 changes: 62 additions & 0 deletions api/RealTimeClock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
RealTimeClock API
Copyright (c) 2016 Arduino LLC. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

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
*/

#ifndef ARDUINO_REAL_TIME_CLOCK_H
#define ARDUINO_REAL_TIME_CLOCK_H

#define ARDUINO_REAL_TIME_CLOCK_API_VERSION 10000 // version 1.0.0

// Functions to get and set current time

int year(); // current year as an integer
int month(); // current month as an integer (1 - 12)
int day(); // current day as an integer (1 - 31)
int hour(); // current hour as an integer (0 - 23)
int minute(); // current minute as an integer (0 - 59)
int second(); // current second as an integer (0 - 59)
void setTime(int hour, int minute, int second, int day, int month, int year); // set the current time

// Functions to get ans set current time with unix-timestamps

unsigned long now(); // current time as seconds since Jan 1 1970
void setTime(unsigned long t); // set the current time from seconds since Jan 1 1970

// Functions to convert time from unix-timestamp to human readable format and viceversa

int year(unsigned long t); // year of t as an integer
int month(unsigned long t); // month of t as an integer (1 - 12)
int day(unsigned long t); // day of t as an integer (1 - 31)
int hour(unsigned long t); // hour of t as an integer (0 - 23)
int minute(unsigned long t); // minute of t as an integer (0 - 59)
int second(unsigned long t); // second of t as an integer (0 - 59)

unsigned long convertTime(int hour, int minute, int second, int day, int month, int year);

// Real Time Clock interface
// Time sources should implement this interfaces
class RealTimeClock
{
public:
virtual unsigned long getTime() = 0;
virtual bool setTime(unsigned long t) = 0;
};

extern RealTimeClock *arduinoSystemRTC;

#endif