Skip to content

Commit

Permalink
Merge pull request #295 from dbambus/main
Browse files Browse the repository at this point in the history
Commits for Release 3.1.0 Bug Tested
  • Loading branch information
dbambus authored Jul 15, 2023
2 parents 7afe87a + e40448e commit ce3305c
Show file tree
Hide file tree
Showing 31 changed files with 755 additions and 509 deletions.
29 changes: 14 additions & 15 deletions include/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Animation {

void begin();
void loop(struct tm &tm);
bool led_show_notify(bool flag, uint8_t minute);
bool ledShowNotify(bool flag, uint8_t minute);
void demoMode(uint8_t &_minute, uint8_t _second);
//------------------------------------------------------------------------------
protected:
Expand Down Expand Up @@ -167,8 +167,7 @@ class Animation {
void saveMatrix();
void analyzeColors(RgbfColor **dest, RgbfColor **source,
RgbfColor &foreground, RgbfColor &background);
uint8_t determineWhichMinuteVariant();
void set_minutes(void);
void setMinute(void);
void copy2Stripe(RgbfColor **source);
void copyMatrix(RgbfColor **dest, RgbfColor **source);
void copyMatrixFlags(RgbfColor **dest, RgbfColor **source);
Expand Down Expand Up @@ -219,8 +218,8 @@ class Rain {
stopPhase = frames - speedlimit * maxRows;
}

RgbaColor get(int32_t r) {
int32_t row = (maxRows - 1 - r);
RgbaColor get(int32_t _row) {
int32_t row = (maxRows - 1 - _row);
// per image row runs from (maxRows - 1) down to 0

int32_t pos = (row + offset) % (deadtime + lifetime);
Expand Down Expand Up @@ -284,12 +283,12 @@ class Ball {
}
virtual ~Ball(){};

void begin(int32_t row, int32_t column, RgbfColor foreground,
void begin(int32_t _row, int32_t _col, RgbfColor foreground,
RgbfColor background, int32_t delay) {
this->delay = delay;
y = row << 8; // increase precision
r = row;
c = column;
y = _row << 8; // increase precision
row = _row;
col = _col;
vy = 0;
colorForeground = foreground;
colorBackground = background;
Expand Down Expand Up @@ -319,15 +318,15 @@ class Ball {
}
lastDown |= (_vy < 0) && (vy >= 0) &&
(y > lastPos); // upper turning point
r = y >> 8;
row = y >> 8;
}
color = end ? colorBackground : colorForeground;
}
return end;
}

public:
int32_t r, c; // after calling move() r and c contain new actual values
int32_t row, col; // after calling move() row & col contain new actual val
RgbfColor color;

protected:
Expand Down Expand Up @@ -508,19 +507,19 @@ class Firework {
maxLayer = layer;
}

bool getPixel(uint8_t r, uint8_t c, RgbColor &color) {
bool getPixel(uint8_t row, uint8_t col, RgbColor &color) {
// void Animation::copyBlock(RgbfColor color, uint32_t block, bool fgbg,
// bool mirrored,
// bool init) {

if ((r < 10) && (r < maxRows) && (c < 11) && (c < maxCols)) {
if ((row < 10) && (row < maxRows) && (col < 11) && (col < maxCols)) {
uint16_t pixels = 0;
for (int32_t layer = 0; layer <= maxLayer; layer++) {
if (icons[layer] != static_cast<Icons>(0)) {
pixels = animation->reverse(
pgm_read_word(&(grafik_11x10[icons[layer]][r])),
pgm_read_word(&(grafik_11x10[icons[layer]][row])),
mirrored);
if (pixels & (1 << c)) {
if (pixels & (1 << col)) {
color = colors[layer];
return true;
}
Expand Down
133 changes: 58 additions & 75 deletions include/Animation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,21 @@ bool Animation::changeBrightness() {
foregroundMinute = RgbColor(hsbColor);
RgbfColor **matrix[3] = {act, old, work};
for (uint8_t m = 0; m < 3; m++) {
for (uint8_t r = 0; r < maxRows; r++) {
for (uint8_t c = 0; c < maxCols; c++) {
for (uint8_t row = 0; row < maxRows; row++) {
for (uint8_t col = 0; col < maxCols; col++) {
if (adjustBg) {
if (!matrix[m][r][c].isForeground()) {
matrix[m][r][c] = newBackground;
if (!matrix[m][row][col].isForeground()) {
matrix[m][row][col] = newBackground;
}
}
if (adjustFg) {
if (matrix[m][r][c].isForeground()) {
if (matrix[m][row][col].isForeground()) {
if (isColorization()) {
hsbColor = HsbColor(matrix[m][r][c]);
hsbColor = HsbColor(matrix[m][row][col]);
hsbColor.B = brightness;
matrix[m][r][c].changeRgb(hsbColor);
matrix[m][row][col].changeRgb(hsbColor);
} else {
matrix[m][r][c].changeRgb(newForeground);
matrix[m][row][col].changeRgb(newForeground);
}
}
}
Expand Down Expand Up @@ -198,14 +198,15 @@ void Animation::colorize(RgbfColor **dest) {
hsbColor.H = pseudoRandomHue();
foregroundMinute = isColorization() ? RgbColor(hsbColor) : foreground;
hsbColor.H = pseudoRandomHue();
for (uint8_t r = 0; r < maxRows; r++) {
for (uint8_t c = 0; c < maxCols; c++) {
if (dest[r][c].isForeground()) {
for (uint8_t row = 0; row < maxRows; row++) {
for (uint8_t col = 0; col < maxCols; col++) {
if (dest[row][col].isForeground()) {
if ((G.animColorize == CHARACTERS) || changeColor) {
changeColor = false;
hsbColor.H = pseudoRandomHue();
}
dest[r][c].changeRgb(isColorization() ? hsbColor : foreground);
dest[row][col].changeRgb(isColorization() ? hsbColor
: foreground);
} else {
changeColor = true;
}
Expand Down Expand Up @@ -238,16 +239,16 @@ void Animation::analyzeColors(RgbfColor **dest, RgbfColor **source,
RgbfColor &foreground, RgbfColor &background) {
RgbfColor color, color1(0), color2(0);
uint32_t colorCounter1 = 0, colorCounter2 = 0;
for (uint8_t r = 0; r < maxRows; r++) {
for (uint8_t c = 0; c < maxCols; c++) {
for (uint8_t row = 0; row < maxRows; row++) {
for (uint8_t col = 0; col < maxCols; col++) {
if (source == STRIPE) {
color = RgbfColor(led.getPixel(usedUhrType->getFrontMatrixIndex(
r + rowStart, c + colStart)));
row + rowStart, col + colStart)));
} else {
color = source[r][c];
color = source[row][col];
}
if (dest != NULL) {
dest[r][c] = color;
dest[row][col] = color;
}
if (color == color1) {
colorCounter1++;
Expand Down Expand Up @@ -279,47 +280,28 @@ void Animation::analyzeColors(RgbfColor **dest, RgbfColor **source,
background.setForeground(false);
background.setOverlay(false);
if (dest != NULL) {
for (uint8_t r = 0; r < maxRows; r++) {
for (uint8_t c = 0; c < maxCols; c++) {
dest[r][c].setForeground(dest[r][c] == foreground);
for (uint8_t row = 0; row < maxRows; row++) {
for (uint8_t col = 0; col < maxCols; col++) {
dest[row][col].setForeground(dest[row][col] == foreground);
}
}
}
}

//------------------------------------------------------------------------------

uint8_t Animation::determineWhichMinuteVariant() {
switch (G.minuteVariant) {
case MinuteVariant::LED4x:
return 0;
break;
case MinuteVariant::LED7x:
return 1;
break;
case MinuteVariant::Corners:
return 2;
break;
default:
Serial.println("[ERROR] G.minuteVariant undefined");
return 0;
break;
}
}

//------------------------------------------------------------------------------

void Animation::set_minutes() {
void Animation::setMinute() {
if (G.minuteVariant != MinuteVariant::Off) {
uint8_t m = lastMinute % 5;
uint16_t minArray[4];
usedUhrType->getMinuteArray(minArray, determineWhichMinuteVariant());
usedUhrType->getMinuteArray(minArray,
clockWork.determineWhichMinuteVariant());
if (G.layoutVariant[ReverseMinDirection]) {
std::reverse(std::begin(minArray), std::end(minArray));
}
for (uint8_t i = 0; i < 4; i++) {
led.setPixel(minArray[i],
Color{m > i ? foregroundMinute : background});
HsbColor{m > i ? foregroundMinute : background});
}
}
}
Expand All @@ -330,29 +312,30 @@ void Animation::set_minutes() {
void Animation::copy2Stripe(RgbfColor **source) {
for (uint8_t row = 0; row < maxRows; row++) {
for (uint8_t col = 0; col < maxCols; col++) {
led.setPixel(usedUhrType->getFrontMatrixIndex(row + rowStart,
col + colStart),
Color{RgbColor(source[row][col].R, source[row][col].G,
source[row][col].B)});
led.setPixel(
usedUhrType->getFrontMatrixIndex(row + rowStart,
col + colStart),
HsbColor{RgbColor(source[row][col].R, source[row][col].G,
source[row][col].B)});
}
}
set_minutes();
setMinute();
}

//------------------------------------------------------------------------------

void Animation::copyMatrix(RgbfColor **dest, RgbfColor **source) {
for (uint8_t r = 0; r < maxRows; r++) {
memcpy(dest[r], source[r], sizeofColumn);
for (uint8_t row = 0; row < maxRows; row++) {
memcpy(dest[row], source[row], sizeofColumn);
}
}

//------------------------------------------------------------------------------

void Animation::copyMatrixFlags(RgbfColor **dest, RgbfColor **source) {
for (uint8_t r = 0; r < maxRows; r++) {
for (uint8_t c = 0; c < maxCols; c++) {
dest[r][c].setFlags(source[r][c].getFlags());
for (uint8_t row = 0; row < maxRows; row++) {
for (uint8_t col = 0; col < maxCols; col++) {
dest[row][col].setFlags(source[row][col].getFlags());
}
}
}
Expand All @@ -371,8 +354,8 @@ void Animation::fillMatrix(RgbfColor **matrix, RgbfColor color) {

// changed: 0 changes, e.g. color, no change of content
// changed: 1 content has changed
bool Animation::led_show_notify(bool changed, uint8_t minute) {
bool led_show = true;
bool Animation::ledShowNotify(bool changed, uint8_t minute) {
bool ledShow = true;

if (animType == KEINE) {
if (changed && (lastMinute != minute)) {
Expand All @@ -388,16 +371,16 @@ bool Animation::led_show_notify(bool changed, uint8_t minute) {
matrixChanged = true;
nextActionTime = 0; // ###################
phase = 1; // -> start Animation
led_show = false; // ###################
ledShow = false; // ###################
}
} else {
if (brightnessChanged) {
copy2Stripe(work);
}
led_show = isIdle();
ledShow = isIdle();
}
}
return led_show;
return ledShow;
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -661,16 +644,16 @@ uint16_t Animation::animScrollRight(bool dirRight) {
uint16_t Animation::animBalls() {
static uint32_t starttime;
static uint32_t numBalls;
uint32_t oldR, r, c, ballsDown;
uint32_t oldR, row, col, ballsDown;
uint32_t timeDelta, now;

if (phase == 1) {
animationDelay = 50; // 20 Frames per second
numBalls = 0;
for (c = 0; (c < maxCols) && (numBalls < maxCols); c++) {
for (r = 0; (r < maxRows) && (numBalls < maxCols); r++) {
if (work[r][c].isForeground()) {
balls[numBalls].begin(r, c, work[r][c], background,
for (col = 0; (col < maxCols) && (numBalls < maxCols); col++) {
for (row = 0; (row < maxRows) && (numBalls < maxCols); row++) {
if (work[row][col].isForeground()) {
balls[numBalls].begin(row, col, work[row][col], background,
100 * numBalls);
numBalls++;
break;
Expand All @@ -684,24 +667,24 @@ uint16_t Animation::animBalls() {
timeDelta = now - starttime;
starttime = now;
ballsDown = 0;
for (uint8_t b = 0; b < numBalls; b++) {
oldR = balls[b].r;
ballsDown += balls[b].move(timeDelta);
r = balls[b].r; // r, c new coordinates
c = balls[b].c;
if (r > oldR) { // down
for (; r > oldR; oldR++) {
work[oldR][c] = background;
for (uint8_t i = 0; i < numBalls; i++) {
oldR = balls[i].row;
ballsDown += balls[i].move(timeDelta);
row = balls[i].row; // row, col new coordinates
col = balls[i].col;
if (row > oldR) { // down
for (; row > oldR; oldR++) {
work[oldR][col] = background;
}
} else { // up
for (; r < oldR; oldR--) {
work[oldR][c] = background;
for (; row < oldR; oldR--) {
work[oldR][col] = background;
}
}
work[r][c] = balls[b].color;
work[row][col] = balls[i].color;
}
if (ballsDown >= numBalls) {
copyMatrix(work, act); // TODO(ATho95): shot Balls up
copyMatrix(work, act);
return 0;
}
return phase + 1;
Expand Down
21 changes: 9 additions & 12 deletions include/EEPROMAnything.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,15 @@ void read() {
Serial.printf("Sernr : %u\n", G.sernr);
Serial.printf("Programm : %u\n", G.prog);
Serial.printf("Conf : %u\n", G.conf);
Serial.printf("FgCol.H : %f\n", G.color[Foreground].hsb.H);
Serial.printf("FgCol.S : %f\n", G.color[Foreground].hsb.S);
Serial.printf("FgCol.V : %f\n", G.color[Foreground].hsb.B);
Serial.printf("FgCol.A : %u\n", G.color[Foreground].alpha);
Serial.printf("BgCol.H : %f\n", G.color[Background].hsb.H);
Serial.printf("BgCol.S : %f\n", G.color[Background].hsb.S);
Serial.printf("BgCol.V : %f\n", G.color[Background].hsb.B);
Serial.printf("BgCol.A : %u\n", G.color[Background].alpha);
Serial.printf("EfCol.H : %f\n", G.color[Effect].hsb.H);
Serial.printf("EfCol.S : %f\n", G.color[Effect].hsb.S);
Serial.printf("EfCol.V : %f\n", G.color[Effect].hsb.B);
Serial.printf("EfCol.A : %u\n", G.color[Effect].alpha);
Serial.printf("FgCol.H : %f\n", G.color[Foreground].H);
Serial.printf("FgCol.S : %f\n", G.color[Foreground].S);
Serial.printf("FgCol.V : %f\n", G.color[Foreground].B);
Serial.printf("BgCol.H : %f\n", G.color[Background].H);
Serial.printf("BgCol.S : %f\n", G.color[Background].S);
Serial.printf("BgCol.V : %f\n", G.color[Background].B);
Serial.printf("EfCol.H : %f\n", G.color[Effect].H);
Serial.printf("EfCol.S : %f\n", G.color[Effect].S);
Serial.printf("EfCol.V : %f\n", G.color[Effect].B);
Serial.printf("Zeitserver: %s\n", G.timeserver);
Serial.printf("Lauftext : %s\n", G.scrollingText);
Serial.printf("H6 : %u\n", G.h6);
Expand Down
Loading

0 comments on commit ce3305c

Please sign in to comment.