-
Notifications
You must be signed in to change notification settings - Fork 8
/
KeyboardioScanner.h
94 lines (78 loc) · 2.52 KB
/
KeyboardioScanner.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
/* KeyboardioScanner
* Copyright (C) 2015-2020 Keyboard.io, Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
#include <Arduino.h>
#include "wire-protocol-constants.h"
// We allow cRGB/CRGB to be defined already when this is included.
//
#ifndef CRGB
struct cRGB {
uint8_t b;
uint8_t g;
uint8_t r;
};
#define CRGB(r,g,b) (cRGB){b, g, r}
#endif
#define LED_BANKS 4
#define LEDS_PER_HAND 32
#define LED_BYTES_PER_BANK sizeof(cRGB) * LEDS_PER_HAND/LED_BANKS
typedef union {
cRGB leds[LEDS_PER_HAND];
byte bytes[LED_BANKS][LED_BYTES_PER_BANK];
} LEDData_t;
typedef union {
uint8_t rows[4];
uint32_t all;
} keydata_t;
// config options
// used to configure interrupts, configuration for a particular controller
class KeyboardioScanner {
public:
KeyboardioScanner(byte setAd01);
~KeyboardioScanner();
int readVersion();
byte setKeyscanInterval(byte delay);
int readKeyscanInterval();
byte setLEDSPIFrequency(byte frequency);
int readLEDSPIFrequency();
void sendLEDData();
void setOneLEDTo(byte led, cRGB color);
void setAllLEDsTo(cRGB color);
keydata_t getKeyData();
bool readKeys();
LEDData_t ledData;
uint8_t controllerAddress();
void setBrightness(uint8_t brightness) {
brightness_adjustment_ = 255 - brightness;
}
uint8_t getBrightness() {
return 255 - brightness_adjustment_;
}
private:
uint8_t brightness_adjustment_ = 0;
int addr;
int ad01;
keydata_t keyData;
byte nextLEDBank = 0;
void sendLEDBank(byte bank);
int readRegister(uint8_t cmd);
};