aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-06-14 15:31:04 +0200
committerMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-06-14 15:31:04 +0200
commit7e32d6a1829b99eac6e0150dd4a80062801d6ffe (patch)
tree0371cb853fa198f5fc1fb2ad1dfbe654fc0bf380
parentac763c2f9e34cdb8e8cc24f96941459f3944011c (diff)
downloadpyParrotZikTCP-7e32d6a1829b99eac6e0150dd4a80062801d6ffe.tar.xz
pyParrotZikTCP-7e32d6a1829b99eac6e0150dd4a80062801d6ffe.zip
Add reading noise_control.
Diffstat (limited to '')
-rw-r--r--ParrotZik.py46
-rwxr-xr-xParrotZikTray75
2 files changed, 85 insertions, 36 deletions
diff --git a/ParrotZik.py b/ParrotZik.py
index a79f410..1240d66 100644
--- a/ParrotZik.py
+++ b/ParrotZik.py
@@ -123,6 +123,28 @@ class Rooms:
SILENT_ROOM: 'Silent Room',
}
+class NoiseControl(object):
+ def __init__(self, type, value):
+ self.type = type
+ self.value = value
+
+ @classmethod
+ def from_noise_control(cls, noise_control):
+ return cls(noise_control['type'], int(noise_control['value']))
+
+ def __eq__(self, other):
+ return self.type == other.type and self.value == other.value
+
+ def __str__(self):
+ return '{}++{}'.format(self.type, self.value)
+
+class NoiseControlTypes:
+ NOISE_CONTROL_MAX = NoiseControl('anc', 2)
+ NOISE_CONTROL_ON = NoiseControl('anc', 1)
+ NOISE_CONTROL_OFF = NoiseControl('off', 1)
+ STREET_MODE = NoiseControl('aoc', 1)
+ STREET_MODE_MAX = NoiseControl('aoc', 2)
+
class ParrotZikBase(object):
def __init__(self, api):
@@ -162,16 +184,6 @@ class ParrotZikBase(object):
return self._result_to_bool(
data.answer.system.anc_phone_mode["enabled"])
- @property
- def cancel_noise(self):
- data = self.api.get("/api/audio/noise_cancellation/enabled")
- return self._result_to_bool(
- data.answer.audio.noise_cancellation["enabled"])
-
- @cancel_noise.setter
- def cancel_noise(self, arg):
- self.api.set("/api/audio/noise_cancellation/enabled", arg)
-
def _result_to_bool(self, result):
if result == "true":
return True
@@ -206,6 +218,16 @@ class ParrotZikVersion1(ParrotZikBase):
def concert_hall(self, arg):
self.api.get("/api/audio/sound_effect/enabled", arg)
+ @property
+ def cancel_noise(self):
+ data = self.api.get("/api/audio/noise_cancellation/enabled")
+ return self._result_to_bool(
+ data.answer.audio.noise_cancellation["enabled"])
+
+ @cancel_noise.setter
+ def cancel_noise(self, arg):
+ self.api.set("/api/audio/noise_cancellation/enabled", arg)
+
class ParrotZikVersion2(ParrotZikBase):
@property
@@ -264,11 +286,11 @@ class ParrotZikVersion2(ParrotZikBase):
@property
def noise_control(self):
data = self.api.get('/api/audio/noise_control')
- return self._result_to_bool(data.answer.audio.noise_control['value'])
+ return NoiseControl.from_noise_control(data.answer.audio.noise_control)
@noise_control.setter
def noise_control(self, arg):
- self.api.set('/api/audio/noise_control', arg)
+ pass
@property
def noise_control_enabled(self):
diff --git a/ParrotZikTray b/ParrotZikTray
index e30631f..07b631a 100755
--- a/ParrotZikTray
+++ b/ParrotZikTray
@@ -5,6 +5,7 @@ import gtk
import BluetoothPairedDevices
from ParrotZik import BatteryStates
+from ParrotZik import NoiseControlTypes
from ParrotZik import connect
from ParrotZik import Rooms
from SysIndicator import MenuItem
@@ -238,26 +239,37 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface):
def __init__(self, indicator):
self.room_dirty = False
self.angle_dirty = False
+ self.noise_cancelation_dirty = False
super(ParrotZikVersion2Interface, self).__init__(indicator)
- self.noise_cancelation = MenuItem("Noise Cancellation", None, visible=False)
+ self.noise_cancelation = MenuItem("Noise Control", None, visible=False)
self.noise_cancelation_submenu = Menu()
self.noise_cancelation.set_submenu(self.noise_cancelation_submenu)
- self.noise_cancelation_enabled = MenuItem(
- "Enabled", self.toggle_noise_cancelation, checkitem=True)
- self.noise_cancelation_mode0 = MenuItem(
- "Mode0", self.toggledummy, checkitem=True)
- self.noise_cancelation_mode1 = MenuItem(
- "Mode1", self.toggledummy, checkitem=True)
- self.noise_cancelation_mode2 = MenuItem(
- "Mode2", self.toggledummy, checkitem=True)
- self.noise_cancelation_mode3 = MenuItem(
- "Mode3", self.toggledummy, checkitem=True)
- self.noise_cancelation_submenu.append(self.noise_cancelation_enabled)
- self.noise_cancelation_submenu.append(self.noise_cancelation_mode0)
- self.noise_cancelation_submenu.append(self.noise_cancelation_mode1)
- self.noise_cancelation_submenu.append(self.noise_cancelation_mode2)
- self.noise_cancelation_submenu.append(self.noise_cancelation_mode3)
+ self.noise_control_cancelation_max = MenuItem(
+ "Max Calcelation", functools.partial(
+ self.toggle_noise_cancelation,
+ NoiseControlTypes.NOISE_CONTROL_MAX), checkitem=True)
+ self.noise_control_cancelation_on = MenuItem(
+ "Normal Cancelation", functools.partial(
+ self.toggle_noise_cancelation,
+ NoiseControlTypes.NOISE_CONTROL_ON), checkitem=True)
+ self.noise_control_off = MenuItem(
+ "Off", functools.partial(
+ self.toggle_noise_cancelation,
+ NoiseControlTypes.NOISE_CONTROL_OFF), checkitem=True)
+ self.noise_control_street_mode = MenuItem(
+ "Street Mode", functools.partial(
+ self.toggle_noise_cancelation,
+ NoiseControlTypes.STREET_MODE), checkitem=True)
+ self.noise_control_street_mode_max = MenuItem(
+ "Street Mode Max", functools.partial(
+ self.toggle_noise_cancelation,
+ NoiseControlTypes.STREET_MODE_MAX), checkitem=True)
+ self.noise_cancelation_submenu.append(self.noise_control_cancelation_max)
+ self.noise_cancelation_submenu.append(self.noise_control_cancelation_on)
+ self.noise_cancelation_submenu.append(self.noise_control_off)
+ self.noise_cancelation_submenu.append(self.noise_control_street_mode)
+ self.noise_cancelation_submenu.append(self.noise_control_street_mode_max)
self.room_sound_effect = MenuItem(
"Room Sound Effect", None, visible=False)
@@ -320,7 +332,7 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface):
self.flight_mode.show()
self.room_sound_effect.show()
super(ParrotZikVersion2Interface, self).activate(parrot)
- self.noise_cancelation_enabled.set_active(self.parrot.cancel_noise)
+ self.read_noise_cancelation()
self.flight_mode.set_active(self.parrot.flight_mode)
self.read_sound_effect_room()
self.read_sound_effect_angle()
@@ -346,13 +358,6 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface):
self.room_sound_effect.hide()
super(ParrotZikVersion2Interface, self).deactivate()
- def toggle_noise_cancelation(self, widget):
- if self.connected:
- self.parrot.cancel_noise = self.noise_cancelation_enabled.get_active()
- self.noise_cancelation_enabled.set_active(self.parrot.cancel_noise)
- else:
- self.deactivate()
-
def toggle_flight_mode(self, widget):
if self.connected:
self.parrot.flight_mode = self.flight_mode.get_active()
@@ -425,6 +430,28 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface):
for angle, menu_item in angle_to_menuitem_map:
menu_item.set_active(angle == active_angle)
+ def toggle_noise_cancelation(self, noise_calcelation, widget):
+ if self.connected:
+ if not self.noise_cancelation_dirty:
+ self.parrot.noise_control = noise_calcelation
+ self.noise_cancelation_dirty = True
+ self.read_noise_cancelation()
+ self.noise_cancelation_dirty = False
+ else:
+ self.deactivate()
+
+ def read_noise_cancelation(self):
+ active_noise_control = self.parrot.noise_control
+ noise_control_to_menuitem_map = (
+ (NoiseControlTypes.NOISE_CONTROL_MAX, self.noise_control_cancelation_max),
+ (NoiseControlTypes.NOISE_CONTROL_ON, self.noise_control_cancelation_on),
+ (NoiseControlTypes.NOISE_CONTROL_OFF, self.noise_control_off),
+ (NoiseControlTypes.STREET_MODE, self.noise_control_street_mode),
+ (NoiseControlTypes.STREET_MODE_MAX, self.noise_control_street_mode_max),
+ )
+ for noise_control, menu_item in noise_control_to_menuitem_map:
+ menu_item.set_active(active_noise_control == noise_control)
+
if __name__ == "__main__":
try: