Skip to content

Commit

Permalink
Add sweep dance
Browse files Browse the repository at this point in the history
  • Loading branch information
AEFeinstein committed Oct 27, 2024
1 parent 19bc0d5 commit 90673f6
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
101 changes: 101 additions & 0 deletions main/modes/utilities/dance/dance.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ const ledDanceArg ledDances[] = {
{.func = danceCondiment, .arg = RGB_2_ARG(0xFF, 0xFF, 0x00), .name = "Mustard"},
{.func = danceCondiment, .arg = RGB_2_ARG(0x00, 0xFF, 0x00), .name = "Relish"},
{.func = danceCondiment, .arg = RGB_2_ARG(0xFF, 0xFF, 0xFF), .name = "Mayo"},
{.func = danceSweep, .arg = RGB_2_ARG(0, 0, 0), .name = "Sweep RGB"},
{.func = danceSweep, .arg = RGB_2_ARG(0xFF, 0, 0), .name = "Sweep R"},
{.func = danceSweep, .arg = RGB_2_ARG(0, 0xFF, 0), .name = "Sweep G"},
{.func = danceSweep, .arg = RGB_2_ARG(0, 0, 0xFF), .name = "Sweep B"},
{.func = danceRise, .arg = RGB_2_ARG(0, 0, 0), .name = "Rise RGB"},
{.func = danceRise, .arg = RGB_2_ARG(0xFF, 0, 0), .name = "Rise R"},
{.func = danceRise, .arg = RGB_2_ARG(0, 0xFF, 0), .name = "Rise G"},
Expand Down Expand Up @@ -1431,3 +1435,100 @@ void danceCondiment(uint32_t tElapsedUs, uint32_t arg, bool reset)
setLeds(leds, CONFIG_NUM_LEDS);
}
}

/**
* @brief TODO doc
*
* @param tElapsedUs
* @param arg
* @param reset
*/
void danceSweep(uint32_t tElapsedUs, uint32_t arg, bool reset)
{
static const int8_t ledOrder[][2] = {
{3, 5}, {4, -1}, {6, -1}, {2, -1}, {7, -1}, {0, -1}, {1, 8},
};

static int32_t sweepTimer = 0;
static int32_t stripExciter = 0;
static int16_t stripVals[ARRAY_SIZE(ledOrder)] = {0};
static bool stripDir = true;
static int32_t rgbAngle = 0;

if (reset)
{
sweepTimer = 0;
stripExciter = 0;
memset(stripVals, 0, sizeof(stripVals));
stripDir = true;
rgbAngle = 0;
}

// Declare some LEDs, all off
led_t leds[CONFIG_NUM_LEDS] = {{0}};
bool ledsUpdated = false;

RUN_TIMER_EVERY(sweepTimer, DEFAULT_FRAME_RATE_US, tElapsedUs, {
// Run an exciter to lead the strip
int8_t stripIdx = stripExciter / 8;
if (stripExciter % 8 == 0 && stripIdx < ARRAY_SIZE(ledOrder))
{
stripVals[stripIdx] = 0xFF;
}

// Flip directions at the end
if (stripIdx < 0 || stripIdx >= ARRAY_SIZE(ledOrder))
{
stripDir = !stripDir;
}

// Move the exciter
if (stripDir)
{
stripExciter++;
}
else
{
stripExciter--;
}

// Apply rainbow if there's no color
if (0 == arg)
{
arg = EHSVtoHEXhelper(rgbAngle, 0xFF, 0xFF, false);
rgbAngle++;
if (256 == rgbAngle)
{
rgbAngle = 0;
}
}

// Decay the strip
for (int32_t sIdx = 0; sIdx < ARRAY_SIZE(ledOrder); sIdx++)
{
stripVals[sIdx] -= 8;
if (stripVals[sIdx] < 0)
{
stripVals[sIdx] = 0;
}

for (int32_t lIdx = 0; lIdx < ARRAY_SIZE(ledOrder[0]); lIdx++)
{
int8_t numLed = ledOrder[sIdx][lIdx];
if (0 <= numLed)
{
leds[ledOrder[sIdx][lIdx]].r = (stripVals[sIdx] * ARG_R(arg)) / 256;
leds[ledOrder[sIdx][lIdx]].g = (stripVals[sIdx] * ARG_G(arg)) / 256;
leds[ledOrder[sIdx][lIdx]].b = (stripVals[sIdx] * ARG_B(arg)) / 256;
}
}
ledsUpdated = true;
}
});

// Light the LEDs
if (ledsUpdated)
{
setLeds(leds, CONFIG_NUM_LEDS);
}
}
1 change: 1 addition & 0 deletions main/modes/utilities/dance/dance.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void danceRandomDance(uint32_t tElapsedUs, uint32_t arg, bool reset);
void danceChristmas(uint32_t tElapsedUs, uint32_t arg, bool reset);
void danceNone(uint32_t tElapsedUs, uint32_t arg, bool reset);
void danceCondiment(uint32_t tElapsedUs, uint32_t arg, bool reset);
void danceSweep(uint32_t tElapsedUs, uint32_t arg, bool reset);

uint8_t getNumDances(void);

Expand Down

0 comments on commit 90673f6

Please sign in to comment.