change the main scan class so they scan only for wanted bits - UNTESTED

This commit is contained in:
Thomas Göttgens
2024-05-19 19:32:08 +02:00
parent 27bb3506d3
commit dbb254ba7a
7 changed files with 51 additions and 38 deletions

View File

@@ -1,6 +1,4 @@
#include "ScanI2C.h"
#include "main.h"
#include <Wire.h>
const ScanI2C::DeviceAddress ScanI2C::ADDRESS_NONE = ScanI2C::DeviceAddress();
const ScanI2C::FoundDevice ScanI2C::DEVICE_NONE = ScanI2C::FoundDevice(ScanI2C::DeviceType::NONE, ADDRESS_NONE);
@@ -8,6 +6,7 @@ const ScanI2C::FoundDevice ScanI2C::DEVICE_NONE = ScanI2C::FoundDevice(ScanI2C::
ScanI2C::ScanI2C() = default;
void ScanI2C::scanPort(ScanI2C::I2CPort port) {}
void ScanI2C::scanPort(ScanI2C::I2CPort port, int *address) {}
void ScanI2C::setSuppressScreen()
{
@@ -29,33 +28,7 @@ ScanI2C::FoundDevice ScanI2C::firstRTC() const
ScanI2C::DeviceType types[] = {RTC_RV3028, RTC_PCF8563};
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::DeviceType types[] = {CARDKB, TDECKKB, BBQ10KB, RAK14004};

View File

@@ -2,7 +2,6 @@
#include <stddef.h>
#include <stdint.h>
bool performScanForCardKB();
class ScanI2C
{
@@ -89,6 +88,7 @@ class ScanI2C
ScanI2C();
virtual void scanPort(ScanI2C::I2CPort);
virtual void scanPort(ScanI2C::I2CPort, int *);
/*
* A bit of a hack, this tells the scanner not to tell later systems there is a screen to avoid enabling it.

View File

@@ -135,7 +135,7 @@ uint16_t ScanI2CTwoWire::getRegisterValue(const ScanI2CTwoWire::RegisterLocation
type = T; \
break;
void ScanI2CTwoWire::scanPort(I2CPort port)
void ScanI2CTwoWire::scanPort(I2CPort port, int *address)
{
concurrency::LockGuard guard((concurrency::Lock *)&lock);
@@ -163,6 +163,10 @@ void ScanI2CTwoWire::scanPort(I2CPort port)
#endif
for (addr.address = 1; addr.address < 127; addr.address++) {
// Skip the address if it is not requested oon a partial scan
if (sizeof(address) > 0 && addr.address != *address) {
continue;
}
i2cBus->beginTransmission(addr.address);
#ifdef ARCH_PORTDUINO
if (i2cBus->read() != -1)
@@ -367,6 +371,11 @@ void ScanI2CTwoWire::scanPort(I2CPort port)
}
}
void ScanI2CTwoWire::scanPort(I2CPort port)
{
scanPort(port, nullptr);
}
TwoWire *ScanI2CTwoWire::fetchI2CBus(ScanI2C::DeviceAddress address) const
{
if (address.port == ScanI2C::I2CPort::WIRE) {

View File

@@ -16,6 +16,8 @@ class ScanI2CTwoWire : public ScanI2C
public:
void scanPort(ScanI2C::I2CPort) override;
void scanPort(ScanI2C::I2CPort, int *) override;
ScanI2C::FoundDevice find(ScanI2C::DeviceType) const override;
TwoWire *fetchI2CBus(ScanI2C::DeviceAddress) const;
@@ -53,4 +55,4 @@ class ScanI2CTwoWire : public ScanI2C
uint16_t getRegisterValue(const RegisterLocation &, ResponseWidth) const;
DeviceType probeOLED(ScanI2C::DeviceAddress) const;
};
};