• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2018 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17import enum
18import time
19
20from acts.controllers.relay_lib.devices.bluetooth_relay_device import BluetoothRelayDevice
21
22WAIT_TIME = 0.05
23
24
25class Buttons(enum.Enum):
26    NEXT = 'Next'
27    PREVIOUS = "Previous"
28    PLAY_PAUSE = 'Play_pause'
29    VOLUME_UP = "Volume_up"
30    VOLUME_DOWN = "Volume_down"
31
32
33class TaoTronicsCarkit(BluetoothRelayDevice):
34
35    def __init__(self, config, relay_rig):
36        BluetoothRelayDevice.__init__(self, config, relay_rig)
37        self._ensure_config_contains_relays(button.value for button in Buttons)
38
39    def setup(self):
40        """Sets all relays to their default state (off)."""
41        BluetoothRelayDevice.setup(self)
42
43    def press_play_pause(self):
44        """
45        Sets relay to
46            Play state : if there is no A2DP_streaming.
47            Pause state : if there is A2DP_streaming.
48        """
49        self.relays[Buttons.PLAY_PAUSE.value].set_no_for(WAIT_TIME)
50
51    def press_next(self):
52        """Skips to next song from relay_device."""
53        self.relays[Buttons.NEXT.value].set_no_for(WAIT_TIME)
54
55    def press_previous(self):
56        """Skips to previous song from relay_device."""
57        self.relays[Buttons.PREVIOUS.value].set_no_for(WAIT_TIME)
58
59    def press_volume_up(self):
60        """Increases volume from relay_device."""
61        self.relays[Buttons.VOLUME_UP.value].set_no_for(WAIT_TIME)
62
63    def press_volume_down(self):
64        """Decreases volume from relay_device."""
65        self.relays[Buttons.VOLUME_DOWN.value].set_no_for(WAIT_TIME)
66
67    def press_initiate_call(self):
68        """Initiate call from relay device."""
69        for i in range(0, 2):
70            self.press(Buttons.PLAY_PAUSE.value)
71            time.sleep(0.2)
72        return True
73
74    def press_accept_call(self):
75        """Accepts call from relay device."""
76        self.press(Buttons.PLAY_PAUSE.value)
77        return True
78