Skip to content

Commit

Permalink
Merge pull request sirleech#36 from edvler/master
Browse files Browse the repository at this point in the history
Update for Web_Net_Setup
  • Loading branch information
unwiredben committed Mar 25, 2013
2 parents 4d62c1a + 871af35 commit 56d91f5
Show file tree
Hide file tree
Showing 3 changed files with 376 additions and 172 deletions.
59 changes: 59 additions & 0 deletions examples/Web_Net_Setup/System.cpp
@@ -0,0 +1,59 @@
#include "Arduino.h"
#include "System.h"

char* System::uptime()
{
char buffer[65];

long days=0;
long hours=0;
long mins=0;
long secs=0;

secs = millis()/1000; //convect milliseconds to seconds
mins=secs/60; //convert seconds to minutes
hours=mins/60; //convert minutes to hours
days=hours/24; //convert hours to days
secs=secs-(mins*60); //subtract the coverted seconds to minutes in order to display 59 secs max
mins=mins-(hours*60); //subtract the coverted minutes to hours in order to display 59 minutes max
hours=hours-(days*24); //subtract the coverted hours to days in order to display 23 hours max

if (days > 0) {
ltoa(days,buffer,10);
strcpy(retval,buffer);
}
else {
strcpy(retval,"0");
}

strcat(retval,":");
ltoa(hours,buffer,10);
strcat(retval,buffer);

strcat(retval,":");
ltoa(mins,buffer,10);
strcat(retval,buffer);

strcat(retval,":");
ltoa(secs,buffer,10);
strcat(retval,buffer);

strcat(retval,'\0');

return retval;
}

int System::ramFree () {
extern int __heap_start, *__brkval;
int v;
int a = (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
return a;
}

int System::ramSize() {
int v;
int a = (int) &v;
return a;
}


39 changes: 39 additions & 0 deletions examples/Web_Net_Setup/System.h
@@ -0,0 +1,39 @@
#ifndef System_h
#define System_h

#include <Arduino.h>

/**
* System Class.
*
* @author Matthias Maderer
* @version 1.1.7
*/
class System {
public:
/**
* Returns the uptime of the arduino with a char pointer.
* Format: DAYS:HOURS:MINUTES:SECONDS
* Sample: 1:20:23:50 = 1 day, 20 hours, 23 minutes and 50 seconds
* @return char *: pointer!
*/
char * uptime();

/**
* Returns the free RAM
* @return int: free RAM
*/
int ramFree();

/**
* Returns the size of the RAM
* @return int: RAM size
*/
int ramSize();

private:
char retval[25];
};

#endif

0 comments on commit 56d91f5

Please sign in to comment.