From d878efb376a64ea440e8b0c0e7c8cda1eb843d9f Mon Sep 17 00:00:00 2001 From: eshifri <46511024+eshifri@users.noreply.github.com> Date: Thu, 1 Jul 2021 06:22:54 -0700 Subject: [PATCH 1/4] range mode RSSI (fix for #356) (#377) * Range mode RSSI (Fix for #356 ) * Formatting --- radio/src/gui/colorlcd/message_dialog.cpp | 15 +++++++---- radio/src/gui/colorlcd/message_dialog.h | 31 +++++++++++------------ radio/src/gui/colorlcd/model_setup.cpp | 28 ++++++++++++++++++++ 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/radio/src/gui/colorlcd/message_dialog.cpp b/radio/src/gui/colorlcd/message_dialog.cpp index 8d5c4571f..067d69500 100644 --- a/radio/src/gui/colorlcd/message_dialog.cpp +++ b/radio/src/gui/colorlcd/message_dialog.cpp @@ -21,18 +21,23 @@ #include "static.h" MessageDialog::MessageDialog(Window* parent, const char* title, - const char* message, const char* info) : + const char* message, const char* info, + const int lineHeight, + const WindowFlags windowFlags, + const LcdFlags textFlags) : Dialog(parent, title, {50, 73, LCD_W - 100, LCD_H - 146}) { + setWindowFlags(windowFlags); + messageWidget = new StaticText( this, {0, coord_t(height() - PAGE_LINE_HEIGHT) / 2, width(), PAGE_LINE_HEIGHT}, message, 0, CENTERED); - infoWidget = new StaticText(this, - {0, 30 + coord_t(height() - PAGE_LINE_HEIGHT) / 2, - width(), PAGE_LINE_HEIGHT}, - info, 0, CENTERED); + infoWidget = new StaticText( + this, + {0, 30 + coord_t(height() - PAGE_LINE_HEIGHT) / 2, width(), lineHeight}, + info, 0, textFlags); setCloseWhenClickOutside(true); setFocus(); } diff --git a/radio/src/gui/colorlcd/message_dialog.h b/radio/src/gui/colorlcd/message_dialog.h index ed2fcf1d2..bf0d570ba 100644 --- a/radio/src/gui/colorlcd/message_dialog.h +++ b/radio/src/gui/colorlcd/message_dialog.h @@ -23,28 +23,27 @@ #include "dialog.h" #include "static.h" -class MessageDialog: public Dialog { - public: - MessageDialog(Window * parent, const char * title, const char * message, const char * info = ""); +class MessageDialog : public Dialog +{ + public: + MessageDialog(Window* parent, const char* title, const char* message, + const char* info = "", const int lineHeight = PAGE_LINE_HEIGHT, + const WindowFlags windowFlags = 0, + const LcdFlags textFlags = CENTERED); + // Attn.: FONT(XXL) is not supported by MessageDialog - void setInfoText(std::string text) - { - infoWidget->setText(std::move(text)); - } - - protected: - StaticText * messageWidget; - StaticText * infoWidget; + void setInfoText(std::string text) { infoWidget->setText(std::move(text)); } + protected: + StaticText* messageWidget; + StaticText* infoWidget; + LcdFlags textFlags; #if defined(DEBUG_WINDOWS) - std::string getName() const override - { - return "MessageDialog"; - } + std::string getName() const override { return "MessageDialog"; } #endif #if defined(HARDWARE_KEYS) - void onEvent(event_t event) override; + void onEvent(event_t event) override; #endif }; diff --git a/radio/src/gui/colorlcd/model_setup.cpp b/radio/src/gui/colorlcd/model_setup.cpp index b7817d2c7..1d21d125f 100644 --- a/radio/src/gui/colorlcd/model_setup.cpp +++ b/radio/src/gui/colorlcd/model_setup.cpp @@ -41,6 +41,27 @@ std::string switchWarninglabel(swsrc_t index) 1); } +class RssiDialog : public MessageDialog +{ + public: + RssiDialog(Window* parent, const char* title, const char* message, + const char* info = "", const int lineHeight = PAGE_LINE_HEIGHT, + const WindowFlags windowFlags = 0, + const LcdFlags textFlags = CENTERED) : + MessageDialog(parent, title, message, info, lineHeight, windowFlags, + textFlags) + { + } + + virtual void checkEvents() + { + char buf[10]; + sprintf(buf, "%d", (int)TELEMETRY_RSSI()); + setInfoText(buf); + MessageDialog::checkEvents(); + } +}; + class ChannelFailsafeBargraph: public Window { public: ChannelFailsafeBargraph(Window * parent, const rect_t & rect, uint8_t moduleIdx, uint8_t channel): @@ -840,6 +861,13 @@ class ModuleWindow : public FormGroup { } else { moduleState[moduleIdx].mode = MODULE_MODE_RANGECHECK; + auto rssiDialog = new RssiDialog( + this, "Range Test", "RSSI:", "", 50, REFRESH_ALWAYS, + DEFAULT_COLOR | CENTERED | FONT(BOLD) | FONT(XL)); + rssiDialog->setCloseHandler([this]() { + rangeButton->check(false); + moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; + }); return 1; } }); From 4667b296989dc19c0d6915c031f401a6f28542d5 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 1 Jul 2021 11:02:22 +0200 Subject: [PATCH 2/4] [color] fix attempt for GT911 touch sensor driver This fix contains 2 modifications: - poll GT911_READ_XY_REG for 20ms in case not yet ready - write 0 to GT911_READ_XY_REG in all cases These fixes are largely inspired from the Linux GT9xx driver (see https://gitlab.com/AdyaAdya/goodix-touchscreen-linux-driver/-/blob/master/goodix.c) --- radio/src/targets/horus/tp_gt911.cpp | 78 +++++++++++++++++----------- radio/src/targets/horus/tp_gt911.h | 7 ++- 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/radio/src/targets/horus/tp_gt911.cpp b/radio/src/targets/horus/tp_gt911.cpp index 624cac3f8..d176b5b71 100644 --- a/radio/src/targets/horus/tp_gt911.cpp +++ b/radio/src/targets/horus/tp_gt911.cpp @@ -711,40 +711,56 @@ void touchPanelRead() if (!touchEventOccured) return; - touchEventOccured = false; - I2C_GT911_ReadRegister(GT911_READ_XY_REG, &state, 1); + touchEventOccured = 0; + + uint32_t startReadStatus = RTOS_GET_MS(); + do { + if (!I2C_GT911_ReadRegister(GT911_READ_XY_REG, &state, 1)) { + TRACE("GT911 I2C read error"); + return; + } + + if (state & 0x80u) { + // ready + break; + } + RTOS_WAIT_MS(1); + } while(RTOS_GET_MS() - startReadStatus < GT911_TIMEOUT); + TRACE("touch state = 0x%x", state); - if ((state & 0x80u) == 0x00) { - // not ready - return; - } + if (state & 0x80u) { + uint8_t pointsCount = (state & 0x0Fu); - uint8_t pointsCount = (state & 0x0Fu); - - if (pointsCount > 0 && pointsCount < GT911_MAX_TP) { - I2C_GT911_ReadRegister(GT911_READ_XY_REG + 1, touchData.data, pointsCount * sizeof(TouchPoint)); - if (touchState.event == TE_NONE || touchState.event == TE_UP || touchState.event == TE_SLIDE_END) { - touchState.event = TE_DOWN; - touchState.startX = touchState.x = touchData.points[0].x; - touchState.startY = touchState.y = touchData.points[0].y; - } - else { - touchState.deltaX = touchData.points[0].x - touchState.x; - touchState.deltaY = touchData.points[0].y - touchState.y; - if (touchState.event == TE_SLIDE || abs(touchState.deltaX) >= SLIDE_RANGE || abs(touchState.deltaY) >= SLIDE_RANGE) { - touchState.event = TE_SLIDE; - touchState.x = touchData.points[0].x; - touchState.y = touchData.points[0].y; + if (pointsCount > 0 && pointsCount <= GT911_MAX_TP) { + if (!I2C_GT911_ReadRegister(GT911_READ_XY_REG + 1, touchData.data, + pointsCount * sizeof(TouchPoint))) { + TRACE("GT911 I2C read error"); + return; + } + if (touchState.event == TE_NONE || touchState.event == TE_UP || + touchState.event == TE_SLIDE_END) { + touchState.event = TE_DOWN; + touchState.startX = touchState.x = touchData.points[0].x; + touchState.startY = touchState.y = touchData.points[0].y; + } else { + touchState.deltaX = touchData.points[0].x - touchState.x; + touchState.deltaY = touchData.points[0].y - touchState.y; + if (touchState.event == TE_SLIDE || + abs(touchState.deltaX) >= SLIDE_RANGE || + abs(touchState.deltaY) >= SLIDE_RANGE) { + touchState.event = TE_SLIDE; + touchState.x = touchData.points[0].x; + touchState.y = touchData.points[0].y; + } + } + } else { + if (touchState.event == TE_SLIDE) { + touchState.event = TE_SLIDE_END; + } else if (touchState.event == TE_DOWN) { + touchState.event = TE_UP; + } else if (touchState.event != TE_SLIDE_END) { + touchState.event = TE_NONE; } - } - } - else { - if (touchState.event == TE_SLIDE) { - touchState.event = TE_SLIDE_END; - } else if (touchState.event == TE_DOWN) { - touchState.event = TE_UP; - } else if (touchState.event != TE_SLIDE_END){ - touchState.event = TE_NONE; } } diff --git a/radio/src/targets/horus/tp_gt911.h b/radio/src/targets/horus/tp_gt911.h index edbf3fd57..1a3371d31 100644 --- a/radio/src/targets/horus/tp_gt911.h +++ b/radio/src/targets/horus/tp_gt911.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef _FT5X06_H_ -#define _FT5X06_H_ +#pragma once #define HAS_TOUCH_PANEL() touchGT911Flag == true @@ -29,6 +28,8 @@ extern bool touchPanelInit(); void touchPanelRead(); bool touchPanelEventOccured(); +#define GT911_TIMEOUT 20 // 20ms + #define GT911_MAX_TP 5 #define GT911_CFG_NUMER 0x6C @@ -81,5 +82,3 @@ PACK(struct TouchData { #define TPINT_LOW() do { TOUCH_INT_GPIO->BSRRH = TOUCH_INT_GPIO_PIN; } while(0) #define TPINT_HIGH() do { TOUCH_INT_GPIO->BSRRL = TOUCH_INT_GPIO_PIN; } while(0) - -#endif // _FT5X06_H_ \ No newline at end of file From 797c3f175a9afe0019fdc9159b53d95dd27b3674 Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Mon, 5 Jul 2021 09:03:00 +1000 Subject: [PATCH 3/4] Show RSSI if RF Freq Fine tuning supported (PR #379) * Show RSSI if RF Freq Fine tuning supported * Increase buffer slightly, add whitespace * Use same buffer size and naming for consistency * Use shorter code that doesn't require buffer variable (Thanks to @eshifri for the hint about DynamicNumber) --- radio/src/gui/colorlcd/model_setup.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/radio/src/gui/colorlcd/model_setup.cpp b/radio/src/gui/colorlcd/model_setup.cpp index 1d21d125f..cbd353bf6 100644 --- a/radio/src/gui/colorlcd/model_setup.cpp +++ b/radio/src/gui/colorlcd/model_setup.cpp @@ -697,6 +697,13 @@ class ModuleWindow : public FormGroup { } else { new NumberEdit(this, grid.getFieldSlot(2,0), -128, 127, GET_SET_DEFAULT(g_model.moduleData[moduleIdx].multi.optionValue)); + + //Show RSSI next to RF Freq Fine Tune + if (getMultiOptionTitle(moduleIdx) == STR_MULTI_RFTUNE) + { + new DynamicNumber(this, grid.getFieldSlot(2, 1), [] { + return (int)TELEMETRY_RSSI();}, 0, "RSSI: ", " db"); + } } } From 6ded23f26bc01580ab7d506941bf72eaee7d77a9 Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Mon, 5 Jul 2021 09:04:06 +1000 Subject: [PATCH 4/4] Reset logical switch v2 range if v1 changes (PR #383) * Reset logical switch v2 range if v1 changes Use the v1 handler to update v2 range if the v2 source box has already been created, so that the min/max values are updated from the default. * Move invalidate, add bounds checking for v2 range * Out of range check doesn't need to be inclusive * Remove range check as is inconsistent with buggy B&W behaviour --- radio/src/gui/colorlcd/model_logical_switches.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/radio/src/gui/colorlcd/model_logical_switches.cpp b/radio/src/gui/colorlcd/model_logical_switches.cpp index 16b6a6ec1..cbe2d968d 100644 --- a/radio/src/gui/colorlcd/model_logical_switches.cpp +++ b/radio/src/gui/colorlcd/model_logical_switches.cpp @@ -161,7 +161,14 @@ class LogicalSwitchEditPage: public Page [=](int32_t newValue) { cs->v1 = newValue; SET_DIRTY(); - v2Edit->invalidate(); + if (v2Edit != nullptr) + { + int16_t v2_min = 0, v2_max = 0; + getMixSrcRange(cs->v1, v2_min, v2_max); + v2Edit->setMin(v2_min); + v2Edit->setMax(v2_max); + v2Edit->invalidate(); + } }); grid.nextLine();