# Control OpenOffice.org Impress using Chronos EZ430 buttons # Code written and commented by Jose Damico jd.comment@gmail.com http://dcon.com.br/jd.comment/comment.php?id=691 # in 2011Oct04 tested on Debian Squeeze 64bits # # Dependencies: # - python >= 2.6 # - xdotool # - openoffice.org or libreoffice3.4 # # Code based on history described bellow: # Get button data from Chronos watch. # Taken from info posted at: http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/t/32714.aspx # # posted here: http://pastebin.com/m5d1b7ced # Written by Sean Brewer (seabre) # # modified by Oliver Smith # http://www.chemicaloliver.net # seabre986@gmail.com # import os # used to run external commands import re # used for regex import serial # used for serial connection (read/write) import array # used for transformation array functions from subprocess import Popen, PIPE from time import sleep # Function used to format Access Point initialization string def startAccessPoint(): return array.array('B', [0xFF, 0x07, 0x03]).tostring() # Function used to format accelerometer/buttons request string def accDataRequest(): return array.array('B', [0xFF, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00]).tostring() # Usb device connection ser = serial.Serial("/dev/ttyACM0",115200,timeout=1) filePath = "/path/to-your-presentation.odp" # file path of OpenOffice Impress presentation # OpenOffice/LibreOffice Impress Command-Line execution p=Popen(["openoffice.org", "-norestore", "-show", "-always_on_top", str(filePath)]) # used for OpenOffice #p=Popen(["libreoffice3.4", "-norestore", "-show", "-always_on_top", str(filePath)]) # used for libreoffice # Waits for Impress to open sleep(10) # xdotool execution that gets the "screens" opened by OpenOffice Impress # It returns an output string with "screens ids" separeted by \n #(output, err) = Popen(["xdotool", "search", "--onlyvisible", "--class", "office"], stdout=PIPE).communicate() # used for libreoffice (output, err) = Popen(["xdotool", "search", "--onlyvisible", "--class", "OpenOffice.org"], stdout=PIPE).communicate() # used for OpenOffice # Substitution of \n by blank spaces output = re.sub("\n", " ", output) print output s1cmd = "" # command to be executed when S1 button is pressed m1cmd = "xdotool " + " key" + " --window " + output + " Next" # command to be executed when M1 button is pressed m2cmd = "xdotool " + " key" + " --window " + output + " Prior" # command to be executed when M2 button is pressed # Start access point ser.write(startAccessPoint()) s1times = 0 m1times = 0 m2times = 0 # Starts the read loop that will listen for all data from ez-430 chronos clock while True: # Send request for acceleration/buttons data ser.write(accDataRequest()) accel = ser.read(7) unknown = 1 # indicate that the received data is of unkown type # Interprets M1 button pressed if ord(accel[6]) == 18 and ord(accel[5]) == 7 and ord(accel[4]) == 6 and ord(accel[3]) == 255 and ord(accel[2]) == 0 and ord(accel[1]) == 0 and ord(accel[0]) == 0: M1 = 1 # The ez-430 chronos clock buttons has a strong sensibility. An one second press, generates a lot of calls, # for that reason we need to increment these calls and just execute a command when at least 4 continous # presses were done. Which means about an one second press. m1times = m1times +1 if(m1times>4): print "M1 pressed" os.popen(m1cmd) # executes the command for this button print str(m1cmd) m1times = 0 unknown = 0 if ord(accel[6]) == 34 and ord(accel[5]) == 7 and ord(accel[4]) == 6 and ord(accel[3]) == 255 and ord(accel[2]) == 0 and ord(accel[1]) == 0 and ord(accel[0]) == 0: M2 = 1 m2times = m2times +1 if(m2times>4): print "M2 pressed" os.popen(m2cmd) print str(m2cmd) m2times = 0 unknown = 0 if ord(accel[6]) == 50 and ord(accel[5]) == 7 and ord(accel[4]) == 6 and ord(accel[3]) == 255 and ord(accel[2]) == 0 and ord(accel[1]) == 0 and ord(accel[0]) == 0: S1 = 1 s1times = s1times +1 if(s1times>4): print "S1 pressed" os.popen(s1cmd) print str(s1cmd) s1times = 0 unknown = 0 continue # Closes the serial connection ser.close()