diff --git a/include/utils.h b/include/utils.h index 5506c27..7a1c978 100644 --- a/include/utils.h +++ b/include/utils.h @@ -13,6 +13,7 @@ namespace Utils { void checkDisplayEcoMode(); String getSmartBeaconState(); void checkFlashlight(); + void i2cScannerForPeripherals(); } diff --git a/include/wx_utils.h b/include/wx_utils.h index 090822b..a11036b 100644 --- a/include/wx_utils.h +++ b/include/wx_utils.h @@ -10,7 +10,6 @@ namespace WX_Utils { - void getWxModuleAddres(); void setup(); const String generateTempString(const float sensorTemp, const uint8_t type); const String generateHumString(const float sensorHum, const uint8_t type); diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index f322b53..fa51ad3 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -57,7 +57,7 @@ TinyGPSPlus gps; BluetoothSerial SerialBT; #endif -String versionDate = "2024.12.09"; +String versionDate = "2024.12.10"; uint8_t myBeaconsIndex = 0; int myBeaconsSize = Config.beacons.size(); @@ -117,10 +117,6 @@ void setup() { displaySetup(); POWER_Utils::externalPinSetup(); - #ifdef HAS_TOUCHSCREEN - TOUCH_Utils::setup(); - #endif - STATION_Utils::loadIndex(0); STATION_Utils::loadIndex(1); STATION_Utils::nearTrackerInit(); @@ -132,6 +128,7 @@ void setup() { GPS_Utils::setup(); currentLoRaType = &Config.loraTypes[loraIndex]; LoRa_Utils::setup(); + Utils::i2cScannerForPeripherals(); WX_Utils::setup(); ackRequestNumber = random(1,999); @@ -155,6 +152,9 @@ void setup() { JOYSTICK_Utils::setup(); #endif KEYBOARD_Utils::setup(); + #ifdef HAS_TOUCHSCREEN + TOUCH_Utils::setup(); + #endif } POWER_Utils::lowerCpuFrequency(); @@ -257,4 +257,6 @@ void loop() { refreshDisplayTime = millis(); } } -} \ No newline at end of file +} + +// eliminar keyboardConnected y reemplazar por validar si es distinto de 0x00 ? \ No newline at end of file diff --git a/src/display.cpp b/src/display.cpp index 2936330..b4511de 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -33,6 +33,12 @@ #define normalSizeFont 2 #define smallSizeFont 1 #define lineSpacing 22 + + extern String topHeader1; + extern String topHeader1_1; + extern String topHeader1_2; + extern String topHeader1_3; + extern String topHeader2; #endif #else #include @@ -83,153 +89,152 @@ extern logging::Logger logger; #if defined(HAS_TFT) && (defined(TTGO_T_DECK_PLUS) || defined(TTGO_T_DECK_GPS)) -void drawButton(int xPos, int yPos, int wide, int height, String buttonText, int color) { - uint16_t baseColor, lightColor, darkColor; - switch (color) { - case 0: // Grey Theme - baseColor = greyColor; - lightColor = greyColorLight; - darkColor = greyColorDark; - break; - case 1: // Green Theme - baseColor = greenColor; - lightColor = greenColorLight; - darkColor = greenColorDark; - break; - case 2: // Red Theme - baseColor = redColor; - lightColor = redColorLight; - darkColor = redColorDark; - break; - default: // Fallback color - baseColor = 0x0000; // Black - lightColor = 0xFFFF; // White - darkColor = 0x0000; // Black - break; + void drawButton(int xPos, int yPos, int wide, int height, String buttonText, int color) { + uint16_t baseColor, lightColor, darkColor; + switch (color) { + case 0: // Grey Theme + baseColor = greyColor; + lightColor = greyColorLight; + darkColor = greyColorDark; + break; + case 1: // Green Theme + baseColor = greenColor; + lightColor = greenColorLight; + darkColor = greenColorDark; + break; + case 2: // Red Theme + baseColor = redColor; + lightColor = redColorLight; + darkColor = redColorDark; + break; + default: // Fallback color + baseColor = 0x0000; // Black + lightColor = 0xFFFF; // White + darkColor = 0x0000; // Black + break; + } + + sprite.fillRect(xPos, yPos, wide, height, baseColor); // Dibuja el fondo del botón + sprite.fillRect(xPos, yPos + height - 2, wide, 2, darkColor); // Línea inferior + sprite.fillRect(xPos, yPos, wide, 2, lightColor); // Línea superior + sprite.fillRect(xPos, yPos, 2, height, lightColor); // Línea izquierda + sprite.fillRect(xPos + wide - 2, yPos, 2, height, darkColor); // Línea derecha + + sprite.setTextSize(2); + sprite.setTextColor(TFT_WHITE, baseColor); + + // Calcula la posición del texto para que esté centrado + int textWidth = sprite.textWidth(buttonText); // Ancho del texto + int textHeight = 16; // Altura aproximada (depende de `setTextSize`) + int textX = xPos + (wide - textWidth) / 2; // Centrado horizontal + int textY = yPos + (height - textHeight) / 2; // Centrado vertical + + sprite.drawString(buttonText, textX, textY); } - sprite.fillRect(xPos, yPos, wide, height, baseColor); // Dibuja el fondo del botón - sprite.fillRect(xPos, yPos + height - 2, wide, 2, darkColor); // Línea inferior - sprite.fillRect(xPos, yPos, wide, 2, lightColor); // Línea superior - sprite.fillRect(xPos, yPos, 2, height, lightColor); // Línea izquierda - sprite.fillRect(xPos + wide - 2, yPos, 2, height, darkColor); // Línea derecha - - sprite.setTextSize(2); - sprite.setTextColor(TFT_WHITE, baseColor); + void draw_T_DECK_Top() {//const String& header, const String& datetime, const String& location) { + sprite.fillSprite(TFT_BLACK); + sprite.fillRect(0, 0, 320, 38, redColor); + sprite.setTextFont(0); + sprite.setTextSize(bigSizeFont); + sprite.setTextColor(TFT_WHITE, redColor); + sprite.drawString(topHeader1, 3, 5); + + sprite.setTextSize(smallSizeFont); + sprite.setTextColor(TFT_WHITE, redColor); + //String date = datetime.substring(0, datetime.indexOf(" ")); + sprite.drawString(topHeader1_1, 258, 5); + //String time = datetime.substring(datetime.indexOf(" ") + 3); + sprite.drawString("UTC:" + topHeader1_2, 246, 15); - // Calcula la posición del texto para que esté centrado - int textWidth = sprite.textWidth(buttonText); // Ancho del texto - int textHeight = 16; // Altura aproximada (depende de `setTextSize`) - int textX = xPos + (wide - textWidth) / 2; // Centrado horizontal - int textY = yPos + (height - textHeight) / 2; // Centrado vertical + sprite.fillRect(0, 38, 320, 2, redColorDark);//TFT_ORANGE); - sprite.drawString(buttonText, textX, textY); -} - -void draw_T_DECK_Top(const String& header, const String& datetime, const String& location) { - sprite.fillSprite(TFT_BLACK); - sprite.fillRect(0, 0, 320, 38, redColor); - sprite.setTextFont(0); - sprite.setTextSize(bigSizeFont); - sprite.setTextColor(TFT_WHITE, redColor); - sprite.drawString(currentBeacon->callsign, 3, 5); - - sprite.setTextSize(smallSizeFont); - sprite.setTextColor(TFT_WHITE, redColor); - String date = datetime.substring(0, datetime.indexOf(" ")); - sprite.drawString(date, 258, 5); - String time = datetime.substring(datetime.indexOf(" ") + 3); - sprite.drawString("UTC:" + time, 246, 15); - - sprite.fillRect(0, 38, 320, 2, redColorDark);//TFT_ORANGE); - - sprite.fillRect(0, 40, 320, 2, greyColorLight); - sprite.fillRect(0, 42, 320, 20, greyColor); - sprite.setTextSize(2); - sprite.setTextColor(TFT_WHITE, greyColor); - sprite.drawString(location, 8, 44); - sprite.fillRect(0, 60, 320, 2, greyColorDark); -} + sprite.fillRect(0, 40, 320, 2, greyColorLight); + sprite.fillRect(0, 42, 320, 20, greyColor); + sprite.setTextSize(2); + sprite.setTextColor(TFT_WHITE, greyColor); + sprite.drawString(topHeader2, 8, 44); + sprite.fillRect(0, 60, 320, 2, greyColorDark); + } -void draw_T_DECK_MenuButtons(int menu) { - int ladoCuadrado = 45; - int curvaCuadrado = 8; - int espacioEntreCuadrados = 18; - int margenLineaCuadrados = 10; - int alturaPrimeraLinea = 75; - int alturaSegundaLinea = 145; - int16_t colorCuadrados = 0x2925; - int16_t colorDestacado = greyColor; + void draw_T_DECK_MenuButtons(int menu) { + int ladoCuadrado = 45; + int curvaCuadrado = 8; + int espacioEntreCuadrados = 18; + int margenLineaCuadrados = 10; + int alturaPrimeraLinea = 75; + int alturaSegundaLinea = 145; + int16_t colorCuadrados = 0x2925; + int16_t colorDestacado = greyColor; - for (int i = 0; i < 5; i++) { - if (i == menu - 1) { - sprite.fillRoundRect( - margenLineaCuadrados + (i * (ladoCuadrado + espacioEntreCuadrados)) - 1, - alturaPrimeraLinea - 1, - ladoCuadrado + 2, - ladoCuadrado + 2, - curvaCuadrado, - TFT_WHITE - ); - sprite.fillRoundRect( - margenLineaCuadrados + (i * (ladoCuadrado + espacioEntreCuadrados)), - alturaPrimeraLinea, - ladoCuadrado, - ladoCuadrado, - curvaCuadrado, - TFT_BLACK - ); + for (int i = 0; i < 5; i++) { + if (i == menu - 1) { + sprite.fillRoundRect( + margenLineaCuadrados + (i * (ladoCuadrado + espacioEntreCuadrados)) - 1, + alturaPrimeraLinea - 1, + ladoCuadrado + 2, + ladoCuadrado + 2, + curvaCuadrado, + TFT_WHITE + ); + sprite.fillRoundRect( + margenLineaCuadrados + (i * (ladoCuadrado + espacioEntreCuadrados)), + alturaPrimeraLinea, + ladoCuadrado, + ladoCuadrado, + curvaCuadrado, + TFT_BLACK + ); + sprite.fillRoundRect( + margenLineaCuadrados + (i * (ladoCuadrado + espacioEntreCuadrados)), // x-coordinate + alturaPrimeraLinea, // y-coordinate + ladoCuadrado, // width + ladoCuadrado, // height + curvaCuadrado, // corner radius + colorDestacado // color + ); + } else { + sprite.fillRoundRect( + margenLineaCuadrados + (i * (ladoCuadrado + espacioEntreCuadrados)), // x-coordinate + alturaPrimeraLinea, // y-coordinate + ladoCuadrado, // width + ladoCuadrado, // height + curvaCuadrado, // corner radius + colorCuadrados // color + ); + } sprite.fillRoundRect( margenLineaCuadrados + (i * (ladoCuadrado + espacioEntreCuadrados)), // x-coordinate - alturaPrimeraLinea, // y-coordinate - ladoCuadrado, // width - ladoCuadrado, // height - curvaCuadrado, // corner radius - colorDestacado // color - ); - } else { - sprite.fillRoundRect( - margenLineaCuadrados + (i * (ladoCuadrado + espacioEntreCuadrados)), // x-coordinate - alturaPrimeraLinea, // y-coordinate + alturaSegundaLinea, // y-coordinate ladoCuadrado, // width ladoCuadrado, // height curvaCuadrado, // corner radius colorCuadrados // color ); } - sprite.fillRoundRect( - margenLineaCuadrados + (i * (ladoCuadrado + espacioEntreCuadrados)), // x-coordinate - alturaSegundaLinea, // y-coordinate - ladoCuadrado, // width - ladoCuadrado, // height - curvaCuadrado, // corner radius - colorCuadrados // color - ); } -} -void draw_T_DECK_Body(const String& line1, const String& line2, const String& line3, const String& line4, const String& line5, const String& line6) { - - if (menuDisplay > 0 && menuDisplay < 6) { - draw_T_DECK_MenuButtons(menuDisplay); - } else { + void draw_T_DECK_Body(const String& line1, const String& line2, const String& line3, const String& line4, const String& line5, const String& line6) { + + /*if (menuDisplay > 0 && menuDisplay < 6) { + draw_T_DECK_MenuButtons(menuDisplay); + } else {*/ sprite.setTextSize(normalSizeFont); sprite.setTextColor(TFT_WHITE, TFT_BLACK); const String* const lines[] = {&line1, &line2, &line3, &line4, &line5, &line6}; for (int i = 0; i < 6; i++) { - sprite.drawString(*lines[i], 60, 70 + (i * 20)); + sprite.drawString(*lines[i], 35, 70 + (i * 20)); } //drawButton(125, 210, 80, 28, "Menu", 0); drawButton(30, 210, 80, 28, "Send", 1); drawButton(125, 210, 80, 28, "Menu", 0); - drawButton(210, 210, 95, 28, "Cancel", 2); + drawButton(220, 210, 80, 28, "Exit", 2); + //} } -} - #endif @@ -394,7 +399,7 @@ void displayToggle(bool toggle) { void displayShow(const String& header, const String& line1, const String& line2, int wait) { #ifdef HAS_TFT #if defined(TTGO_T_DECK_PLUS) || defined(TTGO_T_DECK_GPS) - draw_T_DECK_Top(header, line1, line2); + draw_T_DECK_Top();//header, line1, line2); #endif #if defined(HELTEC_WIRELESS_TRACKER) sprite.fillSprite(TFT_BLACK); @@ -462,7 +467,7 @@ void drawSymbol(int symbolIndex, bool bluetoothActive) { void displayShow(const String& header, const String& line1, const String& line2, const String& line3, const String& line4, const String& line5, int wait) { #ifdef HAS_TFT #if defined(TTGO_T_DECK_PLUS) - draw_T_DECK_Top(header, line1, line2); + draw_T_DECK_Top();//header, line1, line2); draw_T_DECK_Body(header, line1, line2, line3, line4, line5); #endif #if defined(HELTEC_WIRELESS_TRACKER) diff --git a/src/keyboard_utils.cpp b/src/keyboard_utils.cpp index e266ab6..b78971c 100644 --- a/src/keyboard_utils.cpp +++ b/src/keyboard_utils.cpp @@ -11,12 +11,7 @@ #include "sleep_utils.h" #include "msg_utils.h" #include "display.h" - -#if defined(TTGO_T_DECK_GPS) || defined(TTGO_T_DECK_PLUS) - #define KB_ADDR 0x55 // T-Deck internal keyboard (Keyboard Backlight On = ALT + B) -#else - #define KB_ADDR 0x5F // CARDKB from m5stack.com (YEL - SDA / WTH SCL) -#endif +#include "utils.h" extern Configuration Config; @@ -53,6 +48,7 @@ extern String winlinkAliasComplete; extern bool winlinkCommentState; extern bool gpsIsActive; extern bool sendStartTelemetry; +extern uint8_t keyboardAddress; extern std::vector outputMessagesBuffer; @@ -715,8 +711,8 @@ namespace KEYBOARD_Utils { if (keyboardConnected) { uint32_t lastKey = millis() - keyboardTime; if (lastKey > 30 * 1000) keyDetected = false; - Wire.requestFrom(KB_ADDR, 1); - while(Wire.available()) { + Wire.requestFrom(keyboardAddress, static_cast(1)); + while (Wire.available()) { char c = Wire.read(); if (c != 0) { //Serial.print(c, DEC); Serial.print(" "); Serial.print(c, HEX); Serial.print(" "); Serial.println(char(c)); // just for debugging @@ -728,13 +724,7 @@ namespace KEYBOARD_Utils { } void setup() { - Wire.beginTransmission(KB_ADDR); - if (Wire.endTransmission() == 0) { - keyboardConnected = true; - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "Keyboard Connected to I2C"); - } else { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "Main", "No Keyboard Connected to I2C"); - } + if (keyboardAddress != 0x00) keyboardConnected = true; } } \ No newline at end of file diff --git a/src/menu_utils.cpp b/src/menu_utils.cpp index 3e9cc29..fb87932 100644 --- a/src/menu_utils.cpp +++ b/src/menu_utils.cpp @@ -52,6 +52,14 @@ extern bool gpsIsActive; String freqChangeWarning; uint8_t lowBatteryPercent = 21; +#if defined(TTGO_T_DECK_PLUS) || defined(TTGO_T_DECK_GPS) + String topHeader1 = ""; + String topHeader1_1 = ""; + String topHeader1_2 = ""; + String topHeader1_3 = ""; + String topHeader2 = ""; +#endif + namespace MENU_Utils { const String checkBTType() { @@ -96,6 +104,32 @@ namespace MENU_Utils { } else { lastLine = "1P=Down 2P=Back LP=Go"; } + + #if defined(TTGO_T_DECK_PLUS) || defined(TTGO_T_DECK_GPS) + topHeader1 = currentBeacon->callsign; + const auto time_now = now(); + topHeader1_1 = Utils::createDateString(time_now); + topHeader1_2 = Utils::createTimeString(time_now); + topHeader1_3 = ""; + topHeader2 = String(gps.location.lat(), 4); + topHeader2 += " "; + topHeader2 += String(gps.location.lng(), 4); + + for(int i = topHeader2.length(); i < 19; i++) { + topHeader2 += " "; + } + if (gps.satellites.value() <= 9) topHeader2 += " "; + topHeader2 += "SAT:"; + topHeader2 += String(gps.satellites.value()); + if (gps.hdop.hdop() > 5) { + topHeader2 += "X"; + } else if (gps.hdop.hdop() > 2 && gps.hdop.hdop() < 5) { + topHeader2 += "-"; + } else if (gps.hdop.hdop() <= 2) { + topHeader2 += "+"; + } + #endif + switch (menuDisplay) { // Graphic Menu is in here!!!! case 1: // 1. Messages displayShow("__MENU____"," 6.Extras", "> 1.Messages", " 2.Configuration", " 3.Stations", lastLine); diff --git a/src/touch_utils.cpp b/src/touch_utils.cpp index 481663e..2f36302 100644 --- a/src/touch_utils.cpp +++ b/src/touch_utils.cpp @@ -7,8 +7,9 @@ #define TOUCH_MODULES_GT911 #include + extern uint8_t touchModuleAddress; - TouchLib touch(Wire, BOARD_I2C_SDA, BOARD_I2C_SCL, GT911_SLAVE_ADDRESS2); //GT911_SLAVE_ADDRESS2 0X14 + TouchLib touch(Wire, BOARD_I2C_SDA, BOARD_I2C_SCL, 0x00); void (*lastCalledAction)() = nullptr; // keep track of last calledAction from Touch @@ -22,12 +23,14 @@ int16_t xValueMax = 320; int16_t yValueMax = 240; - int touchDebounce = 500; + int touchDebounce = 300; uint32_t lastTouchTime = 0; int16_t xlastValue = 0; int16_t ylastValue = 0; + extern int menuDisplay; + namespace TOUCH_Utils { @@ -35,17 +38,20 @@ void enterMenuFromTouch() { BUTTON_Utils::doublePress();} - void cancelFromTouch() { Serial.println("CANCEL BUTTON PRESSED");} + void exitFromTouch() { + menuDisplay = 0; + //Serial.println("CANCEL BUTTON PRESSED"); + } TouchButton touchButtons_0[] = { - {30, 110, 0, 28, "Send", 1, sendBeaconFromTouch}, // Button Send //drawButton(30, 210, 80, 28, "Send", 1); - {125, 205, 0, 28, "Menu", 0, enterMenuFromTouch}, // Button Menu //drawButton(125, 210, 80, 28, "Menu", 0); - {210, 305, 0, 28, "Cancel", 2, cancelFromTouch} // Button Cancel //drawButton(210, 210, 95, 28, "Cancel", 2); + {30, 110, 0, 28, "Send", 1, sendBeaconFromTouch}, // Button Send //drawButton(30, 210, 80, 28, "Send", 1); + {125, 205, 0, 28, "Menu", 0, enterMenuFromTouch}, // Button Menu //drawButton(125, 210, 80, 28, "Menu", 0); + {210, 305, 0, 28, "Exit", 2, exitFromTouch} // Button Exit //drawButton(210, 210, 95, 28, "Exit", 2); }; bool touchButtonPressed(int touchX, int touchY, int Xmin, int Xmax, int Ymin, int Ymax) { - return (touchX >= Xmin && touchX <= Xmax && touchY >= Ymin && touchY <= Ymax); + return (touchX >= (Xmin - 5) && touchX <= (Xmax + 5) && touchY >= (Ymin - 5) && touchY <= (Ymax + 5)); } void checkLiveButtons(uint16_t x, uint16_t y) { @@ -53,7 +59,7 @@ if (touchButtonPressed(x, y, touchButtons_0[i].Xmin, touchButtons_0[i].Xmax, touchButtons_0[i].Ymin, touchButtons_0[i].Ymax)) { if (touchButtons_0[i].action != nullptr && touchButtons_0[i].action != lastCalledAction) { // Call the action function associated with the button - Serial.println(touchButtons_0[i].label + " pressed"); + Serial.println(touchButtons_0[i].label + " pressed"); touchButtons_0[i].action(); // Call the function pointer lastCalledAction = touchButtons_0[i].action; // Update the last called action } else { @@ -72,12 +78,22 @@ //Serial.print(" X="); Serial.print(xValueTouched); Serial.print(" Y="); Serial.println(yValueTouched); checkLiveButtons(xValueTouched, yValueTouched); } - if (millis() - lastTouchTime > 1500) lastCalledAction = nullptr; // reset touchButton when staying in same menu (like Tx/Send) + if (millis() - lastTouchTime > 1000) lastCalledAction = nullptr; // reset touchButton when staying in same menu (like Tx/Send) } void setup() { - touch.init(); - } + if (touchModuleAddress != 0x00) { + if (touchModuleAddress == 0x14) { + touch = TouchLib(Wire, BOARD_I2C_SDA, BOARD_I2C_SCL, GT911_SLAVE_ADDRESS2); + touch.init(); + } else if (touchModuleAddress == 0x5d) { + touch = TouchLib(Wire, BOARD_I2C_SDA, BOARD_I2C_SCL, GT911_SLAVE_ADDRESS1); + touch.init(); + } else { + Serial.println("No Touch Module Address found"); + } + } + } } diff --git a/src/utils.cpp b/src/utils.cpp index a879883..111ea96 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,25 +1,33 @@ +#include +#include #include "APRSPacketLib.h" #include "configuration.h" +#include "board_pinout.h" #include "lora_utils.h" #include "display.h" #include "utils.h" -extern Beacon *currentBeacon; -extern Configuration Config; +extern Beacon *currentBeacon; +extern Configuration Config; +extern logging::Logger logger; -extern uint32_t lastTx; -extern uint32_t lastTxTime; +extern uint32_t lastTx; +extern uint32_t lastTxTime; -extern bool displayEcoMode; -extern uint32_t displayTime; -extern bool displayState; -extern int menuDisplay; -extern String versionDate; -extern bool flashlight; +extern bool displayEcoMode; +extern uint32_t displayTime; +extern bool displayState; +extern int menuDisplay; +extern String versionDate; +extern bool flashlight; -extern bool statusState; +extern bool statusState; + +uint32_t statusTime = millis(); +uint8_t wxModuleAddress = 0x00; +uint8_t keyboardAddress = 0x00; +uint8_t touchModuleAddress = 0x00; -uint32_t statusTime = millis(); namespace Utils { @@ -115,5 +123,55 @@ namespace Utils { digitalWrite(Config.notification.ledFlashlightPin, LOW); } } + + void i2cScannerForPeripherals() { + uint8_t err, addr; + if (Config.wxsensor.active) { + for(addr = 1; addr < 0x7F; addr++) { + #ifdef HELTEC_V3_GPS + Wire1.beginTransmission(addr); + err = Wire1.endTransmission(); + #else + Wire.beginTransmission(addr); + err = Wire.endTransmission(); + #endif + if (err == 0) { + //Serial.println(addr); this shows any connected board to I2C + if (addr == 0x76 || addr == 0x77) { + wxModuleAddress = addr; + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "Wx Module Connected to I2C"); + } + } + } + } + + for(addr = 1; addr < 0x7F; addr++) { + Wire.beginTransmission(addr); + err = Wire.endTransmission(); + if (err == 0) { + //Serial.println(addr); this shows any connected board to I2C + if (addr == 0x55) { // T-Deck internal keyboard (Keyboard Backlight On = ALT + B) + keyboardAddress = addr; + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "T-Deck Keyboard Connected to I2C"); + } else if (addr == 0x5F) { // CARDKB from m5stack.com (YEL - SDA / WTH SCL) + keyboardAddress = addr; + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "CARDKB Keyboard Connected to I2C"); + } + } + } + + #ifdef HAS_TOUCHSCREEN + for(addr = 1; addr < 0x7F; addr++) { + Wire.beginTransmission(addr); + err = Wire.endTransmission(); + if (err == 0) { + if (addr == 0x14 || addr == 0x5D ) { + touchModuleAddress = addr; + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "Touch Module Connected to I2C"); + } + } + } + #endif + } } \ No newline at end of file diff --git a/src/wx_utils.cpp b/src/wx_utils.cpp index 83fda51..587a090 100644 --- a/src/wx_utils.cpp +++ b/src/wx_utils.cpp @@ -14,11 +14,13 @@ extern Configuration Config; extern logging::Logger logger; extern TinyGPSPlus gps; +extern uint8_t wxModuleAddress; + float newHum, newTemp, newPress, newGas; uint32_t sensorLastReading = -60000; int wxModuleType = 0; -uint8_t wxModuleAddress = 0x00; + bool wxModuleFound = false; @@ -37,36 +39,15 @@ Adafruit_SHTC3 shtc3 = Adafruit_SHTC3(); namespace WX_Utils { - void getWxModuleAddres() { - uint8_t err, addr; - for(addr = 1; addr < 0x7F; addr++) { - #ifdef HELTEC_V3_GPS - Wire1.beginTransmission(addr); - err = Wire1.endTransmission(); - #else - Wire.beginTransmission(addr); - err = Wire.endTransmission(); - #endif - if (err == 0) { - //Serial.println(addr); this shows any connected board to I2C - if (addr == 0x76 || addr == 0x77) { - wxModuleAddress = addr; - return; - } - } - } - } - void setup() { if (Config.wxsensor.active) { #ifdef LIGHTTRACKER_PLUS_1_0 - if (! shtc3.begin()) { + if (!shtc3.begin()) { logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BME", " SHTC3 sensor found"); while (1) delay(1); } logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BME", " SHTC3 sensor found"); #else - getWxModuleAddres(); if (wxModuleAddress != 0x00) { #ifdef HELTEC_V3_GPS if (bme280.begin(wxModuleAddress, &Wire1)) {