From 6507683909c52a011e13f806c7029528e736a430 Mon Sep 17 00:00:00 2001 From: Ihor Nehrutsa Date: Fri, 25 Nov 2022 15:17:24 +0200 Subject: [PATCH 1/2] Squashed commit of the following: commit c8d1bcf04fae5f7ac5b639ddd15a738045014c95 Author: Ihor Nehrutsa Date: Fri Nov 25 15:11:18 2022 +0200 Revert "variants\tbeam\variant.h: Use LORA_CS instead of RF95_NSS" This reverts commit 8d225ced9cbccb44d0b58451029b4bd073a8510e. commit 1c37097448393ea9364c2b9bf10522802c61d5c4 Author: Ihor Nehrutsa Date: Fri Nov 25 15:04:09 2022 +0200 Some little debugs added commit f1b55e11afb11df414969924a1d84f8fa72fbf62 Author: Ihor Nehrutsa Date: Wed Nov 23 15:24:58 2022 +0200 Update variant.h commit 8d225ced9cbccb44d0b58451029b4bd073a8510e Author: Ihor Nehrutsa Date: Wed Nov 23 13:06:49 2022 +0200 variants\tbeam\variant.h: Use LORA_CS instead of RF95_NSS --- src/main.cpp | 9 +++++---- src/mesh/RadioInterface.cpp | 11 ++++++----- src/mesh/SX126xInterface.cpp | 25 +++++++++++++------------ src/modules/esp32/RangeTestModule.cpp | 4 ++-- src/platform/esp32/main-esp32.cpp | 2 +- variants/tbeam/variant.h | 2 +- 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f83909869..98f22ecf1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -140,8 +140,9 @@ bool ButtonThread::shutdown_on_long_stop = false; #endif static Periodic *ledPeriodic; -static OSThread *powerFSMthread, *buttonThread; +static OSThread *powerFSMthread; #if HAS_BUTTON +static OSThread *buttonThread; uint32_t ButtonThread::longPressTime = 0; #endif @@ -269,7 +270,7 @@ void setup() #ifdef HAS_SDCARD setupSDCard(); #endif - + #ifdef RAK4630 // scanEInkDevice(); #endif @@ -303,11 +304,11 @@ void setup() nodeDB.init(); playStartMelody(); - + // fixed screen override? if (config.display.oled != Config_DisplayConfig_OledType_OLED_AUTO) screen_model = config.display.oled; - + // Init our SPI controller (must be before screen and lora) initSPI(); #ifndef ARCH_ESP32 diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 0c68b59a2..4a40c6600 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -177,7 +177,7 @@ uint32_t RadioInterface::getRetransmissionMsec(const MeshPacket *p) static uint8_t bytes[MAX_RHPACKETLEN]; size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), Data_fields, &p->decoded); uint32_t packetAirtime = getPacketTime(numbytes + sizeof(PacketHeader)); - // Make sure enough time has elapsed for this packet to be sent and an ACK is received. + // Make sure enough time has elapsed for this packet to be sent and an ACK is received. // DEBUG_MSG("Waiting for flooding message with airtime %d and slotTime is %d\n", packetAirtime, slotTimeMsec); float channelUtil = airTime->channelUtilizationPercent(); uint8_t CWsize = map(channelUtil, 0, 100, CWmin, CWmax); @@ -189,7 +189,7 @@ uint32_t RadioInterface::getRetransmissionMsec(const MeshPacket *p) uint32_t RadioInterface::getTxDelayMsec() { /** We wait a random multiple of 'slotTimes' (see definition in header file) in order to avoid collisions. - The pool to take a random multiple from is the contention window (CW), which size depends on the + The pool to take a random multiple from is the contention window (CW), which size depends on the current channel utilization. */ float channelUtil = airTime->channelUtilizationPercent(); uint8_t CWsize = map(channelUtil, 0, 100, CWmin, CWmax); @@ -225,7 +225,7 @@ uint32_t RadioInterface::getTxDelayMsecWeighted(float snr) void printPacket(const char *prefix, const MeshPacket *p) { - DEBUG_MSG("%s (id=0x%08x Fr0x%02x To0x%02x, WantAck%d, HopLim%d Ch0x%x", prefix, p->id, p->from & 0xff, p->to & 0xff, + DEBUG_MSG("%s (id=0x%08x fr=0x%02x to=0x%02x, WantAck=%d, HopLim=%d Ch=0x%x", prefix, p->id, p->from & 0xff, p->to & 0xff, p->want_ack, p->hop_limit, p->channel); if (p->which_payload_variant == MeshPacket_decoded_tag) { auto &s = p->decoded; @@ -432,7 +432,7 @@ void RadioInterface::applyModemConfig() // Set final tx_power back onto config loraConfig.tx_power = (int8_t)power; // cppcheck-suppress assignmentAddressToInteger - + // Calculate the number of channels uint32_t numChannels = floor((myRegion->freqEnd - myRegion->freqStart) / (myRegion->spacing + (bw / 1000))); @@ -449,8 +449,9 @@ void RadioInterface::applyModemConfig() saveChannelNum(channel_num); saveFreq(freq + config.lora.frequency_offset); + DEBUG_MSG("Radio freq=%.3f, config.lora.frequency_offset=%.3f\n", freq, config.lora.frequency_offset); DEBUG_MSG("Set radio: region=%s, name=%s, config=%u, ch=%d, power=%d\n", myRegion->name, channelName, loraConfig.modem_preset, channel_num, power); - DEBUG_MSG("Radio myRegion->freqStart / myRegion->freqEnd: %f -> %f (%f mhz)\n", myRegion->freqStart, myRegion->freqEnd, myRegion->freqEnd - myRegion->freqStart); + DEBUG_MSG("Radio myRegion->freqStart -> myRegion->freqEnd: %f -> %f (%f mhz)\n", myRegion->freqStart, myRegion->freqEnd, myRegion->freqEnd - myRegion->freqStart); DEBUG_MSG("Radio myRegion->numChannels: %d x %.3fkHz\n", numChannels, bw); DEBUG_MSG("Radio channel_num: %d\n", channel_num); DEBUG_MSG("Radio frequency: %f\n", getFreq()); diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index 20c8056e2..5559a7063 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -12,6 +12,7 @@ SX126xInterface::SX126xInterface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, SPIClass &spi) : RadioLibInterface(cs, irq, rst, busy, spi, &lora), lora(&module) { + DEBUG_MSG("SX126xInterface(cs=%d, irq=%d, rst=%d, busy=%d)\n", cs, irq, rst, busy); } /// Initialise the Driver transport hardware and software. @@ -56,9 +57,9 @@ bool SX126xInterface::init() // \todo Display actual typename of the adapter, not just `SX126x` DEBUG_MSG("SX126x init result %d\n", res); - DEBUG_MSG("Frequency set to %f\n", getFreq()); - DEBUG_MSG("Bandwidth set to %f\n", bw); - DEBUG_MSG("Power output set to %d\n", power); + DEBUG_MSG("Frequency set to %f\n", getFreq()); + DEBUG_MSG("Bandwidth set to %f\n", bw); + DEBUG_MSG("Power output set to %d\n", power); // current limit was removed from module' ctor // override default value (60 mA) @@ -81,11 +82,11 @@ bool SX126xInterface::init() //if(crcLSB != 0x0f) // RECORD_CRITICALERROR(CriticalErrorCode_SX1262Failure); - + crcLSB = 0x5a; err = lora.writeRegister(SX126X_REG_CRC_POLYNOMIAL_LSB, &crcLSB, 1); if(err != RADIOLIB_ERR_NONE) - RECORD_CRITICALERROR(CriticalErrorCode_SX1262Failure); + RECORD_CRITICALERROR(CriticalErrorCode_SX1262Failure); err = lora.readRegister(SX126X_REG_CRC_POLYNOMIAL_LSB, &crcLSB, 1); if(err != RADIOLIB_ERR_NONE) @@ -146,7 +147,7 @@ bool SX126xInterface::reconfigure() if (power > SX126X_MAX_POWER) // This chip has lower power limits than some power = SX126X_MAX_POWER; - + err = lora.setOutputPower(power); assert(err == RADIOLIB_ERR_NONE); @@ -165,7 +166,7 @@ template void SX126xInterface::setStandby() { checkNotification(); // handle any pending interrupts before we force standby - + int err = lora.standby(); if (err != RADIOLIB_ERR_NONE) @@ -229,7 +230,7 @@ void SX126xInterface::startReceive() #if defined(SX126X_TXEN) && (SX126X_TXEN != RADIOLIB_NC) digitalWrite(SX126X_TXEN, LOW); #endif - + // int err = lora.startReceive(); int err = lora.startReceiveDutyCycleAuto(); // We use a 32 bit preamble so this should save some power by letting radio sit in // standby mostly. @@ -249,13 +250,13 @@ bool SX126xInterface::isChannelActive() // check if we can detect a LoRa preamble on the current channel int16_t result; - setStandby(); + setStandby(); result = lora.scanChannel(); - if (result == RADIOLIB_PREAMBLE_DETECTED) + if (result == RADIOLIB_PREAMBLE_DETECTED) return true; - + assert(result != RADIOLIB_ERR_WRONG_MODEM); - + return false; } diff --git a/src/modules/esp32/RangeTestModule.cpp b/src/modules/esp32/RangeTestModule.cpp index b4cd9254e..d706f8ed3 100644 --- a/src/modules/esp32/RangeTestModule.cpp +++ b/src/modules/esp32/RangeTestModule.cpp @@ -155,8 +155,8 @@ ProcessMessage RangeTestModuleRadio::handleReceived(const MeshPacket &mp) DEBUG_MSG("mp.from %d\n", mp.from); DEBUG_MSG("mp.rx_snr %f\n", mp.rx_snr); DEBUG_MSG("mp.hop_limit %d\n", mp.hop_limit); - DEBUG_MSG("mp.decoded.position.latitude_i %d\n", mp.decoded.position.latitude_i); // Depricated - DEBUG_MSG("mp.decoded.position.longitude_i %d\n", mp.decoded.position.longitude_i); // Depricated + // DEBUG_MSG("mp.decoded.position.latitude_i %d\n", mp.decoded.position.latitude_i); // Depricated + // DEBUG_MSG("mp.decoded.position.longitude_i %d\n", mp.decoded.position.longitude_i); // Depricated DEBUG_MSG("---- Node Information of Received Packet (mp.from):\n"); DEBUG_MSG("n->user.long_name %s\n", n->user.long_name); DEBUG_MSG("n->user.short_name %s\n", n->user.short_name); diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index aaa4f4efe..21df018d8 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -24,7 +24,7 @@ void getMacAddr(uint8_t *dmac) } void setBluetoothEnable(bool on) { - + if (!isWifiAvailable() && config.bluetooth.enabled == true) { if (!nimbleBluetooth) { nimbleBluetooth = new NimbleBluetooth(); diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index fab210683..268e9ef96 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -12,7 +12,7 @@ // TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if // not found then probe for SX1262 -#define USE_RF95 +#define USE_RF95 // RFM95/SX127x #define USE_SX1262 #define USE_SX1268 From c5fe878a6f57e9a9ca0bdd16d890e47270f85053 Mon Sep 17 00:00:00 2001 From: lewis Date: Sat, 26 Nov 2022 21:37:32 +0800 Subject: [PATCH 2/2] Fix the format of t-echo Bluetooth pairing display page --- src/graphics/Screen.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 277127d53..eac78dd64 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -283,27 +283,27 @@ static void drawModuleFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int static void drawFrameBluetooth(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { + int x_offset = display->width() / 2; + int y_offset = display->height() == 64 ? 0 : 32; display->setTextAlignment(TEXT_ALIGN_CENTER); display->setFont(FONT_MEDIUM); - display->drawString(64 + x, y, "Bluetooth"); + display->drawString(x_offset + x, y_offset + y, "Bluetooth"); display->setFont(FONT_SMALL); - display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Enter this code"); + y_offset = display->height() == 64 ? y_offset + FONT_HEIGHT_MEDIUM -4 : y_offset + FONT_HEIGHT_MEDIUM + 5; + display->drawString(x_offset + x, y_offset + y, "Enter this code"); display->setFont(FONT_LARGE); + String displayPin(btPIN); + String pin = displayPin.substring(0, 3) + " " + displayPin.substring(3, 6); + y_offset = display->height() == 64 ? y_offset + FONT_HEIGHT_SMALL - 5 : y_offset + FONT_HEIGHT_SMALL + 5; + display->drawString(x_offset + x, y_offset + y, pin); - auto displayPin = new String(btPIN); - display->setTextAlignment(TEXT_ALIGN_LEFT); - display->drawString(12 + x, 26 + y, displayPin->substring(0, 3)); - display->drawString(72 + x, 26 + y, displayPin->substring(3, 6)); - - display->setTextAlignment(TEXT_ALIGN_CENTER); display->setFont(FONT_SMALL); - char buf[30]; - const char *name = "Name: "; - strcpy(buf, name); - strcat(buf, getDeviceName()); - display->drawString(64 + x, 48 + y, buf); + String deviceName = "Name: "; + deviceName.concat(getDeviceName()); + y_offset = display->height() == 64 ? y_offset + FONT_HEIGHT_LARGE - 6 : y_offset + FONT_HEIGHT_LARGE + 5; + display->drawString(x_offset + x, y_offset + y, deviceName); } static void drawFrameShutdown(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)