add update order array

This commit is contained in:
interfisch 2023-02-11 18:51:33 +01:00
parent a9711fd46d
commit 5f2beca1d0
3 changed files with 49 additions and 4 deletions

View File

@ -37,6 +37,8 @@ private:
unsigned long updateDelay; unsigned long updateDelay;
uint8_t orderArray[COLUMNS];
void serialPrintInt(uint16_t source); void serialPrintInt(uint16_t source);
@ -45,17 +47,22 @@ public:
Image(); Image();
void init(); void init();
UpdateReturn updateByColumn(bool direction, bool clearFirst, bool optimizeClear, bool optimizeSet); UpdateReturn updateByColumn(bool clearFirst, bool optimizeClear, bool optimizeSet);
uint8_t getW(); //returns Columns uint8_t getW(); //returns Columns
uint8_t getH(); //returns Rows uint8_t getH(); //returns Rows
void resetOrder(bool ascending);
void shuffleOrder(uint8_t iterations);
void setBuffer_solid(bool set); void setBuffer_solid(bool set);
void setBuffer_random(uint8_t randomness); void setBuffer_random(uint8_t randomness);
void loop_testDots(); void loop_testDots();
void loop_drawClearTest(); void loop_drawClearTest();
unsigned long updateDuration; //for statistics and debugging. time it took for one update (max) unsigned long updateDuration; //for statistics and debugging. time it took for one update (max)
}; };

View File

@ -21,6 +21,8 @@ void Image::init()
flag_updating=false; flag_updating=false;
update_counter=0; update_counter=0;
updateDelay=5; updateDelay=5;
resetOrder(true);
} }
uint8_t Image::getW() { uint8_t Image::getW() {
@ -62,7 +64,31 @@ void Image::setBuffer_random(uint8_t randomness)
} }
UpdateReturn Image::updateByColumn(bool direction, bool clearFirst, bool optimizeClear, bool optimizeSet) void Image::resetOrder(bool ascending) {
for (uint8_t i=0;i<getW();i++) { //fill with ascending numbers
orderArray[i]=(getW()-1)*!ascending - i;
}
}
void Image::shuffleOrder(uint8_t iterations) {
for (uint8_t s=0;s<iterations;s++) { //shuffle iterations
uint8_t _r1=random(getW());
uint8_t _r2=random(getW());
uint8_t _backup=orderArray[_r1];
//swap numbers
orderArray[_r1]=orderArray[_r2];
orderArray[_r2]=_backup;
}
for (uint8_t i=0;i<getW();i++) { //fill with ascending numbers
Serial.print(orderArray[i]); Serial.print(" ");
}
Serial.println();
}
UpdateReturn Image::updateByColumn(bool clearFirst, bool optimizeClear, bool optimizeSet)
{ {
if (!flag_updating) { if (!flag_updating) {
@ -77,8 +103,18 @@ UpdateReturn Image::updateByColumn(bool direction, bool clearFirst, bool optimiz
uint8_t x=update_counter/2; uint8_t x=update_counter/2;
bool setDot= (update_counter%2==1); bool setDot = (update_counter%2==1);
if (clearFirst) {
x=update_counter%getW();
setDot = !(update_counter/getW() == 0);
}
x = orderArray[x]; //use custom order
if (!setDot) { //even counter numbers are for clearing if (!setDot) { //even counter numbers are for clearing
uint16_t _colClear=frontBuffer[x]& ~backBuffer[x]; //Front & ~Back = Which bits have to be cleared uint16_t _colClear=frontBuffer[x]& ~backBuffer[x]; //Front & ~Back = Which bits have to be cleared

View File

@ -42,13 +42,15 @@ void loop() {
} }
UpdateReturn result=flip.updateByColumn(0,0,true,true); //0=not finished, 1=finished UpdateReturn result=flip.updateByColumn(true,true,true,true); //0=not finished, 1=finished
if (result == finished) //just finished if (result == finished) //just finished
{ {
unsigned long duration=millis()-last_change; unsigned long duration=millis()-last_change;
Serial.print("Last Change took "); Serial.print(duration); Serial.println(" ms"); Serial.print("Last Change took "); Serial.print(duration); Serial.println(" ms");
Serial.print("Update max took "); Serial.print(flip.updateDuration); Serial.println(" ms"); Serial.print("Update max took "); Serial.print(flip.updateDuration); Serial.println(" ms");
flip.updateDuration=0; //reset flip.updateDuration=0; //reset
flip.shuffleOrder(1);
} }
} }