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

36 statements  

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

1import inspect 

2 

3from birdbrain_constant import BirdbrainConstant 

4from birdbrain_request import BirdbrainRequest 

5 

6class BirdbrainMicrobitInput(BirdbrainRequest): 

7 @classmethod 

8 def acceleration(self, device, sensor = "Accelerometer"): 

9 """Gives the acceleration of X,Y,Z in m/sec2.""" 

10 

11 return self.xyz_response(device, sensor, "float") 

12 

13 @classmethod 

14 def compass(self, device, sensor = 'Compass'): 

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

16 magnetic field.""" 

17 

18 sensor_options = {} 

19 sensor_options['min_response'] = BirdbrainConstant.DEFAULT_DEGREES_MIN_RESPONSE 

20 sensor_options['max_response'] = BirdbrainConstant.DEFAULT_DEGREES_MAX_RESPONSE 

21 

22 compass_option = None if sensor == 'Compass' else 'static' 

23 

24 return self.sensor_response(device, sensor, compass_option, sensor_options) 

25 

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") 

30 

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.""" 

35 

36 return self.request_status(self.response('hummingbird', 'in', 'button', button.capitalize(), device)) 

37 

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.""" 

42 

43 response = self.response('hummingbird', 'in', "V2sensor", "Sound", device) 

44 

45 if response == 'micro:bit v2 required': return 0 

46 

47 return int(response) 

48 

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.""" 

53 

54 response = self.response('hummingbird', 'in', "V2sensor", "Temperature", device) 

55 

56 if response == 'micro:bit v2 required': return 0 

57 

58 return int(response) 

59 

60 @classmethod 

61 def is_shaking(self, device): 

62 """Return true if the device is shaking, false otherwise.""" 

63 

64 return self.request_status(self.response('hummingbird', 'in', 'orientation', 'Shake', device)) 

65 

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)