add update order array
This commit is contained in:
parent
a9711fd46d
commit
5f2beca1d0
|
@ -37,6 +37,8 @@ private:
|
|||
|
||||
unsigned long updateDelay;
|
||||
|
||||
uint8_t orderArray[COLUMNS];
|
||||
|
||||
void serialPrintInt(uint16_t source);
|
||||
|
||||
|
||||
|
@ -45,17 +47,22 @@ public:
|
|||
Image();
|
||||
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 getH(); //returns Rows
|
||||
|
||||
void resetOrder(bool ascending);
|
||||
void shuffleOrder(uint8_t iterations);
|
||||
|
||||
void setBuffer_solid(bool set);
|
||||
void setBuffer_random(uint8_t randomness);
|
||||
|
||||
void loop_testDots();
|
||||
void loop_drawClearTest();
|
||||
|
||||
|
||||
|
||||
unsigned long updateDuration; //for statistics and debugging. time it took for one update (max)
|
||||
};
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ void Image::init()
|
|||
flag_updating=false;
|
||||
update_counter=0;
|
||||
updateDelay=5;
|
||||
|
||||
resetOrder(true);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -77,9 +103,19 @@ UpdateReturn Image::updateByColumn(bool direction, bool clearFirst, bool optimiz
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
uint8_t x=update_counter/2;
|
||||
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
|
||||
uint16_t _colClear=frontBuffer[x]& ~backBuffer[x]; //Front & ~Back = Which bits have to be cleared
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
unsigned long duration=millis()-last_change;
|
||||
Serial.print("Last Change took "); Serial.print(duration); Serial.println(" ms");
|
||||
Serial.print("Update max took "); Serial.print(flip.updateDuration); Serial.println(" ms");
|
||||
flip.updateDuration=0; //reset
|
||||
|
||||
flip.shuffleOrder(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue