Compare commits

..

No commits in common. "377ccc477f91444ea08bbcbe2f4eec77d4e03e80" and "359b7a7826b128f626c04468773d6242f991e0ea" have entirely different histories.

4 changed files with 31 additions and 77 deletions

View File

@ -48,40 +48,24 @@ public:
RandomMatrixEffectColumn(Window* win, uint8_t dir, bool rnd=false) : MatrixEffectColumn(win, dir, rnd) {}; RandomMatrixEffectColumn(Window* win, uint8_t dir, bool rnd=false) : MatrixEffectColumn(win, dir, rnd) {};
}; };
class MatrixEffectBase : public Effect { class MatrixEffect : public Effect {
protected: protected:
MatrixEffectColumn** _columns; MatrixEffectColumn** _columns;
uint8_t _count;
virtual uint8_t _get_count();
virtual void _delete();
void _init();
virtual void _create() = 0;
public: public:
boolean can_be_shown_with_clock(); boolean can_be_shown_with_clock();
virtual ~MatrixEffectBase();
void loop(uint16_t ms);
};
class MatrixEffect : public MatrixEffectBase {
protected:
void _create() override;
public:
MatrixEffect(); MatrixEffect();
virtual ~MatrixEffect();
void loop(uint16_t ms);
String get_name() override { return "matrix"; } String get_name() override { return "matrix"; }
}; };
class RainbowMatrixEffect : public MatrixEffectBase { class RainbowMatrixEffect : public MatrixEffect {
protected:
void _create() override;
public: public:
RainbowMatrixEffect(); RainbowMatrixEffect();
String get_name() override { return "rainbow_matrix"; } String get_name() override { return "rainbow_matrix"; }
}; };
class RandomMatrixEffect : public MatrixEffectBase { class RandomMatrixEffect : public MatrixEffect {
protected:
uint8_t _get_count() override;
void _create() override;
public: public:
RandomMatrixEffect(); RandomMatrixEffect();
String get_name() override { return "random_matrix"; } String get_name() override { return "random_matrix"; }

View File

@ -28,8 +28,6 @@ struct Settings {
uint16_t length_max = 20; uint16_t length_max = 20;
uint16_t speed_min = 3; uint16_t speed_min = 3;
uint16_t speed_max = 7; uint16_t speed_max = 7;
uint16_t count = 16;
uint16_t random_count = 32;
} matrix; } matrix;
struct /* confetti */ { struct /* confetti */ {

View File

@ -136,61 +136,37 @@ void RandomMatrixEffectColumn::restart(bool completely_random) {
boolean MatrixEffectBase::can_be_shown_with_clock() { return true; }; boolean MatrixEffect::can_be_shown_with_clock() { return true; };
void MatrixEffectBase::_init() {
_count = _get_count();
_columns = new MatrixEffectColumn* [_count];
}
uint8_t MatrixEffectBase::_get_count() { return settings.effects.matrix.count; }
MatrixEffect::MatrixEffect() { MatrixEffect::MatrixEffect() {
_init(); _columns = new MatrixEffectColumn* [window->width];
_create(); for (int i=0; i<window->width; i++) _columns[i] = new MatrixEffectColumn(window, MatrixEffectColumn::DIR_SOUTH);
}
void MatrixEffect::_create() {
for (int i=0; i<_count; i++) _columns[i] = new MatrixEffectColumn(window, MatrixEffectColumn::DIR_SOUTH);
} }
RandomMatrixEffect::RandomMatrixEffect() { RandomMatrixEffect::RandomMatrixEffect() {
_init(); // No need to initialize _columns, because that will have been done by ctor of MatrixEffect.
_create(); for (int i=0; i<window->width; i++) {
delete _columns[i];
_columns[i] = new RandomMatrixEffectColumn(window, random8(4), true);
}
} }
void RandomMatrixEffect::_create() {
for (int i=0; i<_count; i++) _columns[i] = new RandomMatrixEffectColumn(window, random8(4), true);
}
uint8_t RandomMatrixEffect::_get_count() { return settings.effects.matrix.random_count; }
RainbowMatrixEffect::RainbowMatrixEffect() { RainbowMatrixEffect::RainbowMatrixEffect() {
_init(); // No need to initialize _columns, because that will have been done by ctor of MatrixEffect.
_create(); for (int i=0; i<window->width; i++) {
delete _columns[i];
_columns[i] = new RainbowMatrixEffectColumn(window, MatrixEffectColumn::DIR_SOUTH);
}
} }
void RainbowMatrixEffect::_create() { MatrixEffect::~MatrixEffect() {
for (int i=0; i<_count; i++) _columns[i] = new RainbowMatrixEffectColumn(window, MatrixEffectColumn::DIR_SOUTH); for (int i=0; i<window->width; i++) {
}
MatrixEffectBase::~MatrixEffectBase() {
_delete();
}
void MatrixEffectBase::_delete() {
for (int i=0; i<_count; i++) {
delete _columns[i]; delete _columns[i];
} }
delete[] _columns; delete[] _columns;
} }
void MatrixEffectBase::loop(uint16_t ms) { void MatrixEffect::loop(uint16_t ms) {
if (_count != _get_count()) {
_delete();
_init();
_create();
}
window->clear(); window->clear();
for (int i=0; i<_count; i++) _columns[i]->loop(ms); for (int i=0; i<window->width; i++) _columns[i]->loop(ms);
} }

View File

@ -37,8 +37,6 @@ Setting all_settings[] = {
{"effects.matrix.length_max", &settings.effects.matrix.length_max, TYPE_UINT8}, {"effects.matrix.length_max", &settings.effects.matrix.length_max, TYPE_UINT8},
{"effects.matrix.speed_min", &settings.effects.matrix.speed_min, TYPE_UINT8}, {"effects.matrix.speed_min", &settings.effects.matrix.speed_min, TYPE_UINT8},
{"effects.matrix.speed_max", &settings.effects.matrix.speed_max, TYPE_UINT8}, {"effects.matrix.speed_max", &settings.effects.matrix.speed_max, TYPE_UINT8},
{"effects.matrix.count", &settings.effects.matrix.count, TYPE_UINT8},
{"effects.matrix.random_count", &settings.effects.matrix.random_count, TYPE_UINT8},
{"effects.sines.count", &settings.effects.sines.count, TYPE_UINT8}, {"effects.sines.count", &settings.effects.sines.count, TYPE_UINT8},
@ -47,15 +45,14 @@ Setting all_settings[] = {
{"effects.tv_static.black_bar_speed", &settings.effects.tv_static.black_bar_speed, TYPE_UINT16}, {"effects.tv_static.black_bar_speed", &settings.effects.tv_static.black_bar_speed, TYPE_UINT16},
}; };
const uint8_t all_settings_size = 29; const uint8_t all_settings_size = 26;
bool change_setting(const char* key, uint16_t new_value) { bool change_setting(const char* key, uint16_t new_value) {
LOGln("Settings * Setting %s to new value %d.", key, new_value); LOGln("Settings * Setting %s to new value %d.", key, new_value);
Setting* s = NULL; Setting* s = NULL;
for (uint8_t i=0; i<all_settings_size; i++) { for (uint8_t i=0; i<all_settings_size; i++) {
s = &(all_settings[i]); if (strcmp(key, all_settings[i].name)==0) {
s = &all_settings[i];
if (strcmp(key, s->name)==0) {
break; break;
} }
} }
@ -100,14 +97,13 @@ bool save_settings() {
return false; return false;
} }
Setting* s; for (int i=0; i<all_settings_size; i++) {
for (uint8_t i=0; i<all_settings_size; i++) { Setting s = all_settings[i];
s = &(all_settings[i]); uint16_t value = *(s.value);
uint16_t value = *(s->value); uint16_t default_value = setting_default(&s);
uint16_t default_value = setting_default(s);
if (default_value != value) { if (default_value != value) {
char buf[50]; char buf[50];
snprintf(buf, 50, "%s=%d", s->name, value); snprintf(buf, 50, "%s=%d", s.name, value);
LOGln("Saving: %s", buf); LOGln("Saving: %s", buf);
f.println(buf); f.println(buf);
} }