Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'refs/heads/master' into develop

Conflicts:
	.gitignore
  • Loading branch information...
commit 15b2be4b4846620094eb94b845803620a08a3862 2 parents cc6cadd + 9a298fd
@reefab authored
View
32 README.md
@@ -2,35 +2,34 @@
## Description
-This project provides an [Arduino](http://arduino.cc/) sketch that can power an Arduino + Ethernet Shield (or Arduino with built-in ethernet) to make a stationary bike computer that can upload Cycling workout sessions results to [Runkeeper](http://runkeeper.com/)'s [Healthgraph API](http://developer.runkeeper.com/healthgraph), where it get added to the user's activities feed.
-The activity can then be posted to Twitter or Facebook automatically by Runkeeper.
+This project provides an [Arduino](http://arduino.cc/) sketch that can power an Arduino + Ethernet Shield (or Arduino with built-in ethernet)
+to make a stationary bike computer that can upload Cycling workout sessions results to [Runkeeper](http://runkeeper.com/)'s [Healthgraph API](http://developer.runkeeper.com/healthgraph).
+This activity get added to the user's activities feed and could then be posted to Twitter or Facebook automatically by Runkeeper.
-It doesn't need to be connected to a computer for that purpose, only a wired ethernet connection + DHCP is required.
+It doesn't need to be connected to a computer for that purpose, only a wired ethernet connection is required.
-It'll also display either current speed and total distance or average speed and elapsed time during normal use via a LCD.
+It'll also display the current speed and either the total distance or average speed or elapsed time during normal use via a LCD.
The sensor used is the [reed switch](http://en.wikipedia.org/wiki/Reed_switch) that was already present in my stationary bike connected to the Arduino with a pulldown resistor.
-The elapsed time only counts 15 seconds chunks when there was some activity, otherwise it'll pause.
+The elapsed time only counts 15 seconds chunks when there was some activity, otherwise it'll pause automatically.
-If the pause last more than 5 minutes, it'll upload to Runkeeper the:
+If the pause last more than 2 minutes, it'll upload to Runkeeper the:
* Starting Time
* Total Distance
* Elapsed Time
-for the current session. From this, Runkeeper computes the average speed, pace and
-total calories burned.
+for the current session. From this, Runkeeper computes the average speed, pace and total calories burned.
## Usage
Plug the ethernet cable and the USB/Power cable in.
-The Arduino will beep once it has obtained the current time and is ready for
-use.
+The Arduino will beep once it has obtained the current time and is ready for use.
Pedal away and it'll display the current speed while cycling between the total distance. average speed and elapsed time.
-Stop pedaling for ~ 15 seconds and the pause screen will come up. 60 seconds, the lcd's backlight will be switched off. 5 minutes and it'll end the session and upload the result or discard the session if the "valid activity" threshold hasn't been reached.
+Stop pedaling for ~ 15 seconds and the pause screen will come up. 60 seconds, the lcd's backlight will be switched off. 2 minutes and it'll end the session and upload the result or discard the session if the "valid activity" threshold hasn't been reached.
It'll beep every 5km by default.
@@ -41,10 +40,9 @@ To start a new session, just use the bike again, it'll start over.
### Device
![Device in clear enclosure](https://github.com/reefab/CyclingPusher/raw/master/images/finishedVersion.jpg)
[Prototype during testing](https://github.com/reefab/CyclingPusher/raw/master/images/prototype.jpg)
-### Runkeeper's screenshot
+[Stationary bike's reed switch and magnetic brake](https://github.com/reefab/CyclingPusher/raw/master/images/bike.jpg)
+### Runkeeper screenshot
![Runkeeper screenshot](https://github.com/reefab/CyclingPusher/raw/master/images/BikeProjectRunkeeper.png)
-### Reed Switch (at the top of the picture)
-![Stationary bike's reed switch and magnetic brake](https://github.com/reefab/CyclingPusher/raw/master/images/bike.jpg)
## Setup
@@ -70,9 +68,9 @@ Here is the breadboard view:
You'll need to modify/provide the MAC address and Healthgraph's access token in the config.h (that you'll copy from config.h-dist) file.
You might want to change the number of meters per reed switch activation too.
-### How to get access token
+### How to get the access token
-First, once you have your Runkeeper account got to:
+First, once you have your Runkeeper account go to:
http://runkeeper.com/partner/applications/registerForm
@@ -95,4 +93,4 @@ Now, in a shell:
Please note that the 'redirect_uri' needs to the be exact same one as before.
-It'll then give you the access token you can use in your Arduino's code.
+It'll then give you the access token you can use in your Arduino code.
View
BIN  images/BikeProjectRunkeeper.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
70 lib/Time/examples/Processing/SyncArduinoClock/SyncArduinoClock.pde
@@ -1,70 +0,0 @@
-/**
- * SyncArduinoClock.
- *
- * portIndex must be set to the port connected to the Arduino
- *
- * The current time is sent in response to request message from Arduino
- * or by clicking the display window
- *
- * The time message is 11 ASCII text characters; a header (the letter 'T')
- * followed by the ten digit system time (unix time)
- */
-
-
-import processing.serial.*;
-
-public static final short portIndex = 1; // select the com port, 0 is the first port
-public static final char TIME_HEADER = 'T'; //header byte for arduino serial time message
-public static final char TIME_REQUEST = 7; // ASCII bell character
-public static final char LF = 10; // ASCII linefeed
-public static final char CR = 13; // ASCII linefeed
-Serial myPort; // Create object from Serial class
-
-void setup() {
- size(200, 200);
- println(Serial.list());
- println(" Connecting to -> " + Serial.list()[portIndex]);
- myPort = new Serial(this,Serial.list()[portIndex], 9600);
-}
-
-void draw()
-{
- if ( myPort.available() > 0) { // If data is available,
- char val = char(myPort.read()); // read it and store it in val
- if(val == TIME_REQUEST){
- long t = getTimeNow();
- sendTimeMessage(TIME_HEADER, t);
- }
- else
- {
- if(val == LF)
- ; //igonore
- else if(val == CR)
- println();
- else
- print(val); // echo everying but time request
- }
- }
-}
-
-void mousePressed() {
- sendTimeMessage( TIME_HEADER, getTimeNow());
-}
-
-
-void sendTimeMessage(char header, long time) {
- String timeStr = String.valueOf(time);
- myPort.write(header); // send header and time to arduino
- myPort.write(timeStr);
-}
-
-long getTimeNow(){
- // java time is in ms, we want secs
- GregorianCalendar cal = new GregorianCalendar();
- cal.setTime(new Date());
- int tzo = cal.get(Calendar.ZONE_OFFSET);
- int dst = cal.get(Calendar.DST_OFFSET);
- long now = (cal.getTimeInMillis() / 1000) ;
- now = now + (tzo/1000) + (dst/1000);
- return now;
-}
View
9 lib/Time/examples/Processing/SyncArduinoClock/readme.txt
@@ -1,9 +0,0 @@
-SyncArduinoClock is a Processing sketch that responds to Arduino requests for
-time synchronization messages.
-
-The portIndex must be set the Serial port connected to Arduino.
-
-Download TimeSerial.pde onto Arduino and you should see the time
-message displayed when you run SyncArduinoClock in Processing.
-The Arduino time is set from the time on your computer through the
-Processing sketch.
View
82 lib/Time/examples/TimeGPS/TimeGPS.pde
@@ -1,82 +0,0 @@
-/*
- * TimeGPS.pde
- * example code illustrating time synced from a GPS
- *
- */
-
-#include <Time.h>
-#include <TinyGPS.h> //http://arduiniana.org/libraries/TinyGPS/
-#include <NewSoftSerial.h> //http://arduiniana.org/libraries/newsoftserial/
-// GPS and NewSoftSerial libraries are the work of Mikal Hart
-
-TinyGPS gps;
-NewSoftSerial serial_gps = NewSoftSerial(3, 2); // receive on pin 3
-
-const int offset = 1; // offset hours from gps time (UTC)
-time_t prevDisplay = 0; // when the digital clock was displayed
-
-void setup()
-{
- Serial.begin(9600);
- serial_gps.begin(4800);
- Serial.println("Waiting for GPS time ... ");
- setSyncProvider(gpsTimeSync);
-}
-
-void loop()
-{
- while (serial_gps.available())
- {
- gps.encode(serial_gps.read()); // process gps messages
- }
- if(timeStatus()!= timeNotSet)
- {
- if( now() != prevDisplay) //update the display only if the time has changed
- {
- prevDisplay = now();
- digitalClockDisplay();
- }
- }
-}
-
-void digitalClockDisplay(){
- // digital clock display of the time
- Serial.print(hour());
- printDigits(minute());
- printDigits(second());
- Serial.print(" ");
- Serial.print(day());
- Serial.print(" ");
- Serial.print(month());
- Serial.print(" ");
- Serial.print(year());
- 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);
-}
-
-time_t gpsTimeSync(){
- // returns time if avail from gps, else returns 0
- unsigned long fix_age = 0 ;
- gps.get_datetime(NULL,NULL, &fix_age);
- unsigned long time_since_last_fix;
- if(fix_age < 1000)
- return gpsTimeToArduinoTime(); // return time only if updated recently by gps
- return 0;
-}
-
-time_t gpsTimeToArduinoTime(){
- // returns time_t from gps date and time with the given offset hours
- tmElements_t tm;
- int year;
- gps.crack_datetime(&year, &tm.Month, &tm.Day, &tm.Hour, &tm.Minute, &tm.Second, NULL, NULL);
- tm.Year = year - 1970;
- time_t time = makeTime(tm);
- return time + (offset * SECS_PER_HOUR);
-}
View
120 lib/Time/examples/TimeNTP/TimeNTP.pde
@@ -1,120 +0,0 @@
-/*
- * Time_NTP.pde
- * Example showing time sync to NTP time source
- *
- * This sketch uses the Ethenet library with the user contributed UdpBytewise extension
- */
-
-#include <Time.h>
-#include <Ethernet.h>
-#include <UdpBytewise.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
-#if UDP_TX_PACKET_MAX_SIZE <64 || UDP_RX_PACKET_MAX_SIZE < 64
-#error : UDP packet size to small - modify UdpBytewise.h to set buffers to 64 bytes
-#endif
-/*
- *
- * You may need to modify the UdpBytewise.h library to allow enough space in the buffers for the NTP packets.
- * Open up UdpBytewse.h and set the following buffers to 64 bytes:
- * #define UDP_TX_PACKET_MAX_SIZE 64
- * #define UDP_RX_PACKET_MAX_SIZE 64
- */
-
-
-byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
-byte ip[] = { 192, 168, 1, 44 }; // set the IP address to an unused address on your network
-
-byte SNTP_server_IP[] = { 192, 43, 244, 18}; // time.nist.gov
-//byte SNTP_server_IP[] = { 130,149,17,21}; // ntps1-0.cs.tu-berlin.de
-//byte SNTP_server_IP[] = { 192,53,103,108}; // ptbtime1.ptb.de
-
-
-time_t prevDisplay = 0; // when the digital clock was displayed
-const long timeZoneOffset = 0L; // set this to the offset in seconds to your local time;
-
-void setup()
-{
- Serial.begin(9600);
- Ethernet.begin(mac,ip);
- Serial.println("waiting for sync");
- setSyncProvider(getNtpTime);
- while(timeStatus()== timeNotSet)
- ; // wait until the time is set by the sync provider
-}
-
-void loop()
-{
- if( now() != prevDisplay) //update the display only if the time has changed
- {
- prevDisplay = now();
- digitalClockDisplay();
- }
-}
-
-void digitalClockDisplay(){
- // digital clock display of the time
- Serial.print(hour());
- printDigits(minute());
- printDigits(second());
- Serial.print(" ");
- Serial.print(day());
- Serial.print(" ");
- Serial.print(month());
- Serial.print(" ");
- Serial.print(year());
- 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);
-}
-
-/*-------- NTP code ----------*/
-
-unsigned long getNtpTime()
-{
- sendNTPpacket(SNTP_server_IP);
- delay(1000);
- if ( UdpBytewise.available() ) {
- for(int i=0; i < 40; i++)
- UdpBytewise.read(); // ignore every field except the time
- const unsigned long seventy_years = 2208988800UL + timeZoneOffset;
- return getUlong() - seventy_years;
- }
- return 0; // return 0 if unable to get the time
-}
-
-unsigned long sendNTPpacket(byte *address)
-{
- UdpBytewise.begin(123);
- UdpBytewise.beginPacket(address, 123);
- UdpBytewise.write(B11100011); // LI, Version, Mode
- UdpBytewise.write(0); // Stratum
- UdpBytewise.write(6); // Polling Interval
- UdpBytewise.write(0xEC); // Peer Clock Precision
- write_n(0, 8); // Root Delay & Root Dispersion
- UdpBytewise.write(49);
- UdpBytewise.write(0x4E);
- UdpBytewise.write(49);
- UdpBytewise.write(52);
- write_n(0, 32); //Reference and time stamps
- UdpBytewise.endPacket();
-}
-
-unsigned long getUlong()
-{
- unsigned long ulong = (unsigned long)UdpBytewise.read() << 24;
- ulong |= (unsigned long)UdpBytewise.read() << 16;
- ulong |= (unsigned long)UdpBytewise.read() << 8;
- ulong |= (unsigned long)UdpBytewise.read();
- return ulong;
-}
-
-void write_n(int what, int how_many)
-{
- for( int i = 0; i < how_many; i++ )
- UdpBytewise.write(what);
-}
View
47 lib/Time/examples/TimeRTC/TimeRTC.pde
@@ -1,47 +0,0 @@
-/*
- * TimeRTC.pde
- * example code illustrating Time library with Real Time Clock.
- *
- */
-
-#include <Time.h>
-#include <Wire.h>
-#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
-
-void setup() {
- Serial.begin(9600);
- setSyncProvider(RTC.get); // the function to get the time from the RTC
- if(timeStatus()!= timeSet)
- Serial.println("Unable to sync with the RTC");
- else
- Serial.println("RTC has set the system time");
-}
-
-void loop()
-{
- digitalClockDisplay();
- delay(1000);
-}
-
-void digitalClockDisplay(){
- // digital clock display of the time
- Serial.print(hour());
- printDigits(minute());
- printDigits(second());
- Serial.print(" ");
- Serial.print(day());
- Serial.print(" ");
- Serial.print(month());
- Serial.print(" ");
- Serial.print(year());
- 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);
-}
-
View
106 lib/Time/examples/TimeRTCLog/TimeRTCLog.pde
@@ -1,106 +0,0 @@
-/*
- * TimeRTCLogger.pde
- * example code illustrating adding and subtracting Time.
- *
- * this sketch logs pin state change events
- * 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 <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
-
-const int nbrInputPins = 6; // monitor 6 digital pins
-const int inputPins[nbrInputPins] = {2,3,4,5,6,7}; // pins to monitor
-boolean state[nbrInputPins] ; // the state of the monitored pins
-time_t prevEventTime[nbrInputPins] ; // the time of the previous event
-
-void setup() {
- Serial.begin(9600);
- setSyncProvider(RTC.get); // the function to sync the time from the RTC
- for(int i=0; i < nbrInputPins; i++){
- pinMode( inputPins[i], INPUT);
- // digitalWrite( inputPins[i], HIGH); // uncomment these lines if
- // state[i] = HIGH; // pull-up resistors are wanted
- }
-}
-
-void loop()
-{
- for(int i=0; i < nbrInputPins; i++)
- {
- boolean val = digitalRead(inputPins[i]);
- if(val != state[i])
- {
- time_t duration = 0; // the time since the previous event
- state[i] = val;
- time_t timeNow = now();
- if(prevEventTime[i] > 0)
- // if this was not the first state change, calculate the time from the previous change
- duration = duration = timeNow - prevEventTime[i];
- logEvent(inputPins[i], val, timeNow, duration ); // log the event
- prevEventTime[i] = timeNow; // store the time for this event
- }
- }
-}
-
-void logEvent( int pin, boolean state, time_t timeNow, time_t duration)
-{
- Serial.print("Pin ");
- Serial.print(pin);
- if( state == HIGH)
- Serial.print(" went High at ");
- else
- Serial.print(" went Low at ");
- showTime(timeNow);
- if(duration > 0){
- // only display duration if greater than 0
- Serial.print(", Duration was ");
- showDuration(duration);
- }
- Serial.println();
-}
-
-
-void showTime(time_t t){
- // display the given time
- 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));
-}
-
-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);
-}
-
-void showDuration(time_t duration){
-// prints the duration in days, hours, minutes and seconds
- if(duration >= SECS_PER_DAY){
- Serial.print(duration / SECS_PER_DAY);
- Serial.print(" day(s) ");
- duration = duration % SECS_PER_DAY;
- }
- if(duration >= SECS_PER_HOUR){
- Serial.print(duration / SECS_PER_HOUR);
- Serial.print(" hour(s) ");
- duration = duration % SECS_PER_HOUR;
- }
- if(duration >= SECS_PER_MIN){
- Serial.print(duration / SECS_PER_MIN);
- Serial.print(" minute(s) ");
- duration = duration % SECS_PER_MIN;
- }
- Serial.print(duration);
- Serial.print(" second(s) ");
-}
-
View
82 lib/Time/examples/TimeRTCSet/TimeRTCSet.pde
@@ -1,82 +0,0 @@
-/*
- * TimeRTCSet.pde
- * example code illustrating Time library with Real Time Clock.
- *
- * RTC clock is set in response to serial port time message
- * A Processing example sketch to set the time is inclided in the download
- */
-
-#include <Time.h>
-#include <Wire.h>
-#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
-
-
-void setup() {
- Serial.begin(9600);
- setSyncProvider(RTC.get); // the function to get the time from the RTC
- if(timeStatus()!= timeSet)
- Serial.println("Unable to sync with the RTC");
- else
- Serial.println("RTC has set the system time");
-}
-
-void loop()
-{
- if(Serial.available())
- {
- time_t t = processSyncMessage();
- if(t >0)
- {
- RTC.set(t); // set the RTC and the system time to the received value
- setTime(t);
- }
- }
- digitalClockDisplay();
- delay(1000);
-}
-
-void digitalClockDisplay(){
- // digital clock display of the time
- Serial.print(hour());
- printDigits(minute());
- printDigits(second());
- Serial.print(" ");
- Serial.print(day());
- Serial.print(" ");
- Serial.print(month());
- Serial.print(" ");
- Serial.print(year());
- 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);
-}
-
-/* code to process time sync messages from the serial port */
-#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
-#define TIME_HEADER 'T' // Header tag for serial time sync message
-
-time_t processSyncMessage() {
- // return the time if a valid sync message is received on the serial port.
- while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
- char c = Serial.read() ;
- Serial.print(c);
- if( c == TIME_HEADER ) {
- time_t pctime = 0;
- for(int i=0; i < TIME_MSG_LEN -1; i++){
- c = Serial.read();
- if( c >= '0' && c <= '9'){
- pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
- }
- }
- return pctime;
- }
- }
- return 0;
-}
-
View
82 lib/Time/examples/TimeSerial/TimeSerial.pde
@@ -1,82 +0,0 @@
-/*
- * TimeSerial.pde
- * example code illustrating Time library set through serial port messages.
- *
- * Messages consist of the letter T followed by ten digit time (as seconds since Jan 1 1970)
- * you can send the text on the next line using Serial Monitor to set the clock to noon Jan 1 2010
- T1262347200
- *
- * A Processing example sketch to automatically send the messages is inclided in the download
- */
-
-#include <Time.h>
-
-#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
-#define TIME_HEADER 'T' // Header tag for serial time sync message
-#define TIME_REQUEST 7 // ASCII bell character requests a time sync message
-
-void setup() {
- Serial.begin(9600);
- setSyncProvider( requestSync); //set function to call when sync required
- Serial.println("Waiting for sync message");
-}
-
-void loop(){
- if(Serial.available() )
- {
- processSyncMessage();
- }
- if(timeStatus()!= timeNotSet)
- {
- digitalWrite(13,timeStatus() == timeSet); // on if synced, off if needs refresh
- digitalClockDisplay();
- }
- delay(1000);
-}
-
-void digitalClockDisplay(){
- // digital clock display of the time
- Serial.print(hour());
- printDigits(minute());
- printDigits(second());
- Serial.print(" ");
- Serial.print(day());
- Serial.print(" ");
- Serial.print(month());
- Serial.print(" ");
- Serial.print(year());
- 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);
-}
-
-void processSyncMessage() {
- // if time sync available from serial port, update time and return true
- while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
- char c = Serial.read() ;
- Serial.print(c);
- if( c == TIME_HEADER ) {
- time_t pctime = 0;
- for(int i=0; i < TIME_MSG_LEN -1; i++){
- c = Serial.read();
- if( c >= '0' && c <= '9'){
- pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
- }
- }
- setTime(pctime); // Sync Arduino clock to the time received on the serial port
- }
- }
-}
-
-time_t requestSync()
-{
- Serial.print(TIME_REQUEST,BYTE);
- return 0; // the time will be sent later in response to serial mesg
-}
-
View
80 lib/Time/examples/TimeSerialDateStrings/TimeSerialDateStrings.pde
@@ -1,80 +0,0 @@
-/*
- * TimeSerialDateStrings.pde
- * example code illustrating Time library date strings
- *
- * This sketch adds date string functionality to TimeSerial.pde
- *
- */
-
-#include <Time.h>
-
-#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
-#define TIME_HEADER 'T' // Header tag for serial time sync message
-#define TIME_REQUEST 7 // ASCII bell character requests a time sync message
-
-void setup() {
- Serial.begin(9600);
- setSyncProvider( requestSync); //set function to call when sync required
- Serial.println("Waiting for sync message");
-}
-
-void loop(){
- if(Serial.available() )
- {
- processSyncMessage();
- }
- if(timeStatus()!= timeNotSet)
- {
- digitalClockDisplay();
- }
- delay(1000);
-}
-
-void digitalClockDisplay(){
- // digital clock display of the time
- Serial.print(hour());
- printDigits(minute());
- printDigits(second());
- Serial.print(" ");
- Serial.print(dayStr(weekday()));
- Serial.print(" ");
- Serial.print(day());
- Serial.print(" ");
- Serial.print(monthShortStr(month()));
- Serial.print(" ");
- Serial.print(year());
- 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);
-}
-
-void processSyncMessage() {
- // if time sync available from serial port, update time and return true
- while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
- char c = Serial.read() ;
- Serial.print(c);
- if( c == TIME_HEADER ) {
- time_t pctime = 0;
- for(int i=0; i < TIME_MSG_LEN -1; i++){
- c = Serial.read();
- if( c >= '0' && c <= '9'){
- pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
- }
- }
- setTime(pctime); // Sync Arduino clock to the time received on the serial port
- }
- }
-}
-
-time_t requestSync()
-{
- Serial.print(TIME_REQUEST,BYTE);
- return 0; // the time will be sent later in response to serial mesg
-}
-
View
184 src/display.h
@@ -1,4 +1,4 @@
-#include<stdlib.h>
+#include <stdlib.h>
#define numberOfSecondLine 3
#define pause_str "--===Paused===--"
@@ -15,128 +15,114 @@ float avgSpeed = 0;
String floatToString(float float_val)
{
- char number[6];
- if ((int) float_val > 99) {
- return dtostrf(float_val, 5, 1, number);
- }
- else {
- return dtostrf(float_val, 5, 2, number);
- }
+ char number[6];
+ if ((int) float_val > 99) {
+ return dtostrf(float_val, 5, 1, number);
+ } else {
+ return dtostrf(float_val, 5, 2, number);
+ }
}
String restrictIn16Chars(String line)
{
- if (line.length() > 16) {
- return line.substring(0, 17);
- }
- else {
- return line;
- }
+ if (line.length() > 16) {
+ return line.substring(0, 17);
+ } else {
+ return line;
+ }
}
String getCurrentSpeedLine()
{
- String line = speed_str;
- line += floatToString(currentSpeed);
- line += kmh_str;
- return line;
+ String line = String(speed_str);
+ line += floatToString(currentSpeed);
+ line += kmh_str;
+ return line;
}
String getDistanceLine()
{
- String line = distance_str;
- if (totalDistance < 1000) {
- line += totalDistance;
- line += "m ";
- }
- else {
- line += floatToString((float) totalDistance / 1000U);
- line += "km ";
- }
- return line;
+ String line = String(distance_str);
+ if (totalDistance < 1000) {
+ line += totalDistance;
+ line += "m ";
+ } else {
+ line += floatToString((float) totalDistance / 1000U);
+ line += "km ";
+ }
+ return line;
}
float getAverageSpeed() {
- if (effectiveTime == 0) {
- return 0;
- }
- else {
- return (float) ((float) totalDistance / effectiveTime) * 3600;
- }
+ if (effectiveTime == 0) {
+ return 0;
+ } else {
+ return (float) ((float) totalDistance / effectiveTime) * 3600;
+ }
}
String getTimeLine() {
- String time = time_str
- + elaspedTime(effectiveTime);
- time += " ";
- return time;
+ String time = String(time_str + elaspedTime(effectiveTime));
+ time += " ";
+ return time;
}
String getAvgSpeedLine() {
- String line ="Avg: ";
- line += floatToString(avgSpeed);
- line += kmh_str;
- return line;
+ String line = String("Avg: ");
+ line += floatToString(avgSpeed);
+ line += kmh_str;
+ return line;
}
void displayInfo() {
- if (paused) {
- firstLine = pause_str;
- }
- else {
- firstLine = getCurrentSpeedLine();
- }
- lcd.clear();
- lcd.print(restrictIn16Chars(firstLine));
- if ( (millis() - lastSecondLineChange) > ((unsigned long) changeSecondLine * 1000UL)) {
- currentSecondLine = (currentSecondLine + 1) % numberOfSecondLine;
- lastSecondLineChange = millis();
- avgSpeed = getAverageSpeed();
- }
- lcd.setCursor(0, 1);
- switch (currentSecondLine) {
- case 0:
- secondLine = getDistanceLine();
- break;
- case 1:
- secondLine = getAvgSpeedLine();
- break;
- case 2:
- secondLine = getTimeLine();
- break;
- }
- lcd.print(restrictIn16Chars(secondLine));
-}
-
-void displayInitScreen() {
- String startTimeStr = getTimeString();
- lcd.clear();
- lcd.print("IP: ");
- lcd.print(Ethernet.localIP());
- lcd.setCursor(0, 1);
- for (int i = 0;i < 16;i++) lcd.print(startTimeStr.charAt(i));
- delay(2500);
- lcd.setCursor(0, 1);
- for (int i = 1;i < 32;i++) lcd.print(" ");
- lcd.setCursor(3, 1);
- for (int i = 16;i < startTimeStr.length();i++) lcd.print(startTimeStr.charAt(i));
- delay(2500);
+ if (paused) {
+ firstLine = pause_str;
+ } else {
+ firstLine = getCurrentSpeedLine();
+ }
+ lcd.clear();
+ lcd.print(restrictIn16Chars(firstLine));
+ if ( (millis() - lastSecondLineChange) > ((unsigned long) changeSecondLine * 1000UL)) {
+ currentSecondLine = (currentSecondLine + 1) % numberOfSecondLine;
+ lastSecondLineChange = millis();
+ avgSpeed = getAverageSpeed();
+ }
+ lcd.setCursor(0, 1);
+ switch (currentSecondLine) {
+ case 0:
+ secondLine = getDistanceLine();
+ break;
+ case 1:
+ secondLine = getAvgSpeedLine();
+ break;
+ case 2:
+ secondLine = getTimeLine();
+ break;
+ }
+ lcd.print(restrictIn16Chars(secondLine));
}
-void switchBacklight(boolean bl)
-{
- if (bl)
- {
- digitalWrite(ledblPin, HIGH);
- backlight = true;
- }
- else {
- digitalWrite(ledblPin, LOW);
- backlight = false;
- }
+// void displayInitScreen() {
+// String startTimeStr = getTimeString();
+// lcd.clear();
+// lcd.print("IP: ");
+// lcd.print(Ethernet.localIP());
+// lcd.setCursor(0, 1);
+// for (int i = 0;i < 16;i++) lcd.print(startTimeStr.charAt(i));
+// delay(2500);
+// lcd.setCursor(0, 1);
+// for (int i = 1;i < 32;i++) lcd.print(" ");
+// lcd.setCursor(3, 1);
+// for (int i = 16;i < startTimeStr.length();i++) lcd.print(startTimeStr.charAt(i));
+// delay(2500);
+// }
+
+void switchBacklight(boolean bl) {
+ if (bl) {
+ digitalWrite(ledblPin, HIGH);
+ backlight = true;
+ } else {
+ digitalWrite(ledblPin, LOW);
+ backlight = false;
+ }
}
-
-
-
-
-
View
131 src/ntp.h
@@ -11,87 +11,88 @@ EthernetUDP Udp;
// send an NTP request to the time server at the given address
unsigned long sendNTPpacket(IPAddress& address)
{
- // set all bytes in the buffer to 0
- memset(packetBuffer, 0, NTP_PACKET_SIZE);
- // Initialize values needed to form NTP request
- // (see URL above for details on the packets)
- packetBuffer[0] = 0b11100011; // LI, Version, Mode
- packetBuffer[1] = 0; // Stratum, or type of clock
- packetBuffer[2] = 6; // Polling Interval
- packetBuffer[3] = 0xEC; // Peer Clock Precision
- // 8 bytes of zero for Root Delay & Root Dispersion
- packetBuffer[12] = 49;
- packetBuffer[13] = 0x4E;
- packetBuffer[14] = 49;
- packetBuffer[15] = 52;
+ // set all bytes in the buffer to 0
+ memset(packetBuffer, 0, NTP_PACKET_SIZE);
+ // Initialize values needed to form NTP request
+ // (see URL above for details on the packets)
+ packetBuffer[0] = 0b11100011; // LI, Version, Mode
+ packetBuffer[1] = 0; // Stratum, or type of clock
+ packetBuffer[2] = 6; // Polling Interval
+ packetBuffer[3] = 0xEC; // Peer Clock Precision
+ // 8 bytes of zero for Root Delay & Root Dispersion
+ packetBuffer[12] = 49;
+ packetBuffer[13] = 0x4E;
+ packetBuffer[14] = 49;
+ packetBuffer[15] = 52;
- // all NTP fields have been given values, now
- // you can send a packet requesting a timestamp:
- Udp.beginPacket(address, 123); //NTP requests are to port 123
- Udp.write(packetBuffer,NTP_PACKET_SIZE);
- Udp.endPacket();
+ // all NTP fields have been given values, now
+ // you can send a packet requesting a timestamp:
+ Udp.beginPacket(address, 123); //NTP requests are to port 123
+ Udp.write(packetBuffer,NTP_PACKET_SIZE);
+ Udp.endPacket();
}
unsigned long getTimeStamp() {
- sendNTPpacket(timeServer); // send an NTP packet to a time server
- // wait to see if a reply is available
- delay(1500);
- if ( Udp.parsePacket() ) {
- // We've received a packet, read the data from it
- Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer
- //the timestamp starts at byte 40 of the received packet and is four bytes,
- // or two words, long. First, esxtract the two words:
- unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
- unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
- // combine the four bytes (two words) into a long integer
- // this is NTP time (seconds since Jan 1 1900):
- unsigned long secsSince1900 = highWord << 16 | lowWord;
- // now convert NTP time into Unix timestamp:
- const unsigned long seventyYears = 2208988800UL;
- unsigned long epoch = secsSince1900 - seventyYears;
- return epoch;
- }
+ sendNTPpacket(timeServer); // send an NTP packet to a time server
+ // wait to see if a reply is available
+ delay(1500);
+ if ( Udp.parsePacket() ) {
+ // We've received a packet, read the data from it
+ Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer
+ //the timestamp starts at byte 40 of the received packet and is four bytes,
+ // or two words, long. First, esxtract the two words:
+ unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
+ unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
+ // combine the four bytes (two words) into a long integer
+ // this is NTP time (seconds since Jan 1 1900):
+ unsigned long secsSince1900 = highWord << 16 | lowWord;
+ // now convert NTP time into Unix timestamp:
+ const unsigned long seventyYears = 2208988800UL;
+ unsigned long epoch = secsSince1900 - seventyYears;
+ return epoch;
+ }
}
String prettyDigits(int digits){
- // utility function for digital clock display: prints preceding colon and leading 0
- String output = ":";
- if(digits < 10)
- output += '0';
- output += digits;
- return output;
+ // utility function for digital clock display: prints preceding colon and leading 0
+ String output = ":";
+ if(digits < 10)
+ output += '0';
+ output += digits;
+ return output;
}
String elaspedTime(unsigned long time){
- time = time / 1000UL;
- int hours = numberOfHours(time);
- int minutes = numberOfMinutes(time);
- int seconds = numberOfSeconds(time);
+ time = time / 1000UL;
+ int hours = numberOfHours(time);
+ int minutes = numberOfMinutes(time);
+ int seconds = numberOfSeconds(time);
- String timeStr = " ";
- // digital clock display
- timeStr = String(hours)
- + prettyDigits(minutes)
- + prettyDigits(seconds);
- return timeStr;
+ String timeStr = " ";
+ // digital clock display
+ timeStr = String(hours)
+ + prettyDigits(minutes)
+ + prettyDigits(seconds);
+ return timeStr;
}
String getTimeString() {
- String str_time;
- str_time += String(dayShortStr(weekday())) + ", "
- + String(day()) + " "
- + String(monthShortStr(month())) + " "
- + String(year())
- + " "
- + String(hour())
- + prettyDigits(minute())
+ String str_time;
+ str_time += String(dayShortStr(weekday()))
+ + String(", ")
+ + String(day())
+ + String(" ")
+ + String(monthShortStr(month()))
+ + String(" ")
+ + String(year())
+ + String(" ")
+ + String(hour())
+ + prettyDigits(minute())
+ prettyDigits(second());
- return str_time;
+ return str_time;
}
void setStartTime() {
- Udp.begin(localPort);
- setTime(getTimeStamp());
+ Udp.begin(localPort);
+ setTime(getTimeStamp());
}
-
-
View
62 src/persistent.h
@@ -1,52 +1,52 @@
-void saveProgress(String startTimeStr, unsigned int totalDistance, unsigned long effectiveTime,boolean erase=false) {
+void saveProgress(String startTimeStr, unsigned int totalDistance, unsigned long effectiveTime, boolean erase=false) {
- unsigned int time = effectiveTime / 1000UL;
- int str_size = startTimeStr.length();
+ unsigned int time = effectiveTime / 1000UL;
+ int str_size = startTimeStr.length();
- // To indicate a save is present
- if (erase) {
- EEPROM.write(0, 0);
- } else {
- EEPROM.write(0, 1);
- }
+ // To indicate a save is present
+ if (erase) {
+ EEPROM.write(0, 0);
+ } else {
+ EEPROM.write(0, 1);
+ }
- EEPROM.write(1, highByte(time));
- EEPROM.write(2, lowByte(time));
- EEPROM.write(3, highByte(totalDistance));
- EEPROM.write(4, lowByte(totalDistance));
- EEPROM.write(5, str_size);
+ EEPROM.write(1, highByte(time));
+ EEPROM.write(2, lowByte(time));
+ EEPROM.write(3, highByte(totalDistance));
+ EEPROM.write(4, lowByte(totalDistance));
+ EEPROM.write(5, str_size);
- for (int i = 0;i < str_size;i++)
- {
- EEPROM.write(6 + i, startTimeStr.charAt(i));
- }
+ for (int i = 0;i < str_size;i++)
+ {
+ EEPROM.write(6 + i, startTimeStr.charAt(i));
+ }
}
void eraseProgress() {
- saveProgress("", 0, 0, true);
+ saveProgress("", 0, 0, true);
}
boolean savePresent() {
- return (EEPROM.read(0) > 0);
+ return (EEPROM.read(0) > 0);
}
unsigned long getSavedTime() {
- unsigned int time;
- time = word(EEPROM.read(1), EEPROM.read(2));
- return time * 1000UL;
+ unsigned int time;
+ time = word(EEPROM.read(1), EEPROM.read(2));
+ return time * 1000UL;
}
unsigned int getSavedDistance() {
- return word(EEPROM.read(3), EEPROM.read(4));
+ return word(EEPROM.read(3), EEPROM.read(4));
}
String getSavedStartTimeStr() {
- int str_size = EEPROM.read(5);
- String str_time = "";
- for (int i = 0;i < str_size;i++)
- {
- str_time += char(EEPROM.read(6 + i));
- }
- return str_time;
+ int str_size = EEPROM.read(5);
+ String str_time = "";
+ for (int i = 0;i < str_size;i++)
+ {
+ str_time += char(EEPROM.read(6 + i));
+ }
+ return str_time;
}
View
4 src/runkeeper.h
@@ -39,13 +39,11 @@ boolean uploadResult(String startTimeStr, unsigned int totalDistance, unsigned l
client.println();
client.println(data);
delay(500);
- lcd.clear();
} else {
lcd.print(status_failure);
delay(1000);
}
-
- delay(3000);
+ lcd.clear();
// Extract status code to see if POST was succesful
// Borrowed from https://github.com/interactive-matter/HTTPClient
View
2  src/sketch.ino
@@ -48,7 +48,7 @@ EthernetClient client;
// least amount of effective time for a valid activity (in secs)
#define minTime 60
// Amount of inactive time before either automatic upload or discarding of current session
-#define maxTime 120
+#define maxTime 60
// Change the data displayed on the second line of the lcd every X seconds
#define changeSecondLine 3
// Save session data every X seconds
Please sign in to comment.
Something went wrong with that request. Please try again.