-
Notifications
You must be signed in to change notification settings - Fork 75
add user facing api for autoconfig #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@s-light see here for dealing with clang format: |
|
thanks caternuson! |
|
This seems to work with a basic functional check. Here's the test sketch: #include <Adafruit_MPR121.h>
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
Adafruit_MPR121 cap = Adafruit_MPR121();
// Keeps track of the last pins touched
// so we know when buttons are 'released'
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
void dump_regs() {
Serial.println("========================================");
Serial.println("CHAN 00 01 02 03 04 05 06 07 08 09 10 11");
Serial.println(" -- -- -- -- -- -- -- -- -- -- -- --");
// CDC
Serial.print("CDC: ");
for (int chan=0; chan<12; chan++) {
uint8_t reg = cap.readRegister8(0x5F+chan);
if (reg < 10) Serial.print(" ");
Serial.print(reg);
Serial.print(" ");
}
Serial.println();
// CDT
Serial.print("CDT: ");
for (int chan=0; chan<6; chan++) {
uint8_t reg = cap.readRegister8(0x6C+chan);
uint8_t cdtx = reg & 0b111;
uint8_t cdty = (reg >> 4) & 0b111;
if (cdtx < 10) Serial.print(" ");
Serial.print(cdtx);
Serial.print(" ");
if (cdty < 10) Serial.print(" ");
Serial.print(cdty);
Serial.print(" ");
}
Serial.println();
Serial.println("========================================");
}
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("MPR121 Configuration Dump.");
if (!cap.begin(0x5A)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
Serial.println("MPR121 found!");
delay(100);
Serial.println("Initial CDC/CDT values:");
dump_regs();
cap.setAutoconfig(true);
Serial.println("After autoconfig CDC/CDT values:");
dump_regs();
}
void loop() {
// Get the currently touched pads
currtouched = cap.touched();
for (uint8_t i=0; i<12; i++) {
// it if *is* touched and *wasnt* touched before, alert!
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(" touched");
}
// if it *was* touched and now *isnt*, alert!
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(" released");
}
}
// reset our state
lasttouched = currtouched;
}Only the CDC values are changed, but maybe that's expected. It'd be good if this could be tested (@wystewart ?) in a more realistic setup to see if it has the desired benefits there. |
|
Going to go ahead and merge. This PR will also fix the compile warn brought up in #45. |

fixes #42
i think my changes are fully backwards-compatible.
so old use-cases are not at risk.
please @wystewart test it.
i have no board at hand at the moment.