mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-21 02:02:23 +00:00
Revert "remember which devices were scanned on which bus and set them accordingly." - this is not working at all.
This commit is contained in:
@@ -1,60 +1,52 @@
|
||||
#include "kbI2cBase.h"
|
||||
#include "configuration.h"
|
||||
#include "main.h"
|
||||
#include <Wire.h>
|
||||
|
||||
#if HAS_WIRE
|
||||
extern uint8_t cardkb_found;
|
||||
extern uint8_t kb_model;
|
||||
|
||||
KbI2cBase::KbI2cBase(const char *name) : concurrency::OSThread(name)
|
||||
{
|
||||
this->_originName = name;
|
||||
}
|
||||
|
||||
uint8_t read_from_14004(uint8_t reg, uint8_t *data, uint8_t length, TwoWire myWire)
|
||||
uint8_t read_from_14004(uint8_t reg, uint8_t *data, uint8_t length)
|
||||
{
|
||||
uint8_t readflag = 0;
|
||||
myWire.beginTransmission(CARDKB_ADDR);
|
||||
myWire.write(reg);
|
||||
myWire.endTransmission(); // stop transmitting
|
||||
Wire.beginTransmission(CARDKB_ADDR);
|
||||
Wire.write(reg);
|
||||
Wire.endTransmission(); // stop transmitting
|
||||
delay(20);
|
||||
myWire.requestFrom(CARDKB_ADDR, (int)length);
|
||||
Wire.requestFrom(CARDKB_ADDR, (int)length);
|
||||
int i = 0;
|
||||
while ( myWire.available() ) // slave may send less than requested
|
||||
while ( Wire.available() ) // slave may send less than requested
|
||||
{
|
||||
data[i++] = myWire.read(); // receive a byte as a proper uint8_t
|
||||
data[i++] = Wire.read(); // receive a byte as a proper uint8_t
|
||||
readflag = 1;
|
||||
}
|
||||
return readflag;
|
||||
}
|
||||
|
||||
void write_to_14004(uint8_t reg, uint8_t data, TwoWire myWire)
|
||||
void write_to_14004(uint8_t reg, uint8_t data)
|
||||
{
|
||||
myWire.beginTransmission(CARDKB_ADDR);
|
||||
myWire.write(reg);
|
||||
myWire.write(data);
|
||||
myWire.endTransmission(); // stop transmitting
|
||||
Wire.beginTransmission(CARDKB_ADDR);
|
||||
Wire.write(reg);
|
||||
Wire.write(data);
|
||||
Wire.endTransmission(); // stop transmitting
|
||||
}
|
||||
|
||||
int32_t KbI2cBase::runOnce()
|
||||
{
|
||||
if (i2cScanMap[CARDKB_ADDR].addr != CARDKB_ADDR) {
|
||||
if (cardkb_found != CARDKB_ADDR){
|
||||
// Input device is not detected.
|
||||
return INT32_MAX;
|
||||
}
|
||||
|
||||
TwoWire myWire = Wire;
|
||||
|
||||
if (i2cScanMap[CARDKB_ADDR].bus == 1) {
|
||||
#ifdef I2C_SDA1
|
||||
myWire = Wire1;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (kb_model == 0x02) {
|
||||
// RAK14004
|
||||
uint8_t rDataBuf[8] = {0};
|
||||
uint8_t PrintDataBuf = 0;
|
||||
if (read_from_14004(0x01, rDataBuf, 0x04, myWire) == 1) {
|
||||
if (read_from_14004(0x01, rDataBuf, 0x04) == 1) {
|
||||
for (uint8_t aCount = 0; aCount < 0x04; aCount++) {
|
||||
for (uint8_t bCount = 0; bCount < 0x04; bCount++ ) {
|
||||
if (((rDataBuf[aCount] >> bCount) & 0x01) == 0x01) {
|
||||
@@ -73,10 +65,10 @@ int32_t KbI2cBase::runOnce()
|
||||
}
|
||||
} else {
|
||||
// m5 cardkb
|
||||
myWire.requestFrom(CARDKB_ADDR, 1);
|
||||
Wire.requestFrom(CARDKB_ADDR, 1);
|
||||
|
||||
while (myWire.available()) {
|
||||
char c = myWire.read();
|
||||
while (Wire.available()) {
|
||||
char c = Wire.read();
|
||||
InputEvent e;
|
||||
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_NONE;
|
||||
e.source = this->_originName;
|
||||
@@ -121,5 +113,3 @@ int32_t KbI2cBase::runOnce()
|
||||
}
|
||||
return 500;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user