1   
 2  ''' 
 3   This software is part of the EV3BrickPi library. 
 4   It is Open Source Free Software, so you may 
 5   - run the code for any purpose 
 6   - study how the code works and adapt it to your needs 
 7   - integrate all or parts of the code in your own programs 
 8   - redistribute copies of the code 
 9   - improve the code and release your improvements to the public 
10   However the use of the code is entirely your responsibility. 
11  ''' 
12   
13  from GenericSensor import GenericSensor 
14  import brickpi3  
15  import time 
16  from Tools import * 
17   
20          GenericSensor.__init__(self, port) 
21          self.bp.set_sensor_type(self._getPort(), self.bp.SENSOR_TYPE.EV3_TOUCH) 
22          time.sleep(2)   
 23   
25          ''' 
26          Returns True, if the sensor is pressed; otherwise False. 
27          '''     
28          try: 
29              value = self.bp.get_sensor(self._getPort()) 
30          except brickpi3.SensorError as error: 
31              value = 0 
32          value = (value == 1) 
33          Tools.debug("TouchSensor.isPressed() returned: " + str(value)) 
34          return value 
  35