support RAK14004 in Canned Messages

raytac-diy
Thomas Göttgens 2022-10-06 16:00:33 +02:00
rodzic 1ec1ff0773
commit e34ada3ff1
4 zmienionych plików z 105 dodań i 45 usunięć

Wyświetl plik

@ -2,6 +2,7 @@
#include "Observer.h" #include "Observer.h"
#define ANYKEY 0xFF #define ANYKEY 0xFF
#define MATRIXKEY 0xFE
typedef struct _InputEvent { typedef struct _InputEvent {
const char* source; const char* source;

Wyświetl plik

@ -3,12 +3,38 @@
#include <Wire.h> #include <Wire.h>
extern uint8_t cardkb_found; extern uint8_t cardkb_found;
extern uint8_t kb_model;
KbI2cBase::KbI2cBase(const char *name) : concurrency::OSThread(name) KbI2cBase::KbI2cBase(const char *name) : concurrency::OSThread(name)
{ {
this->_originName = name; this->_originName = name;
} }
uint8_t read_from_14004(uint8_t reg, uint8_t *data, uint8_t length)
{
uint8_t readflag = 0;
Wire.beginTransmission(CARDKB_ADDR);
Wire.write(reg);
Wire.endTransmission(); // stop transmitting
delay(20);
Wire.requestFrom(CARDKB_ADDR, length);
int i = 0;
while ( Wire.available() ) // slave may send less than requested
{
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)
{
Wire.beginTransmission(CARDKB_ADDR);
Wire.write(reg);
Wire.write(data);
Wire.endTransmission(); // stop transmitting
}
int32_t KbI2cBase::runOnce() int32_t KbI2cBase::runOnce()
{ {
if (cardkb_found != CARDKB_ADDR){ if (cardkb_found != CARDKB_ADDR){
@ -16,6 +42,29 @@ int32_t KbI2cBase::runOnce()
return INT32_MAX; return INT32_MAX;
} }
if (kb_model == 0x02) {
// RAK14004
uint8_t rDataBuf[8] = {0};
uint8_t PrintDataBuf = 0;
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) {
PrintDataBuf = aCount * 0x04 + bCount + 1;
}
}
}
}
if (PrintDataBuf != 0) {
DEBUG_MSG("RAK14004 key 0x%x pressed\n", PrintDataBuf);
InputEvent e;
e.inputEvent = MATRIXKEY;
e.source = this->_originName;
e.kbchar = PrintDataBuf;
this->notifyObservers(&e);
}
} else {
// m5 cardkb
Wire.requestFrom(CARDKB_ADDR, 1); Wire.requestFrom(CARDKB_ADDR, 1);
while (Wire.available()) { while (Wire.available()) {
@ -61,5 +110,6 @@ int32_t KbI2cBase::runOnce()
this->notifyObservers(&e); this->notifyObservers(&e);
} }
} }
}
return 500; return 500;
} }

Wyświetl plik

@ -171,7 +171,15 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
this->lastTouchMillis = millis(); this->lastTouchMillis = millis();
validEvent = true; validEvent = true;
} }
if (event->inputEvent == static_cast<char>(MATRIXKEY)) {
DEBUG_MSG("Canned message event Matrix key pressed\n");
// this will send the text immediately on matrix press
this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_SELECT;
this->payload = event->kbchar;
this->currentMessageIndex = event->kbchar -1;
this->lastTouchMillis = millis();
validEvent = true;
}
if (validEvent) { if (validEvent) {
// Let runOnce to be called immediately. // Let runOnce to be called immediately.
@ -203,7 +211,7 @@ int32_t CannedMessageModule::runOnce()
{ {
if ((!moduleConfig.canned_message.enabled) || (this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED) || if ((!moduleConfig.canned_message.enabled) || (this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED) ||
(this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE)) { (this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE)) {
return 30000; // TODO: should return MAX_VAL return INT32_MAX;
} }
DEBUG_MSG("Check status\n"); DEBUG_MSG("Check status\n");
UIFrameEvent e = {false, true}; UIFrameEvent e = {false, true};
@ -235,7 +243,7 @@ int32_t CannedMessageModule::runOnce()
e.frameChanged = true; e.frameChanged = true;
} }
} else { } else {
if (strlen(this->messages[this->currentMessageIndex]) > 0) { if ((this->messagesCount > this->currentMessageIndex) && (strlen(this->messages[this->currentMessageIndex]) > 0)) {
sendText(NODENUM_BROADCAST, this->messages[this->currentMessageIndex], true); sendText(NODENUM_BROADCAST, this->messages[this->currentMessageIndex], true);
this->runState = CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE; this->runState = CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE;
} else { } else {
@ -316,7 +324,7 @@ int32_t CannedMessageModule::runOnce()
return INACTIVATE_AFTER_MS; return INACTIVATE_AFTER_MS;
} }
return 30000; // TODO: should return MAX_VAL return INT32_MAX;
} }
const char *CannedMessageModule::getCurrentMessage() const char *CannedMessageModule::getCurrentMessage()

Wyświetl plik

@ -9,6 +9,7 @@ enum cannedMessageModuleRunState
CANNED_MESSAGE_RUN_STATE_INACTIVE, CANNED_MESSAGE_RUN_STATE_INACTIVE,
CANNED_MESSAGE_RUN_STATE_ACTIVE, CANNED_MESSAGE_RUN_STATE_ACTIVE,
CANNED_MESSAGE_RUN_STATE_FREETEXT, CANNED_MESSAGE_RUN_STATE_FREETEXT,
CANNED_MESSAGE_RUN_STATE_MATRIX,
CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE, CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE,
CANNED_MESSAGE_RUN_STATE_ACTION_SELECT, CANNED_MESSAGE_RUN_STATE_ACTION_SELECT,
CANNED_MESSAGE_RUN_STATE_ACTION_UP, CANNED_MESSAGE_RUN_STATE_ACTION_UP,