1#!/usr/bin/env python 2# 3# Copyright 2016 - 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 17from acts.controllers.relay_lib.relay_device import RelayDevice 18from acts.controllers.relay_lib.relay import SynchronizeRelays 19 20 21class GenericRelayDevice(RelayDevice): 22 """A default, all-encompassing implementation of RelayDevice. 23 24 This class allows for quick access to getting relay switches through the 25 subscript ([]) operator. Note that it does not allow for re-assignment or 26 additions to the relays dictionary. 27 """ 28 29 def __init__(self, config, relay_rig): 30 RelayDevice.__init__(self, config, relay_rig) 31 32 def setup(self): 33 """Sets all relays to their default state (off).""" 34 with SynchronizeRelays(): 35 for relay in self.relays.values(): 36 relay.set_no() 37 38 def clean_up(self): 39 """Sets all relays to their default state (off).""" 40 with SynchronizeRelays(): 41 for relay in self.relays.values(): 42 if relay.is_dirty(): 43 relay.set_no() 44 45 def press(self, button_name): 46 """Presses the button with name 'button_name'.""" 47 self.relays[button_name].set_nc_for() 48 49 def hold_down(self, button_name): 50 """Holds down the button with name 'button_name'.""" 51 self.relays[button_name].set_nc() 52 53 def release(self, button_name): 54 """Releases the held down button with name 'button_name'.""" 55 self.relays[button_name].set_no() 56