Skip to content

Instantly share code, notes, and snippets.

@daeken
Created May 20, 2014 04:52
Show Gist options
  • Save daeken/a3d3c4da11ca1c2d2b84 to your computer and use it in GitHub Desktop.
Save daeken/a3d3c4da11ca1c2d2b84 to your computer and use it in GitHub Desktop.
import serial
class Lifespan(object):
def __init__(self):
self.connect()
def connect(self):
self.port = serial.Serial('/dev/tty.IHP-Serialport', 19200, timeout=1)
while self.port.read(1) != '':
continue
def interrogate(self, type):
self.port.write(''.join(map(chr, (161, type, 0, 0, 0))))
return tuple(map(ord, self.port.read(6))[2:])
@property
def seconds(self):
msg = self.interrogate(137)
return msg[0] * 60 * 60 + msg[1] * 60 + msg[2]
@property
def time(self):
msg = self.interrogate(137)
return msg[0:3]
@property
def distance(self):
msg = self.interrogate(133)
return msg[0] + msg[1] / 100.0
@property
def speed(self):
msg = self.interrogate(130)
return msg[0] + msg[1] / 100.0
@property
def calories(self):
msg = self.interrogate(135)
return msg[0] * 256 + msg[1]
@property
def steps(self):
msg = self.interrogate(136)
return msg[0] * 256 + msg[1]
lifespan = Lifespan()
while True:
print 'Walking for: %i:%i:%i' % lifespan.time
print 'Walked %f miles (currently %f mph)' % (lifespan.distance, lifespan.speed)
print 'Burned %i calories in %i steps' % (lifespan.calories, lifespan.steps)
print
@jbschooley
Copy link

Pins 4 and 5 could just be UART: https://www.reddit.com/r/treadmills/comments/1529dov/lifespan_treadmill_tr1200b_console_detective_need/

I am considering getting one of these treadmills and hooking up my UART adapter is probably one of the first things I'm gonna do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment