forked from adafruit/Adafruit_Seesaw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Adafruit_NeoKey_1x4.h
96 lines (73 loc) · 3 KB
/
Adafruit_NeoKey_1x4.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef _NEOKEY_1X4_H
#define _NEOKEY_1X4_H
#include "Adafruit_seesaw.h"
#include "seesaw_neopixel.h"
#include <Arduino.h>
#define NEOKEY_1X4_ADDR 0x30
#define NEOKEY_1X4_NEOPIN 3
#define NEOKEY_1X4_BUTTONA 4
#define NEOKEY_1X4_BUTTONB 5
#define NEOKEY_1X4_BUTTONC 6
#define NEOKEY_1X4_BUTTOND 7
#define NEOKEY_1X4_BUTTONMASK ((1 << 4) | (1 << 5) | (1 << 6) | (1 << 7))
#define NEOKEY_1X4_ROWS 1
#define NEOKEY_1X4_COLS 4
#define NEOKEY_1X4_KEYS (NEOKEY_1X4_ROWS * NEOKEY_1X4_COLS)
#define NEOKEY_1X4_MAX_CALLBACKS 32
/* NEOKEY_1X4_KEY depends on PCB routing */
// #define NEOKEY_1X4_KEY(x) (((x) / 4) * 8 + ((x) % 4))
#define NEOKEY_1X4_KEY(x) (((x) / 8) * 4 + ((x) % 8))
#define NEOKEY_1X4_X(k) ((k) % 4)
#define NEOKEY_1X4_Y(k) ((k) / 4)
#define NEOKEY_1X4_XY(x, y) ((y)*NEOKEY_1X4_ROWS + (x))
typedef void (*NeoKey1x4Callback)(keyEvent evt);
/**************************************************************************/
/*!
@brief Class that stores state and functions for interacting with the
seesaw NeoKey module
*/
/**************************************************************************/
class Adafruit_NeoKey_1x4 : public Adafruit_seesaw {
public:
Adafruit_NeoKey_1x4(uint8_t addr = NEOKEY_1X4_ADDR, TwoWire *i2c_bus = &Wire);
~Adafruit_NeoKey_1x4(){};
bool begin(uint8_t addr = NEOKEY_1X4_ADDR, int8_t flow = -1);
void registerCallback(uint8_t key, NeoKey1x4Callback (*cb)(keyEvent));
void unregisterCallback(uint8_t key);
uint8_t read(void);
seesaw_NeoPixel pixels; ///< the onboard neopixel matrix
friend class Adafruit_MultiNeoKey1x4; ///< for allowing use of protected
///< methods by aggregate class
protected:
uint8_t last_buttons = 0; ///< The last reading for the buttons
uint8_t _addr; ///< the I2C address of this board
NeoKey1x4Callback (*_callbacks[NEOKEY_1X4_KEYS])(
keyEvent); ///< the array of callback functions
};
/**************************************************************************/
/*!
@brief Class that stores state and functions for interacting with multiple
neotrellis boards
*/
/**************************************************************************/
class Adafruit_MultiNeoKey1x4 {
public:
Adafruit_MultiNeoKey1x4(Adafruit_NeoKey_1x4 *neokeys, uint8_t rows,
uint8_t cols);
~Adafruit_MultiNeoKey1x4(){};
bool begin();
void registerCallback(uint16_t num, NeoKey1x4Callback (*cb)(keyEvent));
void registerCallback(uint8_t x, uint8_t y,
NeoKey1x4Callback (*cb)(keyEvent));
void unregisterCallback(uint16_t num);
void unregisterCallback(uint8_t x, uint8_t y);
void setPixelColor(uint8_t x, uint8_t y, uint32_t color);
void setPixelColor(uint16_t num, uint32_t color);
void show();
void read();
protected:
uint8_t _rows; ///< the number of trellis boards in the Y direction
uint8_t _cols; ///< the number of trellis boards in the X direction
Adafruit_NeoKey_1x4 *_neokeys; ///< a multidimensional array of neokey objects
};
#endif