Loading...
Pages: [1]   Go Down
Author Topic: Due compatible Time library?  (Read 1292 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
any one know if there is a compatible Time library for Arduino Due?
What i use are:

setTime(hour,min,secs,day,mont,year)
hour()
minute()
second()

I am getting this kind of errors:

/home/deco/progetti/arduino/progetti/Arduino/libraries/Time/Time.h:15: error: conflicting declaration 'typedef long unsigned int time_t'
/home/deco/software/arduino2/arduino-1.5.1/hardware/tools/g++_arm_none_eabi/bin/../lib/gcc/arm-none-eabi/4.4.1/../../../../arm-none-eabi/include/sys/types.h:109: error: 'time_t' has a previous declaration as 'typedef long int time_t'

Code compiled correctly (and still compiles) on older arduino versions.
I think the error is quite easy to fix, but I dint manage to get it in about an hour.
Line numbers are not precise, I dont know why, I think some sort of preprocessor passes before gcc.

Thank you all  smiley
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 71
Posts: 6826
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Markus is/was writing one and has posted recently.

http://arduino.cc/forum/index.php/topic,136126.0.html

______
Rob
Logged

Rob Gray aka the GRAYnomad http://www.robgray.com

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Markus is/was writing one and has posted recently.

http://arduino.cc/forum/index.php/topic,136126.0.html

______
Rob

Yes I did, if you have any questions, suggestions or if you need an function let me know.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you both (thank you twice Markus!).
I just downloaded the library and as soon as possible I'll compile it.
I'll keep you in touch  :-)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry for the delay, but yesterday I was busy with work till late.
Just compiled with your library, after translating function calls, and it seems to work correctly smiley-grin
Thank you very much.
By the way, the interface to the rtc_clock is clean and simple, very nice work.
Even if at the moment I dont use it, also the interface for the alarm:
  rtc_clock.set_alarmtime(10, 30, 0); 
  rtc_clock.attachalarm(announcement);
  void announcement(){
    ...
  }
is very clean and I love it.
Thank you again
Logged

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry for the delay, but yesterday I was busy with work till late.
Just compiled with your library, after translating function calls, and it seems to work correctly smiley-grin
Thank you very much.
By the way, the interface to the rtc_clock is clean and simple, very nice work.
Even if at the moment I dont use it, also the interface for the alarm:
  rtc_clock.set_alarmtime(10, 30, 0); 
  rtc_clock.attachalarm(announcement);
  void announcement(){
    ...
  }
is very clean and I love it.
Thank you again
Thanks for the response.

No hurry, lovely that you like it. btw you can set Hours, Minuets and Seconds seperate for the time too, and the function to call the Alarminterrupt takes me the most time.
Logged

0
Offline Offline
Sr. Member
****
Karma: 19
Posts: 420
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I recently ported the Time library for Teensy 3.0.  This doesn't directly support the Due RTC, but it's meant to work together with the library mentioned above.

Michael Margolis (author of this Time library) and I talked about the time_t compatibility issue.  His preference was to rename it to atime_t.  Probably "a" for Arduino?

Here's the modified code:

http://www.pjrc.com/teensy/beta/Time.zip

I really should have followed up by updating the playground page.

Can anyone here please test this on Due and then update the playground page?  The original code has a TimeAlarms library in the same file, which I haven't used (I did start on it... contact me for the code).  It probably needs to be split into a separate download, ported and tested.  The page also mentions "time_t", which needs to be edited to "atime_t".  I simply ran out of time to update the page.
Logged

Dallas, TX USA
Offline Offline
Edison Member
*
Karma: 25
Posts: 1617
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I recently ported the Time library for Teensy 3.0.  This doesn't directly support the Due RTC, but it's meant to work together with the library mentioned above.

Michael Margolis (author of this Time library) and I talked about the time_t compatibility issue.  His preference was to rename it to atime_t.  Probably "a" for Arduino?

Yuck! That seems like a dreadful solution.
Please, please don't go down that route. That is such a Windows-fix-of-the-moment type of fix.
That really breaks compatibility especially for those writing code that will use the time  type for
things like calculating time intervals.
Why not use the   __time_t_defined define to determine whether or not the system has already typed time_t ?
The define could be tested to see if time_t needs to be typed in the library Time.h file.
This seems like a proper fix.

Add this to the Time library Time.h header file:
Code:
#ifndef __time_t_defined
typedef unsigned long time_t;
#endif

Then the STUPID IDE also has an issue that rears it ugly head again that breaks this.
The IDE inserts its prologue which includes
Code:
#include "Arduino.h"
in the middle of the sketch .cpp file so it ends up after the
Code:
#include <Time.h>
So the system version of time_t doesn't get typed before the library Time.h looks at the define.
You have to insert some dummy code to coerce the silly IDE to put the prologue at the top of the .cpp file
I added this to the example sketch:
Code:
int dummy = 0;
right at the top of the sketch.

(Can't the IDE be fixed to avoid this silly wrong location prologue insertion????)

One thing that is concerning to me is that since Windows is doesn't handle mixed case
on its file names, #include <Time.h> might end up pulling in the system time.h since it is earlier on the include path
(I don't do Windows so I'm not sure about that).


--- bill
« Last Edit: December 15, 2012, 04:17:15 am by bperrybap » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Paul Stoffregen,

I have tested your version of Time and it's remotely to be ported for Due. Actually I already did the time_t variable name change, but that is not the only thing that need to be modified (I did it as bperrybap suggest thought).

Code:
#include <machine/types.h>

#ifndef __time_t_defined
//typedef unsigned long time_t; // original library typedef.
typedef _TIME_T_ time_t;
#define __time_t_defined
#endif


After that I have been through several compiling errors I would like to bring them here.
First with setTime function, it seems that overloading that function bothers the compiler
previous declaration 'void setTime(atime_t)' here

I decide to remove (comment out) the version with more arguments as you can use the makeTime to have time_t from individual values.
I also have to remove from Time Folder the file DateStrings.cpp.

After all that I make a simple test file like this

Code:
#include <Wire.h>  
#include <Time.h>  

void setup()  {
  Wire.begin();
  Serial.begin(9600);
  Serial.println("setup RTC test");

  tmElements_t t;
  t.Second = 0;
  t.Minute = 30;
  t.Hour = 19;
  t.Wday = 3;
  t.Day = 16;
  t.Month = 1;
  t.Year = y2kYearToTm(13);
  Serial.println("setup makeTime");
  makeTime(t);
//  setTime(makeTime(t));
  Serial.println("how come  ");

  
}
void loop()
{
   digitalClockDisplay();  
   delay(1000);
}



void digitalClockDisplay(){
  // digital clock display of the time
  time_t t = now();
  Serial.print(hour(t));
  printDigits(minute(t));
  printDigits(second(t));
  Serial.print(" ");
  Serial.print(day(t));
  Serial.print(" ");
  Serial.print(month(t));
  Serial.print(" ");
  Serial.print(year(t));
  Serial.println();
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}


the good thing is that it compiles but the bad is that a warning appears

test_time.cpp.o: In function `setup':
C:\...\arduino-1.5.1r2/test_time.ino:24: warning: undefined reference to `makeTime(tmElements_t&)'
Binary sketch size: 25,856 bytes (of a 524,288 byte maximum)


I recently discover that if you put the Time.h include at the beginning of the import section it produces the above error and the Due hangs before it can print "how come".

If you put any other import before Time.h it compiles cleanly and run without problems.

Maybe it have to do with

Quote
Then the STUPID IDE also has an issue that rears it ugly head again that breaks this.
The IDE inserts its prologue which includes
Code:
#include "Arduino.h"
in the middle of the sketch .cpp file so it ends up after the
Code:
#include <Time.h>
So the system version of time_t doesn't get typed before the library Time.h looks at the define.
You have to insert some dummy code to coerce the silly IDE to put the prologue at the top of the .cpp file
I added this to the example sketch:
Code:
int dummy = 0;
right at the top of the sketch.

I found another issue, in file Time.h the line
Code:
typedef time_t(*getExternalTime)();

should be

Code:
typedef time_t(*getExternalTime)(void);

Best,
« Last Edit: January 17, 2013, 09:53:40 pm by mhanuel26 » Logged

Pages: [1]   Go Up
Print
 
Jump to: