Modify macro definition, remove and open some features

This commit is contained in:
Junhuang 2024-08-30 12:10:07 +08:00
parent d6d29a7959
commit 194580532a
5 changed files with 25 additions and 91 deletions

View File

@ -13,7 +13,7 @@
#ifdef ARCH_PORTDUINO #ifdef ARCH_PORTDUINO
#include "platform/portduino/PortduinoGlue.h" #include "platform/portduino/PortduinoGlue.h"
#endif #endif
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) #if defined(M5STACK_CORE2)
#include <M5Unified.h> #include <M5Unified.h>
#endif #endif
#define DEBUG_BUTTONS 0 #define DEBUG_BUTTONS 0
@ -126,9 +126,6 @@ int32_t ButtonThread::runOnce()
switch (btnEvent) { switch (btnEvent) {
case BUTTON_EVENT_PRESSED: { case BUTTON_EVENT_PRESSED: {
LOG_BUTTON("press!\n"); LOG_BUTTON("press!\n");
#if defined(M5STACK_COREBASIC)
M5.Speaker.tone(1000, 100);
#endif
#ifdef BUTTON_PIN #ifdef BUTTON_PIN
if (((config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN) != if (((config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN) !=
moduleConfig.canned_message.inputbroker_pin_press) || moduleConfig.canned_message.inputbroker_pin_press) ||
@ -149,9 +146,6 @@ int32_t ButtonThread::runOnce()
case BUTTON_EVENT_DOUBLE_PRESSED: { case BUTTON_EVENT_DOUBLE_PRESSED: {
LOG_BUTTON("Double press!\n"); LOG_BUTTON("Double press!\n");
#if defined(M5STACK_COREBASIC)
M5.Speaker.tone(2000, 100);
#endif
service->refreshLocalMeshNode(); service->refreshLocalMeshNode();
auto sentPosition = service->trySendPosition(NODENUM_BROADCAST, true); auto sentPosition = service->trySendPosition(NODENUM_BROADCAST, true);
if (screen) { if (screen) {
@ -193,9 +187,6 @@ int32_t ButtonThread::runOnce()
case BUTTON_EVENT_LONG_PRESSED: { case BUTTON_EVENT_LONG_PRESSED: {
LOG_BUTTON("Long press!\n"); LOG_BUTTON("Long press!\n");
#if defined(M5STACK_COREBASIC)
M5.Speaker.tone(3000, 300);
#endif
powerFSM.trigger(EVENT_PRESS); powerFSM.trigger(EVENT_PRESS);
if (screen) { if (screen) {
screen->startAlert("Shutting down..."); screen->startAlert("Shutting down...");
@ -208,9 +199,6 @@ int32_t ButtonThread::runOnce()
// may wake the board immediatedly. // may wake the board immediatedly.
case BUTTON_EVENT_LONG_RELEASED: { case BUTTON_EVENT_LONG_RELEASED: {
LOG_INFO("Shutdown from long press\n"); LOG_INFO("Shutdown from long press\n");
#if defined(M5STACK_COREBASIC)
M5.Speaker.tone(4000, 300);
#endif
playShutdownMelody(); playShutdownMelody();
delay(3000); delay(3000);
power->shutdown(); power->shutdown();

View File

@ -62,10 +62,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#if ARCH_PORTDUINO #if ARCH_PORTDUINO
#include "platform/portduino/PortduinoGlue.h" #include "platform/portduino/PortduinoGlue.h"
#endif #endif
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) #if defined(M5STACK_CORE2)
#include "M5Unified.h" #include "M5Unified.h"
extern DataInfo DataRegion; #define OLED_BLACK OLEDDISPLAY_COLOR::BLACK
#define OLED_WHITE OLEDDISPLAY_COLOR::WHITE
#else
#define OLED_BLACK BLACK
#define OLED_WHITE WHITE
#endif #endif
extern DataInfo DataRegion;
using namespace meshtastic; /** @todo remove */ using namespace meshtastic; /** @todo remove */
namespace graphics namespace graphics
@ -952,9 +957,7 @@ bool deltaToTimestamp(uint32_t secondsAgo, uint8_t *hours, uint8_t *minutes, int
validCached = true; validCached = true;
return validCached; return validCached;
} }
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2)
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->clear();
display->drawString(x + 0, y + 0, myRegion->name); display->drawString(x + 0, y + 0, myRegion->name);
display->setFont(FONT_MEDIUM); display->setFont(FONT_MEDIUM);
display->drawString(x + 10, y + 30,"channel: "+String(DataRegion.lora_channel_num+1)); display->drawString(x + 10, y + 30,"channel: "+String(DataRegion.lora_channel_num+1));
@ -971,7 +974,6 @@ static void drawLoraMessage(OLEDDisplay *display, OLEDDisplayUiState *state, int
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 display->setTextAlignment(TEXT_ALIGN_LEFT); // Restore left align, just to be kind to any other unsuspecting code
} }
#endif
/// Draw the last text message we received /// Draw the last text message we received
static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{ {
@ -990,11 +992,7 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state
display->setFont(FONT_SMALL); display->setFont(FONT_SMALL);
if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) { if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL); display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL);
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) display->setColor(OLED_BLACK);
display->setColor(OLEDDISPLAY_COLOR::BLACK);
#else
display->setColor(BLACK);
#endif
} }
// For time delta // For time delta
@ -1028,11 +1026,7 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state
} }
} }
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) display->setColor(OLED_WHITE);
display->setColor(OLEDDISPLAY_COLOR::WHITE);
#else
display->setColor(WHITE);
#endif
#ifndef EXCLUDE_EMOJI #ifndef EXCLUDE_EMOJI
if (strcmp(reinterpret_cast<const char *>(mp.decoded.payload.bytes), u8"\U0001F44D") == 0) { if (strcmp(reinterpret_cast<const char *>(mp.decoded.payload.bytes), u8"\U0001F44D") == 0) {
display->drawXbm(x + (SCREEN_WIDTH - thumbs_width) / 2, display->drawXbm(x + (SCREEN_WIDTH - thumbs_width) / 2,
@ -1105,15 +1099,10 @@ void Screen::drawColumns(OLEDDisplay *display, int16_t x, int16_t y, const char
int xo = x, yo = y; int xo = x, yo = y;
while (*f) { while (*f) {
display->drawString(xo, yo, *f); display->drawString(xo, yo, *f);
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2)
if ((display->getColor() == OLEDDISPLAY_COLOR::BLACK) && config.display.heading_bold) if ((display->getColor() == OLED_BLACK) && config.display.heading_bold)
display->drawString(xo + 1, yo, *f); display->drawString(xo + 1, yo, *f);
display->setColor(OLEDDISPLAY_COLOR::WHITE); display->setColor(OLED_WHITE);
#else
if ((display->getColor() == BLACK) && config.display.heading_bold)
display->drawString(xo + 1, yo, *f);
display->setColor(WHITE);
#endif
yo += FONT_HEIGHT_SMALL; yo += FONT_HEIGHT_SMALL;
if (yo > SCREEN_HEIGHT - FONT_HEIGHT_SMALL) { if (yo > SCREEN_HEIGHT - FONT_HEIGHT_SMALL) {
xo += SCREEN_WIDTH / 2; xo += SCREEN_WIDTH / 2;
@ -1523,11 +1512,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
display->drawCircle(compassX, compassY, compassDiam / 2); display->drawCircle(compassX, compassY, compassDiam / 2);
if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) { if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) display->setColor(OLED_BLACK);
display->setColor(OLEDDISPLAY_COLOR::BLACK);
#else
display->setColor(BLACK);
#endif
} }
// Must be after distStr is populated // Must be after distStr is populated
screen->drawColumns(display, x, y, fields); screen->drawColumns(display, x, y, fields);
@ -1641,7 +1626,7 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver)
digitalWrite(VTFT_LEDA, TFT_BACKLIGHT_ON); digitalWrite(VTFT_LEDA, TFT_BACKLIGHT_ON);
#endif #endif
#endif #endif
#if defined(M5STACK_COREBASIC) #ifdef TFT_BL
pinMode(TFT_BL, OUTPUT); pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH); digitalWrite(TFT_BL, HIGH);
#endif #endif
@ -1660,10 +1645,11 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver)
#endif #endif
LOG_INFO("Turning off screen\n"); LOG_INFO("Turning off screen\n");
dispdev->displayOff(); dispdev->displayOff();
#if defined(M5STACK_COREBASIC) #ifdef TFT_BL
pinMode(TFT_BL, OUTPUT); pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, LOW); digitalWrite(TFT_BL, LOW);
#elif defined(M5STACK_CORE2) #endif
#if defined(M5STACK_CORE2)
M5.Power.Axp192.setDCDC3(0); M5.Power.Axp192.setDCDC3(0);
#endif #endif
#ifdef USE_ST7789 #ifdef USE_ST7789
@ -2157,14 +2143,8 @@ void Screen::setFrames(FrameFocus focus)
fsi.positions.textMessage = numframes; fsi.positions.textMessage = numframes;
if (devicestate.has_rx_text_message && shouldDrawMessage(&devicestate.rx_text_message)) { if (devicestate.has_rx_text_message && shouldDrawMessage(&devicestate.rx_text_message)) {
normalFrames[numframes++] = drawTextMessageFrame; normalFrames[numframes++] = drawTextMessageFrame;
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2)
M5.Speaker.tone(3000, 400);
#endif
} }
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2)
normalFrames[numframes++] = drawLoraMessage; normalFrames[numframes++] = drawLoraMessage;
#endif
// then all the nodes // then all the nodes
// We only show a few nodes in our scrolling list - because meshes with many nodes would have too many screens // 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); size_t numToShow = min(numMeshNodes, 4U);
@ -2425,11 +2405,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) { if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL); display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL);
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) display->setColor(OLED_BLACK);
display->setColor(OLEDDISPLAY_COLOR::BLACK);
#else
display->setColor(BLACK);
#endif
} }
char channelStr[20]; char channelStr[20];
@ -2470,11 +2446,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
} }
} }
#endif #endif
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) display->setColor(OLED_WHITE);
display->setColor(OLEDDISPLAY_COLOR::WHITE);
#else
display->setColor(WHITE);
#endif
// Draw the channel name // Draw the channel name
display->drawString(x, y + FONT_HEIGHT_SMALL, channelStr); 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 // Draw our hardware ID to assist with bluetooth pairing. Either prefix with Info or S&F Logo
@ -2547,11 +2519,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i
if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) { if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL); display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL);
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) display->setColor(OLED_BLACK);
display->setColor(OLEDDISPLAY_COLOR::BLACK);
#else
display->setColor(BLACK);
#endif
} }
if (WiFi.status() != WL_CONNECTED) { if (WiFi.status() != WL_CONNECTED) {
@ -2571,11 +2539,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i
} }
} }
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) display->setColor(OLED_WHITE);
display->setColor(OLEDDISPLAY_COLOR::WHITE);
#else
display->setColor(WHITE);
#endif
/* /*
- WL_CONNECTED: assigned when connected to a WiFi network; - WL_CONNECTED: assigned when connected to a WiFi network;
@ -2635,11 +2599,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat
if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) { if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL); display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL);
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) display->setColor(OLED_BLACK);
display->setColor(OLEDDISPLAY_COLOR::BLACK);
#else
display->setColor(BLACK);
#endif
} }
char batStr[20]; char batStr[20];
@ -2678,11 +2638,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat
// minutes %= 60; // minutes %= 60;
// hours %= 24; // hours %= 24;
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) display->setColor(OLED_WHITE);
display->setColor(OLEDDISPLAY_COLOR::WHITE);
#else
display->setColor(WHITE);
#endif
// Show uptime as days, hours, minutes OR seconds // Show uptime as days, hours, minutes OR seconds
std::string uptime = screen->drawTimeDelta(days, hours, minutes, seconds); std::string uptime = screen->drawTimeDelta(days, hours, minutes, seconds);

View File

@ -761,9 +761,6 @@ void setup()
#endif #endif
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2) #if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2)
M5.begin(); M5.begin();
M5.Speaker.tone(2000, 600);
M5.Display.init();
M5.Display.fillScreen(TFT_BLACK);
#endif #endif
#if !MESHTASTIC_EXCLUDE_I2C #if !MESHTASTIC_EXCLUDE_I2C
// Don't call screen setup until after nodedb is setup (because we need // Don't call screen setup until after nodedb is setup (because we need

View File

@ -42,7 +42,6 @@ extern bool isUSBPowered;
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
extern ATECCX08A atecc; extern ATECCX08A atecc;
#endif #endif
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2)
struct DataInfo { struct DataInfo {
int lora_channel_num; int lora_channel_num;
double lora_freq; double lora_freq;
@ -52,7 +51,6 @@ struct DataInfo {
int lora_sf; int lora_sf;
int lora_cr; int lora_cr;
}; };
#endif
#ifdef T_WATCH_S3 #ifdef T_WATCH_S3
#include <Adafruit_DRV2605.h> #include <Adafruit_DRV2605.h>
extern Adafruit_DRV2605 drv; extern Adafruit_DRV2605 drv;

View File

@ -11,9 +11,8 @@
#include <assert.h> #include <assert.h>
#include <pb_decode.h> #include <pb_decode.h>
#include <pb_encode.h> #include <pb_encode.h>
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2)
DataInfo DataRegion; DataInfo DataRegion;
#endif
#define RDEF(name, freq_start, freq_end, duty_cycle, spacing, power_limit, audio_permitted, frequency_switching, wide_lora) \ #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, \ meshtastic_Config_LoRaConfig_RegionCode_##name, freq_start, freq_end, duty_cycle, spacing, power_limit, audio_permitted, \
@ -203,10 +202,8 @@ uint32_t RadioInterface::getPacketTime(uint32_t pl)
float tPacket = tPreamble + tPayload; float tPacket = tPreamble + tPayload;
uint32_t msecs = tPacket * 1000; uint32_t msecs = tPacket * 1000;
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2)
DataRegion.lora_sf=sf; DataRegion.lora_sf=sf;
DataRegion.lora_cr=cr; DataRegion.lora_cr=cr;
#endif
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), 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); pl, msecs);
return msecs; return msecs;
@ -551,13 +548,11 @@ void RadioInterface::applyModemConfig()
slotTimeMsec = computeSlotTimeMsec(bw, sf); slotTimeMsec = computeSlotTimeMsec(bw, sf);
preambleTimeMsec = getPacketTime((uint32_t)0); preambleTimeMsec = getPacketTime((uint32_t)0);
maxPacketTimeMsec = getPacketTime(meshtastic_Constants_DATA_PAYLOAD_LEN + sizeof(PacketHeader)); maxPacketTimeMsec = getPacketTime(meshtastic_Constants_DATA_PAYLOAD_LEN + sizeof(PacketHeader));
#if defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2)
DataRegion.lora_channel_num=channel_num; DataRegion.lora_channel_num=channel_num;
DataRegion.lora_freq=getFreq(); DataRegion.lora_freq=getFreq();
DataRegion.lora_channel_name=channelName; DataRegion.lora_channel_name=channelName;
DataRegion.lora_power_output=power; DataRegion.lora_power_output=power;
DataRegion.lora_bw=bw; DataRegion.lora_bw=bw;
#endif
LOG_INFO("Radio freq=%.3f, config.lora.frequency_offset=%.3f\n", freq, loraConfig.frequency_offset); 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, LOG_INFO("Set radio: region=%s, name=%s, config=%u, ch=%d, power=%d\n", myRegion->name, channelName, loraConfig.modem_preset,
channel_num, power); channel_num, power);