2222class Compass (BaseDigitalSensor ):
2323 """Hitechnic compass sensor."""
2424 I2C_ADDRESS = BaseDigitalSensor .I2C_ADDRESS .copy ()
25- I2C_ADDRESS .update ({'heading' : (0x44 , '<H' ),
26- 'mode' : (0x41 , 'B' ),
25+ I2C_ADDRESS .update ({'mode' : (0x41 , 'B' ),
26+ 'heading' : (0x42 , 'B' ),
27+ 'adder' : (0x43 , 'B' ),
2728 })
2829
2930 class Modes :
@@ -33,15 +34,16 @@ class Modes:
3334
3435 def get_heading (self ):
3536 """Returns heading from North in degrees."""
36- return self .read_value ('heading' )[0 ]
37+
38+ two_degree_heading = self .read_value ('heading' )[0 ]
39+ adder = self .read_value ('adder' )[0 ]
40+ heading = two_degree_heading * 2 + adder
41+
42+ return heading
3743
3844 get_sample = get_heading
3945
4046 def get_relative_heading (self ,target = 0 ):
41- """This function is untested but should work. If it does work, please post a
42- message to the mailing list or email marcusw@cox.net. If it doesn't work, please
43- file an issue in the bug tracker.
44- """
4547 rheading = self .get_sample ()- target
4648 if rheading > 180 :
4749 rheading -= 360
@@ -54,10 +56,6 @@ def is_in_range(self,minval,maxval):
5456if max > min, it's straightforward, but
5557if min > max, it switches the values of max and min
5658and returns true if heading is NOT between the new max and min
57-
58- This function is untested but should work. If it does work, please post a
59- message to the mailing list or email marcusw@cox.net. If it doesn't work, please
60- file an issue in the bug tracker.
6159 """
6260 if minval > maxval :
6361 (maxval ,minval ) = (minval ,maxval )
@@ -76,15 +74,14 @@ def get_mode(self):
7674 return self .read_value ('mode' )[0 ]
7775
7876 def set_mode (self , mode ):
79- if mode != CompassMode .MEASUREMENT and \
80- mode != CompassMode .CALIBRATION :
77+ if mode != self . Modes .MEASUREMENT and \
78+ mode != self . Modes .CALIBRATION :
8179 raise ValueError ('Invalid mode specified: ' + str (mode ))
8280 self .write_value ('mode' , (mode , ))
8381
8482Compass .add_compatible_sensor (None , 'HiTechnc' , 'Compass ' ) #Tested with version '\xfdV1.23 '
8583Compass .add_compatible_sensor (None , 'HITECHNC' , 'Compass ' ) #Tested with version '\xfdV2.1 '
8684
87-
8885class Accelerometer (BaseDigitalSensor ):
8986 'Object for Accelerometer sensors. Thanks to Paulo Vieira.'
9087 I2C_ADDRESS = BaseDigitalSensor .I2C_ADDRESS .copy ()
0 commit comments