-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
361 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ generated/ | |
.gdb_history | ||
test_main | ||
__pycache__/ | ||
simulator/common/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,34 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include "../../device.h" | ||
#include "../../common/key_properties.h" | ||
#include "../../common/constants.h" | ||
#include "color.h" | ||
#include "ledstate.h" | ||
#include "../../common/constants.h" | ||
#include "../util/timer.h" | ||
#include "schemes/scheme.h" | ||
|
||
|
||
namespace core::backlight | ||
{ | ||
|
||
struct LEDState | ||
{ | ||
Color color; | ||
|
||
bool blinking = false; | ||
util::Timer blink_timer; | ||
|
||
bool fading = false; | ||
util::Timer fade_timer; | ||
|
||
const common::LEDDescription* description; | ||
}; | ||
|
||
class Backlight | ||
{ | ||
public: | ||
Backlight(Device& device); | ||
void update(); | ||
Backlight(Device& device, schemes::Scheme* schemes[], int num_schemes); | ||
void update(const core::keyboard::KeyboardScanResult& scan_result); | ||
void increment_scheme(); | ||
|
||
private: | ||
Color update_fade(LEDState& state); | ||
Color update_blink(LEDState& state); | ||
|
||
Device& device; | ||
LEDState ledStates[common::constants::TOTAL_NUM_LEDS]; | ||
LEDState led_states[common::constants::TOTAL_NUM_LEDS]; | ||
|
||
int current_scheme_index = 0; | ||
|
||
const int num_schemes; | ||
schemes::Scheme** schemes; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "ledstate.h" | ||
|
||
namespace core::backlight | ||
{ | ||
|
||
|
||
void LEDState::start_blink(const Device& device, const uint32_t period) | ||
{ | ||
blinking = true; | ||
blink_timer.duration = period; | ||
blink_state = true; | ||
blink_timer.start(device); | ||
} | ||
|
||
void LEDState::start_fade(const Device& device, const Color& fade_start_color, const uint32_t fade_time) | ||
{ | ||
fading = true; | ||
fade_timer.duration = fade_time; | ||
fade_timer.start(device); | ||
this->fade_start_color = fade_start_color; | ||
} | ||
|
||
bool LEDState::is_blinking() const | ||
{ | ||
return blinking; | ||
} | ||
|
||
bool LEDState::get_blink_state() const | ||
{ | ||
return blink_state; | ||
} | ||
|
||
bool LEDState::is_fading() const | ||
{ | ||
return fading; | ||
} | ||
|
||
Color LEDState::update(const Device& device) | ||
{ | ||
if (blinking) | ||
{ | ||
blink_timer.update(device); | ||
if (blink_timer.is_finished()) | ||
{ | ||
blink_state = !blink_state; | ||
blink_timer.start(device); | ||
} | ||
return blink_state ? color : Color{0, 0, 0}; | ||
} | ||
if (fading) | ||
{ | ||
fade_timer.update(device); | ||
if (fade_timer.is_finished()) | ||
{ | ||
fading = false; | ||
return color; | ||
} | ||
const auto progress = fade_timer.progress(); | ||
return (fade_start_color * (1.0f - progress)) + (color * progress); | ||
} | ||
return color; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
#include "../../device.h" | ||
#include "color.h" | ||
#include "../../common/constants.h" | ||
#include "../util/timer.h" | ||
|
||
namespace core::backlight | ||
{ | ||
|
||
struct LEDState | ||
{ | ||
/** | ||
* The current color of the LED, may be overridden by a blink or fade sequence. | ||
*/ | ||
Color color; | ||
|
||
/** | ||
* Whether the current LED is blinking. | ||
*/ | ||
bool is_blinking() const; | ||
|
||
/** | ||
* The state of the blinking, true if illuminated and false if off. | ||
*/ | ||
bool get_blink_state() const; | ||
|
||
/** | ||
* Whether the current LED is fading. | ||
*/ | ||
bool is_fading() const; | ||
|
||
/** | ||
* Starts a blink sequence on the LED. | ||
*/ | ||
void start_blink(const Device& device, const uint32_t period = common::constants::DEFAULT_BLINK_PERIOD); | ||
|
||
/** | ||
* Starts a fade sequence on the LED. Will fade from the fade_start_color | ||
* to the current color. | ||
*/ | ||
void start_fade(const Device& device, const Color& fade_start_color, const uint32_t fade_time = common::constants::DEFAULT_FADE_TIME); | ||
|
||
const common::LEDDescription* description; | ||
|
||
friend class Backlight; | ||
|
||
private: | ||
|
||
/** | ||
* Updates the LED state, returns the current color of the LED. | ||
*/ | ||
Color update(const Device& device); | ||
|
||
Color fade_start_color; | ||
bool blinking = false; | ||
bool fading = false; | ||
bool blink_state = false; | ||
util::Timer blink_timer; | ||
util::Timer fade_timer; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
#include "../../../device.h" | ||
#include "../../keyboard/keyscan.h" | ||
#include "../ledstate.h" | ||
|
||
namespace core::backlight::schemes | ||
{ | ||
|
||
/** | ||
* Base class for backlight schemes. | ||
*/ | ||
class Scheme | ||
{ | ||
public: | ||
Scheme(Device& device) : device(device) { } | ||
|
||
virtual void reset() = 0; | ||
|
||
virtual void update(const core::keyboard::KeyboardScanResult& scan_result, | ||
core::backlight::LEDState led_states[common::constants::TOTAL_NUM_LEDS]) = 0; | ||
|
||
protected: | ||
Device& device; | ||
}; | ||
|
||
} |
Oops, something went wrong.