Coverage for /Users/fmorton/GitHub/BirdBrain-Python-Library-2/src/birdbrain_microbit_input.py: 100%
36 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-12 11:24 -0400
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-12 11:24 -0400
1import inspect
3from birdbrain_constant import BirdbrainConstant
4from birdbrain_request import BirdbrainRequest
6class BirdbrainMicrobitInput(BirdbrainRequest):
7 @classmethod
8 def acceleration(self, device, sensor = "Accelerometer"):
9 """Gives the acceleration of X,Y,Z in m/sec2."""
11 return self.xyz_response(device, sensor, "float")
13 @classmethod
14 def compass(self, device, sensor = 'Compass'):
15 """Returns values 0-359 indicating the orentation of the Earth's
16 magnetic field."""
18 sensor_options = {}
19 sensor_options['min_response'] = BirdbrainConstant.DEFAULT_DEGREES_MIN_RESPONSE
20 sensor_options['max_response'] = BirdbrainConstant.DEFAULT_DEGREES_MAX_RESPONSE
22 compass_option = None if sensor == 'Compass' else 'static'
24 return self.sensor_response(device, sensor, compass_option, sensor_options)
26 @classmethod
27 def magnetometer(self, device, sensor = "Magnetometer"):
28 """Return the values of X,Y,Z of a magnetommeter."""
29 return self.xyz_response(device, sensor, "int")
31 @classmethod
32 def button(self, device, button):
33 """Return the status of the button asked. Specify button 'A', 'B', or
34 'Logo'. Logo available for V2 micro:bit only."""
36 return self.request_status(self.response('hummingbird', 'in', 'button', button.capitalize(), device))
38 @classmethod
39 def sound(self, device):
40 """Return the current sound level as an integer between 1 and 100.
41 Available for V2 micro:bit only."""
43 response = self.response('hummingbird', 'in', "V2sensor", "Sound", device)
45 if response == 'micro:bit v2 required': return 0
47 return int(response)
49 @classmethod
50 def temperature(self, device):
51 """Return the current temperature as an integer in degrees Celcius.
52 Available for V2 micro:bit only."""
54 response = self.response('hummingbird', 'in', "V2sensor", "Temperature", device)
56 if response == 'micro:bit v2 required': return 0
58 return int(response)
60 @classmethod
61 def is_shaking(self, device):
62 """Return true if the device is shaking, false otherwise."""
64 return self.request_status(self.response('hummingbird', 'in', 'orientation', 'Shake', device))
66 @classmethod
67 def orientation(self, device):
68 """Return the orentation of the Microbit. Results found in BirdbrainConstant.HUMMINGBIRD_ORIENTATION_RESULTS"""
69 return self.orientation_response(device, "orientation", BirdbrainConstant.HUMMINGBIRD_ORIENTATIONS,
70 BirdbrainConstant.HUMMINGBIRD_ORIENTATION_RESULTS, BirdbrainConstant.HUMMINGBIRD_ORIENTATION_IN_BETWEEN)