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 22SHORT_PRESS_WAIT_TIME = 0.5 23MED_PRESS_WAIT_TIME = 1.5 24POWER_ON_WAIT_TIME = 2.5 25LONG_PRESS_WAIT_TIME = 4.5 26 27WAIT_FOR_EFFECT_TIME = 2.5 28 29 30class Buttons(enum.Enum): 31 VOLUME_UP = "Volume_up" 32 VOLUME_DOWN = "Volume_down" 33 POWER = "Power" 34 35 36class JaybirdX3Earbuds(BluetoothRelayDevice): 37 """Jaybird X3 earbuds model 38 39 A relay device class for Jaybird X3 earbuds that provides basic Bluetooth 40 """ 41 def __init__(self, config, relay_rig): 42 BluetoothRelayDevice.__init__(self, config, relay_rig) 43 self._ensure_config_contains_relays(button.value for button in Buttons) 44 45 def power_off(self): 46 """If the device powers off, the LED will flash red before it 47 powers off. A voice prompt will say "POWER_OFF". 48 """ 49 self.relays[Buttons.POWER.value].set_nc_for(LONG_PRESS_WAIT_TIME) 50 time.sleep(WAIT_FOR_EFFECT_TIME) 51 52 def power_on(self): 53 """If the device powers on, the LED will flash green. 54 A voice prompt will say "POWER ON". 55 """ 56 self.relays[Buttons.POWER.value].set_nc_for(POWER_ON_WAIT_TIME) 57 time.sleep(WAIT_FOR_EFFECT_TIME) 58 59 def enter_pairing_mode(self): 60 """The Jaybird can only enter pairing mode from an OFF state. 61 """ 62 self.power_on() 63 self.power_off() 64 self.relays[Buttons.POWER.value].set_nc_for(LONG_PRESS_WAIT_TIME) 65 time.sleep(WAIT_FOR_EFFECT_TIME) 66 67 def press_play_pause(self): 68 """Toggles the audio play state.""" 69 self.relays[Buttons.POWER.value].set_nc_for(SHORT_PRESS_WAIT_TIME) 70 time.sleep(WAIT_FOR_EFFECT_TIME) 71 72 def activate_voice_commands(self): 73 """Activates voice commands during music streaming.""" 74 self.relays[Buttons.POWER.value].set_nc_for(MED_PRESS_WAIT_TIME) 75 time.sleep(WAIT_FOR_EFFECT_TIME) 76 77 def press_accept_call(self): 78 """Receives an incoming call.""" 79 self.relays[Buttons.POWER.value].set_nc_for(SHORT_PRESS_WAIT_TIME) 80 time.sleep(WAIT_FOR_EFFECT_TIME) 81 82 def press_reject_call(self): 83 """Rejects an incoming call.""" 84 self.relays[Buttons.POWER.value].set_nc_for(MED_PRESS_WAIT_TIME) 85 time.sleep(WAIT_FOR_EFFECT_TIME) 86 87 def press_next(self): 88 """Skips to the next track.""" 89 self.relays[Buttons.VOLUME_UP.value].set_nc_for(MED_PRESS_WAIT_TIME) 90 time.sleep(WAIT_FOR_EFFECT_TIME) 91 92 def press_previous(self): 93 """Rewinds to beginning of current or previous track.""" 94 self.relays[Buttons.VOLUME_DOWN.value].set_nc_for(MED_PRESS_WAIT_TIME) 95 time.sleep(WAIT_FOR_EFFECT_TIME) 96 97 def press_volume_up(self): 98 """Turns up the volume.""" 99 self.relays[Buttons.VOLUME_UP.value].set_nc_for(SHORT_PRESS_WAIT_TIME) 100 time.sleep(WAIT_FOR_EFFECT_TIME) 101 102 def press_volume_down(self): 103 """Turns down the volume.""" 104 self.relays[Buttons.VOLUME_DOWN.value].set_nc_for(SHORT_PRESS_WAIT_TIME) 105 time.sleep(WAIT_FOR_EFFECT_TIME) 106 107 def toggle_hands_free(self): 108 """Switches call audio between the phone and X3 buds.""" 109 self.relays[Buttons.VOLUME_UP.value].set_nc_for(MED_PRESS_WAIT_TIME) 110 time.sleep(WAIT_FOR_EFFECT_TIME) 111 112 def mute_phone_call(self): 113 """Mutes phone call audio.""" 114 self.relays[Buttons.VOLUME_DOWN.value].set_nc_for(MED_PRESS_WAIT_TIME) 115 time.sleep(WAIT_FOR_EFFECT_TIME)