Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaned up some space and refined some things #15

Merged
merged 11 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Helios Build

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch: # manual trigger

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout current repository
uses: actions/checkout@v3
- name: Update Package Lists
run: sudo apt-get update
- name: Install Dependencies
run: sudo apt-get install valgrind g++ make --fix-missing
- name: Build
run: make -j
working-directory: HeliosCLI
- name: Set execute permissions for test script
run: chmod +x ./runtests.sh
working-directory: tests
- name: Run general tests
run: ./runtests.sh
working-directory: tests

embedded:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install Dependencies
run: make install
- name: Build Binary
run: make build
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: embedded firmware
path: |
helios.bin
helios.elf
helios.map
helios.hex
287 changes: 135 additions & 152 deletions ColorConstants.h

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions Colorset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void Colorset::init(RGBColor c1, RGBColor c2, RGBColor c3, RGBColor c4,

void Colorset::clear()
{
memset(m_palette, 0, sizeof(m_palette));
memset((void *)m_palette, 0, sizeof(m_palette));
m_numColors = 0;
resetIndex();
}
Expand Down Expand Up @@ -179,9 +179,14 @@ void Colorset::randomize(Random &ctx, uint8_t numColors)
numColors = ctx.next8(2, NUM_COLOR_SLOTS);
}
ValueStyle valStyle = (ValueStyle)ctx.next8(0, VAL_STYLE_COUNT);

for (uint8_t i = 0; i < numColors; ++i) {
addColorWithValueStyle(ctx, ctx.next8(), ctx.next8(), valStyle, numColors, i);
// do not put the next8() calls inside arguments, the order functions in
// arguments are called is undefined behaviour and it's important that
// these are called in the right order otherwise different platforms will
// behave differently when performing this randomization
uint8_t sat = ctx.next8();
uint8_t hue = ctx.next8();
addColorWithValueStyle(ctx, hue, sat, valStyle, numColors, i);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Colorset.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef COLORSET_H
#define COLORSET_H

#include "ColorTypes.h"
#include "Colortypes.h"

#include "HeliosConfig.h"

Expand Down
49 changes: 1 addition & 48 deletions Colortypes.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ColorTypes.h"
#include "Colortypes.h"

#if ALTERNATIVE_HSV_RGB == 1
// global hsv to rgb algorithm selector
Expand Down Expand Up @@ -26,35 +26,12 @@ HSVColor::HSVColor(uint32_t dwVal) :
// assignment from uint32_t
HSVColor &HSVColor::operator=(const uint32_t &rhs)
{
// check for the HSV bit!
if (!(rhs & HSV_BIT)) {
// IT'S NOT AN HSV DWORD!!
*this = RGBColor(rhs);
return *this;
}
hue = ((rhs >> 16) & 0xFF);
sat = ((rhs >> 8) & 0xFF);
val = (rhs & 0xFF);
return *this;
}

// copy construction
HSVColor::HSVColor(const HSVColor &rhs)
{
hue = rhs.hue;
sat = rhs.sat;
val = rhs.val;
}

// assignment operator
HSVColor &HSVColor::operator=(const HSVColor &rhs)
{
hue = rhs.hue;
sat = rhs.sat;
val = rhs.val;
return *this;
}

// construction/assignment from RGB
HSVColor::HSVColor(const RGBColor &rhs)
{
Expand Down Expand Up @@ -114,36 +91,12 @@ RGBColor::RGBColor(uint32_t dwVal) :
// assignment from uint32_t
RGBColor &RGBColor::operator=(const uint32_t &rhs)
{
// check for the HSV bit!
if ((rhs & HSV_BIT) != 0) {
// IT'S NOT AN RGB DWORD!!
*this = HSVColor(rhs);
return *this;
}

red = ((rhs >> 16) & 0xFF);
green = ((rhs >> 8) & 0xFF);
blue = (rhs & 0xFF);
return *this;
}

// copy construction
RGBColor::RGBColor(const RGBColor &rhs)
{
red = rhs.red;
green = rhs.green;
blue = rhs.blue;
}

// assignment operator
RGBColor &RGBColor::operator=(const RGBColor &rhs)
{
red = rhs.red;
green = rhs.green;
blue = rhs.blue;
return *this;
}

RGBColor::RGBColor(const HSVColor &rhs)
{
*this = rhs;
Expand Down
13 changes: 1 addition & 12 deletions Colortypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ class HSVColor
HSVColor(uint32_t dwVal);
HSVColor &operator=(const uint32_t &rhs);

// copy/assignment construction
HSVColor(const HSVColor &rhs);
HSVColor &operator=(const HSVColor &rhs);

// construction/assignment from RGB
HSVColor(const RGBColor &rhs);
HSVColor &operator=(const RGBColor &rhs);
Expand All @@ -46,7 +42,7 @@ class HSVColor
bool empty() const;
void clear();

uint32_t raw() const { return HSV_BIT | ((uint32_t)hue << 16) | ((uint32_t)sat << 8) | (uint32_t)val; }
uint32_t raw() const { return ((uint32_t)hue << 16) | ((uint32_t)sat << 8) | (uint32_t)val; }

// public members
uint8_t hue;
Expand All @@ -64,11 +60,6 @@ class RGBColor
RGBColor(uint32_t dwVal);
RGBColor &operator=(const uint32_t &rhs);

// copy/assignment construction
RGBColor(const RGBColor &rhs);
RGBColor &operator=(const RGBColor &rhs);

// construction/assignment from HSV
RGBColor(const HSVColor &rhs);
RGBColor &operator=(const HSVColor &rhs);

Expand All @@ -80,8 +71,6 @@ class RGBColor
void clear();

RGBColor adjustBrightness(uint8_t fadeBy);
void serialize(ByteStream &buffer) const;
void unserialize(ByteStream &buffer);

uint32_t raw() const { return ((uint32_t)red << 16) | ((uint32_t)green << 8) | (uint32_t)blue; }

Expand Down
132 changes: 47 additions & 85 deletions Helios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ void Helios::handle_state()
handle_state_shift_mode();
break;
case STATE_RANDOMIZE:
// TODO: Commented out because for space
// handle_state_randomize();
handle_state_randomize();
break;
#ifdef HELIOS_CLI
case STATE_SLEEP:
Expand Down Expand Up @@ -258,83 +257,56 @@ void Helios::handle_state_modes()
return;
}

// check for lock and go back to sleep
if (has_flag(FLAG_LOCKED) && hasReleased && !Button::onRelease()) {
enter_sleep();
return;
}

if (!has_flag(FLAG_LOCKED) && hasReleased) {
// just play the current mode
pat.play();
}

// check how long the button is held
uint16_t holdDur = (uint16_t)Button::holdDuration();
// calculate a magnitude which corresponds to how many times past the MENU_HOLD_TIME
// the user has held the button, so 0 means haven't held fully past one yet, etc
uint8_t magnitude = (uint8_t)(holdDur / MENU_HOLD_TIME);

// check for lock and go back to sleep
if (has_flag(FLAG_LOCKED)) {
// if the button is released and it wasn't released this tick then go to sleep
// Wait for the button to not be released this tick because it's possible to
// pick up the button releasing and wakeup the device again instantly
if (hasReleased && !Button::onRelease()) {
enter_sleep();
} else if (magnitude == 5) {
// otherwise if they have held for 5 Seconds to Exit Lock
// then show a low red flash to show they have hit the threshold
Led::set(RGB_RED_BRI_LOW);
} else {
// otherwise the rest of the time just turn off the led
Led::clear();
}
return;
} else if (hasReleased) {
// otherwise if we're not locked, and we have released the led
// then just play the current mode
pat.play();
}

// whether the user has held the button longer than a short click
bool heldPast = (holdDur > SHORT_CLICK_THRESHOLD);
// if the button is held for at least 1 second
if (Button::isPressed() && heldPast) {
// if the button has been released before then show the on menu
if (hasReleased) {
switch (magnitude) {
case 0:
Led::clear();
break;
case 1: // Color Selection
Led::set(RGB_TURQUOISE_BRI_LOW);
break;
case 2: // Pattern Selection
Led::set(RGB_MAGENTA_BRI_LOW);
break;
case 3: // Conjure Mode
Led::set(RGB_YELLOW_BRI_LOW);
break;
case 4: // Shift Mode
Led::set(RGB_WHITE_BRI_LOW);
break;
case 5: // Randomizer
Led::set(HSVColor(Time::getCurtime(), 255, 180));
break;
default:
Led::clear();
break;
case 0: Led::clear(); break; // Turn off
case 1: Led::set(RGB_TURQUOISE_BRI_LOW); break; // Color Selection
case 2: Led::set(RGB_MAGENTA_BRI_LOW); break; // Pattern Selection
case 3: Led::set(RGB_YELLOW_BRI_LOW); break; // Conjure Mode
case 4: Led::set(RGB_WHITE_BRI_LOW); break; // Shift Mode
case 5: Led::set(HSVColor(Time::getCurtime(), 255, 180)); break; // Randomizer
default: Led::clear(); break; // hold past
}
} else {
// Hold for 5 Seconds to Exit Lock
if (has_flag(FLAG_LOCKED)) {
switch (magnitude) {
case 0:
Led::clear();
break;
case 5: // Exit Lock
Led::set(RGB_RED_BRI_LOW);
break;
default:
Led::clear();
break;
}
} else {
switch (magnitude) {
case 0:
Led::clear();
break;
case 1: // Enter Glow Lock
Led::set(RGB_RED_BRI_LOW);
break;
case 2: // Master Reset
Led::set(RGB_BLUE_BRI_LOW);
break;
case 3: // Global Brightness
Led::set(RGB_GREEN_BRI_LOW);
break;
default:
Led::clear();
break;
}
switch (magnitude) {
case 0: Led::clear(); break; // nothing
case 1: Led::set(RGB_RED_BRI_LOW); break; // Enter Glow Lock
case 2: Led::set(RGB_BLUE_BRI_LOW); break; // Master Reset
case 3: Led::set(RGB_GREEN_BRI_LOW); break; // Global Brightness
default: Led::clear(); break; // hold past
}
}
}
Expand Down Expand Up @@ -535,12 +507,12 @@ struct ColorsMenuData {
};
// array of hues for selection
static const ColorsMenuData color_menu_data[4] = {
// hue0 hue1 hue2 hue3
// hue0 hue1 hue2 hue3
// ==================================================================================
{ HSV_HUE_RED, HSV_HUE_CORAL_ORANGE, HSV_HUE_ORANGE, HSV_HUE_YELLOW },
{ HSV_HUE_LIME_GREEN, HSV_HUE_GREEN, HSV_HUE_SEAFOAM, HSV_HUE_TURQUOISE },
{ HSV_HUE_ICE_BLUE, HSV_HUE_LIGHT_BLUE, HSV_HUE_BLUE, HSV_HUE_ROYAL_BLUE },
{ HSV_HUE_PURPLE, HSV_HUE_PINK, HSV_HUE_HOT_PINK, HSV_HUE_MAGENTA },
{ HUE_RED, HUE_CORAL_ORANGE, HUE_ORANGE, HUE_YELLOW },
{ HUE_LIME_GREEN, HUE_GREEN, HUE_SEAFOAM, HUE_TURQUOISE },
{ HUE_ICE_BLUE, HUE_LIGHT_BLUE, HUE_BLUE, HUE_ROYAL_BLUE },
{ HUE_PURPLE, HUE_PINK, HUE_HOT_PINK, HUE_MAGENTA },
};

bool Helios::handle_state_col_select_quadrant()
Expand Down Expand Up @@ -618,7 +590,7 @@ bool Helios::handle_state_col_select_sat()
if (menu_selection > 3) {
menu_selection = 3;
}
uint8_t saturation_values[4] = {HSV_SAT_HIGH, HSV_SAT_MEDIUM, HSV_SAT_LOW, HSV_SAT_LOWEST};
static const uint8_t saturation_values[4] = {HSV_SAT_HIGH, HSV_SAT_MEDIUM, HSV_SAT_LOW, HSV_SAT_LOWEST};
uint8_t sat = saturation_values[menu_selection];

// use the nice hue to rgb rainbow
Expand All @@ -636,8 +608,8 @@ bool Helios::handle_state_col_select_val()
if (menu_selection > 3) {
menu_selection = 3;
}
uint8_t brightness_values[4] = {HSV_BRI_HIGH, HSV_BRI_MEDIUM, HSV_BRI_LOW, HSV_BRI_LOWEST};
uint8_t val = brightness_values[menu_selection];
static const uint8_t hsv_values[4] = {HSV_VAL_HIGH, HSV_VAL_MEDIUM, HSV_VAL_LOW, HSV_VAL_LOWEST};
uint8_t val = hsv_values[menu_selection];

RGBColor targetCol = HSVColor(selected_hue, selected_sat, val);
// use the nice hue to rgb rainbow
Expand Down Expand Up @@ -728,18 +700,8 @@ void Helios::handle_state_set_global_brightness()
}
// when the user long clicks a selection
if (Button::onLongClick()) {
// set the brightness based on the selection
switch (menu_selection) {
case 0:
Led::setBrightness(BRIGHTNESS_HIGH);
break;
case 1:
Led::setBrightness(BRIGHNESS_MEDIUM);
break;
case 2:
Led::setBrightness(BRIGHNESS_LOW);
break;
}
// set the brightness based on the selection * the brightness step amount
Led::setBrightness(menu_selection * BRIGHTNESS_STEP);
cur_state = STATE_MODES;
}
show_selection(RGB_WHITE_BRI_LOW);
Expand Down
Loading