Only sync the LEDs, if there is a change

To further improve the LED performance, sync only when there is a change. We do
this by tracking when change happens, assuming everyone uses the provided
accessors.

While we do a bit of extra work each cycle to do the tracking, that pales in
comparison to what we gain by not having to transfer data needlessly.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent 161401b22f
commit 0bfd633cfa

@ -6,6 +6,7 @@
KeyboardioScanner Model01::leftHand(0); KeyboardioScanner Model01::leftHand(0);
KeyboardioScanner Model01::rightHand(3); KeyboardioScanner Model01::rightHand(3);
bool Model01::isLEDChanged;
static constexpr uint8_t key_led_map[4][16] = { static constexpr uint8_t key_led_map[4][16] = {
{3,4,11,12,19,20,26,27, 36,37,43,44,51,52,59,60}, {3,4,11,12,19,20,26,27, 36,37,43,44,51,52,59,60},
@ -62,8 +63,14 @@ void Model01::setup(void) {
void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) { void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) {
if(i<32) { if(i<32) {
cRGB oldColor = led_get_crgb_at(i);
isLEDChanged |= !(oldColor.r == crgb.r && oldColor.g == crgb.g && oldColor.b == crgb.b);
leftHand.ledData.leds[i] = crgb; leftHand.ledData.leds[i] = crgb;
} else if (i<64) { } else if (i<64) {
cRGB oldColor = led_get_crgb_at(i);
isLEDChanged |= !(oldColor.r == crgb.r && oldColor.g == crgb.g && oldColor.b == crgb.b);
rightHand.ledData.leds[i-32] = crgb; rightHand.ledData.leds[i-32] = crgb;
} else { } else {
// TODO how do we want to handle debugging assertions about crazy user // TODO how do we want to handle debugging assertions about crazy user
@ -86,6 +93,9 @@ cRGB Model01::led_get_crgb_at(uint8_t i) {
} }
void Model01::led_sync() { void Model01::led_sync() {
if (!isLEDChanged)
return;
leftHand.sendLEDData(); leftHand.sendLEDData();
rightHand.sendLEDData(); rightHand.sendLEDData();
@ -98,6 +108,7 @@ void Model01::led_sync() {
leftHand.sendLEDData(); leftHand.sendLEDData();
rightHand.sendLEDData(); rightHand.sendLEDData();
isLEDChanged = false;
} }
boolean Model01::led_power_fault() { boolean Model01::led_power_fault() {

@ -38,6 +38,7 @@ class Model01 {
keydata_t previousRightHandState; keydata_t previousRightHandState;
private: private:
static bool isLEDChanged;
static KeyboardioScanner leftHand; static KeyboardioScanner leftHand;
static KeyboardioScanner rightHand; static KeyboardioScanner rightHand;
}; };

Loading…
Cancel
Save