Bugfix 'round' display mode, add some commands

This commit is contained in:
Admar Schoonen 2012-01-09 23:14:32 +01:00
parent 9db65799da
commit b81d180d2e
3 changed files with 98 additions and 115 deletions

View File

@ -108,18 +108,25 @@ void selftest(void){
void displaytime_round(void)
{
int n;
int n, h = hour, m = minute;
// compute the number of seconds that we are in the hour
n = 60 * minute + second;
// compute the hour that we should display
if (n >= 17 * 60 + 30)
{
h = h + 1;
if (h >= 24)
h = 0;
}
// start by clearing the display to a known state
ledsoff();
// Now, turn on the "It is" leds
ITIS;
// now we display the appropriate minute counter
if ((n >= 2 * 60 + 30) && (n < 7 * 60 + 30)) { MFIVE; PAST; }
if ((n >= 7 * 60 + 30) && (n < 12 * 60 + 30)) { MTEN; PAST; }
@ -133,113 +140,42 @@ void displaytime_round(void)
if ((n >= 47 * 60 + 30) && (n < 52 * 60 + 30)) { MTEN; TO; }
if ((n >= 52 * 60 + 30) && (n < 57 * 60 + 30)) { MFIVE; TO; }
switch (h) {
case 1:
case 13: ONE; break;
case 2:
case 14: TWO; break;
case 3:
case 15: THREE; break;
case 4:
case 16: FOUR; break;
case 5:
case 17: HFIVE; break;
case 6:
case 18: SIX; break;
case 7:
case 19: SEVEN; break;
case 8:
case 20: EIGHT; break;
case 9:
case 21: NINE; break;
case 10:
case 22: HTEN; break;
case 11:
case 23: ELEVEN; break;
case 0:
case 12:
case 24: TWELVE; break;
}
if ((n >= 57 * 60 + 30) || (n < 2 * 60 + 30))
{
switch (hour) {
case 1:
case 13: ONE; break;
case 2:
case 14: TWO; break;
case 3:
case 15: THREE; break;
case 4:
case 16: FOUR; break;
case 5:
case 17: HFIVE; break;
case 6:
case 18: SIX; break;
case 7:
case 19: SEVEN; break;
case 8:
case 20: EIGHT; break;
case 9:
case 21: NINE; break;
case 10:
case 22: HTEN; break;
case 11:
case 23: ELEVEN; break;
case 0:
case 12:
case 24: TWELVE; break;
}
HOUR;
}
else
{
//if ((minute < 20) && (minute >4))
if ((n > 2 * 60 + 30) && (n < 17 * 60 + 30))
{
switch (hour) {
case 1:
case 13: ONE; break;
case 2:
case 14: TWO; break;
case 3:
case 15: THREE; break;
case 4:
case 16: FOUR; break;
case 5:
case 17: HFIVE; break;
case 6:
case 18: SIX; break;
case 7:
case 19: SEVEN; break;
case 8:
case 20: EIGHT; break;
case 9:
case 21: NINE; break;
case 10:
case 22: HTEN; break;
case 11:
case 23: ELEVEN; break;
case 0:
case 12:
case 24: TWELVE; break;
}
}
else
{
// if we are greater than 34 minutes past the hour then display
// the next hour
switch (hour) {
case 1:
case 13: TWO; break;
case 14:
case 2: THREE; break;
case 15:
case 3: FOUR; break;
case 4:
case 16: HFIVE; break;
case 5:
case 17: SIX; break;
case 6:
case 18: SEVEN; break;
case 7:
case 19: EIGHT; break;
case 8:
case 20: NINE; break;
case 9:
case 21: HTEN; break;
case 10:
case 22: ELEVEN; break;
case 11:
case 23: TWELVE; break;
case 0:
case 12:
case 24: ONE; break;
}
}
}
// now we can illuminate the extra minute LEDs
if ((n+30-((n/(5*60))*(5*60))) / 60 == 1) { LED1; }
if ((n+30-((n/(5*60))*(5*60))) / 60 == 2) { LED1; LED2; }
if ((n+30-((n/(5*60))*(5*60))) / 60 == 3) { LED3; LED4; }
if ((n+30-((n/(5*60))*(5*60))) / 60 == 4) { LED4; }
// WriteLEDs();
}
void displaytime_floor(void)
@ -378,7 +314,7 @@ void displaytime_floor(void)
void displaytime()
{
#if (DISPLAYTIME == round)
#if (DISPLAYTIME_MODE == DISPLAYTIME_ROUND)
displaytime_round();
#else
displaytime_floor();

View File

@ -10,7 +10,7 @@
// set SKIPSELFTEST to 1 to skip selftest
#define SKIPSELFTEST 1
// DISPLAYTIME_MODE can either be displaytime_floor or displaytime_round:
// DISPLAYTIME_MODE can either be DISPLAYTIME_FLOOR or DISPLAYTIME_ROUND:
//
// * floor: floor() (or truncate) the time to chunks of 5 minutes and where the
// additional 4 leds indicate the number of minutes you have to add to get the
@ -22,7 +22,7 @@
// exact time. Thus, if you only look at the words, you have a maximum error
// of 2 minutes and 29 seconds.
//
#define DISPLAYTIME_MODE floor
#define DISPLAYTIME_MODE DISPLAYTIME_FLOOR
// set USELIGHTSENSOR to 1 to use ambient light sensor connected to ADC0 (pin
// 23)

View File

@ -5,6 +5,10 @@
#include <avr/io.h>
#include <math.h>
#include <pt.h>
#define DISPLAYTIME_FLOOR 1
#define DISPLAYTIME_ROUND 2
#include "settings.h"
// uncomment the following to speed up the timer for testing
@ -575,37 +579,51 @@ static int uart_thread(struct pt *pt)
// 2000
year = 2000 + 10 * (arg2 - 0x30) +
(arg3 - 0x30);
Serial.print("S: Y: ");
Serial.println(year);
break;
case 'M':
// set month
month = 10 * (arg2 - 0x30) +
(arg3 - 0x30);
Serial.print("S: M: ");
Serial.println(month);
break;
case 'D':
// set day of month
day = 10 * (arg2 - 0x30) +
(arg3 - 0x30);
Serial.print("S: D: ");
Serial.println(day);
break;
case 'd':
// set day of week
// Sunday == 1, Saturday == 7
day_week = arg2;
day_week = arg2 - 0x30;
Serial.print("S: d: ");
Serial.println(day_week);
break;
case 'h':
// set hour (24 hour format)
hour = 10 * (arg2 - 0x30) +
(arg3 - 0x30);
Serial.print("S: h: ");
Serial.println(hour);
break;
case 'm':
// set minutes
minute = 10 * (arg2 - 0x30) +
(arg3 - 0x30);
Serial.print("S: m: ");
Serial.println(minute);
break;
case 's':
// set seconds
second = 10 * (arg2 - 0x30) +
(arg3 - 0x30);
Serial.print("S: s: ");
Serial.println(second);
break;
default:
break;
@ -630,44 +648,73 @@ static int uart_thread(struct pt *pt)
switch(arg1)
{
case 'T':
// get time
Serial.print("G: T: ");
Serial.print(year, DEC);
if (month < 10)
Serial.print("-0");
else
Serial.print("-");
Serial.print(month, DEC);
if (day < 10)
Serial.print("-0");
else
Serial.print("-");
Serial.print(day, DEC);
Serial.print(" ");
Serial.print(day_week, DEC);
Serial.print(" ");
Serial.print(hour, DEC);
if (minute < 10)
Serial.print(":0");
else
Serial.print(":");
Serial.print(minute, DEC);
if (second < 10)
Serial.print(":0");
else
Serial.print(":");
Serial.println(second, DEC);
break;
case 'Y':
// get year
Serial.print("g: Y: ");
Serial.print("G: Y: ");
Serial.println(year);
break;
case 'M':
// get month
Serial.print("g: M: ");
Serial.print("G: M: ");
Serial.println(month);
break;
case 'D':
// get day of month
Serial.print("g: D: ");
Serial.print("G: D: ");
Serial.println(day);
break;
case 'd':
// get day of week
Serial.print("g: d: ");
Serial.print("G: d: ");
Serial.println(day_week);
break;
case 'h':
// get hour (24 hour format)
Serial.print("g: h: ");
Serial.print("G: h: ");
if (hour < 10)
Serial.print(0, DEC);
Serial.println(hour);
break;
case 'm':
// get minutes
Serial.print("g: m: ");
Serial.print("G: m: ");
if (minute < 10)
Serial.print(0, DEC);
Serial.println(minute);
break;
case 's':
// get seconds
Serial.print("g: s: ");
Serial.print("G: s: ");
if (second < 10)
Serial.print(0, DEC);
Serial.println(second);
@ -683,13 +730,13 @@ static int uart_thread(struct pt *pt)
{
case 'c':
// get current value
Serial.print("g: Ic: ");
Serial.print("G: Ic: ");
Serial.println(lightlevel_sample,
DEC);
break;
case 'a':
// get average
Serial.print("g: Ia: ");
Serial.print("G: Ia: ");
Serial.println(lightlevel_avg,
DEC);
break;
@ -818,7 +865,7 @@ static int blink_thread(struct pt *pt)
PT_WAIT_UNTIL(pt, millisWillOverflow ? (millis() - msTick > 999) :
((millis() < 4294967295 - 998) && (millis() - msTick > 999)));
msTick=millis();
#if (PRINT_DEBUG_LEVEL <= 1)
#if (PRINT_DEBUG_LEVEL <= 0)
Serial.println("D: blink thread is alive");
#endif