implement basic update by column function
This commit is contained in:
parent
aa14022188
commit
3bb37dc83f
|
@ -10,7 +10,7 @@
|
|||
#define ROWS 16
|
||||
|
||||
|
||||
#define UPDATE_INTERVAL 5
|
||||
#define UPDATE_INTERVAL 5 //TODO: remove this
|
||||
|
||||
class Image
|
||||
{
|
||||
|
@ -18,11 +18,20 @@ class Image
|
|||
private:
|
||||
Flipdot flipdot;
|
||||
|
||||
bool frontBuffer[16][16];
|
||||
//buffer is 16 bit because of 16 Rows
|
||||
uint16_t frontBuffer[COLUMNS]; //1 is bright dot / set dot. 0 is black / cleared
|
||||
uint16_t backBuffer[COLUMNS];
|
||||
|
||||
bool flag_updating; //when true, display flip is in progress. frontBuffer does not match backBuffer
|
||||
|
||||
uint8_t update_counter; //used for keeping track of progress for updating
|
||||
|
||||
int countz=0;
|
||||
|
||||
unsigned long lastUpdateMillis; //time when last dots where started flipping
|
||||
|
||||
unsigned long updateInterval;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
@ -34,6 +43,7 @@ public:
|
|||
uint8_t getW(); //returns Columns
|
||||
uint8_t getH(); //returns Rows
|
||||
|
||||
void setBuffer_solid(bool set);
|
||||
|
||||
void loop_testDots();
|
||||
void loop_drawClearTest();
|
||||
|
|
|
@ -11,6 +11,10 @@ Image::Image()
|
|||
void Image::init()
|
||||
{
|
||||
flipdot.init(); //sets pin modes etc.
|
||||
|
||||
flag_updating=false;
|
||||
update_counter=0;
|
||||
updateInterval=50;
|
||||
}
|
||||
|
||||
uint8_t Image::getW() {
|
||||
|
@ -21,6 +25,61 @@ uint8_t Image::getH() {
|
|||
return ROWS;
|
||||
}
|
||||
|
||||
void Image::setBuffer_solid(bool set)
|
||||
{
|
||||
for (uint8_t x=0;x<getW();x++) {
|
||||
if (set) {
|
||||
backBuffer[x]=0xffff; //all white
|
||||
}else{
|
||||
backBuffer[x]=0x0; //all black
|
||||
}
|
||||
}
|
||||
|
||||
flag_updating=true; //make update run
|
||||
|
||||
}
|
||||
|
||||
bool Image::updateByColumn(bool direction, bool clearFirst, bool optimizeClear, bool optimizeSet)
|
||||
{
|
||||
if (millis()-lastUpdateMillis<updateInterval){ //too early
|
||||
return 0; //not finished
|
||||
}
|
||||
|
||||
if (!flag_updating) {
|
||||
return 1; //finished
|
||||
}
|
||||
|
||||
lastUpdateMillis=millis();
|
||||
|
||||
uint8_t x=update_counter/2;
|
||||
|
||||
if (update_counter%2==0) { //even counter numbers are for clearing
|
||||
flipdot.setRow(0);
|
||||
flipdot.selectColumnClear(x);
|
||||
flipdot.shiftData();
|
||||
if (!flipdot.clearSelectedColumn()) {
|
||||
Serial.println("Error clearing column!");
|
||||
}
|
||||
frontBuffer[x]=0;
|
||||
}else{ //odd counter numbers are for setting
|
||||
flipdot.selectColumnSet(x); //lower column number is on the left
|
||||
|
||||
flipdot.setRow(backBuffer[x]);
|
||||
flipdot.shiftData();
|
||||
flipdot.setSelectedDot();
|
||||
|
||||
frontBuffer[x]=backBuffer[x]; //flip current column in buffer
|
||||
}
|
||||
|
||||
update_counter++; //next column
|
||||
|
||||
if (update_counter/2>=getW()) { //reached last column
|
||||
flag_updating=false;
|
||||
update_counter=0;
|
||||
return 1; //finished
|
||||
}
|
||||
return 0; //not finished
|
||||
}
|
||||
|
||||
|
||||
void Image::loop_testDots() {
|
||||
|
|
|
@ -25,7 +25,29 @@ void setup() {
|
|||
void loop() {
|
||||
loopmillis = millis();
|
||||
|
||||
static unsigned long last_change=0;
|
||||
static bool color=0;
|
||||
if (loopmillis-last_change >= 10000)
|
||||
{
|
||||
Serial.print("Change to Solid color ="); Serial.println(color);
|
||||
flip.setBuffer_solid(color);
|
||||
color=1-color;
|
||||
|
||||
last_change=loopmillis;
|
||||
}
|
||||
|
||||
|
||||
if (loopmillis > last_update + UPDATE_INTERVAL)
|
||||
{
|
||||
Serial.print("UpdateByColumn ");
|
||||
bool result=flip.updateByColumn(0,0,0,0);
|
||||
Serial.println(result);
|
||||
|
||||
last_update=loopmillis;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if (loopmillis > last_update + UPDATE_INTERVAL)
|
||||
{
|
||||
flip.loop_drawClearTest();
|
||||
|
@ -33,6 +55,7 @@ void loop() {
|
|||
|
||||
last_update=loopmillis;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue