#include "image.h" #include "fonts.h" Image::Image() { } void Image::serialPrintInt(uint16_t source) { for(uint8_t i = 0; i < 16; i++) Serial.print((source & (1 << i)) > 0); } void Image::init() { flipdot.init(); //sets pin modes etc. flag_updating=false; update_counter=0; updateDelay=10; resetOrder(true); } uint8_t Image::getW() { return COLUMNS; } uint8_t Image::getH() { return ROWS; } void Image::setBuffer_solid(bool set) { for (uint8_t x=0;x=COLUMNS) { Serial.println("colnum too high"); }else{ backBuffer[_colnum]=_rowdata; //all white flag_updating=true; //make update run } } void Image::setBuffer_random(uint8_t brightness) { for (uint8_t x=0;x0) { //at least on dot has to be cleared in this column flipdot.setRow(0); flipdot.selectColumnClear(x); if (!flipdot.clearSelectedColumn()) { Serial.println("Error clearing column!"); } lastUpdateMillis=millis(); frontBuffer[x]=0; } }else{ //odd counter numbers are for setting uint16_t backBuffer_x=backBuffer[x]; //store buffer, because it may change when different data arrives during setting dots uint16_t _colSet=backBuffer_x& ~frontBuffer[x]; if (!optimizeSet || _colSet>0) { //at least on dot has to be set in this column (if optimize is enabled) flipdot.selectColumnSet(x); //lower column number is on the left if (!optimizeSet) { flipdot.setRow(backBuffer_x); //flip all set dots in this column }else{ flipdot.setRow(_colSet); //flip only currently not set dots in this column that have to be set } if (!flipdot.setSelectedDot()) { Serial.println("Error setting dots!"); } lastUpdateMillis=millis(); frontBuffer[x]=backBuffer_x; //flip current column in buffer } } update_counter++; //next column unsigned long _duration=millis()-functionStartMillis; //how long it took to shift data and flip dots in this update updateDuration=max(updateDuration,_duration); //store maximum value if (update_counter/2>=getW()) { //reached last column flag_updating=false; update_counter=0; flag_redraw=false; if (!isBuffersEqual()) { flag_updating=true; //update again if buffers not equal return updating; } return finished; //finished } return updating; //not finished } bool Image::isBuffersEqual() { for (uint8_t x=0;x