aboutsummaryrefslogtreecommitdiff
path: root/parrot_zik/interface/version2.py
blob: b00eb77ab67604118f06c6e4540d986358c256ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import functools

from parrot_zik import resource_manager
from parrot_zik.interface.base import ParrotZikBaseInterface
from parrot_zik.model.version2 import ParrotZikVersion2
from parrot_zik.model.version2 import NoiseControlTypes
from parrot_zik.model.version2 import Rooms
from parrot_zik.model.version2 import Angles


class ParrotZikVersion2Interface(ParrotZikBaseInterface):
    parrot_class = ParrotZikVersion2

    def __init__(self, indicator):
        super(ParrotZikVersion2Interface, self).__init__(indicator)
        self.noise_control_types = NoiseControlTypes.representation
        self.rooms_types = Rooms.representation
        self.angles = Angles.representation

    def activate(self, manager):
        super(ParrotZikVersion2Interface, self).activate(manager)

    def deactivate(self):
        super(ParrotZikVersion2Interface, self).deactivate()

    def toggle_flight_mode(self, flight_mode):
        try:
            #self.parrot.flight_mode = flight_mode
            warning = {'warning': 'Sorry for this moment this function is disable because you need to connect your system on headset with NFC to disable flight mode.'}
            self.indicator.info(warning)
            return warning
        except resource_manager.DeviceDisconnected:
            self.deactivate()

    def read_flight_mode(self):
        try:
            data = {'data': {'flight_mode': self.parrot.flight_mode}}
            self.indicator.info(data)
            return data
        except resource_manager.DeviceDisconnected:
            self.deactivate()

    def toggle_sound_effect_room(self, room):
        """
        Define ambiance room. Muse be one of the following room:
        'concert', 'jazz', 'living', 'silent'.
        """
        try:
            if room in self.rooms_types:
                self.parrot.room = room
                data = {'data': {'sound_effect_room': self.parrot.room}}
                self.indicator.info(data)
                return data
            else:
                data = {'error': "'" + room + "' is not a correct room name"}
                self.indicator.info(data)
                return data
        except resource_manager.DeviceDisconnected:
            self.deactivate()

    def read_sound_effect_room(self):
        """
        Return current ambiance room value.
        """
        try:
            data = {'data': {'sound_effect_type': self.parrot.room}}
            self.indicator.info(data)
            return data
        except resource_manager.DeviceDisconnected:
            self.deactivate()

    def toggle_sound_effect_room_enabled(self, sound_effect):
        """
        Enable or disable the ambiance room. Must be 'true' or 'false'.
        """
        try:
            self.parrot.sound_effect = sound_effect
            return self.read_sound_effect_room_enabled()
        except resource_manager.DeviceDisconnected:
            self.deactivate()

    def read_sound_effect_room_enabled(self):
        """
        Return current ambiance room status.
        """
        try:
            data = {'data': {'sound_effect_state': self.parrot.sound_effect}}
            self.indicator.info(data)
            return data
        except resource_manager.DeviceDisconnected:
            self.deactivate()

    def toggle_sound_effect_angle(self, angle):
        """
        Define angle, must be one of the following interger:
        30, 60, 90, 120, 150, 180
        """
        try:
            if angle in self.angles:
                self.parrot.angle = angle
                return self.read_sound_effect_angle()
            else:
                data = {'error': "'"+str(angle)+"' is not an accepted angle"}
                self.indicator.info(data)
                return data
        except resource_manager.DeviceDisconnected:
            self.deactivate()

    def read_sound_effect_angle(self):
        """
        Return current sound angle.
        """
        try:
            data = {'data': {'sound_effec_angle': self.parrot.angle}}
            self.indicator.info(data)
            return data
        except resource_manager.DeviceDisconnected:
            self.deactivate()

    def toggle_noise_control(self, noise_control):
        """
        Define noise cancelation mode. Must be one of this value:
        'NOISE_CONTROL_MAX': Noise reduction maximum
        'NOISE_CONTROL_ON': Noise reduction enable
        'NOISE_CONTROL_OFF': Noise reduction disable
        'STREET_MODE': Street mode
        'STREET_MODE_MAX': Street mode maximum
        """
        try:
            for noise_control_type, noise_control_value in self.noise_control_types.items():
                if noise_control == noise_control_type:
                    self.parrot.noise_control = noise_control_value
            return self.read_noise_control()
        except resource_manager.DeviceDisconnected:
            self.deactivate()

    def read_noise_control(self):
        """
        Return current noise cancelation mode.
        """
        try:
            active_noise_control = self.parrot.noise_control
            for noise_control_type, noise_control in self.noise_control_types.items():
                if active_noise_control == noise_control:
                    data = {'data': {'noise_control': noise_control_type}}
                    self.indicator.info(data)
                    return data
        except resource_manager.DeviceDisconnected:
            self.deactivate()

    def toggle_head_detection(self, head_detection):
        """
        Enable or disable head detection. Must be 'true' or 'false'.
        """
        try:
            self.parrot.head_detection = head_detection
            return self.read_head_detection()
        except resource_manager.DeviceDisconnected:
            self.deactivate()

    def read_head_detection(self):
        """
        Return head detector status.
        """
        try:
            data = {'data': {'head_detection': self.parrot.head_detection}}
            self.indicator.info(data)
            return data
        except resource_manager.DeviceDisconnected:
            self.deactivate()