From 65bddab7f591d3863b7383c9b07f3a44b2625bb8 Mon Sep 17 00:00:00 2001 From: Kacper Date: Tue, 1 Mar 2022 09:05:45 +0000 Subject: [PATCH] Update lis3dh.py --- lis3dh.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lis3dh.py b/lis3dh.py index 1d5eb7a..5a3cf44 100644 --- a/lis3dh.py +++ b/lis3dh.py @@ -100,7 +100,14 @@ class lis3dh: X = int.from_bytes(x.buf[0],"big") Y = int.from_bytes(y.buf[0],"big") Z = int.from_bytes(z.buf[0],"big") - # TODO: Need to format this so that it returns values in g - return [X,Y,Z] + new_values = [] + for D in [X,Y,Z]: + MSB = D >> 7 + if MSB == 1: + res = -128 + (D - 128) + else: + res = D + new_values.append(res) + return new_values else: return None # Should never get here lol \ No newline at end of file