diff --git a/Helios/Colorset.cpp b/Helios/Colorset.cpp index e61e83ec..18819194 100644 --- a/Helios/Colorset.cpp +++ b/Helios/Colorset.cpp @@ -59,6 +59,16 @@ bool Colorset::operator!=(const Colorset &other) const return !operator==(other); } +uint32_t Colorset::crc32() const +{ + uint32_t hash = 5381; + for (uint8_t i = 0; i < NUM_COLOR_SLOTS; ++i) { + hash = ((hash << 5) + hash) + m_palette[i].raw(); + } + hash = ((hash << 5) + hash) + m_numColors; + return hash; +} + void Colorset::init(RGBColor c1, RGBColor c2, RGBColor c3, RGBColor c4, RGBColor c5, RGBColor c6, RGBColor c7, RGBColor c8) { diff --git a/Helios/Colorset.h b/Helios/Colorset.h index 0cab1c0c..ba5f64f1 100644 --- a/Helios/Colorset.h +++ b/Helios/Colorset.h @@ -41,6 +41,9 @@ class Colorset // index operator to access color index RGBColor operator[](int index) const; + // crc the colorset + uint32_t crc32() const; + enum ValueStyle : uint8_t { // Random values diff --git a/Helios/Helios.cpp b/Helios/Helios.cpp index 97383b26..d581e47e 100644 --- a/Helios/Helios.cpp +++ b/Helios/Helios.cpp @@ -271,7 +271,7 @@ void Helios::handle_state() handle_state_set_global_brightness(); break; case STATE_SHIFT_MODE: - handle_state_shift_mode(); + // handle_state_shift_mode(); break; case STATE_RANDOMIZE: handle_state_randomize(); @@ -814,8 +814,9 @@ void Helios::handle_state_shift_mode() void Helios::handle_state_randomize() { if (Button::onShortClick()) { - uint32_t seed = crc32((const uint8_t *)&pat.colorset(), COLORSET_SIZE); - Random ctx(seed); + // uint32_t seed = crc32((const uint8_t *)&pat.colorset(), COLORSET_SIZE); + // Random ctx(seed); + Random ctx(pat.colorset().crc32()); Colorset &cur_set = pat.colorset(); uint8_t num_cols = (ctx.next8() + 1) % NUM_COLOR_SLOTS; cur_set.randomizeColors(ctx, num_cols);