-
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.
Backlight and wave scheme works in simulator
- Loading branch information
Showing
15 changed files
with
176 additions
and
28 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
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
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,40 @@ | ||
#include "wave.h" | ||
#include <cmath> | ||
|
||
|
||
namespace core::backlight::schemes | ||
{ | ||
|
||
void Wave::reset() | ||
{ | ||
it = 0; | ||
} | ||
|
||
|
||
void Wave::update(const core::keyboard::KeyboardScanResult& scan_result, | ||
core::backlight::LEDState led_states[common::constants::TOTAL_NUM_LEDS]) | ||
{ | ||
const float fade_x = sin(it * SPEED * X_SPEED); | ||
const float fade_y = sin(it * SPEED * Y_SPEED); | ||
for (int i = 0; i < common::constants::TOTAL_NUM_LEDS; ++i) | ||
{ | ||
auto& state = led_states[i]; | ||
const auto x = state.description->x; | ||
const auto y = state.description->y; | ||
|
||
const float hue = (cos((it * SPEED + x * fade_x + y * fade_y) * MAX_PHASE_DIFFERENCE) + 1.0f) / 2.0f; | ||
const Color color = Color::from_hsv(hue, 1.0f, 1.0f); | ||
state.color = color; | ||
} | ||
|
||
for (int i = 0; i < scan_result.num_pressed; ++i) | ||
{ | ||
const common::LEDDescription pressed = scan_result.just_pressed[i]->get_associated_led(); | ||
led_states[pressed.strip_index].start_fade( | ||
device, Color{1.0f, 1.0f, 1.0f}, PRESS_FADE_TIME); | ||
} | ||
|
||
it++; | ||
} | ||
|
||
} |
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,31 @@ | ||
#pragma once | ||
|
||
#include "../../../device.h" | ||
#include "../../keyboard/keyscan.h" | ||
#include "../ledstate.h" | ||
#include "scheme.h" | ||
|
||
namespace core::backlight::schemes | ||
{ | ||
|
||
const float SPEED = 0.00005f; | ||
const float X_SPEED = 0.8f; | ||
const float Y_SPEED = 1.1f; | ||
const float MAX_PHASE_DIFFERENCE = 0.3f; | ||
const uint32_t PRESS_FADE_TIME = 2000; | ||
|
||
|
||
class Wave : public Scheme | ||
{ | ||
public: | ||
Wave(Device& device) : Scheme{device} { } | ||
|
||
void reset() override; | ||
|
||
void update(const core::keyboard::KeyboardScanResult& scan_result, | ||
core::backlight::LEDState led_states[common::constants::TOTAL_NUM_LEDS]) override; | ||
private: | ||
uint64_t it = 0; | ||
}; | ||
|
||
} |
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
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
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
Oops, something went wrong.