Coverage for /Users/fmorton/GitHub/BirdBrain-Python-Library-2/src/birdbrain_hummingbird_input.py: 100%

62 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-04 20:20 -0500

1from birdbrain_constant import BirdbrainConstant 

2from birdbrain_microbit_input import BirdbrainMicrobitInput 

3from birdbrain_request import BirdbrainRequest 

4 

5class BirdbrainHummingbirdInput(BirdbrainRequest): 

6 @classmethod 

7 def acceleration(self, device): 

8 """Gives the acceleration of X,Y,Z in m/sec2, relative 

9 to the Finch's position.""" 

10 

11 return BirdbrainMicrobitInput.acceleration(device) 

12 

13 @classmethod 

14 def compass(self, device): 

15 """Returns values 0-359 indicating the orentation of the Earth's 

16 magnetic field, relative to the Finch's position.""" 

17 

18 return BirdbrainMicrobitInput.compass(device) 

19 

20 @classmethod 

21 def magnetometer(self, device): 

22 """Return the values of X,Y,Z of a magnetommeter, relative to the Finch's position.""" 

23 

24 return BirdbrainMicrobitInput.magnetometer(device) 

25 

26 @classmethod 

27 def orientation(self, device): 

28 """Return the orentation of the Hummingbird. Results found in BirdbrainConstant.HUMMINGBIRD_ORIENTATION_RESULTS""" 

29 

30 return BirdbrainMicrobitInput.orientation(device) 

31 

32 @classmethod 

33 def sensor(self, device, port): 

34 """Read the value of the sensor attached to a certain port.""" 

35 

36 sensor_options = {} 

37 sensor_options['min_response'] = BirdbrainConstant.DEFAULT_UNLIMITED_MIN_RESPONSE 

38 sensor_options['max_response'] = BirdbrainConstant.DEFAULT_UNLIMITED_MAX_RESPONSE 

39 sensor_options['type_method'] = 'float' 

40 

41 return self.sensor_response(device, 'sensor', port, sensor_options) 

42 

43 @classmethod 

44 def light(self, device, port): 

45 """Read the value of the light sensor attached to a certain port.""" 

46 

47 sensor_options = {} 

48 sensor_options['factor'] = BirdbrainConstant.LIGHT_FACTOR 

49 sensor_options['min_response'] = BirdbrainConstant.DEFAULT_MIN_RESPONSE 

50 sensor_options['max_response'] = BirdbrainConstant.DEFAULT_MAX_RESPONSE 

51 

52 return self.sensor_response(device, 'sensor', port, sensor_options) 

53 

54 @classmethod 

55 def sound(self, device, port): 

56 """Read the value of the sound sensor attached to a certain port.""" 

57 

58 port = str(port).lower() 

59 

60 if port == "microbit" or port == "micro:bit": 

61 return BirdbrainMicrobitInput.sound(device) 

62 

63 sensor_options = {} 

64 sensor_options['factor'] = BirdbrainConstant.SOUND_FACTOR 

65 sensor_options['min_response'] = BirdbrainConstant.DEFAULT_MIN_RESPONSE 

66 sensor_options['max_response'] = BirdbrainConstant.DEFAULT_MAX_RESPONSE 

67 

68 return self.sensor_response(device, 'sensor', port, sensor_options) 

69 

70 @classmethod 

71 def distance(self, device, port): 

72 """Read the value of the distance sensor attached to a certain port.""" 

73 

74 sensor_options = {} 

75 sensor_options['factor'] = BirdbrainConstant.DISTANCE_FACTOR 

76 sensor_options['min_response'] = BirdbrainConstant.DEFAULT_MIN_RESPONSE 

77 sensor_options['max_response'] = BirdbrainConstant.DEFAULT_UNLIMITED_MAX_RESPONSE 

78 

79 return self.sensor_response(device, 'sensor', port, sensor_options) 

80 

81 @classmethod 

82 def dial(self, device, port): 

83 """Read the value of the dial attached to a certain port.""" 

84 

85 sensor_options = {} 

86 sensor_options['factor'] = BirdbrainConstant.DIAL_FACTOR 

87 sensor_options['min_response'] = BirdbrainConstant.DEFAULT_MIN_RESPONSE 

88 sensor_options['max_response'] = BirdbrainConstant.DEFAULT_MAX_RESPONSE 

89 

90 return self.sensor_response(device, 'sensor', port, sensor_options) 

91 

92 @classmethod 

93 def voltage(self, device, port): 

94 """Read the value of the dial attached to a certain port.""" 

95 

96 sensor_options = {} 

97 sensor_options['factor'] = BirdbrainConstant.VOLTAGE_FACTOR 

98 sensor_options['min_response'] = BirdbrainConstant.VOLTAGE_MIN 

99 sensor_options['max_response'] = BirdbrainConstant.VOLTAGE_MAX 

100 sensor_options['type_method'] = 'float' 

101 

102 return self.sensor_response(device, 'sensor', port, sensor_options)