-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add PCF8574(A) port expander as passive 4x4 keyboard
- Loading branch information
Showing
12 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ class ScanI2C | |
TDECKKB, | ||
BBQ10KB, | ||
RAK14004, | ||
PCF8574A, | ||
PMU_AXP192_AXP2101, | ||
BME_680, | ||
BME_280, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "peMatrixBase.h" | ||
|
||
#include "configuration.h" | ||
#include "detect/ScanI2C.h" | ||
|
||
extern ScanI2C::DeviceAddress cardkb_found; | ||
extern uint8_t kb_model; | ||
|
||
I2CKeyPad keyPad(cardkb_found.address); | ||
|
||
PeMatrixBase::PeMatrixBase(const char *name) : concurrency::OSThread(name) | ||
{ | ||
this->_originName = name; | ||
} | ||
|
||
int32_t PeMatrixBase::runOnce() | ||
{ | ||
if (kb_model != 0x12) { | ||
// Input device is not detected. | ||
return disable(); | ||
} | ||
|
||
if (firstTime) { | ||
// This is the first time the OSThread library has called this function, so do port setup | ||
firstTime = 0; | ||
if (!keyPad.begin()) { | ||
LOG_ERROR("Failed to initialize I2C keypad\n"); | ||
return disable(); | ||
} | ||
keyPad.loadKeyMap(keymap); | ||
} else { | ||
if (keyPad.isPressed()) { | ||
key = keyPad.getChar(); | ||
// debounce | ||
if (key != prevkey) { | ||
if (key != 0) { | ||
LOG_DEBUG("Key 0x%x pressed\n", key); | ||
// reset shift now that we have a keypress | ||
InputEvent e; | ||
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; | ||
e.source = this->_originName; | ||
switch (key) { | ||
case 0x1b: // ESC | ||
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL; | ||
break; | ||
case 0x08: // Back | ||
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_BACK; | ||
e.kbchar = key; | ||
break; | ||
case 0xb5: // Up | ||
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP; | ||
break; | ||
case 0xb6: // Down | ||
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN; | ||
break; | ||
case 0xb4: // Left | ||
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT; | ||
e.kbchar = key; | ||
break; | ||
case 0xb7: // Right | ||
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT; | ||
e.kbchar = key; | ||
break; | ||
case 0x0d: // Enter | ||
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT; | ||
break; | ||
case 0x00: // nopress | ||
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; | ||
break; | ||
default: // all other keys | ||
e.inputEvent = ANYKEY; | ||
e.kbchar = key; | ||
break; | ||
} | ||
if (e.inputEvent != meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE) { | ||
this->notifyObservers(&e); | ||
} | ||
} | ||
prevkey = key; | ||
} | ||
} | ||
} | ||
return 50; // Keyscan every 50msec to avoid key bounce | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "InputBroker.h" | ||
#include "concurrency/OSThread.h" | ||
#include <I2CKeyPad.h> | ||
|
||
class PeMatrixBase : public Observable<const InputEvent *>, public concurrency::OSThread | ||
{ | ||
public: | ||
explicit PeMatrixBase(const char *name); | ||
|
||
protected: | ||
virtual int32_t runOnce() override; | ||
|
||
private: | ||
const char *_originName; | ||
bool firstTime = 1; | ||
// char keymap[19] = "123A456B789C*0#DNF"; // N = NoKey, F = Fail | ||
char keymap[19] = {0x1b, 0xb5, '3', 'A', 0xb4, 0x0d, 0xb7, 'B', '7', 0xb6, '9', 'C', 0x09, '0', 0x08, 'D', 'N', 'F'}; | ||
char key = 0; | ||
char prevkey = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "peMatrixImpl.h" | ||
#include "InputBroker.h" | ||
|
||
PeMatrixImpl *peMatrixImpl; | ||
|
||
PeMatrixImpl::PeMatrixImpl() : PeMatrixBase("matrixPE") {} | ||
|
||
void PeMatrixImpl::init() | ||
{ | ||
if (kb_model != 0x12) { | ||
disable(); | ||
return; | ||
} | ||
|
||
inputBroker->registerSource(this); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
#include "main.h" | ||
#include "peMatrixBase.h" | ||
|
||
/** | ||
* @brief The idea behind this class to have static methods for the event handlers. | ||
* Check attachInterrupt() at RotaryEncoderInteruptBase.cpp | ||
* Technically you can have as many rotary encoders hardver attached | ||
* to your device as you wish, but you always need to have separate event | ||
* handlers, thus you need to have a RotaryEncoderInterrupt implementation. | ||
*/ | ||
class PeMatrixImpl : public PeMatrixBase | ||
{ | ||
public: | ||
PeMatrixImpl(); | ||
void init(); | ||
}; | ||
|
||
extern PeMatrixImpl *peMatrixImpl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters