Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support M5 core2、corebasic2.7+Module-LoRa433_V1.1+GNSS Module #4471

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ default_envs = tbeam
;default_envs = heltec_vision_master_e213
;default_envs = heltec_vision_master_e290
;default_envs = heltec_mesh_node_t114

;default_envs = m5stack-corebasic
;default_envs = m5stack-core2
extra_configs =
arch/*/*.ini
variants/*/platformio.ini
Expand Down
88 changes: 86 additions & 2 deletions src/ButtonThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#ifdef ARCH_PORTDUINO
#include "platform/portduino/PortduinoGlue.h"
#endif

#if defined(M5STACK_CORE2)
#include <M5Unified.h>
#endif
#define DEBUG_BUTTONS 0
#if DEBUG_BUTTONS
#define LOG_BUTTON(...) LOG_DEBUG(__VA_ARGS__)
Expand Down Expand Up @@ -327,4 +329,86 @@ void ButtonThread::userButtonPressedLongStop()
if (millis() > c_holdOffTime) {
btnEvent = BUTTON_EVENT_LONG_RELEASED;
}
}
}
#if defined(M5STACK_CORE2)
// Define a constant
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
// 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(){
M5.update();
auto count = M5.Touch.getCount();
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
}

//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");
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;
M5.Speaker.tone(3000, 300);
delay(1000);
M5.Power.powerOff();
}
}
// Check if the touch just ended
if (t.wasReleased()) {
if (is_touching) {
unsigned long duration = millis() - touch_start_time;
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");
M5.Speaker.tone(2000, 100);
service->refreshLocalMeshNode();
auto sentPosition = service->trySendPosition(NODENUM_BROADCAST, true);
if (screen) {
if (sentPosition)
screen->print("Sent ad-hoc position\n");
else
screen->print("Sent ad-hoc nodeinfo\n");
screen->forceDisplay(true); // Force a new UI frame, then force an EInk update
}
clickCount = 0;
}
} else {
clickCount = 1;
}

lastClickTime = currentTime; // Update last click time
}
}
// Reset the touch status
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);

}
}
}
#endif
3 changes: 3 additions & 0 deletions src/ButtonThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ class ButtonThread : public concurrency::OSThread
};

extern ButtonThread *buttonThread;
#if defined(M5STACK_CORE2)
void ScreenTouch();
#endif
69 changes: 54 additions & 15 deletions src/graphics/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#if ARCH_PORTDUINO
#include "platform/portduino/PortduinoGlue.h"
#endif

#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
#endif
extern DataInfo DataRegion;
using namespace meshtastic; /** @todo remove */

namespace graphics
Expand Down Expand Up @@ -949,7 +957,23 @@ 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){
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->setTextAlignment(TEXT_ALIGN_LEFT);
const char *title = "LoRa";
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->setTextAlignment(TEXT_ALIGN_LEFT); // Restore left align, just to be kind to any other unsuspecting code
}
/// Draw the last text message we received
weekroom marked this conversation as resolved.
Show resolved Hide resolved
static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
Expand All @@ -968,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(BLACK);
display->setColor(OLED_BLACK);
}
weekroom marked this conversation as resolved.
Show resolved Hide resolved

// For time delta
Expand Down Expand Up @@ -1002,7 +1026,7 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state
}
}

display->setColor(WHITE);
display->setColor(OLED_WHITE);
#ifndef EXCLUDE_EMOJI
if (strcmp(reinterpret_cast<const char *>(mp.decoded.payload.bytes), u8"\U0001F44D") == 0) {
display->drawXbm(x + (SCREEN_WIDTH - thumbs_width) / 2,
Expand Down Expand Up @@ -1075,10 +1099,10 @@ void Screen::drawColumns(OLEDDisplay *display, int16_t x, int16_t y, const char
int xo = x, yo = y;
while (*f) {
display->drawString(xo, yo, *f);
if ((display->getColor() == BLACK) && config.display.heading_bold)
display->drawString(xo + 1, yo, *f);

display->setColor(WHITE);
if ((display->getColor() == OLED_BLACK) && config.display.heading_bold)
display->drawString(xo + 1, yo, *f);
display->setColor(OLED_WHITE);
yo += FONT_HEIGHT_SMALL;
if (yo > SCREEN_HEIGHT - FONT_HEIGHT_SMALL) {
xo += SCREEN_WIDTH / 2;
Expand Down Expand Up @@ -1503,7 +1527,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
display->drawCircle(compassX, compassY, compassDiam / 2);

if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->setColor(BLACK);
display->setColor(OLED_BLACK);
}
// Must be after distStr is populated
screen->drawColumns(display, x, y, fields);
Expand Down Expand Up @@ -1617,6 +1641,14 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver)
pinMode(VTFT_LEDA, OUTPUT);
digitalWrite(VTFT_LEDA, TFT_BACKLIGHT_ON);
#endif
#endif
#ifdef TFT_BL
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH);
#endif
weekroom marked this conversation as resolved.
Show resolved Hide resolved
#if defined(M5STACK_CORE2)
M5.Power.Axp192.setDCDC3(1000);
M5.Display.setBrightness(130);
#endif
enabled = true;
setInterval(0); // Draw ASAP
Expand All @@ -1629,6 +1661,13 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver)
#endif
LOG_INFO("Turning off screen\n");
dispdev->displayOff();
#ifdef TFT_BL
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, LOW);
#endif
#if defined(M5STACK_CORE2)
M5.Power.Axp192.setDCDC3(0);
#endif
#ifdef USE_ST7789
SPI1.end();
#if defined(ARCH_ESP32)
Expand Down Expand Up @@ -2127,7 +2166,7 @@ void Screen::setFrames(FrameFocus focus)
if (devicestate.has_rx_text_message && shouldDrawMessage(&devicestate.rx_text_message)) {
normalFrames[numframes++] = drawTextMessageFrame;
}

normalFrames[numframes++] = drawLoraMessage;
// then all the nodes
// We only show a few nodes in our scrolling list - because meshes with many nodes would have too many screens
size_t numToShow = min(numMeshNodes, 4U);
Expand Down Expand Up @@ -2388,7 +2427,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16

if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL);
display->setColor(BLACK);
display->setColor(OLED_BLACK);
}

char channelStr[20];
Expand Down Expand Up @@ -2429,7 +2468,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
}
}
#endif
display->setColor(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
Expand Down Expand Up @@ -2502,7 +2541,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i

if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL);
display->setColor(BLACK);
display->setColor(OLED_BLACK);
}

if (WiFi.status() != WL_CONNECTED) {
Expand All @@ -2522,7 +2561,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i
}
}

display->setColor(WHITE);
display->setColor(OLED_WHITE);

/*
- WL_CONNECTED: assigned when connected to a WiFi network;
Expand Down Expand Up @@ -2582,7 +2621,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat

if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL);
display->setColor(BLACK);
display->setColor(OLED_BLACK);
}

char batStr[20];
Expand Down Expand Up @@ -2621,7 +2660,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat
// minutes %= 60;
// hours %= 24;

display->setColor(WHITE);
display->setColor(OLED_WHITE);

// Show uptime as days, hours, minutes OR seconds
std::string uptime = screen->drawTimeDelta(days, hours, minutes, seconds);
Expand Down
23 changes: 15 additions & 8 deletions src/graphics/TFTDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,11 @@ class LGFX : public lgfx::LGFX_Device
cfg.dummy_read_pixel = 8; // 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
#if defined(M5STACK_COREBASIC)
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
#endif
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
Expand All @@ -319,7 +323,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
#endif
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
Expand Down Expand Up @@ -708,7 +714,7 @@ void TFTDisplay::sendCommand(uint8_t com)
display(true);
if (settingsMap[displayBacklight] > 0)
digitalWrite(settingsMap[displayBacklight], TFT_BACKLIGHT_ON);
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE)
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE) && !defined(M5STACK_COREBASIC) && !defined(M5STACK_CORE2)
tft->wakeup();
tft->powerSaveOff();
#endif
Expand All @@ -720,7 +726,7 @@ void TFTDisplay::sendCommand(uint8_t com)
unphone.backlight(true); // using unPhone library
#endif
#ifdef RAK14014
#elif !defined(M5STACK) && !defined(ST7789_CS) // 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;
Expand All @@ -732,7 +738,7 @@ void TFTDisplay::sendCommand(uint8_t com)
tft->clear();
if (settingsMap[displayBacklight] > 0)
digitalWrite(settingsMap[displayBacklight], !TFT_BACKLIGHT_ON);
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE)
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE) && !defined(M5STACK_COREBASIC) && !defined(M5STACK_CORE2)
tft->sleep();
tft->powerSaveOn();
#endif
Expand All @@ -744,7 +750,7 @@ void TFTDisplay::sendCommand(uint8_t com)
unphone.backlight(false); // using unPhone library
#endif
#ifdef RAK14014
#elif !defined(M5STACK)
#elif !defined(M5STACK) || !defined(M5STACK_COREBASIC)
tft->setBrightness(0);
#endif
break;
Expand Down Expand Up @@ -778,7 +784,7 @@ bool TFTDisplay::hasTouch(void)
{
#ifdef RAK14014
return true;
#elif !defined(M5STACK)
#elif !defined(M5STACK) || !defined(M5STACK_COREBASIC)
return tft->touch() != nullptr;
#else
return false;
Expand All @@ -797,7 +803,7 @@ bool TFTDisplay::getTouch(int16_t *x, int16_t *y)
} else {
return false;
}
#elif !defined(M5STACK)
#elif !defined(M5STACK) || !defined(M5STACK_COREBASIC)
return tft->getTouch(x, y);
#else
return false;
Expand Down Expand Up @@ -826,10 +832,11 @@ bool TFTDisplay::connect()
#ifdef UNPHONE
unphone.backlight(true); // using unPhone library
#endif

#if !defined(M5STACK_CORE2)
tft->init();
#endif

#if defined(M5STACK)
#if defined(M5STACK) || defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2)
tft->setRotation(0);
#elif defined(RAK14014)
tft->setRotation(1);
Expand Down
Loading
Loading