I thought git would be smart enough to understand all the whitespace changes but even with all the flags I know to make it ignore theses it still blows up if there are identical changes on both sides.
I have a solution but it require creating a new commit at the merge base for each conflicting PR and merging it into develop.
I don't think blowing up all PRs is worth for now, maybe if we can coordinate this for V3 let's say.
This reverts commit 0d11331d18.
This commit is contained in:
+308
-281
@@ -87,320 +87,347 @@ unsigned char MPR121_LongPressMap[12] = {MPR121_ESC, ' ', MPR121_NONE,
|
||||
// Rotated Layout
|
||||
uint8_t MPR121_KeyMap[12] = {2, 5, 8, 11, 1, 4, 7, 10, 0, 3, 6, 9};
|
||||
|
||||
MPR121Keyboard::MPR121Keyboard() : m_wire(nullptr), m_addr(0), readCallback(nullptr), writeCallback(nullptr) {
|
||||
// LOG_DEBUG("MPR121 @ %02x", m_addr);
|
||||
state = Init;
|
||||
last_key = -1;
|
||||
last_tap = 0L;
|
||||
char_idx = 0;
|
||||
queue = "";
|
||||
MPR121Keyboard::MPR121Keyboard() : m_wire(nullptr), m_addr(0), readCallback(nullptr), writeCallback(nullptr)
|
||||
{
|
||||
// LOG_DEBUG("MPR121 @ %02x", m_addr);
|
||||
state = Init;
|
||||
last_key = -1;
|
||||
last_tap = 0L;
|
||||
char_idx = 0;
|
||||
queue = "";
|
||||
}
|
||||
|
||||
void MPR121Keyboard::begin(uint8_t addr, TwoWire *wire) {
|
||||
m_addr = addr;
|
||||
m_wire = wire;
|
||||
void MPR121Keyboard::begin(uint8_t addr, TwoWire *wire)
|
||||
{
|
||||
m_addr = addr;
|
||||
m_wire = wire;
|
||||
|
||||
m_wire->begin();
|
||||
m_wire->begin();
|
||||
|
||||
reset();
|
||||
reset();
|
||||
}
|
||||
|
||||
void MPR121Keyboard::begin(i2c_com_fptr_t r, i2c_com_fptr_t w, uint8_t addr) {
|
||||
m_addr = addr;
|
||||
m_wire = nullptr;
|
||||
writeCallback = w;
|
||||
readCallback = r;
|
||||
reset();
|
||||
void MPR121Keyboard::begin(i2c_com_fptr_t r, i2c_com_fptr_t w, uint8_t addr)
|
||||
{
|
||||
m_addr = addr;
|
||||
m_wire = nullptr;
|
||||
writeCallback = w;
|
||||
readCallback = r;
|
||||
reset();
|
||||
}
|
||||
|
||||
void MPR121Keyboard::reset() {
|
||||
LOG_DEBUG("MPR121 Reset");
|
||||
// Trigger a MPR121 Soft Reset
|
||||
if (m_wire) {
|
||||
m_wire->beginTransmission(m_addr);
|
||||
m_wire->write(_MPR121_REG_SOFT_RESET);
|
||||
m_wire->endTransmission();
|
||||
}
|
||||
if (writeCallback) {
|
||||
uint8_t data = 0;
|
||||
writeCallback(m_addr, _MPR121_REG_SOFT_RESET, &data, 0);
|
||||
}
|
||||
delay(100);
|
||||
// Reset Electrode Configuration to 0x00, Stop Mode
|
||||
writeRegister(_MPR121_REG_ELECTRODE_CONFIG, 0x00);
|
||||
delay(100);
|
||||
|
||||
LOG_DEBUG("MPR121 Configuring");
|
||||
// Set touch release thresholds
|
||||
for (uint8_t i = 0; i < 12; i++) {
|
||||
// Set touch threshold
|
||||
writeRegister(_MPR121_REG_TOUCH_THRESHOLD + (i * 2), 10);
|
||||
delay(20);
|
||||
// Set release threshold
|
||||
writeRegister(_MPR121_REG_RELEASE_THRESHOLD + (i * 2), 5);
|
||||
delay(20);
|
||||
}
|
||||
// Configure filtering and baseline registers
|
||||
writeRegister(_MPR121_REG_MAX_HALF_DELTA_RISING, 0x05);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_MAX_HALF_DELTA_FALLING, 0x01);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_NOISE_HALF_DELTA_RISING, 0x01);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_NOISE_HALF_DELTA_FALLING, 0x05);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_NOISE_HALF_DELTA_TOUCHED, 0x00);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_NOISE_COUNT_LIMIT_RISING, 0x05);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_NOISE_COUNT_LIMIT_FALLING, 0x01);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_NOISE_COUNT_LIMIT_TOUCHED, 0x00);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_FILTER_DELAY_COUNT_RISING, 0x00);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_FILTER_DELAY_COUNT_FALLING, 0x00);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_FILTER_DELAY_COUNT_TOUCHED, 0x00);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_AUTOCONF_CTRL0, 0x04); // Auto-config enable
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_AUTOCONF_CTRL1, 0x00); // Ensure no auto-config interrupt
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_DEBOUNCE, 0x02);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_CONFIG1, 0x20);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_CONFIG2, 0x21);
|
||||
delay(20);
|
||||
// Enter run mode by Seting partial filter calibration tracking, disable proximity detection, enable 12 channels
|
||||
writeRegister(_MPR121_REG_ELECTRODE_CONFIG, ECR_CALIBRATION_TRACK_FROM_FULL_FILTER | ECR_PROXIMITY_DETECTION_OFF | ECR_TOUCH_DETECTION_12CH);
|
||||
delay(100);
|
||||
LOG_DEBUG("MPR121 Run");
|
||||
state = Idle;
|
||||
}
|
||||
|
||||
void MPR121Keyboard::attachInterrupt(uint8_t pin, void (*func)(void)) const {
|
||||
pinMode(pin, INPUT_PULLUP);
|
||||
::attachInterrupt(digitalPinToInterrupt(pin), func, RISING);
|
||||
}
|
||||
|
||||
void MPR121Keyboard::detachInterrupt(uint8_t pin) const { ::detachInterrupt(pin); }
|
||||
|
||||
uint8_t MPR121Keyboard::status() const { return readRegister16(_MPR121_REG_KEY); }
|
||||
|
||||
uint8_t MPR121Keyboard::keyCount() const {
|
||||
// Read the key register
|
||||
uint16_t keyRegister = readRegister16(_MPR121_REG_KEY);
|
||||
return keyCount(keyRegister);
|
||||
}
|
||||
|
||||
uint8_t MPR121Keyboard::keyCount(uint16_t value) const {
|
||||
// Mask the first 12 bits
|
||||
uint16_t buttonState = value & _KEY_MASK;
|
||||
|
||||
// Count how many bits are set to 1 (i.e., how many buttons are pressed)
|
||||
uint8_t numButtonsPressed = 0;
|
||||
for (uint8_t i = 0; i < 12; ++i) {
|
||||
if (buttonState & (1 << i)) {
|
||||
numButtonsPressed++;
|
||||
void MPR121Keyboard::reset()
|
||||
{
|
||||
LOG_DEBUG("MPR121 Reset");
|
||||
// Trigger a MPR121 Soft Reset
|
||||
if (m_wire) {
|
||||
m_wire->beginTransmission(m_addr);
|
||||
m_wire->write(_MPR121_REG_SOFT_RESET);
|
||||
m_wire->endTransmission();
|
||||
}
|
||||
}
|
||||
if (writeCallback) {
|
||||
uint8_t data = 0;
|
||||
writeCallback(m_addr, _MPR121_REG_SOFT_RESET, &data, 0);
|
||||
}
|
||||
delay(100);
|
||||
// Reset Electrode Configuration to 0x00, Stop Mode
|
||||
writeRegister(_MPR121_REG_ELECTRODE_CONFIG, 0x00);
|
||||
delay(100);
|
||||
|
||||
return numButtonsPressed;
|
||||
LOG_DEBUG("MPR121 Configuring");
|
||||
// Set touch release thresholds
|
||||
for (uint8_t i = 0; i < 12; i++) {
|
||||
// Set touch threshold
|
||||
writeRegister(_MPR121_REG_TOUCH_THRESHOLD + (i * 2), 10);
|
||||
delay(20);
|
||||
// Set release threshold
|
||||
writeRegister(_MPR121_REG_RELEASE_THRESHOLD + (i * 2), 5);
|
||||
delay(20);
|
||||
}
|
||||
// Configure filtering and baseline registers
|
||||
writeRegister(_MPR121_REG_MAX_HALF_DELTA_RISING, 0x05);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_MAX_HALF_DELTA_FALLING, 0x01);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_NOISE_HALF_DELTA_RISING, 0x01);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_NOISE_HALF_DELTA_FALLING, 0x05);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_NOISE_HALF_DELTA_TOUCHED, 0x00);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_NOISE_COUNT_LIMIT_RISING, 0x05);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_NOISE_COUNT_LIMIT_FALLING, 0x01);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_NOISE_COUNT_LIMIT_TOUCHED, 0x00);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_FILTER_DELAY_COUNT_RISING, 0x00);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_FILTER_DELAY_COUNT_FALLING, 0x00);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_FILTER_DELAY_COUNT_TOUCHED, 0x00);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_AUTOCONF_CTRL0, 0x04); // Auto-config enable
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_AUTOCONF_CTRL1, 0x00); // Ensure no auto-config interrupt
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_DEBOUNCE, 0x02);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_CONFIG1, 0x20);
|
||||
delay(20);
|
||||
writeRegister(_MPR121_REG_CONFIG2, 0x21);
|
||||
delay(20);
|
||||
// Enter run mode by Seting partial filter calibration tracking, disable proximity detection, enable 12 channels
|
||||
writeRegister(_MPR121_REG_ELECTRODE_CONFIG,
|
||||
ECR_CALIBRATION_TRACK_FROM_FULL_FILTER | ECR_PROXIMITY_DETECTION_OFF | ECR_TOUCH_DETECTION_12CH);
|
||||
delay(100);
|
||||
LOG_DEBUG("MPR121 Run");
|
||||
state = Idle;
|
||||
}
|
||||
|
||||
bool MPR121Keyboard::hasEvent() { return queue.length() > 0; }
|
||||
|
||||
void MPR121Keyboard::queueEvent(char next) {
|
||||
if (next == MPR121_NONE) {
|
||||
return;
|
||||
}
|
||||
queue.concat(next);
|
||||
void MPR121Keyboard::attachInterrupt(uint8_t pin, void (*func)(void)) const
|
||||
{
|
||||
pinMode(pin, INPUT_PULLUP);
|
||||
::attachInterrupt(digitalPinToInterrupt(pin), func, RISING);
|
||||
}
|
||||
|
||||
char MPR121Keyboard::dequeueEvent() {
|
||||
if (queue.length() < 1) {
|
||||
return MPR121_NONE;
|
||||
}
|
||||
char next = queue.charAt(0);
|
||||
queue.remove(0, 1);
|
||||
return next;
|
||||
void MPR121Keyboard::detachInterrupt(uint8_t pin) const
|
||||
{
|
||||
::detachInterrupt(pin);
|
||||
}
|
||||
|
||||
void MPR121Keyboard::trigger() {
|
||||
// Intended to fire in response to an interrupt from the MPR121 or a longpress callback
|
||||
// Only functional if not in Init state
|
||||
if (state != Init) {
|
||||
uint8_t MPR121Keyboard::status() const
|
||||
{
|
||||
return readRegister16(_MPR121_REG_KEY);
|
||||
}
|
||||
|
||||
uint8_t MPR121Keyboard::keyCount() const
|
||||
{
|
||||
// Read the key register
|
||||
uint16_t keyRegister = readRegister16(_MPR121_REG_KEY);
|
||||
uint8_t keysPressed = keyCount(keyRegister);
|
||||
if (keysPressed == 0) {
|
||||
// No buttons pressed
|
||||
if (state == Held)
|
||||
released();
|
||||
state = Idle;
|
||||
return;
|
||||
}
|
||||
if (keysPressed == 1) {
|
||||
// No buttons pressed
|
||||
if (state == Held || state == HeldLong)
|
||||
held(keyRegister);
|
||||
if (state == Idle)
|
||||
pressed(keyRegister);
|
||||
return;
|
||||
}
|
||||
if (keysPressed > 1) {
|
||||
// Multipress
|
||||
state = Busy;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
return keyCount(keyRegister);
|
||||
}
|
||||
|
||||
void MPR121Keyboard::pressed(uint16_t keyRegister) {
|
||||
if (state == Init || state == Busy) {
|
||||
return;
|
||||
}
|
||||
if (keyCount(keyRegister) != 1) {
|
||||
LOG_DEBUG("Multipress");
|
||||
return;
|
||||
} else {
|
||||
LOG_DEBUG("Pressed");
|
||||
}
|
||||
uint16_t buttonState = keyRegister & _KEY_MASK;
|
||||
uint8_t next_pin = 0;
|
||||
for (uint8_t i = 0; i < 12; ++i) {
|
||||
if (buttonState & (1 << i)) {
|
||||
next_pin = i;
|
||||
uint8_t MPR121Keyboard::keyCount(uint16_t value) const
|
||||
{
|
||||
// Mask the first 12 bits
|
||||
uint16_t buttonState = value & _KEY_MASK;
|
||||
|
||||
// Count how many bits are set to 1 (i.e., how many buttons are pressed)
|
||||
uint8_t numButtonsPressed = 0;
|
||||
for (uint8_t i = 0; i < 12; ++i) {
|
||||
if (buttonState & (1 << i)) {
|
||||
numButtonsPressed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
uint8_t next_key = MPR121_KeyMap[next_pin];
|
||||
LOG_DEBUG("MPR121 Pin: %i Key: %i", next_pin, next_key);
|
||||
uint32_t now = millis();
|
||||
int32_t tap_interval = now - last_tap;
|
||||
if (tap_interval < 0) {
|
||||
// long running, millis has overflowed.
|
||||
last_tap = 0;
|
||||
state = Busy;
|
||||
return;
|
||||
}
|
||||
if (next_key != last_key || tap_interval > MULTI_TAP_THRESHOLD) {
|
||||
char_idx = 0;
|
||||
} else {
|
||||
char_idx += 1;
|
||||
}
|
||||
last_key = next_key;
|
||||
last_tap = now;
|
||||
state = Held;
|
||||
return;
|
||||
|
||||
return numButtonsPressed;
|
||||
}
|
||||
|
||||
void MPR121Keyboard::held(uint16_t keyRegister) {
|
||||
if (state == Init || state == Busy) {
|
||||
return;
|
||||
}
|
||||
if (keyCount(keyRegister) != 1) {
|
||||
return;
|
||||
}
|
||||
LOG_DEBUG("Held");
|
||||
uint16_t buttonState = keyRegister & _KEY_MASK;
|
||||
uint8_t next_key = 0;
|
||||
for (uint8_t i = 0; i < 12; ++i) {
|
||||
if (buttonState & (1 << i)) {
|
||||
next_key = MPR121_KeyMap[i];
|
||||
bool MPR121Keyboard::hasEvent()
|
||||
{
|
||||
return queue.length() > 0;
|
||||
}
|
||||
|
||||
void MPR121Keyboard::queueEvent(char next)
|
||||
{
|
||||
if (next == MPR121_NONE) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
uint32_t now = millis();
|
||||
int32_t held_interval = now - last_tap;
|
||||
if (held_interval < 0 || next_key != last_key) {
|
||||
// long running, millis has overflowed, or a key has been switched quickly...
|
||||
last_tap = 0;
|
||||
state = Busy;
|
||||
return;
|
||||
}
|
||||
if (held_interval > LONG_PRESS_THRESHOLD) {
|
||||
// Set state to heldlong, send a longpress, and reset the timer...
|
||||
state = HeldLong; // heldlong will allow this function to still fire, but prevent a "release"
|
||||
queueEvent(MPR121_LongPressMap[last_key]);
|
||||
queue.concat(next);
|
||||
}
|
||||
|
||||
char MPR121Keyboard::dequeueEvent()
|
||||
{
|
||||
if (queue.length() < 1) {
|
||||
return MPR121_NONE;
|
||||
}
|
||||
char next = queue.charAt(0);
|
||||
queue.remove(0, 1);
|
||||
return next;
|
||||
}
|
||||
|
||||
void MPR121Keyboard::trigger()
|
||||
{
|
||||
// Intended to fire in response to an interrupt from the MPR121 or a longpress callback
|
||||
// Only functional if not in Init state
|
||||
if (state != Init) {
|
||||
// Read the key register
|
||||
uint16_t keyRegister = readRegister16(_MPR121_REG_KEY);
|
||||
uint8_t keysPressed = keyCount(keyRegister);
|
||||
if (keysPressed == 0) {
|
||||
// No buttons pressed
|
||||
if (state == Held)
|
||||
released();
|
||||
state = Idle;
|
||||
return;
|
||||
}
|
||||
if (keysPressed == 1) {
|
||||
// No buttons pressed
|
||||
if (state == Held || state == HeldLong)
|
||||
held(keyRegister);
|
||||
if (state == Idle)
|
||||
pressed(keyRegister);
|
||||
return;
|
||||
}
|
||||
if (keysPressed > 1) {
|
||||
// Multipress
|
||||
state = Busy;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
void MPR121Keyboard::pressed(uint16_t keyRegister)
|
||||
{
|
||||
if (state == Init || state == Busy) {
|
||||
return;
|
||||
}
|
||||
if (keyCount(keyRegister) != 1) {
|
||||
LOG_DEBUG("Multipress");
|
||||
return;
|
||||
} else {
|
||||
LOG_DEBUG("Pressed");
|
||||
}
|
||||
uint16_t buttonState = keyRegister & _KEY_MASK;
|
||||
uint8_t next_pin = 0;
|
||||
for (uint8_t i = 0; i < 12; ++i) {
|
||||
if (buttonState & (1 << i)) {
|
||||
next_pin = i;
|
||||
}
|
||||
}
|
||||
uint8_t next_key = MPR121_KeyMap[next_pin];
|
||||
LOG_DEBUG("MPR121 Pin: %i Key: %i", next_pin, next_key);
|
||||
uint32_t now = millis();
|
||||
int32_t tap_interval = now - last_tap;
|
||||
if (tap_interval < 0) {
|
||||
// long running, millis has overflowed.
|
||||
last_tap = 0;
|
||||
state = Busy;
|
||||
return;
|
||||
}
|
||||
if (next_key != last_key || tap_interval > MULTI_TAP_THRESHOLD) {
|
||||
char_idx = 0;
|
||||
} else {
|
||||
char_idx += 1;
|
||||
}
|
||||
last_key = next_key;
|
||||
last_tap = now;
|
||||
LOG_DEBUG("Long Press Key: %i Map: %i", last_key, MPR121_LongPressMap[last_key]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void MPR121Keyboard::released() {
|
||||
if (state != Held) {
|
||||
state = Held;
|
||||
return;
|
||||
}
|
||||
// would clear longpress callback... later.
|
||||
if (last_key < 0 || last_key > _NUM_KEYS) { // reset to idle if last_key out of bounds
|
||||
last_key = -1;
|
||||
state = Idle;
|
||||
}
|
||||
|
||||
void MPR121Keyboard::held(uint16_t keyRegister)
|
||||
{
|
||||
if (state == Init || state == Busy) {
|
||||
return;
|
||||
}
|
||||
if (keyCount(keyRegister) != 1) {
|
||||
return;
|
||||
}
|
||||
LOG_DEBUG("Held");
|
||||
uint16_t buttonState = keyRegister & _KEY_MASK;
|
||||
uint8_t next_key = 0;
|
||||
for (uint8_t i = 0; i < 12; ++i) {
|
||||
if (buttonState & (1 << i)) {
|
||||
next_key = MPR121_KeyMap[i];
|
||||
}
|
||||
}
|
||||
uint32_t now = millis();
|
||||
int32_t held_interval = now - last_tap;
|
||||
if (held_interval < 0 || next_key != last_key) {
|
||||
// long running, millis has overflowed, or a key has been switched quickly...
|
||||
last_tap = 0;
|
||||
state = Busy;
|
||||
return;
|
||||
}
|
||||
if (held_interval > LONG_PRESS_THRESHOLD) {
|
||||
// Set state to heldlong, send a longpress, and reset the timer...
|
||||
state = HeldLong; // heldlong will allow this function to still fire, but prevent a "release"
|
||||
queueEvent(MPR121_LongPressMap[last_key]);
|
||||
last_tap = now;
|
||||
LOG_DEBUG("Long Press Key: %i Map: %i", last_key, MPR121_LongPressMap[last_key]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
LOG_DEBUG("Released");
|
||||
if (char_idx > 0 && TapMod[last_key] > 1) {
|
||||
queueEvent(MPR121_BSP);
|
||||
LOG_DEBUG("Multi Press, Backspace");
|
||||
}
|
||||
queueEvent(MPR121_TapMap[last_key][(char_idx % TapMod[last_key])]);
|
||||
LOG_DEBUG("Key Press: %i Index:%i if %i Map: %i", last_key, char_idx, TapMod[last_key], MPR121_TapMap[last_key][(char_idx % TapMod[last_key])]);
|
||||
}
|
||||
|
||||
uint8_t MPR121Keyboard::readRegister8(uint8_t reg) const {
|
||||
if (m_wire) {
|
||||
m_wire->beginTransmission(m_addr);
|
||||
m_wire->write(reg);
|
||||
m_wire->endTransmission();
|
||||
|
||||
m_wire->requestFrom(m_addr, (uint8_t)1);
|
||||
if (m_wire->available() < 1)
|
||||
return 0;
|
||||
|
||||
return m_wire->read();
|
||||
}
|
||||
if (readCallback) {
|
||||
uint8_t data;
|
||||
readCallback(m_addr, reg, &data, 1);
|
||||
return data;
|
||||
}
|
||||
return 0;
|
||||
void MPR121Keyboard::released()
|
||||
{
|
||||
if (state != Held) {
|
||||
return;
|
||||
}
|
||||
// would clear longpress callback... later.
|
||||
if (last_key < 0 || last_key > _NUM_KEYS) { // reset to idle if last_key out of bounds
|
||||
last_key = -1;
|
||||
state = Idle;
|
||||
return;
|
||||
}
|
||||
LOG_DEBUG("Released");
|
||||
if (char_idx > 0 && TapMod[last_key] > 1) {
|
||||
queueEvent(MPR121_BSP);
|
||||
LOG_DEBUG("Multi Press, Backspace");
|
||||
}
|
||||
queueEvent(MPR121_TapMap[last_key][(char_idx % TapMod[last_key])]);
|
||||
LOG_DEBUG("Key Press: %i Index:%i if %i Map: %i", last_key, char_idx, TapMod[last_key],
|
||||
MPR121_TapMap[last_key][(char_idx % TapMod[last_key])]);
|
||||
}
|
||||
|
||||
uint16_t MPR121Keyboard::readRegister16(uint8_t reg) const {
|
||||
uint8_t data[2] = {0};
|
||||
// uint8_t low = 0, high = 0;
|
||||
if (m_wire) {
|
||||
m_wire->beginTransmission(m_addr);
|
||||
m_wire->write(reg);
|
||||
m_wire->endTransmission();
|
||||
uint8_t MPR121Keyboard::readRegister8(uint8_t reg) const
|
||||
{
|
||||
if (m_wire) {
|
||||
m_wire->beginTransmission(m_addr);
|
||||
m_wire->write(reg);
|
||||
m_wire->endTransmission();
|
||||
|
||||
m_wire->requestFrom(m_addr, (uint8_t)2);
|
||||
if (m_wire->available() < 2)
|
||||
return 0;
|
||||
data[0] = m_wire->read();
|
||||
data[1] = m_wire->read();
|
||||
}
|
||||
if (readCallback) {
|
||||
readCallback(m_addr, reg, data, 2);
|
||||
}
|
||||
return (data[1] << 8) | data[0];
|
||||
m_wire->requestFrom(m_addr, (uint8_t)1);
|
||||
if (m_wire->available() < 1)
|
||||
return 0;
|
||||
|
||||
return m_wire->read();
|
||||
}
|
||||
if (readCallback) {
|
||||
uint8_t data;
|
||||
readCallback(m_addr, reg, &data, 1);
|
||||
return data;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MPR121Keyboard::writeRegister(uint8_t reg, uint8_t value) {
|
||||
uint8_t data[2];
|
||||
data[0] = reg;
|
||||
data[1] = value;
|
||||
uint16_t MPR121Keyboard::readRegister16(uint8_t reg) const
|
||||
{
|
||||
uint8_t data[2] = {0};
|
||||
// uint8_t low = 0, high = 0;
|
||||
if (m_wire) {
|
||||
m_wire->beginTransmission(m_addr);
|
||||
m_wire->write(reg);
|
||||
m_wire->endTransmission();
|
||||
|
||||
if (m_wire) {
|
||||
m_wire->beginTransmission(m_addr);
|
||||
m_wire->write(data, sizeof(uint8_t) * 2);
|
||||
m_wire->endTransmission();
|
||||
}
|
||||
if (writeCallback) {
|
||||
writeCallback(m_addr, data[0], &(data[1]), 1);
|
||||
}
|
||||
m_wire->requestFrom(m_addr, (uint8_t)2);
|
||||
if (m_wire->available() < 2)
|
||||
return 0;
|
||||
data[0] = m_wire->read();
|
||||
data[1] = m_wire->read();
|
||||
}
|
||||
if (readCallback) {
|
||||
readCallback(m_addr, reg, data, 2);
|
||||
}
|
||||
return (data[1] << 8) | data[0];
|
||||
}
|
||||
|
||||
void MPR121Keyboard::writeRegister(uint8_t reg, uint8_t value)
|
||||
{
|
||||
uint8_t data[2];
|
||||
data[0] = reg;
|
||||
data[1] = value;
|
||||
|
||||
if (m_wire) {
|
||||
m_wire->beginTransmission(m_addr);
|
||||
m_wire->write(data, sizeof(uint8_t) * 2);
|
||||
m_wire->endTransmission();
|
||||
}
|
||||
if (writeCallback) {
|
||||
writeCallback(m_addr, data[0], &(data[1]), 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user