diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-04-05 01:58:10 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-04-05 02:23:55 (GMT) |
| commit | e721c71153d68578e6428c58c6a31698337f7d71 (patch) | |
| tree | d96766fcba99ab53c88d7e96ba51aef7fefa3606 | |
| parent | 20a3b99a978790de692b24d7eb3d1fead3fedc5d (diff) | |
fix for missed updating of display
| -rw-r--r-- | src/displayapp/screens/Motion.cpp | 61 | ||||
| -rw-r--r-- | src/displayapp/screens/Motion.h | 4 |
2 files changed, 32 insertions, 33 deletions
diff --git a/src/displayapp/screens/Motion.cpp b/src/displayapp/screens/Motion.cpp index 9e0c71f..d4eb90a 100644 --- a/src/displayapp/screens/Motion.cpp +++ b/src/displayapp/screens/Motion.cpp @@ -73,8 +73,6 @@ Motion::~Motion() { } void Motion::Refresh() { - bool new_record = false; - bool jump_started_or_ended = false; double X; double Y; double_t Z; double G = systemTask.ReadGXYZ(X,Y,Z); TickType_t current_time = xTaskGetTickCount(); @@ -96,10 +94,10 @@ void Motion::Refresh() { double G_scaled = G * G_SCALE; if (G_scaled < 1.000) { if (!jumping) { - jump_started_or_ended = true; current_jump_speed = 0; current_jump_length = 0; jumping = true; + color = LV_COLOR_CYAN; } double jump_ratio = 1.0 - G_scaled; double current_jump_accel = jump_ratio * 9.8; @@ -108,23 +106,27 @@ void Motion::Refresh() { current_jump_length += current_jump_speed * current_frame_s * jump_ratio; } else { if (jumping) { - double best_jump_length = records[0].jump_length; - if (current_jump_length >= best_jump_length) { - records[4] = records[3]; - records[3] = records[2]; - records[2] = records[1]; - records[1] = records[0]; - records[0].jump_length = current_jump_length; - new_record = 1; + if (current_jump_length * 100 > best_jump_length) { + last_jump_length = current_jump_length; + if (current_jump_length >= best_jump_length) { + records[4] = records[3]; + records[3] = records[2]; + records[2] = records[1]; + records[1] = records[0]; + records[0].jump_length = best_jump_length = current_jump_length; + new_record = 1; + } } jumping = false; - jump_started_or_ended = true; + color = LV_COLOR_ORANGE; } } } last_frame_time = current_time; if (started) { - if (((TickType_t)(current_time - last_redraw_frame_time)) < REDRAW_FRAME_TICKS) { return; } + if (((TickType_t)(current_time - last_redraw_frame_time)) < REDRAW_FRAME_TICKS) { + return; + } } else { started = true; } @@ -141,28 +143,21 @@ void Motion::Refresh() { labelText[0] = '0'+G_uint16; } lv_label_set_text_static(label, labelText); - if (jump_started_or_ended) { - if (new_record) { - uint32_t a = (current_jump_length*100000.0); - lv_label_set_text_fmt(recordLabel, "%d.%03d", a/1000, a%1000); - motorController.RunForDuration(35); - } - lv_color_t color; - if (jumping) { - color = LV_COLOR_CYAN; - } else { - double best_jump_length = records[0].jump_length; - if (current_jump_length * 100 > best_jump_length) { - uint32_t a = (current_jump_length*100000.0); - lv_label_set_text_fmt(lastLabel, "%d.%03d", a/1000, a%1000); - if (!new_record && current_jump_length > 0.05) { - motorController.RunForDuration(11); - } + if (new_record) { + uint32_t a = (best_jump_length*100000.0); + lv_label_set_text_fmt(recordLabel, "%d.%03d", a/1000, a%1000); + motorController.RunForDuration(35); + } + if (last_jump_length > 0) { + uint32_t a = (last_jump_length*100000.0); + lv_label_set_text_fmt(lastLabel, "%d.%03d", a/1000, a%1000); + if (!new_record && last_jump_length > 0.05) { + motorController.RunForDuration(11); } - color = LV_COLOR_ORANGE; - } - lv_obj_set_style_local_text_color(lastLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color); + last_jump_length = 0; } + new_record = false; + lv_obj_set_style_local_text_color(lastLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color); #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 761d90b..3ee6bfc 100644 --- a/src/displayapp/screens/Motion.h +++ b/src/displayapp/screens/Motion.h @@ -30,9 +30,13 @@ namespace Pinetime { // bool calibrating = true; bool started = false; bool jumping = false; + bool new_record = true; TickType_t last_frame_time = 0; TickType_t last_redraw_frame_time = 0; // uint8_t dropped_frames = 0; + double last_jump_length = 0; + double best_jump_length = 0; // Best jump length in this session + lv_color_t color; double current_jump_length; double current_jump_speed; struct Record { |
