Trunk fmt

This commit is contained in:
Ben Meadors 2024-07-31 07:42:23 -05:00
parent 106a50bce2
commit 24ecfa1a45
4 changed files with 53 additions and 70 deletions

View File

@ -6,29 +6,28 @@
#if INPUTBROKER_SERIAL_TYPE == 1 // It's a Chatter
// 3 SHIFT level (lower case, upper case, numbers), up to 4 repeated presses, button number
unsigned char KeyMap[3][4][10]= {{{'.','a','d','g','j','m','p','t','w',' '},
{',','b','e','h','k','n','q','u','x',' '},
{'?','c','f','i','l','o','r','v','y',' '},
{'1','2','3','4','5','6','s','8','z',' '}}, // low case
{{'!','A','D','G','J','M','P','T','W',' '},
{'+','B','E','H','K','N','Q','U','X',' '},
{'-','C','F','I','L','O','R','V','Y',' '},
{'1','2','3','4','5','6','S','8','Z',' '}}, // upper case
{{'1','2','3','4','5','6','7','8','9','0'},
{'1','2','3','4','5','6','7','8','9','0'},
{'1','2','3','4','5','6','7','8','9','0'},
{'1','2','3','4','5','6','7','8','9','0'}}}; // numbers
unsigned char KeyMap[3][4][10] = {{{'.', 'a', 'd', 'g', 'j', 'm', 'p', 't', 'w', ' '},
{',', 'b', 'e', 'h', 'k', 'n', 'q', 'u', 'x', ' '},
{'?', 'c', 'f', 'i', 'l', 'o', 'r', 'v', 'y', ' '},
{'1', '2', '3', '4', '5', '6', 's', '8', 'z', ' '}}, // low case
{{'!', 'A', 'D', 'G', 'J', 'M', 'P', 'T', 'W', ' '},
{'+', 'B', 'E', 'H', 'K', 'N', 'Q', 'U', 'X', ' '},
{'-', 'C', 'F', 'I', 'L', 'O', 'R', 'V', 'Y', ' '},
{'1', '2', '3', '4', '5', '6', 'S', '8', 'Z', ' '}}, // upper case
{{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'},
{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'},
{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'},
{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}}}; // numbers
#endif
SerialKeyboard::SerialKeyboard(const char *name) : concurrency::OSThread(name)
{
this->_originName = name;
}
void SerialKeyboard::erase(){
void SerialKeyboard::erase()
{
InputEvent e;
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_BACK;
e.kbchar = 0x08;
@ -36,7 +35,6 @@ void SerialKeyboard::erase(){
this->notifyObservers(&e);
}
int32_t SerialKeyboard::runOnce()
{
if (!INPUTBROKER_SERIAL_TYPE) {
@ -56,82 +54,71 @@ int32_t SerialKeyboard::runOnce()
LOG_DEBUG("Serial Keyboard setup\n");
}
if (INPUTBROKER_SERIAL_TYPE == 1) { //Chatter V1.0 & V2.0 keypads
if (INPUTBROKER_SERIAL_TYPE == 1) { // Chatter V1.0 & V2.0 keypads
// scan for keypresses
// Write pulse to load pin
digitalWrite(KB_LOAD, LOW);
delayMicroseconds(5);
digitalWrite(KB_LOAD, HIGH);
delayMicroseconds(5);
// Get data from 74HC165
byte shiftRegister1 = shiftIn(KB_DATA, KB_CLK, LSBFIRST);
byte shiftRegister2 = shiftIn(KB_DATA, KB_CLK, LSBFIRST);
keys = (shiftRegister1 << 8) + shiftRegister2;
// Print to serial monitor
//Serial.print (shiftRegister1, BIN);
//Serial.print ("X");
//Serial.println (shiftRegister2, BIN);
// Serial.print (shiftRegister1, BIN);
// Serial.print ("X");
// Serial.println (shiftRegister2, BIN);
if (millis()-lastPressTime > 500){
if (millis() - lastPressTime > 500) {
quickPress = 0;
}
if (keys < prevKeys) { // a new key has been pressed (and not released), doesn't works for multiple presses at once but shouldn't be a limitation
if (keys < prevKeys) { // a new key has been pressed (and not released), doesn't works for multiple presses at once but
// shouldn't be a limitation
InputEvent e;
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE;
e.source = this->_originName;
// SELECT OR SEND OR CANCEL EVENT
if (!(shiftRegister2 & (1 << 3))) {
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP;
}
else if (!(shiftRegister2 & (1 << 2))) {
} else if (!(shiftRegister2 & (1 << 2))) {
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT;
e.kbchar = 0xb7;
}
else if (!(shiftRegister2 & (1 << 1))) {
} else if (!(shiftRegister2 & (1 << 1))) {
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT;
}
else if (!(shiftRegister2 & (1 << 0))) {
} else if (!(shiftRegister2 & (1 << 0))) {
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL;
}
// TEXT INPUT EVENT
else if (!(shiftRegister1 & (1 << 4))) {
keyPressed = 0;
}
else if (!(shiftRegister1 & (1 << 3))) {
} else if (!(shiftRegister1 & (1 << 3))) {
keyPressed = 1;
}
else if (!(shiftRegister2 & (1 << 4))) {
} else if (!(shiftRegister2 & (1 << 4))) {
keyPressed = 2;
}
else if (!(shiftRegister1 & (1 << 5))) {
} else if (!(shiftRegister1 & (1 << 5))) {
keyPressed = 3;
}
else if (!(shiftRegister1 & (1 << 2))) {
} else if (!(shiftRegister1 & (1 << 2))) {
keyPressed = 4;
}
else if (!(shiftRegister2 & (1 << 5))) {
} else if (!(shiftRegister2 & (1 << 5))) {
keyPressed = 5;
}
else if (!(shiftRegister1 & (1 << 6))) {
} else if (!(shiftRegister1 & (1 << 6))) {
keyPressed = 6;
}
else if (!(shiftRegister1 & (1 << 1))) {
} else if (!(shiftRegister1 & (1 << 1))) {
keyPressed = 7;
}
else if (!(shiftRegister2 & (1 << 6))) {
} else if (!(shiftRegister2 & (1 << 6))) {
keyPressed = 8;
}
else if (!(shiftRegister1 & (1 << 0))) {
} else if (!(shiftRegister1 & (1 << 0))) {
keyPressed = 9;
}
// BACKSPACE or TAB
else if (!(shiftRegister1 & (1 << 7))) {
if (shift == 0 || shift ==2){ // BACKSPACE
if (shift == 0 || shift == 2) { // BACKSPACE
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_BACK;
e.kbchar = 0x08;
} else { // shift = 1 => TAB
@ -144,27 +131,25 @@ int32_t SerialKeyboard::runOnce()
keyPressed = 10;
}
if (keyPressed < 11){
if (keyPressed == lastKeyPressed && millis()-lastPressTime < 500){
if (keyPressed < 11) {
if (keyPressed == lastKeyPressed && millis() - lastPressTime < 500) {
quickPress += 1;
if (quickPress > 3){
if (quickPress > 3) {
quickPress = 0;
}
}
if (keyPressed != lastKeyPressed){
if (keyPressed != lastKeyPressed) {
quickPress = 0;
}
if (keyPressed < 10){ // if it's a letter
if (keyPressed == lastKeyPressed && millis()-lastPressTime < 500){
if (keyPressed < 10) { // if it's a letter
if (keyPressed == lastKeyPressed && millis() - lastPressTime < 500) {
erase();
}
}
e.inputEvent = ANYKEY;
e.kbchar = char(KeyMap[shift][quickPress][keyPressed]);
}
else { //then it's shift
} else { // then it's shift
shift += 1;
if (shift > 2){
if (shift > 2) {
shift = 0;
}
}
@ -178,10 +163,8 @@ int32_t SerialKeyboard::runOnce()
}
}
prevKeys = keys;
}
return 50;
}
#endif // INPUTBROKER_SERIAL_TYPE

View File

@ -1,6 +1,6 @@
#include "configuration.h"
#include "InputBroker.h"
#include "SerialKeyboardImpl.h"
#include "InputBroker.h"
#include "configuration.h"
#ifdef INPUTBROKER_SERIAL_TYPE

View File

@ -2,11 +2,11 @@
#if !MESHTASTIC_EXCLUDE_INPUTBROKER
#include "input/InputBroker.h"
#include "input/RotaryEncoderInterruptImpl1.h"
#include "input/SerialKeyboardImpl.h"
#include "input/TrackballInterruptImpl1.h"
#include "input/UpDownInterruptImpl1.h"
#include "input/cardKbI2cImpl.h"
#include "input/kbMatrixImpl.h"
#include "input/SerialKeyboardImpl.h"
#endif
#if !MESHTASTIC_EXCLUDE_ADMIN
#include "modules/AdminModule.h"

View File

@ -34,7 +34,7 @@
// Buzzer
#define PIN_BUZZER 19
// Buttons
//#define BUTTON_PIN 36 // Use the WAKE button as the user button
// #define BUTTON_PIN 36 // Use the WAKE button as the user button
// I2C
// #define I2C_SCL 27
// #define I2C_SDA 26
@ -93,9 +93,9 @@
// keyboard
#define INPUTBROKER_SERIAL_TYPE 1
#define KB_LOAD 21 // load values from the switch and store in shift register
#define KB_CLK 22 // clock pin for serial data out
#define KB_DATA 23 // data pin
#define KB_LOAD 21 // load values from the switch and store in shift register
#define KB_CLK 22 // clock pin for serial data out
#define KB_DATA 23 // data pin
#define CANNED_MESSAGE_MODULE_ENABLE 1
/////////////////////////////////////////////////////////////////////////////////