Permalink
Browse files

clock: add dirty flag to time

Since we are (hopefully) scanning out far more often than updating
the time, it makes sense to use a dirty flag here.
  • Loading branch information...
1 parent 1ad67dc commit 8ed126cf80a06a6150b0edb9a7b6c45c77c454b9 @lynxeye-dev lynxeye-dev committed Apr 13, 2011
Showing with 26 additions and 15 deletions.
  1. +25 −14 clock/clock.c
  2. +1 −0 clock/clock.h
  3. +0 −1 main.c
View
@@ -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,13 +125,16 @@ void descreaseTime() {
if(time.hours == 255) {
time.hours = 23;
}
+
+ time.dirty = 1;
}
void resetTime() {
time.milliseconds = 0;
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;
}
}
View
@@ -45,6 +45,7 @@ enum CLOCK_THEME {
struct timeval_t {
uint8_t seconds, minutes, hours;
uint16_t milliseconds;
+ uint8_t dirty;
};
/**
View
@@ -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);
}

0 comments on commit 8ed126c

Please sign in to comment.