Skip to content
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

Added polling flag to MultiTrellis::read #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Adafruit_NeoTrellis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool Adafruit_NeoTrellis::begin(uint8_t addr, int8_t flow) {
*/
/**************************************************************************/
void Adafruit_NeoTrellis::registerCallback(uint8_t key,
TrellisCallback (*cb)(keyEvent)) {
TrellisCallback cb) {
_callbacks[key] = cb;
}

Expand Down Expand Up @@ -153,7 +153,7 @@ bool Adafruit_MultiTrellis::begin() {
*/
/**************************************************************************/
void Adafruit_MultiTrellis::registerCallback(uint8_t x, uint8_t y,
TrellisCallback (*cb)(keyEvent)) {
TrellisCallback cb) {
Adafruit_NeoTrellis *t =
(_trelli + y / NEO_TRELLIS_NUM_ROWS * _cols) + x / NEO_TRELLIS_NUM_COLS;
int xkey = NEO_TRELLIS_X(x);
Expand All @@ -173,7 +173,7 @@ void Adafruit_MultiTrellis::registerCallback(uint8_t x, uint8_t y,
*/
/**************************************************************************/
void Adafruit_MultiTrellis::registerCallback(uint16_t num,
TrellisCallback (*cb)(keyEvent)) {
TrellisCallback cb) {
uint8_t x = num % (NEO_TRELLIS_NUM_COLS * _cols);
uint8_t y = num / (NEO_TRELLIS_NUM_COLS * _cols);

Expand Down Expand Up @@ -315,9 +315,11 @@ void Adafruit_MultiTrellis::show() {
/*!
@brief read all events currently stored in the seesaw fifo and call any
callbacks.
@param polling pass true if the interrupt pin is not being used, false if
it is. Defaults to true.
*/
/**************************************************************************/
void Adafruit_MultiTrellis::read() {
void Adafruit_MultiTrellis::read(bool polling) {
Adafruit_NeoTrellis *t;
for (int n = 0; n < _rows; n++) {
for (int m = 0; m < _cols; m++) {
Expand All @@ -326,7 +328,8 @@ void Adafruit_MultiTrellis::read() {
uint8_t count = t->getKeypadCount();
delayMicroseconds(500);
if (count > 0) {
count = count + 2;
if (polling)
count = count + 2;
keyEventRaw e[count];
t->readKeypad(e, count);
for (int i = 0; i < count; i++) {
Expand Down
11 changes: 5 additions & 6 deletions Adafruit_NeoTrellis.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Adafruit_NeoTrellis : public Adafruit_seesaw {

bool begin(uint8_t addr = NEO_TRELLIS_ADDR, int8_t flow = -1);

void registerCallback(uint8_t key, TrellisCallback (*cb)(keyEvent));
void registerCallback(uint8_t key, TrellisCallback cb);
void unregisterCallback(uint8_t key);

void activateKey(uint8_t key, uint8_t edge, bool enable = true);
Expand All @@ -53,8 +53,7 @@ class Adafruit_NeoTrellis : public Adafruit_seesaw {

protected:
uint8_t _addr; ///< the I2C address of this board
TrellisCallback (*_callbacks[NEO_TRELLIS_NUM_KEYS])(
keyEvent); ///< the array of callback functions
TrellisCallback _callbacks[NEO_TRELLIS_NUM_KEYS]; ///< the array of callback functions
};

/**************************************************************************/
Expand All @@ -71,8 +70,8 @@ class Adafruit_MultiTrellis {

bool begin();

void registerCallback(uint16_t num, TrellisCallback (*cb)(keyEvent));
void registerCallback(uint8_t x, uint8_t y, TrellisCallback (*cb)(keyEvent));
void registerCallback(uint16_t num, TrellisCallback cb);
void registerCallback(uint8_t x, uint8_t y, TrellisCallback cb);
void unregisterCallback(uint16_t num);
void unregisterCallback(uint8_t x, uint8_t y);

Expand All @@ -83,7 +82,7 @@ class Adafruit_MultiTrellis {
void setPixelColor(uint16_t num, uint32_t color);
void show();

void read();
void read(bool polling = true);

protected:
uint8_t _rows; ///< the number of trellis boards in the Y direction
Expand Down
3 changes: 1 addition & 2 deletions examples/NeoTrellis/multitrellis/basic/basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ uint32_t Wheel(byte WheelPos) {
}

//define a callback for key presses
TrellisCallback blink(keyEvent evt){
void blink(keyEvent evt){

if(evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING)
trellis.setPixelColor(evt.bit.NUM, Wheel(map(evt.bit.NUM, 0, X_DIM*Y_DIM, 0, 255))); //on rising
else if(evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING)
trellis.setPixelColor(evt.bit.NUM, 0); //off falling

trellis.show();
return 0;
}

void setup() {
Expand Down