Skip to content

Commit 3d81631

Browse files
authored
Merge pull request #89 from Unreal-Dan/daniel/crc-fix-2
test crc fix 2
2 parents 436ad19 + 9636da7 commit 3d81631

17 files changed

+32302
-32299
lines changed

Helios/Colorset.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ bool Colorset::equals(const Colorset *set) const
9595
return operator==(*set);
9696
}
9797

98+
// crc the colorset
99+
uint32_t Colorset::crc32() const
100+
{
101+
uint32_t hash = 5381;
102+
for (uint8_t i = 0; i < m_numColors; ++i) {
103+
hash = ((hash << 5) + hash) + m_palette[i].raw();
104+
}
105+
return hash;
106+
}
107+
98108
RGBColor Colorset::operator[](int index) const
99109
{
100110
return get(index);

Helios/Colorset.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class Colorset
3838
bool equals(const Colorset &set) const;
3939
bool equals(const Colorset *set) const;
4040

41+
// crc the colorset
42+
uint32_t crc32() const;
43+
4144
// index operator to access color index
4245
RGBColor operator[](int index) const;
4346

Helios/Helios.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -790,15 +790,6 @@ void Helios::handle_state_set_global_brightness()
790790
show_selection(RGB_WHITE_BRI_LOW);
791791
}
792792

793-
inline uint32_t crc32(const uint8_t *data, uint8_t size)
794-
{
795-
uint32_t hash = 5381;
796-
for (uint8_t i = 0; i < size; ++i) {
797-
hash = ((hash << 5) + hash) + data[i];
798-
}
799-
return hash;
800-
}
801-
802793
void Helios::handle_state_shift_mode()
803794
{
804795
uint8_t new_mode = (cur_mode > 0) ? (uint8_t)(cur_mode - 1) : (uint8_t)(NUM_MODE_SLOTS - 1);
@@ -814,12 +805,11 @@ void Helios::handle_state_shift_mode()
814805
void Helios::handle_state_randomize()
815806
{
816807
if (Button::onShortClick()) {
817-
uint32_t seed = crc32((const uint8_t *)&pat.colorset(), COLORSET_SIZE);
818-
Random ctx(seed);
819808
Colorset &cur_set = pat.colorset();
820-
uint8_t num_cols = (ctx.next8() + 1) % NUM_COLOR_SLOTS;
821-
cur_set.randomizeColors(ctx, num_cols);
822-
Patterns::make_pattern((PatternID)(ctx.next8() % PATTERN_COUNT), pat);
809+
Random ctx(cur_set.crc32());
810+
uint8_t randVal = ctx.next8();
811+
cur_set.randomizeColors(ctx, (randVal + 1) % NUM_COLOR_SLOTS);
812+
Patterns::make_pattern((PatternID)(randVal % PATTERN_COUNT), pat);
823813
pat.init();
824814
}
825815
if (Button::onLongClick()) {

0 commit comments

Comments
 (0)