From 3729635ef5f6ccb660228199c72ba0f58e2af517 Mon Sep 17 00:00:00 2001 From: imliubo Date: Thu, 27 Feb 2025 16:19:43 +0800 Subject: [PATCH] fix the code format by use trunk Signed-off-by: imliubo --- src/ButtonThread.cpp | 43 ++++++++++++++-------------- src/graphics/Screen.cpp | 39 +++++++++++++------------ src/graphics/TFTDisplay.cpp | 13 +++++---- src/main.cpp | 4 +-- src/main.h | 7 ++--- src/mesh/RadioInterface.cpp | 16 +++++------ variants/m5stack_core2/variant.h | 13 ++++----- variants/m5stack_corebasic/variant.h | 13 ++++----- 8 files changed, 73 insertions(+), 75 deletions(-) diff --git a/src/ButtonThread.cpp b/src/ButtonThread.cpp index d82898d0e..fcb61dfe6 100644 --- a/src/ButtonThread.cpp +++ b/src/ButtonThread.cpp @@ -14,7 +14,7 @@ #ifdef ARCH_PORTDUINO #include "platform/portduino/PortduinoGlue.h" #endif -#if defined(M5STACK_CORE2) +#if defined(M5STACK_CORE2) #include #endif #define DEBUG_BUTTONS 0 @@ -372,38 +372,40 @@ void ButtonThread::userButtonPressedLongStop() } #if defined(M5STACK_CORE2) // Define a constant -const unsigned long LONG_PRESS_THRESHOLD = 5000; // Hold the threshold +const unsigned long LONG_PRESS_THRESHOLD = 5000; // Hold the threshold const unsigned long DOUBLE_CLICK_THRESHOLD = 1000; // Double-click the threshold -const int MAX_CLICKS = 2; // Maximum hits +const int MAX_CLICKS = 2; // Maximum hits // Global variable unsigned long lastClickTime = 0; // The time of the last click -int clickCount = 0; // Click count -unsigned long touch_start_time; // Touch start time -bool is_touching = false; // Mark whether you are currently touching -void ScreenTouch(){ +int clickCount = 0; // Click count +unsigned long touch_start_time; // Touch start time +bool is_touching = false; // Mark whether you are currently touching +void ScreenTouch() +{ M5.update(); auto count = M5.Touch.getCount(); - if (count == 0) return; + if (count == 0) + return; for (std::size_t i = 0; i < count; ++i) { auto t = M5.Touch.getDetail(i); // If touch starts if (t.wasPressed()) { touch_start_time = millis(); // Record the time when the touch began - is_touching = true; // Set to touch + is_touching = true; // Set to touch } - //Check the current touch status + // Check the current touch status if (is_touching) { unsigned long duration = millis() - touch_start_time; - if (duration >= LONG_PRESS_THRESHOLD) { - LOG_INFO("Long Press Detected\n"); + if (duration >= LONG_PRESS_THRESHOLD) { + LOG_INFO("Long Press Detected\n"); powerFSM.trigger(EVENT_PRESS); screen->startAlert("Shutting down..."); screen->forceDisplay(true); // Executive logic, such as shutdown, display menu, etc // To avoid duplicate detection, set is_touching to false here - is_touching = false; + is_touching = false; M5.Speaker.tone(3000, 300); delay(1000); M5.Power.powerOff(); @@ -413,13 +415,13 @@ void ScreenTouch(){ if (t.wasReleased()) { if (is_touching) { unsigned long duration = millis() - touch_start_time; - if (duration < LONG_PRESS_THRESHOLD) { - unsigned long currentTime = millis(); + if (duration < LONG_PRESS_THRESHOLD) { + unsigned long currentTime = millis(); // Check whether it is a double click if (currentTime - lastClickTime <= DOUBLE_CLICK_THRESHOLD) { clickCount++; if (clickCount == MAX_CLICKS) { - LOG_INFO("Double Click Detected\n"); + LOG_INFO("Double Click Detected\n"); M5.Speaker.tone(2000, 100); service->refreshLocalMeshNode(); auto sentPosition = service->trySendPosition(NODENUM_BROADCAST, true); @@ -430,24 +432,23 @@ void ScreenTouch(){ screen->print("Sent ad-hoc nodeinfo\n"); screen->forceDisplay(true); // Force a new UI frame, then force an EInk update } - clickCount = 0; + clickCount = 0; } } else { - clickCount = 1; + clickCount = 1; } - + lastClickTime = currentTime; // Update last click time } } // Reset the touch status - is_touching = false; + is_touching = false; } // You can add more status checks, such as sliding and dragging if (t.wasFlickStart()) { LOG_INFO("Flick Start Detected\n"); M5.Speaker.tone(1000, 100); powerFSM.trigger(EVENT_PRESS); - } } } diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index e88e0b646..de0473528 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -64,15 +64,15 @@ along with this program. If not, see . #include "modules/StoreForwardModule.h" #include "platform/portduino/PortduinoGlue.h" #endif -#if defined(M5STACK_CORE2) +#if defined(M5STACK_CORE2) #include "M5Unified.h" #define OLED_BLACK OLEDDISPLAY_COLOR::BLACK #define OLED_WHITE OLEDDISPLAY_COLOR::WHITE #else - #define OLED_BLACK BLACK - #define OLED_WHITE WHITE +#define OLED_BLACK BLACK +#define OLED_WHITE WHITE #endif -extern DataInfo DataRegion; +extern DataInfo DataRegion; using namespace meshtastic; /** @todo remove */ namespace graphics @@ -956,21 +956,22 @@ bool deltaToTimestamp(uint32_t secondsAgo, uint8_t *hours, uint8_t *minutes, int validCached = true; return validCached; } -static void drawLoraMessage(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y){ +static void drawLoraMessage(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) +{ display->drawString(x + 0, y + 0, myRegion->name); display->setFont(FONT_MEDIUM); - display->drawString(x + 10, y + 30,"channel: "+String(DataRegion.lora_channel_num+1)); - display->drawString(x + 10, y + 60,"bw: "+ String(DataRegion.lora_bw)); - display->drawString(x + SCREEN_WIDTH/2+10, y+30,"freq: "+String(DataRegion.lora_freq)); - display->drawString(x + SCREEN_WIDTH/2+10, y+60,"power: "+ String(DataRegion.lora_power_output)); - display->drawString(x + 10, y + 90,"sf: "+String(DataRegion.lora_sf)); - display->drawString(x + SCREEN_WIDTH/2+10, y+90,"cr: 4/:"+ String(DataRegion.lora_cr)); + display->drawString(x + 10, y + 30, "channel: " + String(DataRegion.lora_channel_num + 1)); + display->drawString(x + 10, y + 60, "bw: " + String(DataRegion.lora_bw)); + display->drawString(x + SCREEN_WIDTH / 2 + 10, y + 30, "freq: " + String(DataRegion.lora_freq)); + display->drawString(x + SCREEN_WIDTH / 2 + 10, y + 60, "power: " + String(DataRegion.lora_power_output)); + display->drawString(x + 10, y + 90, "sf: " + String(DataRegion.lora_sf)); + display->drawString(x + SCREEN_WIDTH / 2 + 10, y + 90, "cr: 4/:" + String(DataRegion.lora_cr)); display->setTextAlignment(TEXT_ALIGN_LEFT); const char *title = "LoRa"; - display->drawString(x + SCREEN_WIDTH/2-20, y +0, title); + display->drawString(x + SCREEN_WIDTH / 2 - 20, y + 0, title); display->setFont(FONT_SMALL); display->setTextAlignment(TEXT_ALIGN_RIGHT); - display->drawString(x + SCREEN_WIDTH, y,String(DataRegion.lora_channel_name)); + display->drawString(x + SCREEN_WIDTH, y, String(DataRegion.lora_channel_name)); display->setTextAlignment(TEXT_ALIGN_LEFT); // Restore left align, just to be kind to any other unsuspecting code } /// Draw the last text message we received @@ -991,7 +992,7 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state display->setFont(FONT_SMALL); if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) { display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL); - display->setColor(OLED_BLACK); + display->setColor(OLED_BLACK); } // For time delta @@ -1659,9 +1660,9 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) pinMode(TFT_BL, OUTPUT); digitalWrite(TFT_BL, HIGH); #endif -#if defined(M5STACK_CORE2) +#if defined(M5STACK_CORE2) M5.Power.Axp192.setDCDC3(1000); - M5.Display.setBrightness(130); + M5.Display.setBrightness(130); #endif enabled = true; setInterval(0); // Draw ASAP @@ -1678,7 +1679,7 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) pinMode(TFT_BL, OUTPUT); digitalWrite(TFT_BL, LOW); #endif -#if defined(M5STACK_CORE2) +#if defined(M5STACK_CORE2) M5.Power.Axp192.setDCDC3(0); #endif #ifdef USE_ST7789 @@ -2512,7 +2513,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 } } #endif - display->setColor(OLED_WHITE); + display->setColor(OLED_WHITE); // Draw the channel name display->drawString(x, y + FONT_HEIGHT_SMALL, channelStr); // Draw our hardware ID to assist with bluetooth pairing. Either prefix with Info or S&F Logo @@ -2605,7 +2606,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i } } - display->setColor(OLED_WHITE); + display->setColor(OLED_WHITE); /* - WL_CONNECTED: assigned when connected to a WiFi network; diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 9a60d2e3d..3386cfc0e 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -310,9 +310,9 @@ class LGFX : public lgfx::LGFX_Device 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 #if defined(M5STACK_COREBASIC) - cfg.invert = true; // Set to true if the light/darkness of the panel is reversed + cfg.invert = true; // Set to true if the light/darkness of the panel is reversed #else - cfg.invert = false; // Set to true if the light/darkness of the panel is reversed + cfg.invert = false; // Set to true if the light/darkness of the panel is reversed #endif cfg.rgb_order = false; // Set to true if the panel's red and blue are swapped cfg.dlen_16bit = @@ -332,9 +332,9 @@ class LGFX : public lgfx::LGFX_Device auto cfg = _light_instance.config(); // Gets a structure for backlight settings. #if !defined(M5STACK_CORE2) - cfg.pin_bl = TFT_BL; // Pin number to which the backlight is connected + cfg.pin_bl = TFT_BL; // Pin number to which the backlight is connected #endif - cfg.invert = false; // true to invert the brightness of the backlight + cfg.invert = false; // true to invert the brightness of the backlight // cfg.freq = 44100; // PWM frequency of backlight // cfg.pwm_channel = 1; // PWM channel number to use @@ -747,7 +747,8 @@ void TFTDisplay::sendCommand(uint8_t com) unphone.backlight(true); // using unPhone library #endif #ifdef RAK14014 -#elif !defined(M5STACK) && !defined(ST7789_CS) && !defined(M5STACK_COREBASIC) && !defined(M5STACK_CORE2)// T-Deck gets brightness set in Screen.cpp in the handleSetOn function +#elif !defined(M5STACK) && !defined(ST7789_CS) && !defined(M5STACK_COREBASIC) && \ + !defined(M5STACK_CORE2) // T-Deck gets brightness set in Screen.cpp in the handleSetOn function tft->setBrightness(172); #endif break; @@ -857,7 +858,7 @@ bool TFTDisplay::connect() tft->init(); #endif -#if defined(M5STACK) || defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) +#if defined(M5STACK) || defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) tft->setRotation(0); #elif defined(RAK14014) tft->setRotation(1); diff --git a/src/main.cpp b/src/main.cpp index 373d6f258..db404e3fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -115,11 +115,10 @@ AccelerometerThread *accelerometerThread = nullptr; AudioThread *audioThread = nullptr; #endif - #if defined(TCXO_OPTIONAL) float tcxoVoltage = SX126X_DIO3_TCXO_VOLTAGE; // if TCXO is optional, put this here so it can be changed further down. #endif -#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) +#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) #include #endif @@ -1234,6 +1233,5 @@ void loop() #if defined(M5STACK_CORE2) ScreenTouch(); #endif - } #endif diff --git a/src/main.h b/src/main.h index 056ed9452..5a5b12c52 100644 --- a/src/main.h +++ b/src/main.h @@ -39,14 +39,13 @@ extern bool pmu_found; extern bool isCharging; extern bool isUSBPowered; - struct DataInfo { int lora_channel_num; double lora_freq; - const char* lora_channel_name; - int lora_power_output; + const char *lora_channel_name; + int lora_power_output; float lora_bw; - int lora_sf; + int lora_sf; int lora_cr; }; diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 218e4f37d..46d707fa4 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -12,7 +12,7 @@ #include #include -DataInfo DataRegion; +DataInfo DataRegion; #define RDEF(name, freq_start, freq_end, duty_cycle, spacing, power_limit, audio_permitted, frequency_switching, wide_lora) \ { \ meshtastic_Config_LoRaConfig_RegionCode_##name, freq_start, freq_end, duty_cycle, spacing, power_limit, audio_permitted, \ @@ -213,8 +213,8 @@ uint32_t RadioInterface::getPacketTime(uint32_t pl) float tPacket = tPreamble + tPayload; uint32_t msecs = tPacket * 1000; - DataRegion.lora_sf=sf; - DataRegion.lora_cr=cr; + DataRegion.lora_sf = sf; + DataRegion.lora_cr = cr; LOG_DEBUG("(bw=%d, sf=%d, cr=4/%d) packet symLen=%d ms, payloadSize=%u, time %d ms\n", (int)bw, sf, cr, (int)(tSym * 1000), pl, msecs); return msecs; @@ -574,11 +574,11 @@ void RadioInterface::applyModemConfig() preambleTimeMsec = getPacketTime((uint32_t)0); maxPacketTimeMsec = getPacketTime(meshtastic_Constants_DATA_PAYLOAD_LEN + sizeof(PacketHeader)); - DataRegion.lora_channel_num=channel_num; - DataRegion.lora_freq=getFreq(); - DataRegion.lora_channel_name=channelName; - DataRegion.lora_power_output=power; - DataRegion.lora_bw=bw; + DataRegion.lora_channel_num = channel_num; + DataRegion.lora_freq = getFreq(); + DataRegion.lora_channel_name = channelName; + DataRegion.lora_power_output = power; + DataRegion.lora_bw = bw; LOG_INFO("Radio freq=%.3f, config.lora.frequency_offset=%.3f\n", freq, loraConfig.frequency_offset); LOG_INFO("Set radio: region=%s, name=%s, config=%u, ch=%d, power=%d\n", myRegion->name, channelName, loraConfig.modem_preset, channel_num, power); diff --git a/variants/m5stack_core2/variant.h b/variants/m5stack_core2/variant.h index 605a6be6a..38c82fb34 100644 --- a/variants/m5stack_core2/variant.h +++ b/variants/m5stack_core2/variant.h @@ -1,14 +1,13 @@ // #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep - // #define BUTTON_PIN 39 // 38, 37 // #define BUTTON_PIN 0 #define BUTTON_NEED_PULLUP // #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Plugin. -//#define BUTTON_PIN +// #define BUTTON_PIN -//#define PIN_BUZZER 25 +// #define PIN_BUZZER 25 #undef LORA_SCK #undef LORA_MISO #undef LORA_MOSI @@ -17,11 +16,11 @@ #define LORA_SCK 18 #define LORA_MISO 38 #define LORA_MOSI 23 -#define LORA_CS 33 //NSS +#define LORA_CS 33 // NSS #define USE_RF95 #define RF95_MAX_POWER 17 -#define LORA_DIO0 35 // IRQ +#define LORA_DIO0 35 // IRQ #define LORA_RESET 19 #define LORA_DIO1 RADIOLIB_NC // Not really used #define LORA_DIO2 RADIOLIB_NC // Not really used @@ -41,5 +40,5 @@ // LCD screens are slow, so slowdown the wipe so it looks better #define SCREEN_TRANSITION_FRAMERATE 30 // fps // Picomputer gets a white on black display -#define TFT_MESH COLOR565 (0xA0, 0xFF, 0x00)//(0x94, 0xEA, 0x67) -#define ILI9341_SPI_HOST VSPI_HOST // VSPI_HOST or HSPI_HOST \ No newline at end of file +#define TFT_MESH COLOR565(0xA0, 0xFF, 0x00) //(0x94, 0xEA, 0x67) +#define ILI9341_SPI_HOST VSPI_HOST // VSPI_HOST or HSPI_HOST \ No newline at end of file diff --git a/variants/m5stack_corebasic/variant.h b/variants/m5stack_corebasic/variant.h index 3d4233ce5..1da4fbe5d 100644 --- a/variants/m5stack_corebasic/variant.h +++ b/variants/m5stack_corebasic/variant.h @@ -20,12 +20,12 @@ #define LORA_SCK 18 #define LORA_MISO 19 #define LORA_MOSI 23 -#define LORA_CS 5 //NSS +#define LORA_CS 5 // NSS #define USE_RF95 #define RF95_MAX_POWER 17 -#define LORA_DIO0 35 // IRQ -#define LORA_RESET 13 // RST +#define LORA_DIO0 35 // IRQ +#define LORA_RESET 13 // RST #define LORA_DIO1 RADIOLIB_NC // Not really used #define LORA_DIO2 RADIOLIB_NC // Not really used @@ -35,10 +35,9 @@ #define GPS_RX_PIN 16 #define GPS_TX_PIN 17 - -//Note: If you use corebasic version 2.7 or later, -//you need to go to the src>graphics>TFTDisplay.cpp file to change the value of cfg.invert, -//this one is to set the color inversion +// Note: If you use corebasic version 2.7 or later, +// you need to go to the src>graphics>TFTDisplay.cpp file to change the value of cfg.invert, +// this one is to set the color inversion #define TFT_HEIGHT 240 #define TFT_WIDTH 320 #define TFT_OFFSET_X 0