sforkowany z mirror/meshtastic-firmware
support RAK14004 in Canned Messages
rodzic
1ec1ff0773
commit
e34ada3ff1
|
@ -2,6 +2,7 @@
|
|||
#include "Observer.h"
|
||||
|
||||
#define ANYKEY 0xFF
|
||||
#define MATRIXKEY 0xFE
|
||||
|
||||
typedef struct _InputEvent {
|
||||
const char* source;
|
||||
|
|
|
@ -3,12 +3,38 @@
|
|||
#include <Wire.h>
|
||||
|
||||
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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
if (cardkb_found != CARDKB_ADDR){
|
||||
|
@ -16,6 +42,29 @@ int32_t KbI2cBase::runOnce()
|
|||
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);
|
||||
|
||||
while (Wire.available()) {
|
||||
|
@ -61,5 +110,6 @@ int32_t KbI2cBase::runOnce()
|
|||
this->notifyObservers(&e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 500;
|
||||
}
|
||||
|
|
|
@ -171,7 +171,15 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
|
|||
this->lastTouchMillis = millis();
|
||||
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) {
|
||||
// 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) ||
|
||||
(this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE)) {
|
||||
return 30000; // TODO: should return MAX_VAL
|
||||
return INT32_MAX;
|
||||
}
|
||||
DEBUG_MSG("Check status\n");
|
||||
UIFrameEvent e = {false, true};
|
||||
|
@ -235,7 +243,7 @@ int32_t CannedMessageModule::runOnce()
|
|||
e.frameChanged = true;
|
||||
}
|
||||
} 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);
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE;
|
||||
} else {
|
||||
|
@ -316,7 +324,7 @@ int32_t CannedMessageModule::runOnce()
|
|||
return INACTIVATE_AFTER_MS;
|
||||
}
|
||||
|
||||
return 30000; // TODO: should return MAX_VAL
|
||||
return INT32_MAX;
|
||||
}
|
||||
|
||||
const char *CannedMessageModule::getCurrentMessage()
|
||||
|
|
|
@ -9,6 +9,7 @@ enum cannedMessageModuleRunState
|
|||
CANNED_MESSAGE_RUN_STATE_INACTIVE,
|
||||
CANNED_MESSAGE_RUN_STATE_ACTIVE,
|
||||
CANNED_MESSAGE_RUN_STATE_FREETEXT,
|
||||
CANNED_MESSAGE_RUN_STATE_MATRIX,
|
||||
CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE,
|
||||
CANNED_MESSAGE_RUN_STATE_ACTION_SELECT,
|
||||
CANNED_MESSAGE_RUN_STATE_ACTION_UP,
|
||||
|
|
Ładowanie…
Reference in New Issue