Compare commits

..

2 Commits

Author SHA1 Message Date
377ccc477f Small changes in settings.
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2019-10-11 12:14:32 +02:00
efebe9adb4 The *matrix effects now are all derived from MatrixEffectBase class. Also, you can now set the amount of columns for these effects. 2019-10-11 06:21:32 +02:00
4 changed files with 77 additions and 31 deletions

View File

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

View File

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

View File

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

View File

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