From 0fe99b0caa94d51cc4794a1475b873968b854f8c Mon Sep 17 00:00:00 2001 From: mverch67 Date: Tue, 8 Aug 2023 18:06:39 +0200 Subject: [PATCH 1/6] T-Watch fixes --- boards/t-watch-s3.json | 2 +- src/PowerFSM.cpp | 3 ++- src/graphics/TFTDisplay.cpp | 40 ++++++++++++++++++----------- src/graphics/TFTDisplay.h | 3 +++ src/input/TouchScreenBase.cpp | 2 +- src/input/TouchScreenImpl1.cpp | 5 ++++ src/modules/CannedMessageModule.cpp | 4 +-- variants/t-deck/variant.h | 1 + variants/t-watch-s3/variant.h | 1 + 9 files changed, 41 insertions(+), 20 deletions(-) diff --git a/boards/t-watch-s3.json b/boards/t-watch-s3.json index d4c9f2abd..e86917df6 100644 --- a/boards/t-watch-s3.json +++ b/boards/t-watch-s3.json @@ -15,7 +15,7 @@ "f_cpu": "240000000L", "f_flash": "80000000L", "flash_mode": "dio", - "hwids": [["0X303A", "0x1001"]], + "hwids": [["0x303A", "0x1001"]], "mcu": "esp32s3", "variant": "t-watch-s3" }, diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 6c6069365..a873e93c7 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -297,7 +297,8 @@ void PowerFSM_setup() powerFSM.add_transition(&stateLS, &stateON, EVENT_INPUT, NULL, "Input Device"); powerFSM.add_transition(&stateNB, &stateON, EVENT_INPUT, NULL, "Input Device"); powerFSM.add_transition(&stateDARK, &stateON, EVENT_INPUT, NULL, "Input Device"); - powerFSM.add_transition(&stateON, &stateON, EVENT_INPUT, NULL, "Input Device"); // restarts the sleep timer + powerFSM.add_transition(&stateON, &stateON, EVENT_INPUT, NULL, "Input Device"); // restarts the sleep timer + powerFSM.add_transition(&statePOWER, &statePOWER, EVENT_INPUT, NULL, "Input Device"); // restarts the sleep timer powerFSM.add_transition(&stateDARK, &stateON, EVENT_BLUETOOTH_PAIR, NULL, "Bluetooth pairing"); powerFSM.add_transition(&stateON, &stateON, EVENT_BLUETOOTH_PAIR, NULL, "Bluetooth pairing"); diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 186887457..08ed66337 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -148,16 +148,16 @@ class LGFX : public lgfx::LGFX_Device // The following setting values ​​are general initial values ​​for each panel, so please comment out any // unknown items and try them. - cfg.panel_width = TFT_WIDTH; // actual displayable width - cfg.panel_height = TFT_HEIGHT; // actual displayable height - cfg.offset_x = TFT_OFFSET_X; // Panel offset amount in X direction - cfg.offset_y = TFT_OFFSET_Y; // Panel offset amount in Y direction - cfg.offset_rotation = 0; // Rotation direction value offset 0~7 (4~7 is mirrored) - cfg.dummy_read_pixel = 9; // Number of bits for dummy read before pixel readout - cfg.dummy_read_bits = 1; // Number of bits for dummy read before non-pixel data read - cfg.readable = true; // Set to true if data can be read - cfg.invert = true; // Set to true if the light/darkness of the panel is reversed - cfg.rgb_order = false; // Set to true if the panel's red and blue are swapped + cfg.panel_width = TFT_WIDTH; // actual displayable width + cfg.panel_height = TFT_HEIGHT; // actual displayable height + cfg.offset_x = TFT_OFFSET_X; // Panel offset amount in X direction + cfg.offset_y = TFT_OFFSET_Y; // Panel offset amount in Y direction + cfg.offset_rotation = TFT_OFFSET_ROTATION; // Rotation direction value offset 0~7 (4~7 is mirrored) + cfg.dummy_read_pixel = 9; // Number of bits for dummy read before pixel readout + cfg.dummy_read_bits = 1; // Number of bits for dummy read before non-pixel data read + cfg.readable = true; // Set to true if data can be read + cfg.invert = true; // Set to true if the light/darkness of the panel is reversed + cfg.rgb_order = false; // Set to true if the panel's red and blue are swapped cfg.dlen_16bit = false; // Set to true for panels that transmit data length in 16-bit units with 16-bit parallel or SPI cfg.bus_shared = true; // If the bus is shared with the SD card, set to true (bus control with drawJpgFile etc.) @@ -192,7 +192,7 @@ class LGFX : public lgfx::LGFX_Device cfg.y_max = TFT_WIDTH - 1; cfg.pin_int = SCREEN_TOUCH_INT; cfg.bus_shared = true; - cfg.offset_rotation = 0; + cfg.offset_rotation = TFT_OFFSET_ROTATION; // cfg.freq = 2500000; // I2C @@ -389,6 +389,14 @@ void TFTDisplay::sendCommand(uint8_t com) // Drop all other commands to device (we just update the buffer) } +void TFTDisplay::flipScreenVertically() +{ +#if defined(T_WATCH_S3) + LOG_DEBUG("Flip TFT vertically\n"); // T-Watch S3 right-handed orientation + tft.setRotation(0); +#endif +} + bool TFTDisplay::hasTouch(void) { #ifndef M5STACK @@ -424,10 +432,12 @@ bool TFTDisplay::connect() #endif tft.init(); -#if defined(T_DECK) - tft.setRotation(1); // M5Stack/T-Deck have the TFT in landscape -#elif defined(M5STACK) || defined(T_WATCH_S3) - tft.setRotation(0); // T-Watch S3 has the TFT in portrait +#if defined(M5STACK) + tft.setRotation(0); +#elif defined(T_DECK) + tft.setRotation(1); // T-Deck has the TFT in landscape +#elif defined(T_WATCH_S3) + tft.setRotation(2); // T-Watch S3 left-handed orientation #else tft.setRotation(3); // Orient horizontal and wide underneath the silkscreen name label #endif diff --git a/src/graphics/TFTDisplay.h b/src/graphics/TFTDisplay.h index dee31acf1..8c9a9b62e 100644 --- a/src/graphics/TFTDisplay.h +++ b/src/graphics/TFTDisplay.h @@ -22,6 +22,9 @@ class TFTDisplay : public OLEDDisplay // Write the buffer to the display memory virtual void display(void) override; + // Turn the display upside down + virtual void flipScreenVertically(); + // Touch screen (static handlers) static bool hasTouch(void); static bool getTouch(int16_t *x, int16_t *y); diff --git a/src/input/TouchScreenBase.cpp b/src/input/TouchScreenBase.cpp index dad1bb56c..2f361ac4c 100644 --- a/src/input/TouchScreenBase.cpp +++ b/src/input/TouchScreenBase.cpp @@ -40,13 +40,13 @@ int32_t TouchScreenBase::runOnce() int16_t x, y; bool touched = getTouch(x, y); if (touched) { - hapticFeedback(); this->setInterval(20); _last_x = x; _last_y = y; } if (touched != _touchedOld) { if (touched) { + hapticFeedback(); _state = TOUCH_EVENT_OCCURRED; _start = millis(); _first_x = x; diff --git a/src/input/TouchScreenImpl1.cpp b/src/input/TouchScreenImpl1.cpp index 9a7ecd4a2..b3152c88a 100644 --- a/src/input/TouchScreenImpl1.cpp +++ b/src/input/TouchScreenImpl1.cpp @@ -1,5 +1,6 @@ #include "TouchScreenImpl1.h" #include "InputBroker.h" +#include "PowerFSM.h" #include "configuration.h" TouchScreenImpl1 *touchScreenImpl1; @@ -61,6 +62,10 @@ void TouchScreenImpl1::onEvent(const TouchEvent &event) e.inputEvent = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL); break; } + case TOUCH_ACTION_TAP: { + powerFSM.trigger(EVENT_INPUT); + break; + } default: return; } diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 3ca718e99..952e9065a 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -221,8 +221,8 @@ void CannedMessageModule::sendText(NodeNum dest, const char *message, bool wantR p->decoded.payload.size = strlen(message); memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size); if (moduleConfig.canned_message.send_bell) { - p->decoded.payload.bytes[p->decoded.payload.size - 1] = 7; // Bell character - p->decoded.payload.bytes[p->decoded.payload.size] = '\0'; // Bell character + p->decoded.payload.bytes[p->decoded.payload.size] = 7; // Bell character + p->decoded.payload.bytes[p->decoded.payload.size + 1] = '\0'; // Bell character p->decoded.payload.size++; } diff --git a/variants/t-deck/variant.h b/variants/t-deck/variant.h index 04f20fa74..9613d882a 100644 --- a/variants/t-deck/variant.h +++ b/variants/t-deck/variant.h @@ -15,6 +15,7 @@ #define TFT_WIDTH 240 #define TFT_OFFSET_X 0 #define TFT_OFFSET_Y 0 +#define TFT_OFFSET_ROTATION 0 #define SCREEN_ROTATE #define SCREEN_TRANSITION_FRAMERATE 5 diff --git a/variants/t-watch-s3/variant.h b/variants/t-watch-s3/variant.h index 8c0fc9122..dc363603b 100644 --- a/variants/t-watch-s3/variant.h +++ b/variants/t-watch-s3/variant.h @@ -15,6 +15,7 @@ #define TFT_WIDTH 240 #define TFT_OFFSET_X 0 #define TFT_OFFSET_Y 0 +#define TFT_OFFSET_ROTATION 2 #define SCREEN_ROTATE #define SCREEN_TRANSITION_FRAMERATE 5 // fps From 746d7268a2af9d731dc4f8d757cf5f8d02b4ef5d Mon Sep 17 00:00:00 2001 From: mverch67 Date: Tue, 8 Aug 2023 18:51:11 +0200 Subject: [PATCH 2/6] fix picomputer --- variants/picomputer-s3/variant.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/variants/picomputer-s3/variant.h b/variants/picomputer-s3/variant.h index 0f416efe0..03d8b8440 100644 --- a/variants/picomputer-s3/variant.h +++ b/variants/picomputer-s3/variant.h @@ -39,16 +39,17 @@ #define TFT_WIDTH 240 #define TFT_OFFSET_X 0 #define TFT_OFFSET_Y 0 +#define TFT_OFFSET_ROTATION 0 #define SCREEN_ROTATE #define SCREEN_TRANSITION_FRAMERATE 5 #define INPUTBROKER_MATRIX_TYPE 1 -#define KEYS_COLS \ - { \ - 44, 47, 17, 15, 13, 41 \ +#define KEYS_COLS \ + { \ + 44, 47, 17, 15, 13, 41 \ } -#define KEYS_ROWS \ - { \ - 12, 16, 42, 18, 14, 7 \ +#define KEYS_ROWS \ + { \ + 12, 16, 42, 18, 14, 7 \ } From 1d0ac2caf73bc04bd517e12cc44eaa2ecde8639f Mon Sep 17 00:00:00 2001 From: mverch67 Date: Tue, 8 Aug 2023 18:55:00 +0200 Subject: [PATCH 3/6] trunk fmt --- variants/picomputer-s3/variant.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/variants/picomputer-s3/variant.h b/variants/picomputer-s3/variant.h index 03d8b8440..197eb3da1 100644 --- a/variants/picomputer-s3/variant.h +++ b/variants/picomputer-s3/variant.h @@ -45,11 +45,11 @@ #define INPUTBROKER_MATRIX_TYPE 1 -#define KEYS_COLS \ - { \ - 44, 47, 17, 15, 13, 41 \ +#define KEYS_COLS \ + { \ + 44, 47, 17, 15, 13, 41 \ } -#define KEYS_ROWS \ - { \ - 12, 16, 42, 18, 14, 7 \ +#define KEYS_ROWS \ + { \ + 12, 16, 42, 18, 14, 7 \ } From 1986267d65d95ee0c2a9e5592716c7e90f57323e Mon Sep 17 00:00:00 2001 From: mverch67 Date: Tue, 8 Aug 2023 20:02:29 +0200 Subject: [PATCH 4/6] check payload size --- src/modules/CannedMessageModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 5f6a374a1..0a3aaafb4 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -224,7 +224,7 @@ void CannedMessageModule::sendText(NodeNum dest, const char *message, bool wantR p->want_ack = true; p->decoded.payload.size = strlen(message); memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size); - if (moduleConfig.canned_message.send_bell) { + if (moduleConfig.canned_message.send_bell && p->decoded.payload.size < meshtastic_Constants_DATA_PAYLOAD_LEN) { p->decoded.payload.bytes[p->decoded.payload.size] = 7; // Bell character p->decoded.payload.bytes[p->decoded.payload.size + 1] = '\0'; // Bell character p->decoded.payload.size++; From 616553ed7200825a13cc4cb5000bf709d6aeaf01 Mon Sep 17 00:00:00 2001 From: mverch67 Date: Tue, 8 Aug 2023 20:14:12 +0200 Subject: [PATCH 5/6] doing the math :) --- src/modules/CannedMessageModule.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 0a3aaafb4..314624a13 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -398,9 +398,10 @@ int32_t CannedMessageModule::runOnce() this->freetext.substring(0, this->cursor) + this->payload + this->freetext.substring(this->cursor); } this->cursor += 1; - if (this->freetext.length() > meshtastic_Constants_DATA_PAYLOAD_LEN) { - this->cursor = meshtastic_Constants_DATA_PAYLOAD_LEN; - this->freetext = this->freetext.substring(0, meshtastic_Constants_DATA_PAYLOAD_LEN); + uint16_t maxChars = meshtastic_Constants_DATA_PAYLOAD_LEN - (moduleConfig.canned_message.send_bell ? 1 : 0); + if (this->freetext.length() > maxChars) { + this->cursor = maxChars; + this->freetext = this->freetext.substring(0, maxChars); } break; } @@ -499,7 +500,8 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st } display->drawStringf(0 + x, 0 + y, buffer, "To: %s", cannedMessageModule->getNodeName(this->dest)); // used chars right aligned - snprintf(buffer, sizeof(buffer), "%d left", meshtastic_Constants_DATA_PAYLOAD_LEN - this->freetext.length()); + uint16_t charsLeft = meshtastic_Constants_DATA_PAYLOAD_LEN - this->freetext.length() - (moduleConfig.canned_message.send_bell ? 1 : 0); + snprintf(buffer, sizeof(buffer), "%d left", charsLeft); display->drawString(x + display->getWidth() - display->getStringWidth(buffer), y + 0, buffer); if (this->destSelect) { display->drawString(x + display->getWidth() - display->getStringWidth(buffer) - 1, y + 0, buffer); From dd69de9f320b04bd4a23f2766222448b31ab30cf Mon Sep 17 00:00:00 2001 From: mverch67 Date: Tue, 8 Aug 2023 20:21:20 +0200 Subject: [PATCH 6/6] trunk fmt --- src/modules/CannedMessageModule.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 314624a13..71a9d746c 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -500,7 +500,8 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st } display->drawStringf(0 + x, 0 + y, buffer, "To: %s", cannedMessageModule->getNodeName(this->dest)); // used chars right aligned - uint16_t charsLeft = meshtastic_Constants_DATA_PAYLOAD_LEN - this->freetext.length() - (moduleConfig.canned_message.send_bell ? 1 : 0); + uint16_t charsLeft = + meshtastic_Constants_DATA_PAYLOAD_LEN - this->freetext.length() - (moduleConfig.canned_message.send_bell ? 1 : 0); snprintf(buffer, sizeof(buffer), "%d left", charsLeft); display->drawString(x + display->getWidth() - display->getStringWidth(buffer), y + 0, buffer); if (this->destSelect) {