diff --git a/include/BoardConfig.h b/include/BoardConfig.h index b6273f3d..4e97934e 100644 --- a/include/BoardConfig.h +++ b/include/BoardConfig.h @@ -6,6 +6,8 @@ #ifndef BOARD_CONFIG_H_ #define BOARD_CONFIG_H_ +#include + #define DEBUG_BOARD 0 #define PICO_BOARD 1 #define OPEN_STICK_BOARD 2 @@ -14,12 +16,15 @@ #if BOARD_CONFIG == DEBUG_BOARD #include "definitions/DebugBoard.h" +#include "LEDConfig.h" #elif BOARD_CONFIG == OPEN_STICK_BOARD #include "definitions/OpenStickBoard.h" +#include "LEDConfig.h" #elif BOARD_CONFIG == TEST_BOARD #include "definitions/TestBoard.h" #else #include "definitions/RP2040Board.h" #endif + #endif diff --git a/include/LEDConfig.h b/include/LEDConfig.h index 8374e850..6e3abf42 100644 --- a/include/LEDConfig.h +++ b/include/LEDConfig.h @@ -1,46 +1,7 @@ +#include #include #include "AnimationStation.hpp" - -static AnimationHotkey animationHotkeys(MPG gamepad) -{ - AnimationHotkey action = HOTKEY_LEDS_NONE; - - if (gamepad.pressedF1()) - { - if (gamepad.pressedB3()) - { - action = HOTKEY_LEDS_ANIMATION_UP; - gamepad.state.buttons &= ~(GAMEPAD_MASK_B3 | GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); - } - else if (gamepad.pressedB1()) - { - action = HOTKEY_LEDS_ANIMATION_DOWN; - gamepad.state.buttons &= ~(GAMEPAD_MASK_B1 | GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); - } - else if (gamepad.pressedB4()) - { - action = HOTKEY_LEDS_BRIGHTNESS_UP; - gamepad.state.buttons &= ~(GAMEPAD_MASK_B4 | GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); - } - else if (gamepad.pressedB2()) - { - action = HOTKEY_LEDS_BRIGHTNESS_DOWN; - gamepad.state.buttons &= ~(GAMEPAD_MASK_B2 | GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); - } - else if (gamepad.pressedR1()) - { - action = HOTKEY_LEDS_PARAMETER_UP; - gamepad.state.buttons &= ~(GAMEPAD_MASK_R1 | GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); - } - else if (gamepad.pressedR2()) - { - action = HOTKEY_LEDS_PARAMETER_DOWN; - gamepad.state.buttons &= ~(GAMEPAD_MASK_R2 | GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); - } - } - - return action; -} +#include "LEDThemes.h" #ifndef LEDS_DPAD_LEFT #define LEDS_DPAD_LEFT -1 @@ -139,5 +100,54 @@ static AnimationHotkey animationHotkeys(MPG gamepad) #endif #ifndef LEDS_STATIC_COLOR_COLOR -#define LEDS_STATIC_COLOR_COLOR 255 +#define LEDS_STATIC_COLOR_COLOR ColorRed #endif + +extern const std::vector pixels; + +static void configureAnimations(AnimationStation *as) { + as->SetStaticColor(LEDS_STATIC_COLOR_COLOR); + for (size_t i = 0; i < customThemes.size(); i++) + as->AddAnimation(&customThemes[i]); +} + +static AnimationHotkey animationHotkeys(MPG gamepad) +{ + AnimationHotkey action = HOTKEY_LEDS_NONE; + + if (gamepad.pressedF1()) + { + if (gamepad.pressedB3()) + { + action = HOTKEY_LEDS_ANIMATION_UP; + gamepad.state.buttons &= ~(GAMEPAD_MASK_B3 | GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); + } + else if (gamepad.pressedB1()) + { + action = HOTKEY_LEDS_ANIMATION_DOWN; + gamepad.state.buttons &= ~(GAMEPAD_MASK_B1 | GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); + } + else if (gamepad.pressedB4()) + { + action = HOTKEY_LEDS_BRIGHTNESS_UP; + gamepad.state.buttons &= ~(GAMEPAD_MASK_B4 | GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); + } + else if (gamepad.pressedB2()) + { + action = HOTKEY_LEDS_BRIGHTNESS_DOWN; + gamepad.state.buttons &= ~(GAMEPAD_MASK_B2 | GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); + } + else if (gamepad.pressedR1()) + { + action = HOTKEY_LEDS_PARAMETER_UP; + gamepad.state.buttons &= ~(GAMEPAD_MASK_R1 | GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); + } + else if (gamepad.pressedR2()) + { + action = HOTKEY_LEDS_PARAMETER_DOWN; + gamepad.state.buttons &= ~(GAMEPAD_MASK_R2 | GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); + } + } + + return action; +} diff --git a/include/LEDThemes.h b/include/LEDThemes.h new file mode 100644 index 00000000..c203256f --- /dev/null +++ b/include/LEDThemes.h @@ -0,0 +1,200 @@ +#ifndef LED_THEMES_H_ +#define LED_THEMES_H_ + +#include +#include +#include "AnimationStation.hpp" + +extern const std::vector pixels; + +static StaticTheme themeStaticRainbow( + pixels, + { + { GAMEPAD_MASK_LEFT, ColorRed }, + { GAMEPAD_MASK_DOWN, ColorOrange }, + { GAMEPAD_MASK_RIGHT, ColorYellow }, + { GAMEPAD_MASK_UP, ColorYellow }, + { GAMEPAD_MASK_B3, ColorGreen }, + { GAMEPAD_MASK_B1, ColorGreen }, + { GAMEPAD_MASK_B4, ColorAqua }, + { GAMEPAD_MASK_B2, ColorAqua }, + { GAMEPAD_MASK_R1, ColorBlue }, + { GAMEPAD_MASK_R2, ColorBlue }, + { GAMEPAD_MASK_L1, ColorMagenta }, + { GAMEPAD_MASK_L2, ColorMagenta }, + } +); + +static StaticTheme themeGuiltyGearTypeA( + pixels, + { + { GAMEPAD_MASK_UP, ColorWhite }, + { GAMEPAD_MASK_DOWN, ColorWhite }, + { GAMEPAD_MASK_LEFT, ColorWhite }, + { GAMEPAD_MASK_RIGHT, ColorWhite }, + { GAMEPAD_MASK_B1, ColorPink }, + { GAMEPAD_MASK_B3, ColorBlue }, + { GAMEPAD_MASK_B4, ColorGreen }, + { GAMEPAD_MASK_R1, ColorRed }, + { GAMEPAD_MASK_R2, ColorOrange }, + } +); + +static StaticTheme themeGuiltyGearTypeD( + pixels, + { + { GAMEPAD_MASK_UP, ColorWhite }, + { GAMEPAD_MASK_DOWN, ColorWhite }, + { GAMEPAD_MASK_LEFT, ColorWhite }, + { GAMEPAD_MASK_RIGHT, ColorWhite }, + { GAMEPAD_MASK_B3, ColorPink }, + { GAMEPAD_MASK_B1, ColorBlue }, + { GAMEPAD_MASK_B4, ColorGreen }, + { GAMEPAD_MASK_B2, ColorRed }, + { GAMEPAD_MASK_R1, ColorOrange }, + } +); + +static StaticTheme themeGuiltyGearCustom( + pixels, + { + { GAMEPAD_MASK_UP, ColorWhite }, + { GAMEPAD_MASK_DOWN, ColorWhite }, + { GAMEPAD_MASK_LEFT, ColorWhite }, + { GAMEPAD_MASK_RIGHT, ColorWhite }, + { GAMEPAD_MASK_B3, ColorPink }, + { GAMEPAD_MASK_B1, ColorBlue }, + { GAMEPAD_MASK_B4, ColorGreen }, + { GAMEPAD_MASK_R1, ColorRed }, + { GAMEPAD_MASK_R2, ColorOrange }, + { GAMEPAD_MASK_L1, ColorSeafoam }, + } +); + +static StaticTheme themeNeoGeo( + pixels, + { + { GAMEPAD_MASK_UP, ColorWhite }, + { GAMEPAD_MASK_DOWN, ColorWhite }, + { GAMEPAD_MASK_LEFT, ColorWhite }, + { GAMEPAD_MASK_RIGHT, ColorWhite }, + { GAMEPAD_MASK_B3, ColorRed }, + { GAMEPAD_MASK_B4, ColorYellow }, + { GAMEPAD_MASK_R1, ColorGreen }, + { GAMEPAD_MASK_L1, ColorBlue }, + } +); + +static StaticTheme themeNeoGeoCurved( + pixels, + { + { GAMEPAD_MASK_UP, ColorWhite }, + { GAMEPAD_MASK_DOWN, ColorWhite }, + { GAMEPAD_MASK_LEFT, ColorWhite }, + { GAMEPAD_MASK_RIGHT, ColorWhite }, + { GAMEPAD_MASK_B1, ColorRed }, + { GAMEPAD_MASK_B3, ColorYellow }, + { GAMEPAD_MASK_B4, ColorGreen }, + { GAMEPAD_MASK_R1, ColorBlue }, + } +); + +static StaticTheme themeNeoGeoModern( + pixels, + { + { GAMEPAD_MASK_UP, ColorWhite }, + { GAMEPAD_MASK_DOWN, ColorWhite }, + { GAMEPAD_MASK_LEFT, ColorWhite }, + { GAMEPAD_MASK_RIGHT, ColorWhite }, + { GAMEPAD_MASK_B3, ColorRed }, + { GAMEPAD_MASK_B1, ColorYellow }, + { GAMEPAD_MASK_B4, ColorGreen }, + { GAMEPAD_MASK_B2, ColorBlue }, + } +); + +static StaticTheme themeSixButtonFighter( + pixels, + { + { GAMEPAD_MASK_UP, ColorWhite }, + { GAMEPAD_MASK_DOWN, ColorWhite }, + { GAMEPAD_MASK_LEFT, ColorWhite }, + { GAMEPAD_MASK_RIGHT, ColorWhite }, + { GAMEPAD_MASK_B3, ColorBlue }, + { GAMEPAD_MASK_B1, ColorBlue }, + { GAMEPAD_MASK_B4, ColorYellow }, + { GAMEPAD_MASK_B2, ColorYellow }, + { GAMEPAD_MASK_R1, ColorRed }, + { GAMEPAD_MASK_R2, ColorRed }, + } +); + +static StaticTheme themeSixButtonFighterPlus( + pixels, + { + { GAMEPAD_MASK_UP, ColorWhite }, + { GAMEPAD_MASK_DOWN, ColorWhite }, + { GAMEPAD_MASK_LEFT, ColorWhite }, + { GAMEPAD_MASK_RIGHT, ColorWhite }, + { GAMEPAD_MASK_B3, ColorBlue }, + { GAMEPAD_MASK_B1, ColorBlue }, + { GAMEPAD_MASK_B4, ColorYellow }, + { GAMEPAD_MASK_B2, ColorYellow }, + { GAMEPAD_MASK_R1, ColorRed }, + { GAMEPAD_MASK_R2, ColorRed }, + { GAMEPAD_MASK_L1, ColorMagenta }, + { GAMEPAD_MASK_L2, ColorMagenta }, + } +); + +static StaticTheme themeSuperFamicom( + pixels, + { + { GAMEPAD_MASK_UP, ColorWhite }, + { GAMEPAD_MASK_DOWN, ColorWhite }, + { GAMEPAD_MASK_LEFT, ColorWhite }, + { GAMEPAD_MASK_RIGHT, ColorWhite }, + { GAMEPAD_MASK_B1, ColorYellow }, + { GAMEPAD_MASK_B2, ColorRed }, + { GAMEPAD_MASK_B3, ColorGreen }, + { GAMEPAD_MASK_B4, ColorBlue }, + { GAMEPAD_MASK_R1, ColorSeafoam }, + { GAMEPAD_MASK_R2, ColorMagenta }, + { GAMEPAD_MASK_L1, ColorOrange }, + { GAMEPAD_MASK_L2, ColorAqua }, + } +); + +static StaticTheme themeXbox( + pixels, + { + { GAMEPAD_MASK_UP, ColorWhite }, + { GAMEPAD_MASK_DOWN, ColorWhite }, + { GAMEPAD_MASK_LEFT, ColorWhite }, + { GAMEPAD_MASK_RIGHT, ColorWhite }, + { GAMEPAD_MASK_B1, ColorGreen }, + { GAMEPAD_MASK_B2, ColorRed }, + { GAMEPAD_MASK_B3, ColorBlue }, + { GAMEPAD_MASK_B4, ColorYellow }, + { GAMEPAD_MASK_R1, ColorSeafoam }, + { GAMEPAD_MASK_R2, ColorMagenta }, + { GAMEPAD_MASK_L1, ColorOrange }, + { GAMEPAD_MASK_L2, ColorAqua }, + } +); + +static std::vector customThemes = { + themeStaticRainbow, + themeSuperFamicom, + themeXbox, + themeNeoGeo, + themeNeoGeoCurved, + themeNeoGeoModern, + themeSixButtonFighter, + themeSixButtonFighterPlus, + themeGuiltyGearTypeA, + themeGuiltyGearTypeD, + themeGuiltyGearCustom, +}; + +#endif diff --git a/include/definitions/DebugBoard.h b/include/definitions/DebugBoard.h index 2a1d4069..60f89a0a 100644 --- a/include/definitions/DebugBoard.h +++ b/include/definitions/DebugBoard.h @@ -6,7 +6,9 @@ #ifndef DEBUG_BOARD_H_ #define DEBUG_BOARD_H_ +#include #include +#include #include "Animation.hpp" /* Mapped to pins on Waveshare IPS panel w/4 button + HAT */ @@ -33,18 +35,19 @@ #define PIN_BUTTON_A1 28 #define PIN_BUTTON_A2 0 -#define LEDS_DPAD_UP 3 -#define LEDS_DPAD_DOWN 1 #define LEDS_DPAD_LEFT 0 +#define LEDS_DPAD_DOWN 1 #define LEDS_DPAD_RIGHT 2 -#define LEDS_BUTTON_01 8 -#define LEDS_BUTTON_02 9 +#define LEDS_DPAD_UP 3 #define LEDS_BUTTON_03 4 #define LEDS_BUTTON_04 5 -#define LEDS_BUTTON_05 7 #define LEDS_BUTTON_06 6 -#define LEDS_BUTTON_07 11 +#define LEDS_BUTTON_05 7 +#define LEDS_BUTTON_01 8 +#define LEDS_BUTTON_02 9 #define LEDS_BUTTON_08 10 +#define LEDS_BUTTON_07 11 + #define DEFAULT_SOCD_MODE SOCD_MODE_NEUTRAL #define BOARD_LEDS_PIN 22 @@ -52,4 +55,20 @@ #define LEDS_BASE_ANIMATION CHASE +const static std::vector pixels = +{ + { .index = LEDS_DPAD_LEFT, .mask = GAMEPAD_MASK_LEFT, .positions = { 0, 1, 2, 3 } }, + { .index = LEDS_DPAD_DOWN, .mask = GAMEPAD_MASK_DOWN, .positions = { 4, 5, 6, 7 } }, + { .index = LEDS_DPAD_RIGHT, .mask = GAMEPAD_MASK_RIGHT, .positions = { 8, 9, 10, 11 } }, + { .index = LEDS_DPAD_UP, .mask = GAMEPAD_MASK_UP, .positions = { 12, 13, 14, 15 } }, + { .index = LEDS_BUTTON_03, .mask = GAMEPAD_MASK_B3, .positions = { 16, 17, 18, 19} }, + { .index = LEDS_BUTTON_04, .mask = GAMEPAD_MASK_B4, .positions = { 20, 21, 22, 23 } }, + { .index = LEDS_BUTTON_06, .mask = GAMEPAD_MASK_R1, .positions = { 24, 25, 26, 27 } }, + { .index = LEDS_BUTTON_05, .mask = GAMEPAD_MASK_L1, .positions = { 28, 29, 30, 31 } }, + { .index = LEDS_BUTTON_01, .mask = GAMEPAD_MASK_B1, .positions = { 32, 33, 34, 35 } }, + { .index = LEDS_BUTTON_02, .mask = GAMEPAD_MASK_B2, .positions = { 36, 37, 38, 39 } }, + { .index = LEDS_BUTTON_08, .mask = GAMEPAD_MASK_R2, .positions = { 40, 41, 42, 43 } }, + { .index = LEDS_BUTTON_07, .mask = GAMEPAD_MASK_L2, .positions = { 44, 45, 46, 47 } }, +}; + #endif diff --git a/include/definitions/OpenStickBoard.h b/include/definitions/OpenStickBoard.h index 215046ee..387f876a 100644 --- a/include/definitions/OpenStickBoard.h +++ b/include/definitions/OpenStickBoard.h @@ -6,7 +6,10 @@ #ifndef OPEN_STICK_BOARD_H_ #define OPEN_STICK_BOARD_H_ +#include #include +#include +#include "Pixel.hpp" #define PIN_DPAD_UP 13 #define PIN_DPAD_DOWN 11 @@ -45,4 +48,20 @@ #define DEFAULT_SOCD_MODE SOCD_MODE_NEUTRAL +const static std::vector pixels = +{ + { .index = LEDS_DPAD_LEFT, .mask = GAMEPAD_MASK_LEFT, .positions = { LEDS_DPAD_LEFT } }, + { .index = LEDS_DPAD_DOWN, .mask = GAMEPAD_MASK_DOWN, .positions = { LEDS_DPAD_DOWN } }, + { .index = LEDS_DPAD_RIGHT, .mask = GAMEPAD_MASK_RIGHT, .positions = { LEDS_DPAD_RIGHT } }, + { .index = LEDS_DPAD_UP, .mask = GAMEPAD_MASK_UP, .positions = { LEDS_DPAD_UP } }, + { .index = LEDS_BUTTON_03, .mask = GAMEPAD_MASK_B3, .positions = { LEDS_BUTTON_03 } }, + { .index = LEDS_BUTTON_04, .mask = GAMEPAD_MASK_B4, .positions = { LEDS_BUTTON_04 } }, + { .index = LEDS_BUTTON_06, .mask = GAMEPAD_MASK_R1, .positions = { LEDS_BUTTON_06 } }, + { .index = LEDS_BUTTON_05, .mask = GAMEPAD_MASK_L1, .positions = { LEDS_BUTTON_05 } }, + { .index = LEDS_BUTTON_01, .mask = GAMEPAD_MASK_B1, .positions = { LEDS_BUTTON_01 } }, + { .index = LEDS_BUTTON_02, .mask = GAMEPAD_MASK_B2, .positions = { LEDS_BUTTON_02 } }, + { .index = LEDS_BUTTON_08, .mask = GAMEPAD_MASK_R2, .positions = { LEDS_BUTTON_08 } }, + { .index = LEDS_BUTTON_07, .mask = GAMEPAD_MASK_L2, .positions = { LEDS_BUTTON_07 } }, +}; + #endif diff --git a/lib/AnimationStation/.editorconfig b/lib/AnimationStation/.editorconfig new file mode 100644 index 00000000..ee7b59b8 --- /dev/null +++ b/lib/AnimationStation/.editorconfig @@ -0,0 +1,17 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = crlf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +indent_style = space +indent_size = 2 +trim_trailing_whitespace = false diff --git a/lib/AnimationStation/src/Animation.cpp b/lib/AnimationStation/src/Animation.cpp index 06623396..0d33c5d2 100644 --- a/lib/AnimationStation/src/Animation.cpp +++ b/lib/AnimationStation/src/Animation.cpp @@ -1,10 +1,8 @@ -#include -#include - #include "Animation.hpp" -int Animation::defaultFirstPixel = 0; -int Animation::defaultLastPixel = 0; +Animation::Animation(std::vector pixels) : pixels(pixels) { + this->totalLoops = 1; +} bool Animation::isComplete() { if (this->baseAnimation || this->currentLoop < this->totalLoops) { @@ -12,4 +10,4 @@ bool Animation::isComplete() { } return true; -} \ No newline at end of file +} diff --git a/lib/AnimationStation/src/Animation.hpp b/lib/AnimationStation/src/Animation.hpp index d9aa2c60..9b80fd12 100644 --- a/lib/AnimationStation/src/Animation.hpp +++ b/lib/AnimationStation/src/Animation.hpp @@ -2,36 +2,67 @@ #define _ANIMATION_H_ #include +#include +#include +#include +#include "Pixel.hpp" -typedef enum +struct RGB { - STATIC, - RAINBOW, - CHASE, -} AnimationMode; + RGB() + : r(0), g(0), b(0) { } + + RGB(uint8_t r, uint8_t g, uint8_t b) + : r(r), g(g), b(b) { } + + uint8_t r; + uint8_t g; + uint8_t b; + + inline static RGB wheel(uint8_t pos) { + pos = 255 - pos; + if (pos < 85) { + return RGB(255 - pos * 3, 0, pos * 3); + } else if (pos < 170) { + pos -= 85; + return RGB(0, pos * 3, 255 - pos * 3); + } else { + pos -= 170; + return RGB(pos * 3, 255 - pos * 3, 0); + } + } + + inline uint32_t value(float brightnessX = 1.0F) { + return ((uint32_t)(r * brightnessX) << 8) + | ((uint32_t)(g * brightnessX) << 16) + | (uint32_t)(b * brightnessX); + } + +}; + +static const RGB ColorBlack(0, 0, 0); +static const RGB ColorWhite(255, 255, 255); +static const RGB ColorRed(255, 0, 0); +static const RGB ColorOrange(255, 128, 0); +static const RGB ColorYellow(255, 255, 0); +static const RGB ColorLimeGreen(128, 255, 0); +static const RGB ColorGreen(0, 255, 0); +static const RGB ColorSeafoam(0, 255, 128); +static const RGB ColorAqua(0, 255, 255); +static const RGB ColorSkyBlue(0, 128, 255); +static const RGB ColorBlue(0, 0, 255); +static const RGB ColorPurple(128, 0, 255); +static const RGB ColorPink(255, 0, 255); +static const RGB ColorMagenta(255, 0, 128); class Animation { public: - Animation() { - this->firstPixel = Animation::defaultFirstPixel; - this->lastPixel = Animation::defaultLastPixel; - this->totalLoops = 1; - } - virtual void Animate(uint32_t (&frame)[100]); - AnimationMode mode; + Animation(std::vector pixels); + virtual void Animate(RGB (&frame)[100]) = 0; bool isComplete(); - - static void SetDefaultPixels(int firstPixel, int lastPixel) { - Animation::defaultFirstPixel = firstPixel; - Animation::defaultLastPixel = lastPixel; - } protected: - static int defaultFirstPixel; - static int defaultLastPixel; - - int firstPixel; - int lastPixel; + std::vector pixels; int currentLoop = 0; int totalLoops; bool baseAnimation = true; diff --git a/lib/AnimationStation/src/AnimationStation.cpp b/lib/AnimationStation/src/AnimationStation.cpp index 6c0b3835..274a599f 100644 --- a/lib/AnimationStation/src/AnimationStation.cpp +++ b/lib/AnimationStation/src/AnimationStation.cpp @@ -5,24 +5,27 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include -#include -#include -#include - #include "AnimationStation.hpp" -#include "Effects/Chase.hpp" -#include "Effects/Rainbow.hpp" -#include "Effects/StaticColor.hpp" uint8_t AnimationStation::brightness = 0; float AnimationStation::brightnessX = 0; absolute_time_t AnimationStation::nextAnimationChange = 0; absolute_time_t AnimationStation::nextBrightnessChange = 0; +StaticColor *staticColor; + +AnimationStation::AnimationStation(std::vector pixels) : pixels(pixels) { + AnimationStation::SetBrightness(1); -AnimationStation::AnimationStation(int numPixels) { - this->numPixels = numPixels; - AnimationStation::SetBrightness(1); + staticColor = new StaticColor(pixels, ColorWhite); + + animations.push_back(new StaticColor(pixels, ColorBlack)); + animations.push_back(staticColor); + animations.push_back(new Rainbow(pixels)); + animations.push_back(new Chase(pixels)); +} + +void AnimationStation::AddAnimation(Animation *animation) { + animations.push_back(animation); } void AnimationStation::HandleEvent(AnimationHotkey action) { @@ -35,11 +38,11 @@ void AnimationStation::HandleEvent(AnimationHotkey action) { } if (action == HOTKEY_LEDS_ANIMATION_UP) { - this->ChangeAnimation(); + ChangeAnimation(); } if (action == HOTKEY_LEDS_ANIMATION_DOWN) { - this->ChangeAnimation(); + ChangeAnimation(); } } @@ -48,59 +51,24 @@ void AnimationStation::ChangeAnimation() { return; } - if (this->animations.size() > 0) { - switch (this->animations.at(0)->mode) { - case STATIC: - this->animations.push_back(new Rainbow()); - break; - case RAINBOW: - this->animations.push_back(new Chase()); - break; - default: - this->animations.push_back(new StaticColor()); - break; - } - - this->animations.erase(this->animations.begin()); - } - + animationIndex = (animationIndex + 1) % animations.size(); AnimationStation::nextAnimationChange = make_timeout_time_ms(250); } -void AnimationStation::SetStaticColor() { - this->animations.push_back(new StaticColor()); -} - -void AnimationStation::SetRainbow() { - this->animations.push_back(new Rainbow()); -} - -void AnimationStation::SetChase() { this->animations.push_back(new Chase()); } - void AnimationStation::Animate() { - if (this->animations.size() == 0) { + if (animations.size() == 0) { this->Clear(); return; } - for (auto &element : this->animations) { - /* non-base animations (eg. button presses) only run - a certain number of times. before we animate, we need - to verify that it isn't already complete */ - - if (element->isComplete()) { - this->animations.erase(std::remove(this->animations.begin(), this->animations.end(), element), this->animations.end()); - } - else { - element->Animate(this->frame); - } + Animation *animation = animations[animationIndex]; + if (!animation->isComplete()) { + animation->Animate(frame); } } void AnimationStation::Clear() { - for (int i = 0; i < this->numPixels; ++i) { - frame[i] = 0; - } + memset(frame, 0, sizeof(frame)); } float AnimationStation::GetBrightnessX() { @@ -111,6 +79,19 @@ uint8_t AnimationStation::GetBrightness() { return AnimationStation::brightness; } +uint8_t AnimationStation::GetMode() { + return animationIndex; +} + +void AnimationStation::SetMode(uint8_t mode) { + animationIndex = mode; +} + +void AnimationStation::ApplyBrightness(uint32_t *frameValue) { + for (int i = 0; i < 100; i++) + frameValue[i] = this->frame[i].value(brightnessX); +} + void AnimationStation::SetBrightness(uint8_t brightness) { AnimationStation::brightness = (brightness > BRIGHTNESS_STEPS) ? BRIGHTNESS_STEPS : brightness; AnimationStation::brightnessX = (AnimationStation::brightness * BRIGHTNESS_STEP_SIZE) / 255.0F; @@ -121,6 +102,10 @@ void AnimationStation::SetBrightness(uint8_t brightness) { AnimationStation::brightnessX = 0; } +void AnimationStation::SetStaticColor(RGB color) { + staticColor->SetColor(color); +} + void AnimationStation::DecreaseBrightness() { if (!time_reached(AnimationStation::nextBrightnessChange)) return; @@ -142,22 +127,3 @@ void AnimationStation::IncreaseBrightness() { AnimationStation::nextBrightnessChange = make_timeout_time_ms(250); } - -uint32_t AnimationStation::RGB(uint8_t r, uint8_t g, uint8_t b) { - return ((uint32_t)(r * brightnessX) << 8) | - ((uint32_t)(g * brightnessX) << 16) | - (uint32_t)(b * brightnessX); -} - -uint32_t AnimationStation::Wheel(uint8_t pos) { - pos = 255 - pos; - if (pos < 85) { - return AnimationStation::RGB(255 - pos * 3, 0, pos * 3); - } else if (pos < 170) { - pos -= 85; - return AnimationStation::RGB(0, pos * 3, 255 - pos * 3); - } else { - pos -= 170; - return AnimationStation::RGB(pos * 3, 255 - pos * 3, 0); - } -} diff --git a/lib/AnimationStation/src/AnimationStation.hpp b/lib/AnimationStation/src/AnimationStation.hpp index c06e8162..27279145 100644 --- a/lib/AnimationStation/src/AnimationStation.hpp +++ b/lib/AnimationStation/src/AnimationStation.hpp @@ -1,12 +1,19 @@ #ifndef _ANIMATION_STATION_H_ #define _ANIMATION_STATION_H_ +#include +#include #include #include #include #include "hardware/clocks.h" +#include "NeoPico.hpp" #include "Animation.hpp" +#include "Effects/Chase.hpp" +#include "Effects/Rainbow.hpp" +#include "Effects/StaticColor.hpp" +#include "Effects/StaticTheme.hpp" #define BRIGHTNESS_MAXIMUM 100 #define BRIGHTNESS_STEPS 5 @@ -26,35 +33,34 @@ typedef enum class AnimationStation { public: - AnimationStation(int numPixels); + AnimationStation(std::vector pixels); void Animate(); + void AddAnimation(Animation *animation); void HandleEvent(AnimationHotkey action); - void SetStaticColor(); - void SetRainbow(); - void SetChase(); + void SetStaticColor(RGB color); void Clear(); void ChangeAnimation(); + void ApplyBrightness(uint32_t *frameValue); + uint8_t GetMode(); + void SetMode(uint8_t mode); static float GetBrightnessX(); static uint8_t GetBrightness(); static void SetBrightness(uint8_t brightness); static void DecreaseBrightness(); static void IncreaseBrightness(); - static uint32_t RGB(uint8_t r, uint8_t g, uint8_t b); - static uint32_t Wheel(uint8_t pos); std::vector animations; static absolute_time_t nextAnimationChange; static absolute_time_t nextBrightnessChange; - uint32_t frame[100]; + RGB frame[100]; protected: static uint8_t brightness; static float brightnessX; - -private: - int numPixels = 0; + uint8_t animationIndex = 0; + std::vector pixels; }; #endif diff --git a/lib/AnimationStation/src/AnimationStorage.hpp b/lib/AnimationStation/src/AnimationStorage.hpp index 1653c4d7..38393e03 100644 --- a/lib/AnimationStation/src/AnimationStorage.hpp +++ b/lib/AnimationStation/src/AnimationStorage.hpp @@ -3,18 +3,19 @@ #include "Animation.hpp" #include "AnimationStation.hpp" -#include "Effects/StaticColor.hpp" class AnimationStorage { - public: - void setup(); - void save(AnimationStation as); + public: + void setup(AnimationStation *as); + void save(); - AnimationMode getBaseAnimation(); - void setBaseAnimation(AnimationMode mode); - uint8_t getBrightness(); - void setBrightness(uint8_t brightness); + uint8_t getMode(); + void setMode(uint8_t mode); + uint8_t getBrightness(); + void setBrightness(uint8_t brightness); + protected: + AnimationStation *as; }; static AnimationStorage AnimationStore; diff --git a/lib/AnimationStation/src/Effects/Chase.cpp b/lib/AnimationStation/src/Effects/Chase.cpp index 38ffbba2..97a31270 100644 --- a/lib/AnimationStation/src/Effects/Chase.cpp +++ b/lib/AnimationStation/src/Effects/Chase.cpp @@ -2,23 +2,32 @@ int Chase::defaultCycleTime = 85; -void Chase::Animate(uint32_t (&frame)[100]) { +Chase::Chase(std::vector pixels) : Animation(pixels) { + this->cycleTime = Chase::defaultCycleTime; +} + +void Chase::Animate(RGB (&frame)[100]) { if (!time_reached(this->nextRunTime)) { return; } - for (int i = this->firstPixel; i < this->lastPixel + 1; ++i) { - if (this->IsChasePixel(i)) { - frame[i] = AnimationStation::Wheel(this->WheelFrame(i)); + for (size_t i = 0; i != pixels.size(); i++) { + if (this->IsChasePixel(pixels[i].index)) { + RGB color = RGB::wheel(this->WheelFrame(i)); + for (size_t j = 0; j != pixels[i].positions.size(); j++) { + frame[pixels[i].positions[j]] = color; + } } else { - frame[i] = 0; + for (size_t j = 0; j != pixels[i].positions.size(); j++) { + frame[pixels[i].positions[j]] = ColorBlack; + } } } currentPixel++; - if (currentPixel > this->lastPixel) { - currentPixel = this->firstPixel; + if (currentPixel > pixels.size() - 1) { + currentPixel = 0; } if (reverse) { @@ -43,8 +52,8 @@ void Chase::Animate(uint32_t (&frame)[100]) { } bool Chase::IsChasePixel(int i) { - if (i == this->currentPixel || i == (this->currentPixel - 1) % this->totalPixels || i == (this->currentPixel - 2) % this->totalPixels) { - return true; + if (i == this->currentPixel || i == (this->currentPixel - 1) || i == (this->currentPixel - 2)) { + return true; } return false; @@ -53,7 +62,7 @@ bool Chase::IsChasePixel(int i) { int Chase::WheelFrame(int i) { int frame = this->currentFrame; - if (i == (this->currentPixel - 1) % totalPixels) { + if (i == (this->currentPixel - 1) % pixels.size()) { if (this->reverse) { frame = frame + 16; } @@ -61,8 +70,8 @@ int Chase::WheelFrame(int i) { frame = frame - 16; } } - - if (i == (this->currentPixel - 2) % totalPixels) { + + if (i == (this->currentPixel - 2) % pixels.size()) { if (this->reverse) { frame = frame + 32; } @@ -76,4 +85,4 @@ int Chase::WheelFrame(int i) { } return frame; -} \ No newline at end of file +} diff --git a/lib/AnimationStation/src/Effects/Chase.hpp b/lib/AnimationStation/src/Effects/Chase.hpp index 33e356f9..8ed260a6 100644 --- a/lib/AnimationStation/src/Effects/Chase.hpp +++ b/lib/AnimationStation/src/Effects/Chase.hpp @@ -1,21 +1,17 @@ #ifndef _CHASE_H_ #define _CHASE_H_ +#include #include #include #include "../Animation.hpp" -#include "../AnimationStation.hpp" #include "hardware/clocks.h" class Chase : public Animation { public: - Chase() : Animation() { - this->cycleTime = Chase::defaultCycleTime; - this->currentPixel = this->firstPixel; - this->totalPixels = this->lastPixel - this->firstPixel + 1; - this->mode = CHASE; - } - void Animate(uint32_t (&frame)[100]); + Chase(std::vector pixels); + + void Animate(RGB (&frame)[100]); static void SetDefaultCycleTime(int cycleTime) { Chase::defaultCycleTime = cycleTime; @@ -28,9 +24,8 @@ class Chase : public Animation { int cycleTime; int currentFrame = 0; int currentPixel = 0; - int totalPixels; bool reverse = false; absolute_time_t nextRunTime = 0; }; -#endif \ No newline at end of file +#endif diff --git a/lib/AnimationStation/src/Effects/Rainbow.cpp b/lib/AnimationStation/src/Effects/Rainbow.cpp index 21acbb66..4d37d2c3 100644 --- a/lib/AnimationStation/src/Effects/Rainbow.cpp +++ b/lib/AnimationStation/src/Effects/Rainbow.cpp @@ -1,17 +1,21 @@ -#include -#include - #include "Rainbow.hpp" int Rainbow::defaultCycleTime = 40; -void Rainbow::Animate(uint32_t (&frame)[100]) { +Rainbow::Rainbow(std::vector pixels) : Animation(pixels) { + this->cycleTime = Rainbow::defaultCycleTime; +} + +void Rainbow::Animate(RGB (&frame)[100]) { if (!time_reached(this->nextRunTime)) { return; } - for (int i = this->firstPixel; i < this->lastPixel + 1; ++i) { - frame[i] = AnimationStation::Wheel(this->currentFrame); + for (size_t i = 0; i != pixels.size(); i++) { + RGB color = RGB::wheel(this->currentFrame); + for (size_t j = 0; j != pixels[i].positions.size(); j++) { + frame[pixels[i].positions[j]] = color; + } } if (reverse) { diff --git a/lib/AnimationStation/src/Effects/Rainbow.hpp b/lib/AnimationStation/src/Effects/Rainbow.hpp index 8308de62..4f4cc92a 100644 --- a/lib/AnimationStation/src/Effects/Rainbow.hpp +++ b/lib/AnimationStation/src/Effects/Rainbow.hpp @@ -1,19 +1,17 @@ #ifndef _RAINBOW_H_ #define _RAINBOW_H_ +#include #include #include #include "../Animation.hpp" -#include "../AnimationStation.hpp" #include "hardware/clocks.h" class Rainbow : public Animation { public: - Rainbow() : Animation() { - this->cycleTime = Rainbow::defaultCycleTime; - this->mode = RAINBOW; - } - void Animate(uint32_t (&frame)[100]); + Rainbow(std::vector pixels); + + void Animate(RGB (&frame)[100]); static void SetDefaultCycleTime(int cycleTime) { Rainbow::defaultCycleTime = cycleTime; @@ -26,4 +24,4 @@ class Rainbow : public Animation { absolute_time_t nextRunTime = 0; }; -#endif \ No newline at end of file +#endif diff --git a/lib/AnimationStation/src/Effects/StaticColor.cpp b/lib/AnimationStation/src/Effects/StaticColor.cpp index 8c412d25..eb1da758 100644 --- a/lib/AnimationStation/src/Effects/StaticColor.cpp +++ b/lib/AnimationStation/src/Effects/StaticColor.cpp @@ -1,13 +1,13 @@ -#include -#include - #include "StaticColor.hpp" -uint32_t StaticColor::defaultColor = 255; +StaticColor::StaticColor(std::vector pixels, RGB color) : Animation(pixels), color(color) { + +} -void StaticColor::Animate(uint32_t (&frame)[100]) { - float brightness = AnimationStation::GetBrightnessX(); - for (int i = this->firstPixel; i < this->lastPixel + 1; ++i) { - frame[i] = this->color * brightness; +void StaticColor::Animate(RGB (&frame)[100]) { + for (size_t i = 0; i != pixels.size(); i++) { + for (size_t j = 0; j != pixels[i].positions.size(); j++) { + frame[pixels[i].positions[j]] = color; + } } } diff --git a/lib/AnimationStation/src/Effects/StaticColor.hpp b/lib/AnimationStation/src/Effects/StaticColor.hpp index 06aa6e34..b1a7bd2e 100644 --- a/lib/AnimationStation/src/Effects/StaticColor.hpp +++ b/lib/AnimationStation/src/Effects/StaticColor.hpp @@ -1,24 +1,22 @@ #ifndef _STATIC_COLOR_H_ #define _STATIC_COLOR_H_ +#include +#include +#include #include "../Animation.hpp" -#include "../AnimationStation.hpp" class StaticColor : public Animation { public: - StaticColor() : Animation() { - this->color = StaticColor::defaultColor; - this->mode = STATIC; - } + StaticColor(std::vector pixels, RGB color); - void Animate(uint32_t (&frame)[100]); + void Animate(RGB (&frame)[100]); - static void SetDefaultColor(uint32_t color) { - StaticColor::defaultColor = color; + void SetColor(RGB color) { + this->color = color; } protected: - static uint32_t defaultColor; - uint32_t color; + RGB color; }; -#endif \ No newline at end of file +#endif diff --git a/lib/AnimationStation/src/Effects/StaticTheme.cpp b/lib/AnimationStation/src/Effects/StaticTheme.cpp new file mode 100644 index 00000000..1fdbc6f0 --- /dev/null +++ b/lib/AnimationStation/src/Effects/StaticTheme.cpp @@ -0,0 +1,22 @@ +#include "StaticTheme.hpp" + +StaticTheme::StaticTheme(std::vector pixels, std::map theme, RGB defaultColor) + : Animation(pixels), theme(theme), defaultColor(defaultColor) { } + +void StaticTheme::Animate(RGB (&frame)[100]) { + for (size_t i = 0; i != pixels.size(); i++) { + bool found = false; + + auto itr = theme.find(pixels[i].mask); + if (itr != theme.end()) { + for (size_t j = 0; j != pixels[i].positions.size(); j++) { + frame[pixels[i].positions[j]] = itr->second; + } + } + else { + for (size_t j = 0; j != pixels[i].positions.size(); j++) { + frame[pixels[i].positions[j]] = defaultColor; + } + } + } +} diff --git a/lib/AnimationStation/src/Effects/StaticTheme.hpp b/lib/AnimationStation/src/Effects/StaticTheme.hpp new file mode 100644 index 00000000..a5981942 --- /dev/null +++ b/lib/AnimationStation/src/Effects/StaticTheme.hpp @@ -0,0 +1,22 @@ +#ifndef STATIC_THEME_H_ +#define STATIC_THEME_H_ + +#include +#include +#include +#include +#include +#include +#include "../Animation.hpp" + +class StaticTheme : public Animation { +public: + StaticTheme(std::vector pixels, std::map theme, RGB defaultColor = ColorBlack); + + void Animate(RGB (&frame)[100]); + std::map theme; +protected: + RGB defaultColor; +}; + +#endif diff --git a/lib/AnimationStation/src/Pixel.hpp b/lib/AnimationStation/src/Pixel.hpp new file mode 100644 index 00000000..98edcaf9 --- /dev/null +++ b/lib/AnimationStation/src/Pixel.hpp @@ -0,0 +1,19 @@ +#ifndef PIXEL_HPP_ +#define PIXEL_HPP_ + +struct Pixel { + uint8_t index; // The pixel index + uint32_t mask; // Used to detect per-pixel lighting + std::vector positions; // The actual LED indexes on the chain + + static uint16_t getPixelCount(std::vector pixels) { + uint16_t count = 0; + for (int i = 0; i != pixels.size(); i++) + count += pixels[i].positions.size(); + + return count; + } +}; + + +#endif diff --git a/lib/NeoPico/.editorconfig b/lib/NeoPico/.editorconfig new file mode 100644 index 00000000..ee7b59b8 --- /dev/null +++ b/lib/NeoPico/.editorconfig @@ -0,0 +1,17 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = crlf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +indent_style = space +indent_size = 2 +trim_trailing_whitespace = false diff --git a/lib/NeoPico/src/NeoPico.cpp b/lib/NeoPico/src/NeoPico.cpp index 105daf44..18b3c4eb 100644 --- a/lib/NeoPico/src/NeoPico.cpp +++ b/lib/NeoPico/src/NeoPico.cpp @@ -15,22 +15,27 @@ #include "NeoPico.hpp" void NeoPico::PutPixel(uint32_t pixel_grb) { - pio_sm_put_blocking(pio0, 0, pixel_grb << 8u); + pio_sm_put_blocking(pio0, 0, pixel_grb << 8u); } -NeoPico::NeoPico(int ledPin, int numPixels) { - PIO pio = pio0; - int sm = 0; - this->numPixels = numPixels; - uint offset = pio_add_program(pio, &ws2812_program); - ws2812_program_init(pio, sm, offset, ledPin, 800000, false); - this->Clear(); - sleep_ms(10); +NeoPico::NeoPico(int ledPin, int numPixels) : numPixels(numPixels) { + PIO pio = pio0; + int sm = 0; + uint offset = pio_add_program(pio, &ws2812_program); + ws2812_program_init(pio, sm, offset, ledPin, 800000, false); + this->Clear(); + sleep_ms(10); } -void NeoPico::SetPixel(int pixel, uint32_t color) { - this->frame[pixel] = color; -} +// void NeoPico::SetPixel(int pixel, uint32_t color) { +// if (pixels.size() > 0) { +// for (size_t i = 0; i != pixels[pixel].positions.size(); i++) { +// this->frame[pixels[pixel].positions[i]] = color; +// } +// } else { +// this->frame[pixel] = color; +// } +// } void NeoPico::Clear() { memset(frame, 0, sizeof(frame)); diff --git a/lib/NeoPico/src/NeoPico.hpp b/lib/NeoPico/src/NeoPico.hpp index e727b648..83073c29 100644 --- a/lib/NeoPico/src/NeoPico.hpp +++ b/lib/NeoPico/src/NeoPico.hpp @@ -1,7 +1,8 @@ #ifndef _NEO_PICO_H_ -#define _NEO_PICO_H_ +#define _NEO_PICO_H_ #include "ws2812.pio.h" +#include class NeoPico { @@ -9,7 +10,7 @@ class NeoPico NeoPico(int ledPin, int numPixels); void Show(); void Clear(); - void SetPixel(int pixel, uint32_t color); + // void SetPixel(int pixel, uint32_t color); void SetFrame(uint32_t newFrame[100]); private: void PutPixel(uint32_t pixel_grb); @@ -18,5 +19,4 @@ class NeoPico uint32_t frame[100]; }; - -#endif \ No newline at end of file +#endif diff --git a/src/gamepad.cpp b/src/gamepad.cpp index a2c95118..46131cb6 100644 --- a/src/gamepad.cpp +++ b/src/gamepad.cpp @@ -8,34 +8,32 @@ #include "pico/stdlib.h" #include "BoardConfig.h" -#include "LEDConfig.h" struct GamepadButtonMapping { const uint8_t pin; const uint32_t pinMask; const uint32_t buttonMask; - const int8_t ledPos; }; -GamepadButtonMapping mapDpadUp = { .pin = PIN_DPAD_UP, .pinMask = (1 << PIN_DPAD_UP), .buttonMask = GAMEPAD_MASK_UP, .ledPos = LEDS_DPAD_UP }; -GamepadButtonMapping mapDpadDown = { .pin = PIN_DPAD_DOWN, .pinMask = (1 << PIN_DPAD_DOWN), .buttonMask = GAMEPAD_MASK_DOWN, .ledPos = LEDS_DPAD_DOWN }; -GamepadButtonMapping mapDpadLeft = { .pin = PIN_DPAD_LEFT, .pinMask = (1 << PIN_DPAD_LEFT), .buttonMask = GAMEPAD_MASK_LEFT, .ledPos = LEDS_DPAD_LEFT }; -GamepadButtonMapping mapDpadRight = { .pin = PIN_DPAD_RIGHT, .pinMask = (1 << PIN_DPAD_RIGHT), .buttonMask = GAMEPAD_MASK_RIGHT, .ledPos = LEDS_DPAD_RIGHT }; -GamepadButtonMapping mapButtonB1 = { .pin = PIN_BUTTON_B1, .pinMask = (1 << PIN_BUTTON_B1), .buttonMask = GAMEPAD_MASK_B1, .ledPos = LEDS_BUTTON_01 }; -GamepadButtonMapping mapButtonB2 = { .pin = PIN_BUTTON_B2, .pinMask = (1 << PIN_BUTTON_B2), .buttonMask = GAMEPAD_MASK_B2, .ledPos = LEDS_BUTTON_02 }; -GamepadButtonMapping mapButtonB3 = { .pin = PIN_BUTTON_B3, .pinMask = (1 << PIN_BUTTON_B3), .buttonMask = GAMEPAD_MASK_B3, .ledPos = LEDS_BUTTON_03 }; -GamepadButtonMapping mapButtonB4 = { .pin = PIN_BUTTON_B4, .pinMask = (1 << PIN_BUTTON_B4), .buttonMask = GAMEPAD_MASK_B4, .ledPos = LEDS_BUTTON_04 }; -GamepadButtonMapping mapButtonL1 = { .pin = PIN_BUTTON_L1, .pinMask = (1 << PIN_BUTTON_L1), .buttonMask = GAMEPAD_MASK_L1, .ledPos = LEDS_BUTTON_05 }; -GamepadButtonMapping mapButtonR1 = { .pin = PIN_BUTTON_R1, .pinMask = (1 << PIN_BUTTON_R1), .buttonMask = GAMEPAD_MASK_R1, .ledPos = LEDS_BUTTON_06 }; -GamepadButtonMapping mapButtonL2 = { .pin = PIN_BUTTON_L2, .pinMask = (1 << PIN_BUTTON_L2), .buttonMask = GAMEPAD_MASK_L2, .ledPos = LEDS_BUTTON_07 }; -GamepadButtonMapping mapButtonR2 = { .pin = PIN_BUTTON_R2, .pinMask = (1 << PIN_BUTTON_R2), .buttonMask = GAMEPAD_MASK_R2, .ledPos = LEDS_BUTTON_08 }; -GamepadButtonMapping mapButtonS1 = { .pin = PIN_BUTTON_S1, .pinMask = (1 << PIN_BUTTON_S1), .buttonMask = GAMEPAD_MASK_S1, .ledPos = LEDS_BUTTON_09 }; -GamepadButtonMapping mapButtonS2 = { .pin = PIN_BUTTON_S2, .pinMask = (1 << PIN_BUTTON_S2), .buttonMask = GAMEPAD_MASK_S2, .ledPos = LEDS_BUTTON_10 }; -GamepadButtonMapping mapButtonL3 = { .pin = PIN_BUTTON_L3, .pinMask = (1 << PIN_BUTTON_L3), .buttonMask = GAMEPAD_MASK_L3, .ledPos = LEDS_BUTTON_11 }; -GamepadButtonMapping mapButtonR3 = { .pin = PIN_BUTTON_R3, .pinMask = (1 << PIN_BUTTON_R3), .buttonMask = GAMEPAD_MASK_R3, .ledPos = LEDS_BUTTON_12 }; -GamepadButtonMapping mapButtonA1 = { .pin = PIN_BUTTON_A1, .pinMask = (1 << PIN_BUTTON_A1), .buttonMask = GAMEPAD_MASK_A1, .ledPos = LEDS_BUTTON_13 }; -GamepadButtonMapping mapButtonA2 = { .pin = PIN_BUTTON_A2, .pinMask = (1 << PIN_BUTTON_A2), .buttonMask = GAMEPAD_MASK_A2, .ledPos = LEDS_BUTTON_14 }; +GamepadButtonMapping mapDpadUp = { .pin = PIN_DPAD_UP, .pinMask = (1 << PIN_DPAD_UP), .buttonMask = GAMEPAD_MASK_UP }; +GamepadButtonMapping mapDpadDown = { .pin = PIN_DPAD_DOWN, .pinMask = (1 << PIN_DPAD_DOWN), .buttonMask = GAMEPAD_MASK_DOWN }; +GamepadButtonMapping mapDpadLeft = { .pin = PIN_DPAD_LEFT, .pinMask = (1 << PIN_DPAD_LEFT), .buttonMask = GAMEPAD_MASK_LEFT }; +GamepadButtonMapping mapDpadRight = { .pin = PIN_DPAD_RIGHT, .pinMask = (1 << PIN_DPAD_RIGHT), .buttonMask = GAMEPAD_MASK_RIGHT }; +GamepadButtonMapping mapButtonB1 = { .pin = PIN_BUTTON_B1, .pinMask = (1 << PIN_BUTTON_B1), .buttonMask = GAMEPAD_MASK_B1 }; +GamepadButtonMapping mapButtonB2 = { .pin = PIN_BUTTON_B2, .pinMask = (1 << PIN_BUTTON_B2), .buttonMask = GAMEPAD_MASK_B2 }; +GamepadButtonMapping mapButtonB3 = { .pin = PIN_BUTTON_B3, .pinMask = (1 << PIN_BUTTON_B3), .buttonMask = GAMEPAD_MASK_B3 }; +GamepadButtonMapping mapButtonB4 = { .pin = PIN_BUTTON_B4, .pinMask = (1 << PIN_BUTTON_B4), .buttonMask = GAMEPAD_MASK_B4 }; +GamepadButtonMapping mapButtonL1 = { .pin = PIN_BUTTON_L1, .pinMask = (1 << PIN_BUTTON_L1), .buttonMask = GAMEPAD_MASK_L1 }; +GamepadButtonMapping mapButtonR1 = { .pin = PIN_BUTTON_R1, .pinMask = (1 << PIN_BUTTON_R1), .buttonMask = GAMEPAD_MASK_R1 }; +GamepadButtonMapping mapButtonL2 = { .pin = PIN_BUTTON_L2, .pinMask = (1 << PIN_BUTTON_L2), .buttonMask = GAMEPAD_MASK_L2 }; +GamepadButtonMapping mapButtonR2 = { .pin = PIN_BUTTON_R2, .pinMask = (1 << PIN_BUTTON_R2), .buttonMask = GAMEPAD_MASK_R2 }; +GamepadButtonMapping mapButtonS1 = { .pin = PIN_BUTTON_S1, .pinMask = (1 << PIN_BUTTON_S1), .buttonMask = GAMEPAD_MASK_S1 }; +GamepadButtonMapping mapButtonS2 = { .pin = PIN_BUTTON_S2, .pinMask = (1 << PIN_BUTTON_S2), .buttonMask = GAMEPAD_MASK_S2 }; +GamepadButtonMapping mapButtonL3 = { .pin = PIN_BUTTON_L3, .pinMask = (1 << PIN_BUTTON_L3), .buttonMask = GAMEPAD_MASK_L3 }; +GamepadButtonMapping mapButtonR3 = { .pin = PIN_BUTTON_R3, .pinMask = (1 << PIN_BUTTON_R3), .buttonMask = GAMEPAD_MASK_R3 }; +GamepadButtonMapping mapButtonA1 = { .pin = PIN_BUTTON_A1, .pinMask = (1 << PIN_BUTTON_A1), .buttonMask = GAMEPAD_MASK_A1 }; +GamepadButtonMapping mapButtonA2 = { .pin = PIN_BUTTON_A2, .pinMask = (1 << PIN_BUTTON_A2), .buttonMask = GAMEPAD_MASK_A2 }; uint32_t GamepadDebouncer::getMillis() { return to_ms_since_boot(get_absolute_time()); } diff --git a/src/main.cpp b/src/main.cpp index 9792077d..d692b77f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,16 +14,16 @@ #include "NeoPico.hpp" #include "AnimationStation.hpp" #include "AnimationStorage.hpp" +#include "Pixel.hpp" #include "usb_driver.h" #include "BoardConfig.h" -#include "LEDConfig.h" MPGS gamepad(GAMEPAD_DEBOUNCE_MILLIS); #ifdef BOARD_LEDS_PIN -NeoPico leds(BOARD_LEDS_PIN, BOARD_LEDS_COUNT); -AnimationStation as(BOARD_LEDS_COUNT); +NeoPico leds(BOARD_LEDS_PIN, Pixel::getPixelCount(pixels)); +AnimationStation as(pixels); queue_t animationQueue; #endif @@ -104,31 +104,16 @@ void loop() void core1() { - static const uint32_t intervalMS = 20; + static const uint32_t intervalMS = 10; static uint32_t nextRuntime = 0; multicore_lockout_victim_init(); #ifdef BOARD_LEDS_PIN static AnimationHotkey action; + static uint32_t frame[100]; - AnimationStore.setup(); - - AnimationMode mode = AnimationStore.getBaseAnimation(); - switch (mode) - { - case RAINBOW: - as.SetRainbow(); - break; - - case CHASE: - as.SetChase(); - break; - - default: - as.SetStaticColor(); - break; - } + AnimationStore.setup(&as); #endif while (1) @@ -141,11 +126,12 @@ void core1() { queue_remove_blocking(&animationQueue, &action); as.HandleEvent(action); - AnimationStore.save(as); + AnimationStore.save(); } as.Animate(); - leds.SetFrame(as.frame); + as.ApplyBrightness(frame); + leds.SetFrame(frame); leds.Show(); #endif diff --git a/src/storage.cpp b/src/storage.cpp index 2a54cebe..c427c003 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -5,11 +5,7 @@ #include #include "FlashPROM.h" -#include "AnimationStorage.hpp" -#include "LEDConfig.h" - -#define STORAGE_LEDS_BRIGHTNESS_INDEX (STORAGE_FIRST_AVAILBLE_INDEX) // 1 byte -#define STORAGE_LEDS_BASE_ANIMATION_MODE_INDEX (STORAGE_FIRST_AVAILBLE_INDEX + 1) // 4 bytes +#include "BoardConfig.h" static void getStorageValue(int index, void *data, uint16_t size) { @@ -52,16 +48,24 @@ void GamepadStorage::set(int index, void *data, uint16_t size) /* Animation stuffs */ -AnimationMode AnimationStorage::getBaseAnimation() +#ifdef BOARD_LEDS_PIN + +#include "AnimationStorage.hpp" +#include "AnimationStation/src/Effects/StaticColor.hpp" + +#define STORAGE_LEDS_BRIGHTNESS_INDEX (STORAGE_FIRST_AVAILBLE_INDEX) // 1 byte +#define STORAGE_LEDS_BASE_ANIMATION_MODE_INDEX (STORAGE_FIRST_AVAILBLE_INDEX + 1) // 1 byte + +uint8_t AnimationStorage::getMode() { - AnimationMode mode = RAINBOW; - getStorageValue(STORAGE_LEDS_BASE_ANIMATION_MODE_INDEX, &mode, sizeof(AnimationMode)); + uint8_t mode = 0; + getStorageValue(STORAGE_LEDS_BASE_ANIMATION_MODE_INDEX, &mode, sizeof(uint8_t)); return mode; } -void AnimationStorage::setBaseAnimation(AnimationMode mode) +void AnimationStorage::setMode(uint8_t mode) { - setStorageValue(STORAGE_LEDS_BASE_ANIMATION_MODE_INDEX, &mode, sizeof(AnimationMode)); + setStorageValue(STORAGE_LEDS_BASE_ANIMATION_MODE_INDEX, &mode, sizeof(uint8_t)); } uint8_t AnimationStorage::getBrightness() @@ -76,30 +80,34 @@ void AnimationStorage::setBrightness(uint8_t brightness) setStorageValue(STORAGE_LEDS_BRIGHTNESS_INDEX, &brightness, sizeof(uint8_t)); } -void AnimationStorage::setup() +void AnimationStorage::setup(AnimationStation *as) { + this->as = as; AnimationStation::SetBrightness(this->getBrightness()); - Animation::SetDefaultPixels(LEDS_BASE_ANIMATION_FIRST_PIXEL, LEDS_BASE_ANIMATION_LAST_PIXEL); - StaticColor::SetDefaultColor(LEDS_STATIC_COLOR_COLOR); + as->SetMode(getMode()); + configureAnimations(as); } -void AnimationStorage::save(AnimationStation as) +void AnimationStorage::save() { bool dirty = false; - uint8_t brightness = as.GetBrightness(); + uint8_t brightness = as->GetBrightness(); if (brightness != getBrightness()) { setBrightness(brightness); dirty = true; } - if (as.animations.size() > 0 && as.animations.at(0)->mode != getBaseAnimation()) + uint8_t mode = as->GetMode(); + if (mode != getMode()) { - setBaseAnimation(as.animations.at(0)->mode); + setMode(mode); dirty = true; } if (dirty) EEPROM.commit(); } + +#endif