Added fix for ESP32

pull/3933/head
HarukiToreda 2024-05-18 22:14:22 -04:00 zatwierdzone przez Thomas Göttgens
rodzic a38a18da0d
commit 27bb3506d3
4 zmienionych plików z 34 dodań i 1 usunięć

Wyświetl plik

@ -1,4 +1,6 @@
#include "ScanI2C.h" #include "ScanI2C.h"
#include "main.h"
#include <Wire.h>
const ScanI2C::DeviceAddress ScanI2C::ADDRESS_NONE = ScanI2C::DeviceAddress(); const ScanI2C::DeviceAddress ScanI2C::ADDRESS_NONE = ScanI2C::DeviceAddress();
const ScanI2C::FoundDevice ScanI2C::DEVICE_NONE = ScanI2C::FoundDevice(ScanI2C::DeviceType::NONE, ADDRESS_NONE); const ScanI2C::FoundDevice ScanI2C::DEVICE_NONE = ScanI2C::FoundDevice(ScanI2C::DeviceType::NONE, ADDRESS_NONE);
@ -27,7 +29,33 @@ ScanI2C::FoundDevice ScanI2C::firstRTC() const
ScanI2C::DeviceType types[] = {RTC_RV3028, RTC_PCF8563}; ScanI2C::DeviceType types[] = {RTC_RV3028, RTC_PCF8563};
return firstOfOrNONE(2, types); return firstOfOrNONE(2, types);
} }
bool performScanForCardKB() {
// Example I2C scan code for CardKB (adjust as needed)
Wire.beginTransmission(CARDKB_I2C_ADDRESS);
if (Wire.endTransmission() == 0) {
return true; // CardKB detected
}
return false; // CardKB not detected
}
void scanForCardKB() {
const int maxRetries = 10; // Maximum number of retries
const int retryDelay = 100; // Delay between retries in milliseconds
for (int i = 0; i < maxRetries; ++i) {
// Perform the scan (example scan code, adjust as needed)
cardKBDetected = performScanForCardKB();
if (cardKBDetected) {
Serial.println("CardKB Keyboard detected.");
break;
}
delay(retryDelay); // Wait before the next retry
}
if (!cardKBDetected) {
Serial.println("CardKB Keyboard not detected. Canned Message Module Disabled.");
}
}
ScanI2C::FoundDevice ScanI2C::firstKeyboard() const ScanI2C::FoundDevice ScanI2C::firstKeyboard() const
{ {
ScanI2C::DeviceType types[] = {CARDKB, TDECKKB, BBQ10KB, RAK14004}; ScanI2C::DeviceType types[] = {CARDKB, TDECKKB, BBQ10KB, RAK14004};

Wyświetl plik

@ -2,6 +2,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
bool performScanForCardKB();
class ScanI2C class ScanI2C
{ {

Wyświetl plik

@ -35,6 +35,8 @@
#include <utility> #include <utility>
// #include <driver/rtc_io.h> // #include <driver/rtc_io.h>
bool cardKBDetected = false;
void scanForCardKB();
#ifdef ARCH_ESP32 #ifdef ARCH_ESP32
#if !MESHTASTIC_EXCLUDE_WEBSERVER #if !MESHTASTIC_EXCLUDE_WEBSERVER
#include "mesh/http/WebServer.h" #include "mesh/http/WebServer.h"
@ -376,6 +378,7 @@ void setup()
// otherwise keyboard and touch screen will not work // otherwise keyboard and touch screen will not work
delay(800); delay(800);
#endif #endif
scanForCardKB(); // Initial scan for CardKB
// Currently only the tbeam has a PMU // Currently only the tbeam has a PMU
// PMU initialization needs to be placed before i2c scanning // PMU initialization needs to be placed before i2c scanning

Wyświetl plik

@ -21,7 +21,7 @@ extern NimbleBluetooth *nimbleBluetooth;
#include "NRF52Bluetooth.h" #include "NRF52Bluetooth.h"
extern NRF52Bluetooth *nrf52Bluetooth; extern NRF52Bluetooth *nrf52Bluetooth;
#endif #endif
extern bool cardKBDetected;
#if ARCH_PORTDUINO #if ARCH_PORTDUINO
extern HardwareSPI *DisplaySPI; extern HardwareSPI *DisplaySPI;
extern HardwareSPI *LoraSPI; extern HardwareSPI *LoraSPI;
@ -39,6 +39,7 @@ extern bool pmu_found;
extern bool isCharging; extern bool isCharging;
extern bool isUSBPowered; extern bool isUSBPowered;
#define CARDKB_I2C_ADDRESS 0x5F // Replace 0x5F with the actual address if different
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
extern ATECCX08A atecc; extern ATECCX08A atecc;
#endif #endif