summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Baumann <derflob@derflob.de>2015-04-22 09:58:47 +0200
committerFlorian Baumann <derflob@derflob.de>2015-04-22 09:58:47 +0200
commit8e167e3d69ba209e0051e564463c03ecee330f70 (patch)
tree0d2ee83537623349f5411e9a2325a2cb016ad955
parenta146685583906177ed2a67fc1008a12c88764917 (diff)
downloadStripClock-optimize.tar.gz
StripClock-optimize.tar.bz2
some clean upoptimize
-rw-r--r--StripClock.c95
1 files changed, 47 insertions, 48 deletions
diff --git a/StripClock.c b/StripClock.c
index cfb4448..94857d8 100644
--- a/StripClock.c
+++ b/StripClock.c
@@ -48,6 +48,8 @@ uint8_t updateStrip(void);
uint8_t updateStripSimple(void);
uint8_t updateStripEncoder(void);
+uint8_t display_number(uint8_t number, struct cRGB *color);
+
int main(void)
{
cli();
@@ -151,41 +153,43 @@ ISR(PCINT0_vect)
}
}
+uint8_t display_number(uint8_t number, struct cRGB *color)
+{
+ for (uint8_t i = 0; i < number; i++) {
+ leds[i].r = color->r;
+ leds[i].g = color->g;
+ leds[i].b = color->b;
+ if (i % 5 == 4) {
+ leds[i].r *= 2;
+ leds[i].g *= 2;
+ leds[i].b *= 2;
+ }
+ }
+
+ return 0;
+}
+
uint8_t updateStripEncoder(void)
{
+ struct cRGB c = { 0, 0, 0 };
switch (mode) {
case DM_HOUR:
memset(leds, 0, sizeof(struct cRGB) * LEDS);
dt.hour = (dt.hour + rotary_updated) % 24;
- for (uint8_t i = 0; i < dt.hour; i++) {
- leds[i].r = 127;
- if (i % 5 == 4) {
- leds[i].g = 50;
- leds[i].b = 50;
- }
- }
+ c.r = 50;
+ display_number(dt.hour, &c);
break;
case DM_MINUTE:
memset(leds, 0, sizeof(struct cRGB) * LEDS);
dt.minute = (dt.minute + rotary_updated) % 60;
- for (uint8_t i = 0; i < dt.minute; i++) {
- leds[i].g = 127;
- if (i % 5 == 4) {
- leds[i].r = 50;
- leds[i].b = 50;
- }
- }
+ c.g = 50;
+ display_number(dt.minute, &c);
break;
case DM_SECOND:
memset(leds, 0, sizeof(struct cRGB) * LEDS);
dt.second = (dt.second + rotary_updated) % 60;
- for (uint8_t i = 0; i < dt.second; i++) {
- leds[i].b = 127;
- if (i % 5 == 4) {
- leds[i].r = 50;
- leds[i].g = 50;
- }
- }
+ c.b = 50;
+ display_number(dt.second, &c);
break;
case DM_NONE:
if (rotary_updated > 0 && brightness < MAX_BRIGHTNESS) {
@@ -254,47 +258,42 @@ uint8_t updateStrip(void)
hour_led = 59;
for (uint8_t i = 0; i < LEDS; i++) {
- uint8_t r, g, b = 0;
+
+ if (i == hour_led) {
+ leds[i].r = cur_hour_r;
+ leds[i].g = cur_hour_g;
+ leds[i].b = cur_hour_b;
+ continue;
+ }
if (i < dt.minute - 1) {
//past minute
if (i % 5 == 4) {
//hour leds
- r = past_min_r * 5;
- g = past_min_g * 5;
- b = past_min_b * 5;
+ leds[i].r = past_min_r * 5;
+ leds[i].g = past_min_g * 5;
+ leds[i].b = past_min_b * 5;
} else {
- r = past_min_r;
- g = past_min_g;
- b = past_min_b;
+ leds[i].r = past_min_r;
+ leds[i].g = past_min_g;
+ leds[i].b = past_min_b;
}
} else if (i == dt.minute - 1) {
//running minute
- r = cur_min_r;
- g = cur_min_g;
- b = cur_min_b;
+ leds[i].r = cur_min_r;
+ leds[i].g = cur_min_g;
+ leds[i].b = cur_min_b;
} else if (i % 5 == 4) {
//hour leds
- r = past_min_r;
- g = past_min_g;
- b = past_min_b;
+ leds[i].r = past_min_r;
+ leds[i].g = past_min_g;
+ leds[i].b = past_min_b;
} else {
- r = g = b = 0;
- }
-
- if (i == hour_led) {
- if (i == dt.minute - 1) {
- b = 30;
- } else {
- r = cur_hour_r;
- g = cur_hour_g;
- b = cur_hour_b;
- }
+ leds[i].r = 0;
+ leds[i].g = 0;
+ leds[i].b = 0;
}
- leds[i].r = r;
- leds[i].g = g;
- leds[i].b = b;
}
ws2812_setleds(leds, LEDS);