Skip to content

Commit

Permalink
Merge branch 'master' into kurt/extract-upload-eeprom
Browse files Browse the repository at this point in the history
  • Loading branch information
livingkurt committed Dec 8, 2024
2 parents 42e6002 + 24e7bcc commit 86ea579
Show file tree
Hide file tree
Showing 64 changed files with 64,098 additions and 63,407 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
!*.pattern
!*.h
!*.cpp
!*.py
!*.atsln
!*.componentinfo.xml
!*.cppproj
Expand All @@ -29,3 +30,8 @@
# Ignore bitmap files
*.bmp

# Ignore png
*.png

!*.md

18 changes: 9 additions & 9 deletions Helios/Colorset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,19 @@ void Colorset::removeColor(uint8_t index)
m_palette[--m_numColors].clear();
}

uint8_t current_color_mode = Colorset::THEORY;

void Colorset::randomizeColors(Random &ctx, uint8_t numColors)
void Colorset::randomizeColors(Random &ctx, uint8_t numColors, ColorMode mode)
{
current_color_mode = (current_color_mode + 1) % COLOR_MODE_COUNT;
ColorMode mode = (ColorMode)current_color_mode;
// if they specify randomly pick the color mode then roll it
if (mode >= COLOR_MODE_RANDOMLY_PICK) {
mode = (ColorMode)(ctx.next8() % COLOR_MODE_COUNT);
}
clear();
if (!numColors) {
numColors = ctx.next8(mode == MONOCHROMATIC ? 2 : 1, 9);
numColors = ctx.next8(mode == COLOR_MODE_MONOCHROMATIC ? 2 : 1, 9);
}
uint8_t randomizedHue = ctx.next8();
uint8_t colorGap = 0;
if (mode == THEORY && numColors > 1) {
if (mode == COLOR_MODE_COLOR_THEORY && numColors > 1) {
colorGap = ctx.next8(16, 256 / (numColors - 1));
}
ValueStyle valStyle = (ValueStyle)ctx.next8(0, VAL_STYLE_COUNT);
Expand All @@ -208,9 +208,9 @@ void Colorset::randomizeColors(Random &ctx, uint8_t numColors)
for (uint8_t i = 0; i < numColors; i++) {
uint8_t hueToUse;
uint8_t valueToUse = 255;
if (mode == THEORY) {
if (mode == COLOR_MODE_COLOR_THEORY) {
hueToUse = (randomizedHue + (i * colorGap));
} else if (mode == MONOCHROMATIC) {
} else if (mode == COLOR_MODE_MONOCHROMATIC) {
hueToUse = randomizedHue;
valueToUse = 255 - (i * (256 / numColors));
} else { // EVENLY_SPACED
Expand Down
22 changes: 15 additions & 7 deletions Helios/Colorset.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,23 @@ class Colorset
ValueStyle valStyle, uint8_t numColors, uint8_t colorPos);
void removeColor(uint8_t index);


// function to randomize the colors with various different modes of randomization
// various modes of randomization types to use with randomizeColors
enum ColorMode {
THEORY,
MONOCHROMATIC,
EVENLY_SPACED,
COLOR_MODE_COUNT
// randomize with color theory
COLOR_MODE_COLOR_THEORY,
// randomize a nonochromatic set
COLOR_MODE_MONOCHROMATIC,
// randomize an evenly spaced hue set
COLOR_MODE_EVENLY_SPACED,

// total different randomize modes above
COLOR_MODE_COUNT,

// EXTRA OPTION: randomly pick one of the other 3 options
COLOR_MODE_RANDOMLY_PICK = COLOR_MODE_COUNT,
};
void randomizeColors(Random &ctx, uint8_t numColors);
// function to randomize the colors with various different modes of randomization
void randomizeColors(Random &ctx, uint8_t numColors, ColorMode color_mode);

// fade all of the colors in the set
void adjustBrightness(uint8_t fadeby);
Expand Down
6 changes: 3 additions & 3 deletions Helios/Helios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,8 @@ void Helios::handle_state_pat_select()
cur_state = STATE_MODES;
}
if (Button::onShortClick()) {
menu_selection = (menu_selection + 1) % PATTERN_COUNT;
Patterns::make_pattern((PatternID)menu_selection, pat);
menu_selection = (menu_selection + 1) % PATTERN_COUNT;
pat.init();
}
pat.play();
Expand Down Expand Up @@ -807,9 +807,9 @@ void Helios::handle_state_randomize()
{
if (Button::onShortClick()) {
Colorset &cur_set = pat.colorset();
Random ctx(cur_set.crc32());
Random ctx(pat.crc32());
uint8_t randVal = ctx.next8();
cur_set.randomizeColors(ctx, (randVal + 1) % NUM_COLOR_SLOTS);
cur_set.randomizeColors(ctx, (randVal + 1) % NUM_COLOR_SLOTS, Colorset::COLOR_MODE_RANDOMLY_PICK);
Patterns::make_pattern((PatternID)(randVal % PATTERN_COUNT), pat);
pat.init();
}
Expand Down
9 changes: 9 additions & 0 deletions Helios/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ void Pattern::updateColor(uint8_t index, const RGBColor &col)
init();
}

uint32_t Pattern::crc32() const
{
uint32_t hash = 5381;
for (uint8_t i = 0; i < PATTERN_SIZE; ++i) {
hash = ((hash << 5) + hash) + ((uint8_t *)this)[i];
}
return hash;
}

void Pattern::blendBlinkOn()
{
// if we reached the next color, then cycle the colorset
Expand Down
3 changes: 3 additions & 0 deletions Helios/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class Pattern
// set a color in the colorset and re-initialize
void updateColor(uint8_t index, const RGBColor &col);

// calculate crc of the colorset + pattern
uint32_t crc32() const;

// get the pattern flags
uint32_t getFlags() const { return m_patternFlags; }
bool hasFlags(uint32_t flags) const { return (m_patternFlags & flags) != 0; }
Expand Down
34 changes: 17 additions & 17 deletions Helios/Patterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void Patterns::make_pattern(PatternID id, Pattern &pat)
default:

case PATTERN_RIBBON:
args.on_dur = 9;
args.on_dur = 9; // 10 for flashing pattern circles
break;

case PATTERN_ULTRA_DOPS:
Expand All @@ -97,7 +97,7 @@ void Patterns::make_pattern(PatternID id, Pattern &pat)

case PATTERN_STROBE:
args.on_dur = 5;
args.off_dur = 8;
args.off_dur = 8; // 10 for flashing pattern circles
break;

case PATTERN_HYPNOSTROBE:
Expand All @@ -107,87 +107,87 @@ void Patterns::make_pattern(PatternID id, Pattern &pat)

case PATTERN_STROBIE:
args.on_dur = 3;
args.off_dur = 23;
args.off_dur = 23; // 21 for flashing pattern circles
break;

case PATTERN_RAZOR:
args.on_dur = 3;
args.off_dur = 1;
args.gap_dur = 30;
args.gap_dur = 30; // 29 for flashing pattern circles
break;

case PATTERN_FLARE:
args.on_dur = 2;
args.off_dur = 30;
args.off_dur = 30; // 28 for flashing pattern circles
break;

case PATTERN_BURST:
args.on_dur = 3;
args.off_dur = 40;
args.off_dur = 40; // 37 for flashing pattern circles
break;

case PATTERN_GLOW:
args.on_dur = 2;
args.gap_dur = 40;
args.gap_dur = 40; // 39 for flashing pattern circles
break;

case PATTERN_FLICKER:
args.on_dur = 1;
args.off_dur = 50;
args.off_dur = 50; // 44 for flashing pattern circles
break;

case PATTERN_FLASH:
args.on_dur = 10;
args.off_dur = 250;
args.off_dur = 250; // 120 for flashing pattern circles
break;

case PATTERN_MORPH:
args.on_dur = 9;
args.blend_speed = 5;
args.blend_speed = 5; // 14 for flashing pattern circles
break;

case PATTERN_MORPH_STROBE:
args.on_dur = 5;
args.off_dur = 8;
args.blend_speed = 10;
args.blend_speed = 10; // 19 for flashing pattern circles
break;

case PATTERN_MORPH_STROBIE:
args.on_dur = 3;
args.off_dur = 23;
args.blend_speed = 10;
args.blend_speed = 10; // 35 for flashing pattern circles
break;

case PATTERN_MORPH_GLOW:
args.on_dur = 1;
args.off_dur = 3;
args.gap_dur = 40;
args.gap_dur = 40; // 36 for flashing pattern circles
args.blend_speed = 30;
break;

case PATTERN_DASH_DOPS:
args.on_dur = 1;
args.off_dur = 9;
args.gap_dur = 6;
args.dash_dur = 15;
args.dash_dur = 15; // 17 for flashing pattern circles
break;

case PATTERN_DASH_DOT:
args.on_dur = 2;
args.off_dur = 3;
args.dash_dur = 24;
args.dash_dur = 24; // 22 for flashing pattern circles
break;

case PATTERN_WAVE_PARTICLE:
args.on_dur = 1;
args.off_dur = 9;
args.dash_dur = 5;
args.dash_dur = 5; // 10 for flashing pattern circles
break;

case PATTERN_LIGHTSPEED:
args.on_dur = 2;
args.off_dur = 3;
args.dash_dur = 24;
args.dash_dur = 24; // 23 for flashing pattern circles
args.blend_speed = 10;
break;
}
Expand Down
14 changes: 13 additions & 1 deletion HeliosCLI/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.SUFFIXES:

# List all make targets which are not filenames
.PHONY: all tests clean clean_storage
.PHONY: all tests clean pngs bmps clean_storage

# compiler tool definitions
CC=g++
Expand Down Expand Up @@ -105,6 +105,18 @@ FORCE:
clean:
@$(RM) $(DFILES) $(OBJS) $(TARGETS) $(TESTS)

# generate svg
svgs: bmps
./generate_svgs.sh

# generate pngs
pngs: bmps
./generate_pngs.sh

# generate pngs
bmps:
./generate_bmps.sh -c

clean_storage:
@echo "Cleaning Helios storage file..."
@$(RM) Helios.storage
Expand Down
101 changes: 101 additions & 0 deletions HeliosCLI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Helios Engine CLI

## CLI Tool

The Helios Engine project includes a powerful Command Line Interface (CLI) tool that allows users to interact with and test the firmware without the need for physical hardware. This tool is invaluable for development, testing, and pattern creation.

### Key CLI Features

1. **Pattern Simulation**: Simulate any pattern supported by the firmware.
2. **Color Output**: Display LED colors in the terminal using ANSI color codes or hexadecimal values.
3. **Input Simulation**: Simulate button presses and holds to test firmware behavior.
4. **Timestep Control**: Run simulations in real-time or as fast as possible.
5. **Storage Emulation**: Emulate EEPROM storage for testing persistence features.
6. **BMP Generation**: Generate bitmap images of pattern outputs for documentation or analysis.

### CLI Usage

To use the CLI tool, navigate to the `HeliosCLI` directory and run the `helios` executable with various command-line options. Here are some examples:

```bash
./helios --color --in-place
```

```bash
./helios -cl <<< 300wcw300wcp1500wr300wq
```

```bash
./helios --pattern 1 --colorset "red,green,blue" --bmp output.bmp
```

For a full list of options, run `./helios --help`.

### Input Commands

The CLI tool accepts the following input commands:

- `c`: Simulate a short click
- `l`: Simulate a long click
- `p`: Simulate pressing and holding the button
- `r`: Simulate releasing the button
- `t`: Toggle button press state
- `w`: Wait for one tick
- `q`: Quit the simulation

These commands can be chained together to create complex input sequences for testing.

## Pattern Visualization

The Helios Engine project includes tools for generating visual representations of patterns in both PNG and SVG formats. These visualizations are useful for documentation, analysis, and sharing pattern designs.

### Generating BMPs and PNG

To generate bitmap (BMP) and PNG images of patterns:

1. Navigate to the `HeliosCLI` directory.
2. Run the `make pngs` command:

```bash
make pngs
```

This script will:

- Generate BMP files for all default patterns and generic flashing patterns.
- Save the BMP files in the `bmp_patterns` directory.
- Convert the BMP files to PNG format using the `convert_bmp_to_png.py` script.

The resulting PNG files will be saved in the `circular_patterns_png` directory.

### Generating SVGs

To generate Scalable Vector Graphics (SVG) representations of patterns:

1. Navigate to the `HeliosCLI` directory.
2. Run the `make svgs` command:

```bash
make svgs
```

This script will:

- Process all BMP files in the `bmp_patterns` directory.
- Convert each BMP to an SVG format using the `convert_bmp_to_svg.py` script.
- Save the resulting SVG files in the `circular_patterns_svg` directory.

### Customizing Pattern Visualizations

You can customize the pattern visualization process by modifying the following files:

- `generate_bmps.sh`: Adjust parameters such as brightness scale, color sets, or cycle count.
- `convert_bmp_to_png.py`: Modify the PNG conversion process or output format.
- `convert_bmp_to_svg.py`: Customize the SVG generation, such as changing colors or layout.

These visualizations are particularly useful for:

- Documenting the available patterns in the Helios Engine project.
- Analyzing pattern behavior and timing.
- Sharing pattern designs with the community.
- Creating visual aids for user manuals or promotional materials.
Loading

0 comments on commit 86ea579

Please sign in to comment.