Skip to content

Commit

Permalink
Merge branch 'master' into kurt/shift-mode-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
livingkurt committed Jul 14, 2024
2 parents 592fbd4 + 298ee39 commit b7d172a
Show file tree
Hide file tree
Showing 10 changed files with 358 additions and 90 deletions.
50 changes: 35 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,40 @@ on:
branches: ["master"]
pull_request:
branches: ["master"]
workflow_dispatch: # manual trigger

jobs:
test:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout current repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Update Package Lists
run: sudo apt-get update
- name: Install Dependencies
run: sudo apt-get install valgrind g++ make --fix-missing
- name: Build
- name: Build HeliosCLI
run: make -j
working-directory: HeliosCLI
- name: Archive HeliosCLI artifacts
run: zip -r "helioscli.zip" .
working-directory: HeliosCLI
- name: Upload HeliosCLI Artifact
uses: actions/upload-artifact@v4
with:
name: helioscli-artifacts
path: HeliosCLI/helioscli.zip

tests:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout current repository
uses: actions/checkout@v4
- name: Download HeliosCLI Artifact
uses: actions/download-artifact@v4
with:
name: helioscli-artifacts
path: ./HeliosCLI
- name: Set execute permissions for test script
run: chmod +x ./runtests.sh
working-directory: tests
Expand All @@ -28,12 +47,13 @@ jobs:
working-directory: tests

embedded:
needs: test
needs: tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout current repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install Dependencies
Expand All @@ -42,12 +62,12 @@ jobs:
- name: Build Binary
run: make build
working-directory: HeliosEmbedded
- name: Archive production artifacts
uses: actions/upload-artifact@v3
- name: Archive HeliosEmbedded artifacts
run: zip -r "embedded-firmware.zip" .
working-directory: HeliosEmbedded
- name: Upload HeliosEmbedded Artifact
uses: actions/upload-artifact@v4
with:
name: embedded firmware
path: |
HeliosEmbedded/helios.bin
HeliosEmbedded/helios.elf
HeliosEmbedded/helios.map
HeliosEmbedded/helios.hex
name: embedded-firmware
path: HeliosEmbedded/embedded-firmware.zip

211 changes: 211 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
name: Helios Release

on:
workflow_dispatch: # manual trigger

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout current repository
uses: actions/checkout@v4
- name: Update Package Lists
run: sudo apt-get update
- name: Install Dependencies
run: sudo apt-get install valgrind g++ make --fix-missing
- name: Build HeliosCLI
run: make -j
working-directory: HeliosCLI
- name: Archive HeliosCLI artifacts
run: zip -r "helioscli.zip" .
working-directory: HeliosCLI
- name: Upload HeliosCLI Artifact
uses: actions/upload-artifact@v4
with:
name: helioscli-artifacts
path: HeliosCLI/helioscli.zip

tests:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout current repository
uses: actions/checkout@v4
- name: Download HeliosCLI Artifact
uses: actions/download-artifact@v4
with:
name: helioscli-artifacts
path: ./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: tests
runs-on: ubuntu-latest
steps:
- name: Checkout current repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install Dependencies
run: make install
working-directory: HeliosEmbedded
- name: Build Binary
run: make build
working-directory: HeliosEmbedded
- name: Archive HeliosEmbedded artifacts
run: zip -r "embedded-firmware.zip" .
working-directory: HeliosEmbedded
- name: Upload HeliosEmbedded Artifact
uses: actions/upload-artifact@v4
with:
name: embedded-firmware
path: HeliosEmbedded/embedded-firmware.zip

release:
needs: embedded
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout current repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for calculating version

- name: Get the latest tag
id: get_tag
run: |
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "none")
echo "tag=$latest_tag" >> $GITHUB_ENV
- name: Check for existing tags
id: check_tag
run: |
if [ "${{ env.tag }}" == "none" ]; then
echo "No tags found. Creating initial tag 1.0.0."
echo "new_tag=1.0.0" >> $GITHUB_ENV
fi
- name: Calculate new version
id: calc_version
run: |
if [ "${{ env.new_tag }}" == "" ]; then
latest_tag=${{ env.tag }}
commits_since_tag=$(git rev-list $latest_tag..HEAD --count)
IFS='.' read -ra ADDR <<< "$latest_tag"
patch=$((ADDR[2] + commits_since_tag))
new_version="${ADDR[0]}.${ADDR[1]}.$patch"
echo "new_version=$new_version" >> $GITHUB_ENV
echo "new_tag=$new_version" >> $GITHUB_ENV
else
echo "new_version=${{ env.new_tag }}" >> $GITHUB_ENV
fi
- name: Check if new tag exists
run: |
if git rev-parse "refs/tags/${{ env.new_tag }}" >/dev/null 2>&1; then
echo "Tag ${{ env.new_tag }} already exists. Skipping tag creation."
echo "tag_exists=true" >> $GITHUB_ENV
else
echo "tag_exists=false" >> $GITHUB_ENV
fi
- name: Create a new tag
if: env.tag_exists == 'false'
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git tag ${{ env.new_tag }}
git push origin ${{ env.new_tag }}
- name: Download HeliosCLI Artifact
uses: actions/download-artifact@v4
with:
name: helioscli-artifacts
path: ./artifact/helioscli

- name: Download HeliosEmbedded Artifact
uses: actions/download-artifact@v4
with:
name: embedded-firmware
path: ./artifact/embedded

- name: Create directories for unzipping
run: mkdir -p ./artifact/unzipped/helioscli ./artifact/unzipped/embedded

- name: Unzip HeliosCLI Artifact
run: unzip ./artifact/helioscli/helioscli.zip -d ./artifact/unzipped/helioscli

- name: Unzip HeliosEmbedded Artifact
run: unzip ./artifact/embedded/embedded-firmware.zip -d ./artifact/unzipped/embedded

- name: Create GitHub Release
id: create_release
uses: ncipollo/release-action@v1
with:
tag: ${{ env.new_tag }}
name: Helios Vortex ${{ env.new_version }}
body: |
Release of Helios Vortex version ${{ env.new_version }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Release Assets (helios.bin)
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./artifact/unzipped/embedded/helios.bin
asset_name: helios.bin
asset_content_type: application/octet-stream
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Release Assets (helios.elf)
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./artifact/unzipped/embedded/helios.elf
asset_name: helios.elf
asset_content_type: application/octet-stream
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Release Assets (helios.map)
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./artifact/unzipped/embedded/helios.map
asset_name: helios.map
asset_content_type: application/octet-stream
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Release Assets (helios.hex)
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./artifact/unzipped/embedded/helios.hex
asset_name: helios.hex
asset_content_type: application/octet-stream
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Release Assets (Helios CLI)
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./artifact/unzipped/helioscli/helios
asset_name: helios
asset_content_type: application/octet-stream
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

48 changes: 30 additions & 18 deletions Helios/Helios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void Helios::save_cur_mode()
Storage::write_pattern(cur_mode, pat);
}

void Helios::load_global_flags()
void Helios::load_global_flags()
{
// read the global flags from index 0 config
global_flags = (Flags)Storage::read_global_flags();
Expand All @@ -198,6 +198,10 @@ void Helios::load_global_flags()
// If brightness is set in storage, use it
if (saved_brightness > 0) {
Led::setBrightness(saved_brightness);
} else {
// if the brightness was 0 then the storage was likely
// uninitialized or corrupt so write out the defaults
factory_reset();
}
}

Expand Down Expand Up @@ -715,26 +719,31 @@ void Helios::handle_state_set_defaults()
if (Button::onLongClick()) {
// if the user actually selected 'yes'
if (menu_selection == 1) {
for (uint8_t i = 0; i < NUM_MODE_SLOTS; ++i) {
Patterns::make_default(i, pat);
Storage::write_pattern(i, pat);
}
// Reset global brightness to default
Led::setBrightness(DEFAULT_BRIGHTNESS);
Storage::write_brightness(DEFAULT_BRIGHTNESS);
// reset global flags
global_flags = FLAG_NONE;
cur_mode = 0;
// save global flags
save_global_flags();
// re-load current mode
load_cur_mode();
factory_reset();
}
cur_state = STATE_MODES;
}
show_selection(RGB_WHITE_BRI_LOW);
}

void Helios::factory_reset()
{
for (uint8_t i = 0; i < NUM_MODE_SLOTS; ++i) {
Patterns::make_default(i, pat);
Storage::write_pattern(i, pat);
}
// Reset global brightness to default
Led::setBrightness(DEFAULT_BRIGHTNESS);
Storage::write_brightness(DEFAULT_BRIGHTNESS);
// reset global flags
global_flags = FLAG_NONE;
cur_mode = 0;
// save global flags
save_global_flags();
// re-load current mode
load_cur_mode();
}

void Helios::handle_state_set_global_brightness()
{
if (Button::onShortClick()) {
Expand Down Expand Up @@ -783,9 +792,13 @@ inline uint32_t crc32(const uint8_t *data, uint8_t size)

void Helios::handle_state_shift_mode()
{
uint8_t new_mode = cur_mode ? (uint8_t)(cur_mode - 1) : (uint8_t)(NUM_MODE_SLOTS - 1);
Storage::swap_pattern(cur_mode, new_mode);
uint8_t new_mode = (cur_mode > 0) ? (uint8_t)(cur_mode - 1) : (uint8_t)(NUM_MODE_SLOTS - 1);
// copy the storage from the new position into our current position
Storage::copy_slot(new_mode, cur_mode);
// point at the new position
cur_mode = new_mode;
// write out the current mode to the newly updated position
save_cur_mode();
cur_state = STATE_MODES;
}

Expand All @@ -796,7 +809,6 @@ void Helios::handle_state_randomize()
Random ctx(seed);
Colorset &cur_set = pat.colorset();
uint8_t num_cols = (ctx.next8() + 1) % NUM_COLOR_SLOTS;

cur_set.randomizeColors(ctx, num_cols);
Patterns::make_pattern((PatternID)(ctx.next8() % PATTERN_COUNT), pat);
pat.init();
Expand Down
1 change: 1 addition & 0 deletions Helios/Helios.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Helios
static void handle_state_randomize();
static void show_long_selection(RGBColor color);
static void show_selection(RGBColor color);
static void factory_reset();

enum State : uint8_t {
STATE_MODES,
Expand Down
Loading

0 comments on commit b7d172a

Please sign in to comment.