Added datetime to simpletools library
Rsadeika
Posts: 3,837
in Propeller 1
The datetime lib is not available in the SimpleIDE library selection, so you will have to get it from the hackable badge tools. After you find the lib you can then copy the folder to /Documents/SimpleIDE/Learn/Simple Libraries folder, that way it will be available when you use Add Simple Libraries.
Below is a program that I put together to make sure the datetime lib is working, as expected, in a regular, non Hackable Badge setup. Yesterday I put together a program using the C available softRTC, with all the trimmings added the program size was ~20K. Even when I used the RTC with the DNA-RTC board the program size was about ~20K. The program below comes in at about ~8K, Andy did a great job with the lib.
The program below is basically set up to work with the XBee installed on the Activity Board, but I left some examples of how you could change it over to use the terminal window. There are other functions in the Hackable Badge lib that could be used for stand alone items, but some of that stuff is embedded in the hackablebadge lib, not enough skill to break it out for a stand alone lib.
Ray
Below is a program that I put together to make sure the datetime lib is working, as expected, in a regular, non Hackable Badge setup. Yesterday I put together a program using the C available softRTC, with all the trimmings added the program size was ~20K. Even when I used the RTC with the DNA-RTC board the program size was about ~20K. The program below comes in at about ~8K, Andy did a great job with the lib.
The program below is basically set up to work with the XBee installed on the Activity Board, but I left some examples of how you could change it over to use the terminal window. There are other functions in the Hackable Badge lib that could be used for stand alone items, but some of that stuff is embedded in the hackablebadge lib, not enough skill to break it out for a stand alone lib.
Ray
/* rb5x_ab_dt.c January 5,2017 */ #include "simpletools.h" #include "simpletext.h" #include "fdserial.h" #include "datetime.h" serial *xbee; /* DateTime */ /* Starting base for datetime. */ datetime dt = {2016, 1, 1, 0, 0, 0}; char dates[9]; char times[9]; void get_Time(); void get_Date(); void set_Clock(); /*************************/ /* General functions */ void menu(); /*************************/ char inBuff[40]; int main() { // Add startup code here. /* Start datetime*/ dt_run(dt); /* Rx Tx BAUD */ xbee = fdserial_open(11, 10, 0, 9600); while(1) { // Add main loop code here. //putStr("> "); // Use for terminal window; writeStr(xbee,">"); //getStr(inBuff,40); // Use for terminal window; readStr(xbee,inBuff,40); if(!strcmp(inBuff,"time")) get_Time(); else if(!strcmp(inBuff,"date")) get_Date(); else if(!strcmp(inBuff,"setclock")) set_Clock(); else if(!strcmp(inBuff, "help")) menu(); else { //putLine("Invalid Command"); // Use for terminal window. writeLine(xbee,"Invalid Command"); } } } /*************************/ /* DateTime functions */ void set_Clock() { writeStr(xbee,"Year: "); int y = readDec(xbee); dt.y = y; writeStr(xbee,"\nMonth: "); int mo = readDec(xbee); dt.mo = mo; writeStr(xbee,"\nDay: "); int d = readDec(xbee); dt.d = d; writeStr(xbee,"\nHour: "); int h = readDec(xbee); dt.h = h; writeStr(xbee,"\nMinutes: "); int m = readDec(xbee); dt.m = m; writeStr(xbee,"\nSeconds: "); int s = readDec(xbee); dt.s = s; /* Set the new values. */ dt_set(dt); /* Show the new clock values. */ get_Date(); get_Time(); } void get_Time() { dt = dt_get(); dt_toTimeStr(dt, times); //print("%s\n",times); // Use for terminal window. writeStr(xbee,times); writeStr(xbee,"\n"); } void get_Date() { dt = dt_get(); dt_toDateStr(dt, dates); //print("%s\n",dates); // Use for terminal window. writeStr(xbee,dates); writeStr(xbee,"\n"); } /*************************/ /* General functions */ void menu() { writeStr(xbee,"Menu - time, date, setclock \n"); } /*************************/