Autoformat

This commit is contained in:
Ludovic BOUÉ 2024-10-13 21:05:15 +00:00
parent f6c019c948
commit 27a0d03ab6
4 changed files with 35 additions and 34 deletions

View File

@ -339,38 +339,40 @@ void ButtonThread::userButtonPressedLongStop()
#if defined(M5STACK_CORE2) #if defined(M5STACK_CORE2)
// Define a constant // 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 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 // Global variable
unsigned long lastClickTime = 0; // The time of the last click unsigned long lastClickTime = 0; // The time of the last click
int clickCount = 0; // Click count int clickCount = 0; // Click count
unsigned long touch_start_time; // Touch start time unsigned long touch_start_time; // Touch start time
bool is_touching = false; // Mark whether you are currently touching bool is_touching = false; // Mark whether you are currently touching
void ScreenTouch(){ void ScreenTouch()
{
M5.update(); M5.update();
auto count = M5.Touch.getCount(); auto count = M5.Touch.getCount();
if (count == 0) return; if (count == 0)
return;
for (std::size_t i = 0; i < count; ++i) { for (std::size_t i = 0; i < count; ++i) {
auto t = M5.Touch.getDetail(i); auto t = M5.Touch.getDetail(i);
// If touch starts // If touch starts
if (t.wasPressed()) { if (t.wasPressed()) {
touch_start_time = millis(); // Record the time when the touch began 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) { if (is_touching) {
unsigned long duration = millis() - touch_start_time; unsigned long duration = millis() - touch_start_time;
if (duration >= LONG_PRESS_THRESHOLD) { if (duration >= LONG_PRESS_THRESHOLD) {
LOG_INFO("Long Press Detected\n"); LOG_INFO("Long Press Detected\n");
powerFSM.trigger(EVENT_PRESS); powerFSM.trigger(EVENT_PRESS);
screen->startAlert("Shutting down..."); screen->startAlert("Shutting down...");
screen->forceDisplay(true); screen->forceDisplay(true);
// Executive logic, such as shutdown, display menu, etc // Executive logic, such as shutdown, display menu, etc
// To avoid duplicate detection, set is_touching to false here // To avoid duplicate detection, set is_touching to false here
is_touching = false; is_touching = false;
M5.Speaker.tone(3000, 300); M5.Speaker.tone(3000, 300);
delay(1000); delay(1000);
M5.Power.powerOff(); M5.Power.powerOff();
@ -380,13 +382,13 @@ void ScreenTouch(){
if (t.wasReleased()) { if (t.wasReleased()) {
if (is_touching) { if (is_touching) {
unsigned long duration = millis() - touch_start_time; unsigned long duration = millis() - touch_start_time;
if (duration < LONG_PRESS_THRESHOLD) { if (duration < LONG_PRESS_THRESHOLD) {
unsigned long currentTime = millis(); unsigned long currentTime = millis();
// Check whether it is a double click // Check whether it is a double click
if (currentTime - lastClickTime <= DOUBLE_CLICK_THRESHOLD) { if (currentTime - lastClickTime <= DOUBLE_CLICK_THRESHOLD) {
clickCount++; clickCount++;
if (clickCount == MAX_CLICKS) { if (clickCount == MAX_CLICKS) {
LOG_INFO("Double Click Detected\n"); LOG_INFO("Double Click Detected\n");
M5.Speaker.tone(2000, 100); M5.Speaker.tone(2000, 100);
service->refreshLocalMeshNode(); service->refreshLocalMeshNode();
auto sentPosition = service->trySendPosition(NODENUM_BROADCAST, true); auto sentPosition = service->trySendPosition(NODENUM_BROADCAST, true);
@ -397,24 +399,23 @@ void ScreenTouch(){
screen->print("Sent ad-hoc nodeinfo\n"); screen->print("Sent ad-hoc nodeinfo\n");
screen->forceDisplay(true); // Force a new UI frame, then force an EInk update screen->forceDisplay(true); // Force a new UI frame, then force an EInk update
} }
clickCount = 0; clickCount = 0;
} }
} else { } else {
clickCount = 1; clickCount = 1;
} }
lastClickTime = currentTime; // Update last click time lastClickTime = currentTime; // Update last click time
} }
} }
// Reset the touch status // Reset the touch status
is_touching = false; is_touching = false;
} }
// You can add more status checks, such as sliding and dragging // You can add more status checks, such as sliding and dragging
if (t.wasFlickStart()) { if (t.wasFlickStart()) {
LOG_INFO("Flick Start Detected\n"); LOG_INFO("Flick Start Detected\n");
M5.Speaker.tone(1000, 100); M5.Speaker.tone(1000, 100);
powerFSM.trigger(EVENT_PRESS); powerFSM.trigger(EVENT_PRESS);
} }
} }
} }

View File

@ -71,8 +71,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define OLED_BLACK OLEDDISPLAY_COLOR::BLACK #define OLED_BLACK OLEDDISPLAY_COLOR::BLACK
#define OLED_WHITE OLEDDISPLAY_COLOR::WHITE #define OLED_WHITE OLEDDISPLAY_COLOR::WHITE
#else #else
#define OLED_BLACK BLACK #define OLED_BLACK BLACK
#define OLED_WHITE WHITE #define OLED_WHITE WHITE
#endif #endif
using namespace meshtastic; /** @todo remove */ using namespace meshtastic; /** @todo remove */
@ -1635,7 +1635,7 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver)
pinMode(TFT_BL, OUTPUT); pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH); digitalWrite(TFT_BL, HIGH);
#endif #endif
#if defined(M5STACK_CORE2) #if defined(M5STACK_CORE2)
M5.Power.Axp192.setDCDC3(1000); M5.Power.Axp192.setDCDC3(1000);
M5.Display.setBrightness(130); M5.Display.setBrightness(130);
#endif #endif
@ -1654,7 +1654,7 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver)
pinMode(TFT_BL, OUTPUT); pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, LOW); digitalWrite(TFT_BL, LOW);
#endif #endif
#if defined(M5STACK_CORE2) #if defined(M5STACK_CORE2)
M5.Power.Axp192.setDCDC3(0); M5.Power.Axp192.setDCDC3(0);
#endif #endif
#ifdef USE_ST7789 #ifdef USE_ST7789

View File

@ -328,9 +328,9 @@ class LGFX : public lgfx::LGFX_Device
auto cfg = _light_instance.config(); // Gets a structure for backlight settings. auto cfg = _light_instance.config(); // Gets a structure for backlight settings.
#if !defined(M5STACK_CORE2) #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 #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.freq = 44100; // PWM frequency of backlight
// cfg.pwm_channel = 1; // PWM channel number to use // cfg.pwm_channel = 1; // PWM channel number to use
@ -732,7 +732,8 @@ void TFTDisplay::sendCommand(uint8_t com)
unphone.backlight(true); // using unPhone library unphone.backlight(true); // using unPhone library
#endif #endif
#ifdef RAK14014 #ifdef RAK14014
#elif !defined(M5STACK) && !defined(ST7789_CS) && !defined(M5STACK_CORE2) // T-Deck gets brightness set in Screen.cpp in the handleSetOn function #elif !defined(M5STACK) && !defined(ST7789_CS) && \
!defined(M5STACK_CORE2) // T-Deck gets brightness set in Screen.cpp in the handleSetOn function
tft->setBrightness(172); tft->setBrightness(172);
#endif #endif
break; break;
@ -864,4 +865,4 @@ bool TFTDisplay::connect()
return true; return true;
} }
#endif #endif

View File

@ -1,14 +1,13 @@
// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep // #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 39 // 38, 37
// #define BUTTON_PIN 0 // #define BUTTON_PIN 0
#define BUTTON_NEED_PULLUP #define BUTTON_NEED_PULLUP
// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Plugin. // #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_SCK
#undef LORA_MISO #undef LORA_MISO
#undef LORA_MOSI #undef LORA_MOSI
@ -17,10 +16,10 @@
#define LORA_SCK 18 #define LORA_SCK 18
#define LORA_MISO 38 #define LORA_MISO 38
#define LORA_MOSI 23 #define LORA_MOSI 23
#define LORA_CS 33 //NSS #define LORA_CS 33 // NSS
#define USE_RF95 #define USE_RF95
#define LORA_DIO0 35 // IRQ #define LORA_DIO0 35 // IRQ
#define LORA_RESET 19 #define LORA_RESET 19
#define LORA_DIO1 RADIOLIB_NC // Not really used #define LORA_DIO1 RADIOLIB_NC // Not really used
#define LORA_DIO2 RADIOLIB_NC // Not really used #define LORA_DIO2 RADIOLIB_NC // Not really used
@ -40,5 +39,5 @@
// LCD screens are slow, so slowdown the wipe so it looks better // LCD screens are slow, so slowdown the wipe so it looks better
#define SCREEN_TRANSITION_FRAMERATE 30 // fps #define SCREEN_TRANSITION_FRAMERATE 30 // fps
// Picomputer gets a white on black display // Picomputer gets a white on black display
#define TFT_MESH COLOR565 (0xA0, 0xFF, 0x00)//(0x94, 0xEA, 0x67) #define TFT_MESH COLOR565(0xA0, 0xFF, 0x00) //(0x94, 0xEA, 0x67)
#define ILI9341_SPI_HOST VSPI_HOST // VSPI_HOST or HSPI_HOST #define ILI9341_SPI_HOST VSPI_HOST // VSPI_HOST or HSPI_HOST