From 612a87992db2a3d1ad53f43104d92dc965a34abd Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 10:32:02 -0500 Subject: [PATCH 1/5] Added fix to temp examples --- examples/bno055_i2c-gpio_simpletest.py | 12 +++++++++++- examples/bno055_simpletest.py | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/examples/bno055_i2c-gpio_simpletest.py b/examples/bno055_i2c-gpio_simpletest.py index 19ff0ef..fb07d33 100644 --- a/examples/bno055_i2c-gpio_simpletest.py +++ b/examples/bno055_i2c-gpio_simpletest.py @@ -21,8 +21,18 @@ i2c = I2C(1) # Device is /dev/i2c-1 sensor = adafruit_bno055.BNO055_I2C(i2c) +last_val = 0xFFFF +def temperature(): + global last_val #pylint: disable=global-statement + if abs(sensor.temperature - last_val) == 128: + result = sensor.temperature + if abs(result - last_val) == 128: + return 0b00111111 & result + last_val = result + return result + while True: - print("Temperature: {} degrees C".format(sensor.temperature)) + print("Temperature: {} degrees C".format(temperature)) print("Accelerometer (m/s^2): {}".format(sensor.acceleration)) print("Magnetometer (microteslas): {}".format(sensor.magnetic)) print("Gyroscope (rad/sec): {}".format(sensor.gyro)) diff --git a/examples/bno055_simpletest.py b/examples/bno055_simpletest.py index 1e3fa6c..455d04c 100644 --- a/examples/bno055_simpletest.py +++ b/examples/bno055_simpletest.py @@ -11,8 +11,19 @@ # uart = busio.UART(board.TX, board.RX) # sensor = adafruit_bno055.BNO055_UART(uart) +last_val = 0xFFFF +def temperature(): + global last_val #pylint: disable=global-statement + if abs(sensor.temperature - last_val) == 128: + result = sensor.temperature + if abs(result - last_val) == 128: + return 0b00111111 & result + last_val = result + return result + while True: print("Temperature: {} degrees C".format(sensor.temperature)) + #print("Temperature: {} degrees C".format(temperature(last_val))) # Uncomment if using a Raspberry Pi print("Accelerometer (m/s^2): {}".format(sensor.acceleration)) print("Magnetometer (microteslas): {}".format(sensor.magnetic)) print("Gyroscope (rad/sec): {}".format(sensor.gyro)) From 90a5fb3c77ed03bc76fab7f2c4885f12f0255f5c Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 11:03:08 -0500 Subject: [PATCH 2/5] Made fixes to modified examples, linted --- examples/bno055_i2c-gpio_simpletest.py | 10 +++++++--- examples/bno055_simpletest.py | 14 ++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/examples/bno055_i2c-gpio_simpletest.py b/examples/bno055_i2c-gpio_simpletest.py index fb07d33..f921d07 100644 --- a/examples/bno055_i2c-gpio_simpletest.py +++ b/examples/bno055_i2c-gpio_simpletest.py @@ -22,17 +22,21 @@ sensor = adafruit_bno055.BNO055_I2C(i2c) last_val = 0xFFFF + + def temperature(): - global last_val #pylint: disable=global-statement - if abs(sensor.temperature - last_val) == 128: + global last_val # pylint: disable=global-statement + result = sensor.temperature + if abs(result - last_val) == 128: result = sensor.temperature if abs(result - last_val) == 128: return 0b00111111 & result last_val = result return result + while True: - print("Temperature: {} degrees C".format(temperature)) + print("Temperature: {} degrees C".format(temperature())) print("Accelerometer (m/s^2): {}".format(sensor.acceleration)) print("Magnetometer (microteslas): {}".format(sensor.magnetic)) print("Gyroscope (rad/sec): {}".format(sensor.gyro)) diff --git a/examples/bno055_simpletest.py b/examples/bno055_simpletest.py index 455d04c..a7e7a9d 100644 --- a/examples/bno055_simpletest.py +++ b/examples/bno055_simpletest.py @@ -12,18 +12,24 @@ # sensor = adafruit_bno055.BNO055_UART(uart) last_val = 0xFFFF + + def temperature(): - global last_val #pylint: disable=global-statement - if abs(sensor.temperature - last_val) == 128: + global last_val # pylint: disable=global-statement + result = sensor.temperature + if abs(result - last_val) == 128: result = sensor.temperature if abs(result - last_val) == 128: return 0b00111111 & result last_val = result return result + while True: - print("Temperature: {} degrees C".format(sensor.temperature)) - #print("Temperature: {} degrees C".format(temperature(last_val))) # Uncomment if using a Raspberry Pi + # print("Temperature: {} degrees C".format(sensor.temperature)) + print( + "Temperature: {} degrees C".format(temperature()) + ) # Uncomment if using a Raspberry Pi print("Accelerometer (m/s^2): {}".format(sensor.acceleration)) print("Magnetometer (microteslas): {}".format(sensor.magnetic)) print("Gyroscope (rad/sec): {}".format(sensor.gyro)) From cae5460140b3b8c0f97f2f5f120b01c7d122ac3d Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 11:04:21 -0500 Subject: [PATCH 3/5] Ran black --- adafruit_bno055.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/adafruit_bno055.py b/adafruit_bno055.py index 16a290a..fb426e1 100644 --- a/adafruit_bno055.py +++ b/adafruit_bno055.py @@ -456,7 +456,7 @@ def _gravity(self): @property def accel_range(self): - """ Switch the accelerometer range and return the new range. Default value: +/- 4g + """Switch the accelerometer range and return the new range. Default value: +/- 4g See table 3-8 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -474,7 +474,7 @@ def accel_range(self, rng=ACCEL_4G): @property def accel_bandwidth(self): - """ Switch the accelerometer bandwidth and return the new bandwidth. Default value: 62.5 Hz + """Switch the accelerometer bandwidth and return the new bandwidth. Default value: 62.5 Hz See table 3-8 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -494,7 +494,7 @@ def accel_bandwidth(self, bandwidth=ACCEL_62_5HZ): @property def accel_mode(self): - """ Switch the accelerometer mode and return the new mode. Default value: Normal + """Switch the accelerometer mode and return the new mode. Default value: Normal See table 3-8 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -514,7 +514,7 @@ def accel_mode(self, mode=ACCEL_NORMAL_MODE): @property def gyro_range(self): - """ Switch the gyroscope range and return the new range. Default value: 2000 dps + """Switch the gyroscope range and return the new range. Default value: 2000 dps See table 3-9 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -534,7 +534,7 @@ def gyro_range(self, rng=GYRO_2000_DPS): @property def gyro_bandwidth(self): - """ Switch the gyroscope bandwidth and return the new bandwidth. Default value: 32 Hz + """Switch the gyroscope bandwidth and return the new bandwidth. Default value: 32 Hz See table 3-9 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -554,7 +554,7 @@ def gyro_bandwidth(self, bandwidth=GYRO_32HZ): @property def gyro_mode(self): - """ Switch the gyroscope mode and return the new mode. Default value: Normal + """Switch the gyroscope mode and return the new mode. Default value: Normal See table 3-9 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -574,7 +574,7 @@ def gyro_mode(self, mode=GYRO_NORMAL_MODE): @property def magnet_rate(self): - """ Switch the magnetometer data output rate and return the new rate. Default value: 20Hz + """Switch the magnetometer data output rate and return the new rate. Default value: 20Hz See table 3-10 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -594,7 +594,7 @@ def magnet_rate(self, rate=MAGNET_20HZ): @property def magnet_operation_mode(self): - """ Switch the magnetometer operation mode and return the new mode. Default value: Regular + """Switch the magnetometer operation mode and return the new mode. Default value: Regular See table 3-10 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -614,7 +614,7 @@ def magnet_operation_mode(self, mode=MAGNET_REGULAR_MODE): @property def magnet_mode(self): - """ Switch the magnetometer power mode and return the new mode. Default value: Forced + """Switch the magnetometer power mode and return the new mode. Default value: Forced See table 3-10 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) From adc553af11e481e11d3798533f9c781ee2eabab6 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 11:08:14 -0500 Subject: [PATCH 4/5] Commented correct line --- examples/bno055_simpletest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/bno055_simpletest.py b/examples/bno055_simpletest.py index a7e7a9d..3a399ad 100644 --- a/examples/bno055_simpletest.py +++ b/examples/bno055_simpletest.py @@ -26,10 +26,12 @@ def temperature(): while True: - # print("Temperature: {} degrees C".format(sensor.temperature)) + print("Temperature: {} degrees C".format(sensor.temperature)) + """ print( "Temperature: {} degrees C".format(temperature()) ) # Uncomment if using a Raspberry Pi + """ print("Accelerometer (m/s^2): {}".format(sensor.acceleration)) print("Magnetometer (microteslas): {}".format(sensor.magnetic)) print("Gyroscope (rad/sec): {}".format(sensor.gyro)) From 2cb82fc7af5be2561f16ab59a89719099f40e437 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 11:15:18 -0500 Subject: [PATCH 5/5] Added pointless-string-statement to globally disabled pylint checks --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index d8f0ee8..cc63488 100644 --- a/.pylintrc +++ b/.pylintrc @@ -52,7 +52,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,pointless-string-statement # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option