diff --git a/clock/clock.c b/clock/clock.c index f79736f..a987490 100644 --- a/clock/clock.c +++ b/clock/clock.c @@ -31,7 +31,8 @@ volatile struct timeval_t time = { .seconds = 0, .minutes = 0, .hours = 0, - .milliseconds = 0 + .milliseconds = 0, + .dirty = 0 }; #ifdef STOP_WATCH @@ -93,6 +94,8 @@ void increaseTime() { if(time.hours == 24) { time.hours = 0; } + + time.dirty = 1; } void descreaseTime() { @@ -122,6 +125,8 @@ void descreaseTime() { if(time.hours == 255) { time.hours = 23; } + + time.dirty = 1; } void resetTime() { @@ -129,6 +134,7 @@ void resetTime() { time.hours = 0; time.minutes = 0; time.seconds = 0; + time.dirty = 1; } void switchToNextMode() { @@ -167,19 +173,24 @@ inline uint8_t getMode() { } void printTime(bitmap_t destination, const enum CLOCK_THEME theme) { - switch(theme) { - case THEME_ANALOG: - pt_analogClock(destination, time, currentMode); - break; - case THEME_BARS: - pt_raisingBars(destination, time, currentMode); - break; - case THEME_BINARY: - pt_simpleBinary(destination, time, currentMode); - break; - case THEME_DICES: - pt_dices(destination, time, currentMode); - break; + if(time.dirty) + { + switch(theme) { + case THEME_ANALOG: + pt_analogClock(destination, time, currentMode); + break; + case THEME_BARS: + pt_raisingBars(destination, time, currentMode); + break; + case THEME_BINARY: + pt_simpleBinary(destination, time, currentMode); + break; + case THEME_DICES: + pt_dices(destination, time, currentMode); + break; + } + + time.dirty = 0; } } diff --git a/clock/clock.h b/clock/clock.h index 8f1ca23..ea97337 100644 --- a/clock/clock.h +++ b/clock/clock.h @@ -45,6 +45,7 @@ enum CLOCK_THEME { struct timeval_t { uint8_t seconds, minutes, hours; uint16_t milliseconds; + uint8_t dirty; }; /** diff --git a/main.c b/main.c index b1e71d7..a7bc22f 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,6 @@ int main(void) while(1) { handleKeyInput(); - // XXX: this should only be called if there is actually something new printTime(bitmap, THEME_BARS); scanout(bitmap); }