aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-06-12 13:40:17 +0200
committerMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-06-12 13:42:27 +0200
commit419e24ce24087a3f0159fb5c7527eab766987155 (patch)
tree08ab2675cd0fdb42f1cb227b8a48ed541dca63b8
parent7dff0e8494563b037808dda635dd73d243eb2ae7 (diff)
downloadpyParrotZikTCP-419e24ce24087a3f0159fb5c7527eab766987155.tar.xz
pyParrotZikTCP-419e24ce24087a3f0159fb5c7527eab766987155.zip
Replace tabs with 4 spaces.
-rw-r--r--BluetoothPairedDevices.py62
-rw-r--r--ParrotProtocol.py20
-rw-r--r--ParrotZik.py270
-rwxr-xr-xParrotZikTray2
-rw-r--r--StatusAppMac.py2
-rw-r--r--SysIndicator.py4
6 files changed, 180 insertions, 180 deletions
diff --git a/BluetoothPairedDevices.py b/BluetoothPairedDevices.py
index 6f9f673..e7b1e49 100644
--- a/BluetoothPairedDevices.py
+++ b/BluetoothPairedDevices.py
@@ -1,44 +1,44 @@
#!/usr/bin/python
-import sys
+import sys
import re
import os
def ParrotZikMac():
- p = re.compile('90:03:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}')
- if sys.platform == "linux2":
- out = os.popen("bluez-test-device list").read()
- res = p.findall(out)
- if len(res)>0:
- return res[0]
+ p = re.compile('90:03:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}')
+ if sys.platform == "linux2":
+ out = os.popen("bluez-test-device list").read()
+ res = p.findall(out)
+ if len(res)>0:
+ return res[0]
- elif sys.platform == "darwin":
- fd = open("/Library/Preferences/com.apple.Bluetooth.plist", "rb")
- plist = binplist.BinaryPlist(file_obj=fd)
- parsed_plist = plist.Parse()
- try :
- for mac in parsed_plist['PairedDevices']:
- if p.match(mac.replace("-",":")):
- return mac.replace("-",":")
- except:
- pass
+ elif sys.platform == "darwin":
+ fd = open("/Library/Preferences/com.apple.Bluetooth.plist", "rb")
+ plist = binplist.BinaryPlist(file_obj=fd)
+ parsed_plist = plist.Parse()
+ try :
+ for mac in parsed_plist['PairedDevices']:
+ if p.match(mac.replace("-",":")):
+ return mac.replace("-",":")
+ except:
+ pass
- elif sys.platform == "win32":
- aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
- aKey = _winreg.OpenKey(aReg, 'SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Devices')
- for i in range(10):
- try:
- asubkey_name=_winreg.EnumKey(aKey,i)
- mac =':'.join(asubkey_name[i:i+2] for i in range(0,12,2))
- res = p.findall(mac)
- if len(res)>0:
- return res[0]
+ elif sys.platform == "win32":
+ aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
+ aKey = _winreg.OpenKey(aReg, 'SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Devices')
+ for i in range(10):
+ try:
+ asubkey_name=_winreg.EnumKey(aKey,i)
+ mac =':'.join(asubkey_name[i:i+2] for i in range(0,12,2))
+ res = p.findall(mac)
+ if len(res)>0:
+ return res[0]
- except EnvironmentError:
- pass
+ except EnvironmentError:
+ pass
if sys.platform == "darwin":
- from binplist import binplist
+ from binplist import binplist
elif sys.platform == "win32":
- import _winreg \ No newline at end of file
+ import _winreg
diff --git a/ParrotProtocol.py b/ParrotProtocol.py
index 9324b8b..1973ba0 100644
--- a/ParrotProtocol.py
+++ b/ParrotProtocol.py
@@ -1,19 +1,19 @@
#!/usr/bin/env python
def generateRequest(requestString):
- message=bytearray()
- message.extend(generateHeader(requestString))
- message.extend(bytearray(requestString))
- return message
+ message=bytearray()
+ message.extend(generateHeader(requestString))
+ message.extend(bytearray(requestString))
+ return message
def generateHeader(requestString):
- header = bytearray([0])
- header.append(len(requestString)+3)
- header.append("\x80")
- return header
+ header = bytearray([0])
+ header.append(len(requestString)+3)
+ header.append("\x80")
+ return header
def getRequest(apiString):
- return generateRequest("GET "+apiString)
+ return generateRequest("GET "+apiString)
def setRequest(apiString,args):
- return generateRequest("SET "+apiString+"?arg="+args) \ No newline at end of file
+ return generateRequest("SET "+apiString+"?arg="+args)
diff --git a/ParrotZik.py b/ParrotZik.py
index 8a2fca6..327a136 100644
--- a/ParrotZik.py
+++ b/ParrotZik.py
@@ -2,145 +2,145 @@
import sys
if sys.platform == "darwin":
- import lightblue
+ import lightblue
else:
- import bluetooth
+ import bluetooth
import ParrotProtocol
import struct
from BeautifulSoup import BeautifulSoup
class ParrotZik(object):
- def __init__(self,addr=None):
- uuid = "0ef0f502-f0ee-46c9-986c-54ed027807fb"
-
-
- if sys.platform == "darwin":
- service_matches = lightblue.findservices( name = "Parrot RFcomm service", addr = addr )
- else:
- service_matches = bluetooth.find_service( uuid = uuid, address = addr )
-
-
- if len(service_matches) == 0:
- print "Failed to find Parrot Zik RFCOMM service"
- self.sock =""
- return
-
- if sys.platform == "darwin":
- first_match = service_matches[0]
- port = first_match[1]
- name = first_match[2]
- host = first_match[0]
- else:
- first_match = service_matches[0]
- port = first_match["port"]
- name = first_match["name"]
- host = first_match["host"]
-
- print "Connecting to \"%s\" on %s" % (name, host)
-
- if sys.platform == "darwin":
- self.sock=lightblue.socket()
- else:
- self.sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
-
- self.sock.connect((host, port))
-
- self.sock.send('\x00\x03\x00')
- data = self.sock.recv(1024)
-
- self.BatteryLevel = 100
- self.BatteryCharging = False
- print "Connected"
-
- def getBatteryState(self):
- data = self.sendGetMessage("/api/system/battery/get")
- return data.answer.system.battery["state"]
-
- def getBatteryLevel(self):
- data = self.sendGetMessage("/api/system/battery/get")
- try:
- if data.answer.system.battery["level"] <> '':
- self.BatteryLevel = data.answer.system.battery["level"]
- if data.answer.system.battery["state"] == 'charging':
- self.BatteryCharging = True
- else:
- self.BatteryCharging = False
- except:
- pass
-
- try:
- print "notification received" + data.notify["path"]
- except:
- pass
-
- return self.BatteryLevel
-
- def getVersion(self):
- data = self.sendGetMessage("/api/software/version/get")
- return data.answer.software["version"]
-
- def getFriendlyName(self):
- data = self.sendGetMessage("/api/bluetooth/friendlyname/get")
- return data.answer.bluetooth["friendlyname"]
-
- def getAutoConnection(self):
- data = self.sendGetMessage("/api/system/auto_connection/enabled/get")
- return data.answer.system.auto_connection["enabled"]
-
- def setAutoConnection(self,arg):
- data = self.sendSetMessage("/api/system/auto_connection/enabled/set",arg)
- return data
-
- def getAncPhoneMode(self):
- data = self.sendGetMessage("/api/system/anc_phone_mode/enabled/get")
- return data.answer.system.anc_phone_mode["enabled"]
-
- def getNoiseCancel(self):
- data = self.sendGetMessage("/api/audio/noise_cancellation/enabled/get")
- return data.answer.audio.noise_cancellation["enabled"]
-
- def setNoiseCancel(self,arg):
- data = self.sendSetMessage("/api/audio/noise_cancellation/enabled/set",arg)
- return data
-
- def getLouReedMode(self):
- data = self.sendGetMessage("/api/audio/specific_mode/enabled/get")
- return data.answer.audio.specific_mode["enabled"]
-
- def setLouReedMode(self,arg):
- data = self.sendSetMessage("/api/audio/specific_mode/enabled/set",arg)
- return data
-
- def getParrotConcertHall(self):
- data = self.sendGetMessage("/api/audio/sound_effect/enabled/get")
- return data.answer.audio.sound_effect["enabled"]
-
- def setParrotConcertHall(self,arg):
- data = self.sendSetMessage("/api/audio/sound_effect/enabled/set",arg)
- return data
-
- def sendGetMessage(self,message):
- message = ParrotProtocol.getRequest(message)
- return self.sendMessage(message)
-
- def sendSetMessage(self,message,arg):
- message = ParrotProtocol.setRequest(message,arg)
- return self.sendMessage(message)
-
- def sendMessage(self,message):
- try:
- self.sock.send(str(message))
- except:
- self.sock =""
- return
- if sys.platform == "darwin":
- data = self.sock.recv(30)
- else:
- data = self.sock.recv(7)
- data = self.sock.recv(1024)
- data=BeautifulSoup(data)
- return data
-
- def Close(self):
- self.sock.close() \ No newline at end of file
+ def __init__(self,addr=None):
+ uuid = "0ef0f502-f0ee-46c9-986c-54ed027807fb"
+
+
+ if sys.platform == "darwin":
+ service_matches = lightblue.findservices( name = "Parrot RFcomm service", addr = addr )
+ else:
+ service_matches = bluetooth.find_service( uuid = uuid, address = addr )
+
+
+ if len(service_matches) == 0:
+ print "Failed to find Parrot Zik RFCOMM service"
+ self.sock =""
+ return
+
+ if sys.platform == "darwin":
+ first_match = service_matches[0]
+ port = first_match[1]
+ name = first_match[2]
+ host = first_match[0]
+ else:
+ first_match = service_matches[0]
+ port = first_match["port"]
+ name = first_match["name"]
+ host = first_match["host"]
+
+ print "Connecting to \"%s\" on %s" % (name, host)
+
+ if sys.platform == "darwin":
+ self.sock=lightblue.socket()
+ else:
+ self.sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
+
+ self.sock.connect((host, port))
+
+ self.sock.send('\x00\x03\x00')
+ data = self.sock.recv(1024)
+
+ self.BatteryLevel = 100
+ self.BatteryCharging = False
+ print "Connected"
+
+ def getBatteryState(self):
+ data = self.sendGetMessage("/api/system/battery/get")
+ return data.answer.system.battery["state"]
+
+ def getBatteryLevel(self):
+ data = self.sendGetMessage("/api/system/battery/get")
+ try:
+ if data.answer.system.battery["level"] <> '':
+ self.BatteryLevel = data.answer.system.battery["level"]
+ if data.answer.system.battery["state"] == 'charging':
+ self.BatteryCharging = True
+ else:
+ self.BatteryCharging = False
+ except:
+ pass
+
+ try:
+ print "notification received" + data.notify["path"]
+ except:
+ pass
+
+ return self.BatteryLevel
+
+ def getVersion(self):
+ data = self.sendGetMessage("/api/software/version/get")
+ return data.answer.software["version"]
+
+ def getFriendlyName(self):
+ data = self.sendGetMessage("/api/bluetooth/friendlyname/get")
+ return data.answer.bluetooth["friendlyname"]
+
+ def getAutoConnection(self):
+ data = self.sendGetMessage("/api/system/auto_connection/enabled/get")
+ return data.answer.system.auto_connection["enabled"]
+
+ def setAutoConnection(self,arg):
+ data = self.sendSetMessage("/api/system/auto_connection/enabled/set",arg)
+ return data
+
+ def getAncPhoneMode(self):
+ data = self.sendGetMessage("/api/system/anc_phone_mode/enabled/get")
+ return data.answer.system.anc_phone_mode["enabled"]
+
+ def getNoiseCancel(self):
+ data = self.sendGetMessage("/api/audio/noise_cancellation/enabled/get")
+ return data.answer.audio.noise_cancellation["enabled"]
+
+ def setNoiseCancel(self,arg):
+ data = self.sendSetMessage("/api/audio/noise_cancellation/enabled/set",arg)
+ return data
+
+ def getLouReedMode(self):
+ data = self.sendGetMessage("/api/audio/specific_mode/enabled/get")
+ return data.answer.audio.specific_mode["enabled"]
+
+ def setLouReedMode(self,arg):
+ data = self.sendSetMessage("/api/audio/specific_mode/enabled/set",arg)
+ return data
+
+ def getParrotConcertHall(self):
+ data = self.sendGetMessage("/api/audio/sound_effect/enabled/get")
+ return data.answer.audio.sound_effect["enabled"]
+
+ def setParrotConcertHall(self,arg):
+ data = self.sendSetMessage("/api/audio/sound_effect/enabled/set",arg)
+ return data
+
+ def sendGetMessage(self,message):
+ message = ParrotProtocol.getRequest(message)
+ return self.sendMessage(message)
+
+ def sendSetMessage(self,message,arg):
+ message = ParrotProtocol.setRequest(message,arg)
+ return self.sendMessage(message)
+
+ def sendMessage(self,message):
+ try:
+ self.sock.send(str(message))
+ except:
+ self.sock =""
+ return
+ if sys.platform == "darwin":
+ data = self.sock.recv(30)
+ else:
+ data = self.sock.recv(7)
+ data = self.sock.recv(1024)
+ data=BeautifulSoup(data)
+ return data
+
+ def Close(self):
+ self.sock.close()
diff --git a/ParrotZikTray b/ParrotZikTray
index d9bdbc1..57464a7 100755
--- a/ParrotZikTray
+++ b/ParrotZikTray
@@ -171,4 +171,4 @@ class ParrotZikIndicator(SysIndicator):
if __name__ == "__main__":
indicator = ParrotZikIndicator()
- indicator.main() \ No newline at end of file
+ indicator.main()
diff --git a/StatusAppMac.py b/StatusAppMac.py
index fc0bc64..109532f 100644
--- a/StatusAppMac.py
+++ b/StatusAppMac.py
@@ -22,4 +22,4 @@ class StatusApp(NSApplication):
def clicked_(self, notification):
self.mymenu.actions[notification._.title]()
- NSLog('clicked!') \ No newline at end of file
+ NSLog('clicked!')
diff --git a/SysIndicator.py b/SysIndicator.py
index 3c79286..1b344c8 100644
--- a/SysIndicator.py
+++ b/SysIndicator.py
@@ -22,7 +22,7 @@ class SysIndicator:
import appindicator
self.icon_directory = os.path.sep + 'usr' + os.path.sep+ 'share' + os.path.sep+'icons' + os.path.sep+'zik'+ os.path.sep
if not os.path.isdir(self.icon_directory):
- self.icon_directory = os.path.dirname(sys.argv[0]) + os.path.sep + 'share' + os.path.sep+'icons' + os.path.sep+'zik'+ os.path.sep
+ self.icon_directory = os.path.dirname(sys.argv[0]) + os.path.sep + 'share' + os.path.sep+'icons' + os.path.sep+'zik'+ os.path.sep
self.statusicon = appindicator.Indicator("new-parrotzik-indicator",
"indicator-messages",
appindicator.CATEGORY_APPLICATION_STATUS)
@@ -152,4 +152,4 @@ if __name__ == "__main__":
menu.append(quit_item)
indicator = SysIndicator(icon = "zik-audio-headset",menu = menu)
- indicator.main() \ No newline at end of file
+ indicator.main()