diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-03-31 19:05:36 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-03-31 19:05:36 (GMT) |
| commit | c7f80dc5b3ccb2db08355b993a7855a5655e7d6b (patch) | |
| tree | 870a7d7573fafbf48558379d58da3cf9faaf7c8a /src/components | |
| parent | ee48e3f35b732eeddc9496da396aa33a31ebee2d (diff) | |
More testing of G sensor
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/motion/MotionController.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index a7c5ecc..6a3a84d 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -9,11 +9,12 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z) { this->z = z; } -int16_t MotionController::G() { +uint16_t MotionController::G() { float X = x; X *= X; - float Y = y; Y *= Y; - float Z = z; Z *= Z; - return (int16_t) std::sqrt(X + Y + Z); + float Y = y; X += Y * Y; + Y = z; X += Y * Y; + X = std::sqrt(X); + if (X > 0xffff) { return 0xffff; } else { return X; } } bool MotionController::Should_RaiseWake(bool isSleeping) { |
