2014-03-01 03:50:09 +01:00
|
|
|
|
2014-03-01 03:54:52 +01:00
|
|
|
/*
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
|
|
|
* <struppi@struppi.name> wrote this file. As long as you retain this notice you
|
|
|
|
* can do whatever you want with this stuff. If we meet some day, and you think
|
|
|
|
* this stuff is worth it, you can buy me a beer in return.
|
|
|
|
* (c) 2014 Stefan Rupp
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2014-03-01 03:50:09 +01:00
|
|
|
|
|
|
|
#include "rgbyteclock.h"
|
2014-03-03 05:01:36 +01:00
|
|
|
#include "timer.h"
|
2014-03-14 03:21:39 +01:00
|
|
|
#include "rtc.h"
|
2014-03-03 05:01:36 +01:00
|
|
|
#include "lcd.h"
|
|
|
|
#include "ledcontroller.h"
|
2014-03-01 03:50:09 +01:00
|
|
|
|
|
|
|
|
2014-03-14 11:34:51 +01:00
|
|
|
|
|
|
|
enum { LED_OFF, LED_GLOW, LED_S0, LED_S1, LED_S2, LED_S3, LED_S4, LED_S5};
|
|
|
|
uint16_t led_values[] = {0x00, 0x00cf, 0x02ff, 0x04ff, 0x08ff, 0x10ff, 0x20ff};
|
|
|
|
|
|
|
|
|
2014-03-14 03:21:39 +01:00
|
|
|
void rgbyteclock_rounds(void)
|
2014-03-01 03:50:09 +01:00
|
|
|
{
|
|
|
|
|
2014-03-12 21:12:16 +01:00
|
|
|
ledcontroller_turn_all_on();
|
|
|
|
|
2014-03-13 01:33:13 +01:00
|
|
|
while (1) {
|
2014-03-13 03:25:12 +01:00
|
|
|
//PORTC ^= (1<<PC5);
|
2014-03-13 03:03:08 +01:00
|
|
|
for (int i=0; i<14; i++) {
|
2014-03-14 03:21:39 +01:00
|
|
|
led_set(i, 0x1ff, 0x00, 0x00);
|
2014-03-03 05:01:36 +01:00
|
|
|
led_flush();
|
2014-03-14 03:21:39 +01:00
|
|
|
timer_wait(50);
|
2014-03-03 05:01:36 +01:00
|
|
|
}
|
|
|
|
|
2014-03-13 03:03:08 +01:00
|
|
|
for (int i=0; i<14; i++) {
|
2014-03-14 03:21:39 +01:00
|
|
|
led_set(i, 0x00, 0x1ff, 0x00);
|
2014-03-03 05:01:36 +01:00
|
|
|
led_flush();
|
2014-03-14 03:21:39 +01:00
|
|
|
timer_wait(50);
|
2014-03-03 05:01:36 +01:00
|
|
|
}
|
2014-03-14 03:21:39 +01:00
|
|
|
//timer_wait(100);
|
2014-03-03 05:01:36 +01:00
|
|
|
|
2014-03-13 03:03:08 +01:00
|
|
|
for (int i=0; i<14; i++) {
|
2014-03-14 03:21:39 +01:00
|
|
|
led_set(i, 0x00, 0x00, 0x1ff);
|
2014-03-03 05:01:36 +01:00
|
|
|
led_flush();
|
2014-03-14 03:21:39 +01:00
|
|
|
timer_wait(20);
|
2014-03-03 05:01:36 +01:00
|
|
|
}
|
2014-03-14 03:21:39 +01:00
|
|
|
//timer_wait(100);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void rgbyteclock_secwatch(void)
|
|
|
|
{
|
|
|
|
uint8_t hours, mins;
|
|
|
|
|
|
|
|
uint32_t t, t_last=0;
|
|
|
|
|
|
|
|
ledcontroller_turn_all_on();
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
t = timer_get()/1000;
|
|
|
|
if (t != t_last) {
|
|
|
|
t_last = t;
|
|
|
|
mins = t%60;
|
|
|
|
hours = t/60;
|
|
|
|
uint8_t l_mins = mins/5;
|
|
|
|
uint8_t l_hours = hours/5;
|
|
|
|
ledcontroller_clear();
|
|
|
|
if (l_mins != l_hours) {
|
|
|
|
led_set(l_mins, 0, 0x7ff, 0);
|
|
|
|
led_set(l_hours, 0, 0, 0x7ff);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
led_set(l_mins, 0, 0x7ff, 0x7ff);
|
|
|
|
}
|
|
|
|
led_flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rgbyteclock_secwatch_glide(void)
|
|
|
|
{
|
|
|
|
uint8_t hours, mins;
|
|
|
|
|
|
|
|
uint32_t t, t_last=0;
|
|
|
|
|
|
|
|
ledcontroller_turn_all_on();
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
t = rtc_get();
|
|
|
|
if (t != t_last) {
|
|
|
|
t_last = t;
|
|
|
|
mins = t%60;
|
|
|
|
hours = t/60;
|
|
|
|
uint8_t l_mins = mins/5;
|
|
|
|
uint8_t l_hours = hours/5;
|
|
|
|
uint8_t l_mins_next = l_mins+1;
|
|
|
|
uint8_t l_hours_next = l_hours+1;
|
|
|
|
|
|
|
|
if (l_mins_next > 11) { l_mins_next = 0; }
|
|
|
|
if (l_hours_next > 11) { l_hours_next = 0; }
|
|
|
|
|
|
|
|
uint16_t d_m1, d_m2;
|
|
|
|
uint16_t d_h1, d_h2;
|
2014-03-01 03:50:09 +01:00
|
|
|
|
2014-03-14 11:34:51 +01:00
|
|
|
/*
|
|
|
|
d_m2 = ((mins%5)*d_bright)/4;
|
|
|
|
d_h2 = ((hours%5)*d_bright)/4;
|
|
|
|
d_m1 = ((4-(mins%5))*d_bright)/4;
|
|
|
|
d_h1 = ((4-(hours%5))*d_bright)/4;
|
|
|
|
*/
|
|
|
|
d_m2 = led_values[(mins%5)+2];
|
|
|
|
d_h2 = led_values[(hours%5)+2];
|
|
|
|
d_m1 = led_values[4-(mins%5)+2];
|
|
|
|
d_h1 = led_values[4-(hours%5)+2];
|
|
|
|
uint16_t d_dark = led_values[1];
|
2014-03-14 03:21:39 +01:00
|
|
|
|
|
|
|
ledcontroller_clear();
|
|
|
|
for (int led=0;led<12;led++) {
|
2014-03-14 11:34:51 +01:00
|
|
|
led_set(led, d_dark, 0, 0);
|
2014-03-14 03:21:39 +01:00
|
|
|
}
|
|
|
|
if (l_mins != l_hours) {
|
2014-03-14 11:34:51 +01:00
|
|
|
led_set(l_mins, d_dark, d_m1, 0);
|
|
|
|
led_set(l_hours, d_dark, 0, d_h1);
|
|
|
|
led_set(l_mins_next, d_dark, d_m2, 0);
|
|
|
|
led_set(l_hours_next, d_dark, 0, d_h2);
|
2014-03-14 03:21:39 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
led_set(l_mins, 0xf, d_m1, d_h1);
|
|
|
|
led_set(l_mins_next, 0xf, d_m2, d_h2);
|
|
|
|
}
|
|
|
|
led_flush();
|
|
|
|
}
|
2014-03-01 03:50:09 +01:00
|
|
|
}
|
2014-03-14 03:21:39 +01:00
|
|
|
}
|
2014-03-01 03:50:09 +01:00
|
|
|
|
2014-03-14 03:21:39 +01:00
|
|
|
|
|
|
|
void rgbyteclock(void)
|
|
|
|
{
|
|
|
|
//rgbyteclock_rounds();
|
|
|
|
//rgbyteclock_secwatch();
|
|
|
|
rgbyteclock_secwatch_glide();
|
2014-03-01 03:50:09 +01:00
|
|
|
}
|