You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.5 KiB
91 lines
2.5 KiB
6 years ago
|
/* -*- mode: c++ -*-
|
||
|
* Kaleidoscope-LEDEffect-BootAnimation -- Small greeting at boot time
|
||
|
* Copyright (C) 2018 Keyboard.io, Inc
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify it under
|
||
|
* the terms of the GNU General Public License as published by the Free Software
|
||
|
* Foundation, version 3.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
|
* details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License along with
|
||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include "Kaleidoscope-LEDEffect-BootAnimation.h"
|
||
5 years ago
|
#include "kaleidoscope/layers.h"
|
||
6 years ago
|
|
||
|
namespace kaleidoscope {
|
||
|
namespace plugin {
|
||
|
|
||
|
bool BootAnimationEffect::done_ = false;
|
||
|
cRGB BootAnimationEffect::color = CRGB(150, 0, 0);
|
||
|
uint16_t BootAnimationEffect::start_time_ = 0;
|
||
|
uint16_t BootAnimationEffect::timeout = 1000;
|
||
|
uint8_t BootAnimationEffect::current_index_ = 0;
|
||
|
const uint8_t BootAnimationEffect::greeting_[11] PROGMEM = {
|
||
5 years ago
|
Key_K.getKeyCode(),
|
||
|
Key_E.getKeyCode(),
|
||
|
Key_Y.getKeyCode(),
|
||
|
Key_B.getKeyCode(),
|
||
|
Key_O.getKeyCode(),
|
||
|
Key_A.getKeyCode(),
|
||
|
Key_R.getKeyCode(),
|
||
|
Key_D.getKeyCode(),
|
||
|
Key_Period.getKeyCode(),
|
||
|
Key_I.getKeyCode(),
|
||
|
Key_O.getKeyCode()
|
||
6 years ago
|
};
|
||
|
|
||
|
EventHandlerResult BootAnimationEffect::onSetup() {
|
||
|
return EventHandlerResult::OK;
|
||
|
}
|
||
|
|
||
|
EventHandlerResult BootAnimationEffect::afterEachCycle() {
|
||
5 years ago
|
if (!Runtime.has_leds)
|
||
6 years ago
|
return EventHandlerResult::OK;
|
||
|
|
||
6 years ago
|
//If already done or we're not in a ready state, bail
|
||
|
if (done_) {
|
||
|
return EventHandlerResult::OK;
|
||
|
}
|
||
|
|
||
5 years ago
|
KeyAddr key_addr_found;
|
||
6 years ago
|
|
||
5 years ago
|
for (auto key_addr : KeyAddr::all()) {
|
||
|
Key k = Layer.lookupOnActiveLayer(key_addr);
|
||
5 years ago
|
Key g(pgm_read_byte(&greeting_[current_index_]), // key_code
|
||
|
0); // flags
|
||
6 years ago
|
|
||
5 years ago
|
if (k == g) {
|
||
5 years ago
|
key_addr_found = key_addr;
|
||
|
break;
|
||
6 years ago
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
if (Runtime.hasTimeExpired(start_time_, timeout)) {
|
||
6 years ago
|
current_index_++;
|
||
|
if (current_index_ == sizeof(greeting_))
|
||
|
done_ = true;
|
||
|
|
||
6 years ago
|
start_time_ += timeout;
|
||
5 years ago
|
if (key_addr_found.isValid())
|
||
|
::LEDControl.refreshAt(KeyAddr(key_addr_found));
|
||
6 years ago
|
return EventHandlerResult::OK;
|
||
|
}
|
||
|
|
||
5 years ago
|
if (key_addr_found.isValid()) {
|
||
|
::LEDControl.setCrgbAt(KeyAddr(key_addr_found), color);
|
||
6 years ago
|
}
|
||
|
|
||
|
return EventHandlerResult::OK;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
kaleidoscope::plugin::BootAnimationEffect BootAnimationEffect;
|