Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What if I don't have serial for pebble in /dev? #33

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The following are currently supported:
* Getting the installed firmware versions
* Installing firmware
* Getting device data (serial, BT MAC etc)
* Remote support for Keynote and iTunes

REPL
----
Expand Down
10 changes: 10 additions & 0 deletions p.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def cmd_get_time(pebble, args):
def cmd_set_time(pebble, args):
pebble.set_time(args.timestamp)

def cmd_remote(pebble, args):
pebble.remote(args.app)
#keep open to receive remote events
while True:
time.sleep(1)

def main():
parser = argparse.ArgumentParser(description='a utility belt for pebble development')
parser.add_argument('--pebble_id', type=str, help='the last 4 digits of the target Pebble\'s MAC address')
Expand Down Expand Up @@ -102,6 +108,10 @@ def main():
set_time_parser.add_argument('timestamp', type=int, help='time stamp to be sent')
set_time_parser.set_defaults(func=cmd_set_time)

remote_parser = subparsers.add_parser('remote', help='remote control Mac applications')
remote_parser.add_argument('app', metavar='APP', choices=('itunes', 'keynote', 'powerpoint'), type=str, help='either itunes or keynote')
remote_parser.set_defaults(func=cmd_remote)

args = parser.parse_args()

attempts = 0
Expand Down
91 changes: 90 additions & 1 deletion pebble/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,69 @@ class Pebble(object):
to the watch through an instance of this class.
"""

_remote_commands = {
"ITUNES": [
"""
osascript -e 'tell application "System Events"
tell application "iTunes" to activate
key code 49
end tell'
""",
"""
osascript -e 'tell application "System Events"
tell application "iTunes" to activate
key code 124 using command down
end tell'
""",
"""
osascript -e 'tell application "System Events"
tell application "iTunes" to activate
key code 123 using command down
end tell'
"""
],
"KEYNOTE": [
"""
osascript -e 'tell application "System Events"
tell application "Keynote" to activate
key code 35 using {command down, option down}
end tell'
""",
"""
osascript -e 'tell application "System Events"
tell application "Keynote" to activate
key code 124 using command down
end tell'
""",
"""
osascript -e 'tell application "System Events"
tell application "Keynote" to activate
key code 123 using command down
end tell'
"""
],
"POWERPOINT": [
"""
osascript -e 'tell application "Microsoft PowerPoint"
activate
run slide show slide show settings of active presentation
end tell'
""",
"""
osascript -e 'tell application "Microsoft PowerPoint"
activate
go to next slide slide show view of slide show window 1
end tell'
""",
"""
osascript -e 'tell application "Microsoft PowerPoint"
activate
go to previous slide slide show view of slide show window 1
end tell'
"""
]
}

endpoints = {
"TIME": 11,
"VERSION": 16,
Expand Down Expand Up @@ -156,7 +219,8 @@ def __init__(self, id = None):
self.endpoints["SYSTEM_MESSAGE"]: self._system_message_response,
self.endpoints["LOGS"]: self._log_response,
self.endpoints["PING"]: self._ping_response,
self.endpoints["APP_MANAGER"]: self._appbank_status_response
self.endpoints["APP_MANAGER"]: self._appbank_status_response,
self.endpoints["MUSIC_CONTROL"]: self._remote_response
}

try:
Expand All @@ -168,6 +232,8 @@ def __init__(self, id = None):
# we get a null response when we connect, discard it
self._ser.read(5)

self._ser.write("\x00\x0d\x00\x11\x01\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x32")

# Eat any cruft that might be sitting in the serial buffer...
while self._ser.read():
pass
Expand Down Expand Up @@ -467,6 +533,29 @@ def disconnect(self):
self._alive = False
self._ser.close()

def remote(self, remote_app):
app_string = {
"ITUNES" : "iTunes",
"KEYNOTE" : "Keynote",
"POWERPOINT" : "PowerPoint"
}
self._remote_app = remote_app.upper()
log.info("Remote: Control " + app_string[self._remote_app] + " with Pebble" )
self.set_nowplaying_metadata(app_string[self._remote_app], "libpebble", "Pebble")


def _remote_response(self, endpoint, data):
res, = unpack("!b", data)
# log.info("Remote: %s" % res)
cmd = ""
if res == 1:
cmd = self._remote_commands[self._remote_app][0]
elif res == 4:
cmd = self._remote_commands[self._remote_app][1]
elif res == 5:
cmd = self._remote_commands[self._remote_app][2]
os.system(cmd)

def _add_app(self, index):
data = pack("!bI", 3, index)
self._send_message("APP_MANAGER", data)
Expand Down