Skip to content

Commit

Permalink
clock: add dirty flag to time
Browse files Browse the repository at this point in the history
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
lynxeye-dev committed Apr 13, 2011
1 parent 1ad67dc commit 8ed126c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
39 changes: 25 additions & 14 deletions clock/clock.c
Expand Up @@ -31,7 +31,8 @@ volatile struct timeval_t time = {
.seconds = 0,
.minutes = 0,
.hours = 0,
.milliseconds = 0
.milliseconds = 0,
.dirty = 0
};

#ifdef STOP_WATCH
Expand Down Expand Up @@ -93,6 +94,8 @@ void increaseTime() {
if(time.hours == 24) {
time.hours = 0;
}

time.dirty = 1;
}

void descreaseTime() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}

Expand Down
1 change: 1 addition & 0 deletions clock/clock.h
Expand Up @@ -45,6 +45,7 @@ enum CLOCK_THEME {
struct timeval_t {
uint8_t seconds, minutes, hours;
uint16_t milliseconds;
uint8_t dirty;
};

/**
Expand Down
1 change: 0 additions & 1 deletion main.c
Expand Up @@ -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);
}
Expand Down

0 comments on commit 8ed126c

Please sign in to comment.