Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
LED Refactor (#12)
Browse files Browse the repository at this point in the history
* Support arbitrary number of LEDs per pixel

* Rework colors, add first rev theme

* Move color stuff into Animation

* Move Pixel into AS (removes NeoPico dep)

* Prep for rename, pt1

* Rename pt2

* Add StaticTheme, make animation selection flexible

* Fix saving LED mode

* Fix Chase

* Fix static color

* Fix builds for boards without LEDs

* Bump up dev board to 4 LEDs per pixel

* Add off LED option

* Name things better

* Rework static theme config

* Add themes
  • Loading branch information
FeralAI authored Sep 14, 2021
1 parent 78b2503 commit 6ddfd4e
Show file tree
Hide file tree
Showing 26 changed files with 651 additions and 298 deletions.
5 changes: 5 additions & 0 deletions include/BoardConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef BOARD_CONFIG_H_
#define BOARD_CONFIG_H_

#include <vector>

#define DEBUG_BOARD 0
#define PICO_BOARD 1
#define OPEN_STICK_BOARD 2
Expand All @@ -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
94 changes: 52 additions & 42 deletions include/LEDConfig.h
Original file line number Diff line number Diff line change
@@ -1,46 +1,7 @@
#include <vector>
#include <MPG.h>
#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
Expand Down Expand Up @@ -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<Pixel> 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;
}
200 changes: 200 additions & 0 deletions include/LEDThemes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
#ifndef LED_THEMES_H_
#define LED_THEMES_H_

#include <vector>
#include <MPG.h>
#include "AnimationStation.hpp"

extern const std::vector<Pixel> 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<StaticTheme> customThemes = {
themeStaticRainbow,
themeSuperFamicom,
themeXbox,
themeNeoGeo,
themeNeoGeoCurved,
themeNeoGeoModern,
themeSixButtonFighter,
themeSixButtonFighterPlus,
themeGuiltyGearTypeA,
themeGuiltyGearTypeD,
themeGuiltyGearCustom,
};

#endif
31 changes: 25 additions & 6 deletions include/definitions/DebugBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#ifndef DEBUG_BOARD_H_
#define DEBUG_BOARD_H_

#include <vector>
#include <GamepadEnums.h>
#include <GamepadState.h>
#include "Animation.hpp"

/* Mapped to pins on Waveshare IPS panel w/4 button + HAT */
Expand All @@ -33,23 +35,40 @@
#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
#define BOARD_LEDS_COUNT 16

#define LEDS_BASE_ANIMATION CHASE

const static std::vector<Pixel> 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
Loading

0 comments on commit 6ddfd4e

Please sign in to comment.