Coverage for /Users/fmorton/GitHub/Birdbrain-Python-Library-2/src/birdbrain_hummingbird_input.py: 100%
62 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-21 08:37 -0400
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-21 08:37 -0400
1from birdbrain_constant import BirdbrainConstant
2from birdbrain_microbit_input import BirdbrainMicrobitInput
3from birdbrain_request import BirdbrainRequest
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."""
11 return BirdbrainMicrobitInput.acceleration(device)
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."""
18 return BirdbrainMicrobitInput.compass(device)
20 @classmethod
21 def magnetometer(self, device):
22 """Return the values of X,Y,Z of a magnetommeter, relative to the Finch's position."""
24 return BirdbrainMicrobitInput.magnetometer(device)
26 @classmethod
27 def orientation(self, device):
28 """Return the orentation of the Hummingbird. Results found in BirdbrainConstant.HUMMINGBIRD_ORIENTATION_RESULTS"""
30 return BirdbrainMicrobitInput.orientation(device)
32 @classmethod
33 def sensor(self, device, port):
34 """Read the value of the sensor attached to a certain port."""
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'
41 return self.sensor_response(device, 'sensor', port, sensor_options)
43 @classmethod
44 def light(self, device, port):
45 """Read the value of the light sensor attached to a certain port."""
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
52 return self.sensor_response(device, 'sensor', port, sensor_options)
54 @classmethod
55 def sound(self, device, port):
56 """Read the value of the sound sensor attached to a certain port."""
58 port = str(port).lower()
60 if port == "microbit" or port == "micro:bit":
61 return BirdbrainMicrobitInput.sound(device)
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
68 return self.sensor_response(device, 'sensor', port, sensor_options)
70 @classmethod
71 def distance(self, device, port):
72 """Read the value of the distance sensor attached to a certain port."""
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
79 return self.sensor_response(device, 'sensor', port, sensor_options)
81 @classmethod
82 def dial(self, device, port):
83 """Read the value of the dial attached to a certain port."""
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
90 return self.sensor_response(device, 'sensor', port, sensor_options)
92 @classmethod
93 def voltage(self, device, port):
94 """Read the value of the dial attached to a certain port."""
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'
102 return self.sensor_response(device, 'sensor', port, sensor_options)