From c7f80dc5b3ccb2db08355b993a7855a5655e7d6b Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Thu, 31 Mar 2022 21:05:36 +0200 Subject: More testing of G sensor 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) { diff --git a/src/displayapp/screens/Motion.cpp b/src/displayapp/screens/Motion.cpp index 97e01af..00c3172 100644 --- a/src/displayapp/screens/Motion.cpp +++ b/src/displayapp/screens/Motion.cpp @@ -27,7 +27,8 @@ Motion::Motion(Pinetime::Applications::DisplayApp* app, Controllers::MotionContr // lv_chart_init_points(chart, ser3, 0); lv_chart_refresh(chart); /*Required after direct set*/ - // label = lv_label_create(lv_scr_act(), NULL); + label = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text_static(label, labelText); // lv_label_set_text_fmt(label, "X #FF0000 %d# Y #008000 %d# Z #FFFF00 %d#", 0, 0, 0); // lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); // lv_obj_align(label, NULL, LV_ALIGN_IN_TOP_MID, 0, 10); @@ -42,9 +43,16 @@ Motion::~Motion() { } void Motion::Refresh() { + uint16_t G = motionController.G() lv_chart_set_next(chart, ser1, motionController.G()); // lv_chart_set_next(chart, ser2, motionController.Y()); // lv_chart_set_next(chart, ser3, motionController.Z()); + labelText[4] = '0'+(G%10); G /= 10; + labelText[3] = '0'+(G%10); G /= 10; + labelText[2] = '0'+(G%10); G /= 10; + labelText[1] = '0'+(G%10); G /= 10; + labelText[0] = '0'+G; G /= 10; + lv_label_set_text_static(label, labelText); #if 0 lv_label_set_text_fmt(label, "X #FF0000 %d# Y #008000 %d# Z #FFFF00 %d#", diff --git a/src/displayapp/screens/Motion.h b/src/displayapp/screens/Motion.h index 4d2bd4f..2341f24 100644 --- a/src/displayapp/screens/Motion.h +++ b/src/displayapp/screens/Motion.h @@ -20,6 +20,7 @@ namespace Pinetime { private: Controllers::MotionController& motionController; + char labelText = { '0', '0', '0', '0', '0', 0 }; lv_obj_t* chart; lv_chart_series_t* ser1; lv_chart_series_t* ser2; -- cgit v0.10.2