Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge https://github.com/qdot/libfitbit

  • Loading branch information...
commit eb88b4f14b31b9d3f9c8cf8873cf64994169f6ad 2 parents 3022afa + ee607b2
John Lamb authored
View
2  ChangeLog.txt
@@ -2,6 +2,6 @@ libfitbit ChangeLog
=====================
Numbers refer to bug listings in the tracking system - https://github.com/openyou/libfitbit/issues
-2010-02-07 Kyle Machulis <kyle@nonpolynomial.com>
+2011-02-07 Kyle Machulis <kyle@nonpolynomial.com>
* Release v0.0.1
* First version with working web sync, though not all steps run (can't burst data to device)
View
1  README.asciidoc
@@ -78,7 +78,6 @@ Don't even know if it works there yet. :D
* Windows support
* Finish figuring out data types
* Implement library in C
-* Sync fitbit using any ANT receiver (pretty much done, just need to abstract receiver classes)
== License ==
View
5 python/antprotocol/bases.py
@@ -28,11 +28,6 @@ def open(self, vid = None, pid = None):
self.init()
return True
- def reset_connection(self):
- super(FitBitANT, self).reset_connection()
- self._connection.set_configuration()
- self._receive()
-
def init(self):
# Device setup
# bmRequestType, bmRequest, wValue, wIndex, data
View
12 python/antprotocol/libusb.py
@@ -64,8 +64,18 @@ def open(self, vid = None, pid = None):
idProduct = pid)
if self._connection is None:
return False
-
+
+ # For some reason, we have to set config, THEN reset,
+ # otherwise we segfault back in the ctypes (on linux, at
+ # least).
+ self._connection.set_configuration()
+ self._connection.reset()
+ # The we have to set our configuration again
self._connection.set_configuration()
+
+ # Then we should get back a reset check, with 0x80
+ # (SUSPEND_RESET) as our status
+ self._check_reset_response(0x80)
return True
def close(self):
View
18 python/antprotocol/protocol.py
@@ -123,16 +123,13 @@ def _event_to_string(self, event):
except:
return "%02x" % event
- def _check_reset_response(self):
+ def _check_reset_response(self, status):
data = self._receive()
- # Sometimes we have to check for reset twice, if the first response is null
- if len(data) == 0:
- data = self._receive()
-
- if data[2] == 0x6f:
+ # Expect a startup message return
+ if data[2] == 0x6f and data[3] == status:
return
- raise ANTStatusException("Reset expects message type 0x6f, got %02x" % (data[2]))
+ raise ANTStatusException("Reset expects message type 0x6f status 0x%02x, got type 0x%02x status 0x%02x" % (status, data[2], data[3]))
def _check_ok_response(self):
# response packets will always be 7 bytes
@@ -148,7 +145,12 @@ def _check_ok_response(self):
def reset(self):
self._send_message(0x4a, 0x00)
- self._check_reset_response()
+ # According to protocol docs, the system will take a maximum
+ # of .5 seconds to restart
+ time.sleep(.6)
+ # This is a requested reset, so we expect back 0x20
+ # (COMMAND_RESET)
+ self._check_reset_response(0x20)
def set_channel_frequency(self, freq):
self._send_message(0x45, self._chan, freq)
View
31 python/fitbit.py
@@ -185,6 +185,7 @@ def wait_for_beacon(self):
# FitBit device initialization
while 1:
try:
+ print "Waiting for receive"
d = self.base._receive()
if d[2] == 0x4E:
break
@@ -226,9 +227,9 @@ def send_tracker_payload(self, payload):
current_prefix = prefix.next()
plist = []
if i+8 >= len(payload):
- plist += [(current_prefix + 0x80) | self._chan]
+ plist += [(current_prefix + 0x80) | self.base._chan]
else:
- plist += [current_prefix | self._chan]
+ plist += [current_prefix | self.base._chan]
plist += map(ord, payload[i:i+8])
while len(plist) < 9:
plist += [0x0]
@@ -321,24 +322,24 @@ def main():
device.init_tracker_for_transfer()
- # device.get_tracker_info()
+ device.get_tracker_info()
# print device.tracker
device.parse_bank2_data(device.run_data_bank_opcode(0x02))
print "---"
device.parse_bank0_data(device.run_data_bank_opcode(0x00))
- # device.run_data_bank_opcode(0x04)
- # d = device.run_data_bank_opcode(0x02) # 13
- # for i in range(0, len(d), 13):
- # print ["%02x" % x for x in d[i:i+13]]
- # d = device.run_data_bank_opcode(0x00) # 7
- # print ["%02x" % x for x in d[0:7]]
- # print ["%02x" % x for x in d[7:14]]
- # j = 0
- # for i in range(14, len(d), 3):
- # print d[i:i+3]
- # j += 1
- # print "Records: %d" % (j)
+ device.run_data_bank_opcode(0x04)
+ d = device.run_data_bank_opcode(0x02) # 13
+ for i in range(0, len(d), 13):
+ print ["%02x" % x for x in d[i:i+13]]
+ d = device.run_data_bank_opcode(0x00) # 7
+ print ["%02x" % x for x in d[0:7]]
+ print ["%02x" % x for x in d[7:14]]
+ j = 0
+ for i in range(14, len(d), 3):
+ print d[i:i+3]
+ j += 1
+ print "Records: %d" % (j)
device.parse_bank1_data(device.run_data_bank_opcode(0x01))
# for i in range(0, len(d), 14):
View
15 python/fitbit_client.py
@@ -50,6 +50,7 @@
import base64
import xml.etree.ElementTree as et
from fitbit import FitBit
+from antprotocol.bases import FitBitANT, DynastreamANT
class FitBitResponse(object):
def __init__(self, response):
@@ -64,7 +65,7 @@ def __init__(self, response):
self.path = self.root.find("response").attrib["path"]
if self.root.find("response").text:
# Quick and dirty url encode split
- self.response = dict([x.split("=") for x in urllib.unquote(self.root.find("response/").text).split("&")])
+ self.response = dict([x.split("=") for x in urllib.unquote(self.root.find("response").text).split("&")])
for opcode in self.root.findall("device/remoteOps/remoteOp"):
op = {}
@@ -81,7 +82,12 @@ class FitBitClient(object):
def __init__(self):
self.info_dict = {}
- self.fitbit = FitBit(True)
+ base = FitBitANT(debug=True)
+ if not base.open():
+ print "No devices connected!"
+ return 1
+
+ self.fitbit = FitBit(base)
self.remote_info = None
def form_base_info(self):
@@ -95,7 +101,6 @@ def form_base_info(self):
self.info_dict = dict(self.info_dict, **self.remote_info)
def run_upload_request(self):
- self.fitbit.open()
self.fitbit.init_tracker_for_transfer()
url = self.FITBIT_HOST + self.START_PATH
@@ -121,11 +126,11 @@ def run_upload_request(self):
else:
print "No URL returned. Quitting."
break
- self.fitbit.close()
+ self.fitbit.base.close()
def main():
f = FitBitClient()
- f.run_upload_request()
+ f.run_upload_request()
return 0
if __name__ == '__main__':
Please sign in to comment.
Something went wrong with that request. Please try again.