Permalink
Browse files

Add PHONE_VERSION endpoint handler

Add a phone version endpoint handler so that we respond appropriately when
connecting to a pebble.  The pebble sends this query at the start of an RFCOMM
connection and will assume a bare minimum of supported features if we don't
respond.

The only feature this controls (that I can tell) is whether or not the music
app sends next/previous/pause commands back to us.  Soo...this fixes the music
app so that it actually works.  Yay!
  • Loading branch information...
1 parent bb849dd commit ffd28244391d181ba90fcc1c97e939bde830fdb2 @bldewolf bldewolf committed with Mar 12, 2013
Showing with 40 additions and 7 deletions.
  1. +40 −7 pebble/pebble.py
View
@@ -154,6 +154,7 @@ def __init__(self, id = None):
self._internal_endpoint_handlers = {
self.endpoints["TIME"]: self._get_time_response,
self.endpoints["VERSION"]: self._version_response,
+ self.endpoints["PHONE_VERSION"]: self._phone_version_response,
self.endpoints["SYSTEM_MESSAGE"]: self._system_message_response,
self.endpoints["LOGS"]: self._log_response,
self.endpoints["PING"]: self._ping_response,
@@ -165,13 +166,7 @@ def __init__(self, id = None):
log.debug("Attempting to open %s as Pebble device %s" % (devicefile, id))
self._ser = serial.Serial(devicefile, 115200, timeout=1)
- log.debug("Connected, discarding null response")
- # we get a null response when we connect, discard it
- self._ser.read(5)
-
- # Eat any cruft that might be sitting in the serial buffer...
- while self._ser.read():
- pass
+ log.debug("Connected")
log.debug("Initializing reader thread")
self._read_thread = threading.Thread(target=self._reader)
@@ -559,6 +554,44 @@ def _version_response(self, endpoint, data):
return resp
+ def _phone_version_response(self, endpoint, data):
+ session_cap = {
+ "GAMMA_RAY" : 0x80000000,
+ }
+ remote_cap = {
+ "TELEPHONY" : 16,
+ "SMS" : 32,
+ "GPS" : 64,
+ "BTLE" : 128,
+ # XXX: CAMERA_FRONT is 240 in the APK, but this can't
+ # be right, as this will ruin the bitmask. Check
+ # future app versions
+ "CAMERA_FRONT" : 240,
+ "CAMERA_REAR" : 256,
+ "ACCEL" : 512,
+ "GYRO" : 1024,
+ "COMPASS" : 2048,
+ }
+ os = {
+ "UNKNOWN" : 0,
+ "IOS" : 1,
+ "ANDROID" : 2,
+ "OSX" : 3,
+ "LINUX" : 4,
+ "WINDOWS" : 5,
+ }
+ # Magic prefix that the app adds
+ prefix = "\x01\xff\xff\xff\xff"
+ # Then session capabilities, android adds GAMMA_RAY and it's
+ # the only session flag so far
+ session = session_cap["GAMMA_RAY"]
+ # Then phone capabilities, android app adds TELEPHONY and SMS,
+ # and the phone type (we know android works for now)
+ remote = remote_cap["TELEPHONY"] | remote_cap["SMS"] | os["ANDROID"]
+ msg = prefix + pack("!II", session, remote)
+ self._send_message("PHONE_VERSION", msg);
+ return data
+
class PutBytesClient(object):
states = {
"NOT_STARTED": 0,

0 comments on commit ffd2824

Please sign in to comment.