Added get/set date + lightsensor reading, bugfixes
Added commands to get / set date from rtc. Added commands to get current and average reading from light sensor. Fixed bug in display mode 'round'.
This commit is contained in:
parent
6ac27a1183
commit
9db65799da
|
@ -233,11 +233,10 @@ void displaytime_round(void)
|
|||
}
|
||||
|
||||
// now we can illuminate the extra minute LEDs
|
||||
|
||||
if ((minute-(minute/5)*5)==1) { LED1; }
|
||||
if ((minute-(minute/5)*5)==2) { LED1; LED2; }
|
||||
if ((minute-(minute/5)*5)==3) { LED3; LED4; }
|
||||
if ((minute-(minute/5)*5)==4) { LED4; }
|
||||
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();
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ void SWversion(void);
|
|||
// scale the brightness levels to something closer to avoid having to work with
|
||||
// floating point numbers
|
||||
|
||||
unsigned int year = 2010, month = 4, day = 28, day_week = 1;
|
||||
int hour=12, minute=0, second=0;
|
||||
// incremented the second counter
|
||||
int count;
|
||||
|
@ -73,6 +74,8 @@ char Display1=0, Display2=0, Display3=0, Led1=0, Led2=0, Led3=0, Led4=0;
|
|||
int OldHardware = 0; // 1 = we are running on old hardware
|
||||
int BTNActive = 1; // the sense of the button inputs (Changes based on hardware type)
|
||||
int timercount=10; // used for interrupt counting to determine the brightnes of the display
|
||||
unsigned long int lightlevel_avg;
|
||||
unsigned long int lightlevel_sample;
|
||||
|
||||
// hardware constants
|
||||
int LEDClockPin=5; // Arduino Pin#11 - 4094 Pin 3 clock
|
||||
|
@ -307,6 +310,10 @@ void setup()
|
|||
if (DS1302Present==1) {
|
||||
// Get the current time and date from the chip
|
||||
Time t = rtc.time();
|
||||
year = t.yr;
|
||||
month = t.mon;
|
||||
day = t.date;
|
||||
day_week = t.day;
|
||||
second=t.sec;
|
||||
minute=t.min;
|
||||
hour=t.hr;
|
||||
|
@ -392,6 +399,7 @@ void incrementtime(void)
|
|||
minute=0;
|
||||
if (++hour == 25) {
|
||||
hour=1;
|
||||
// should we increment date here as well?
|
||||
}
|
||||
}
|
||||
/* // debug outputs
|
||||
|
@ -404,7 +412,6 @@ void incrementtime(void)
|
|||
Serial.print(":");
|
||||
Serial.print(second);
|
||||
Serial.print(" ");*/
|
||||
|
||||
}
|
||||
|
||||
void SWversion(void)
|
||||
|
@ -476,7 +483,7 @@ void process_buttons(unsigned char button_status)
|
|||
// flash doesnt happen when setting time
|
||||
if (DS1302Present==1) {
|
||||
// Make a new time object to set the date and time
|
||||
Time t(2010, 04, 28, hour, minute, second, 01);
|
||||
Time t(year, month, day, hour, minute, second, day_week);
|
||||
// Set the time and date on the chip
|
||||
rtc.time(t);
|
||||
}
|
||||
|
@ -502,7 +509,7 @@ void process_buttons(unsigned char button_status)
|
|||
|
||||
if (DS1302Present==1) {
|
||||
// Make a new time object to set the date and time
|
||||
Time t(2010, 04, 28, hour, minute, second, 01);
|
||||
Time t(year, month, day, hour, minute, second, day_week);
|
||||
// Set the time and date on the chip
|
||||
rtc.time(t);
|
||||
}
|
||||
|
@ -525,7 +532,7 @@ void process_buttons(unsigned char button_status)
|
|||
|
||||
static int uart_thread(struct pt *pt)
|
||||
{
|
||||
char cmd, arg1, arg2, arg3;
|
||||
unsigned char cmd, arg1, arg2, arg3;
|
||||
int length;
|
||||
|
||||
PT_BEGIN(pt);
|
||||
|
@ -564,16 +571,25 @@ static int uart_thread(struct pt *pt)
|
|||
switch(arg1)
|
||||
{
|
||||
case 'Y':
|
||||
// set year
|
||||
// set year, assuming offset of
|
||||
// 2000
|
||||
year = 2000 + 10 * (arg2 - 0x30) +
|
||||
(arg3 - 0x30);
|
||||
break;
|
||||
case 'M':
|
||||
// set month
|
||||
month = 10 * (arg2 - 0x30) +
|
||||
(arg3 - 0x30);
|
||||
break;
|
||||
case 'D':
|
||||
// set day of month
|
||||
day = 10 * (arg2 - 0x30) +
|
||||
(arg3 - 0x30);
|
||||
break;
|
||||
case 'd':
|
||||
// set day of week
|
||||
// Sunday == 1, Saturday == 7
|
||||
day_week = arg2;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
|
@ -595,10 +611,12 @@ static int uart_thread(struct pt *pt)
|
|||
break;
|
||||
}
|
||||
|
||||
// Set the time and date on the chip
|
||||
Time t(2010, 4, 28, hour, minute,
|
||||
second, 1);
|
||||
rtc.time(t);
|
||||
if (DS1302Present==1) {
|
||||
// Set the time and date on the chip
|
||||
Time t(year, month, day, hour,
|
||||
minute, second, day_week);
|
||||
rtc.time(t);
|
||||
}
|
||||
displaytime();
|
||||
}
|
||||
break;
|
||||
|
@ -614,15 +632,23 @@ static int uart_thread(struct pt *pt)
|
|||
{
|
||||
case 'Y':
|
||||
// get year
|
||||
Serial.print("g: Y: ");
|
||||
Serial.println(year);
|
||||
break;
|
||||
case 'M':
|
||||
// get month
|
||||
Serial.print("g: M: ");
|
||||
Serial.println(month);
|
||||
break;
|
||||
case 'D':
|
||||
// get day of month
|
||||
Serial.print("g: D: ");
|
||||
Serial.println(day);
|
||||
break;
|
||||
case 'd':
|
||||
// get day of week
|
||||
Serial.print("g: d: ");
|
||||
Serial.println(day_week);
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
|
@ -646,6 +672,33 @@ static int uart_thread(struct pt *pt)
|
|||
Serial.print(0, DEC);
|
||||
Serial.println(second);
|
||||
break;
|
||||
case 'I':
|
||||
//get ambient light intensity
|
||||
if (length < 2)
|
||||
Serial.println("E: too few arguments");
|
||||
else
|
||||
{
|
||||
arg2 = inputBuffer.charAt(2);
|
||||
switch(arg2)
|
||||
{
|
||||
case 'c':
|
||||
// get current value
|
||||
Serial.print("g: Ic: ");
|
||||
Serial.println(lightlevel_sample,
|
||||
DEC);
|
||||
break;
|
||||
case 'a':
|
||||
// get average
|
||||
Serial.print("g: Ia: ");
|
||||
Serial.println(lightlevel_avg,
|
||||
DEC);
|
||||
break;
|
||||
default:
|
||||
Serial.println("E: unknown argument for command I");
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -692,8 +745,6 @@ static int buttons_thread(struct pt *pt)
|
|||
static int lightsensor_thread(struct pt *pt)
|
||||
{
|
||||
static unsigned long msTick =0; // the number of Millisecond Ticks since we last
|
||||
static unsigned long int lightlevel_avg;
|
||||
unsigned long int lightlevel_sample;
|
||||
static char millisWillOverflow = 0;
|
||||
static char n_lightlevel_samples = 0;
|
||||
|
||||
|
@ -742,12 +793,14 @@ static int lightsensor_thread(struct pt *pt)
|
|||
|
||||
current_brightness = ambient_light_to_brightness[lightlevel_avg];
|
||||
|
||||
#if (PRINT_DEBUG_LEVEL <= 0)
|
||||
Serial.print("D: lightsensor: ");
|
||||
Serial.print(lightlevel_sample);
|
||||
Serial.print(", avg: ");
|
||||
Serial.print(lightlevel_avg);
|
||||
Serial.print(", brightness: ");
|
||||
Serial.println(current_brightness);
|
||||
#endif
|
||||
}
|
||||
|
||||
PT_END(pt);
|
||||
|
@ -817,7 +870,10 @@ static int wordclock_thread(struct pt *pt)
|
|||
second++;
|
||||
|
||||
//test to see if we need to increment the time counters
|
||||
if ((second==60) || (second == 30))
|
||||
if (second == 30)
|
||||
displaytime();
|
||||
|
||||
if (second == 60)
|
||||
{
|
||||
incrementtime();
|
||||
displaytime();
|
||||
|
@ -840,6 +896,10 @@ static int wordclock_thread(struct pt *pt)
|
|||
if (DS1302Present==1) {
|
||||
// Get the current time and date from the chip
|
||||
Time t = rtc.time();
|
||||
year = t.yr;
|
||||
month = t.mon;
|
||||
day = t.date;
|
||||
day_week = t.day;
|
||||
second=t.sec;
|
||||
minute=t.min;
|
||||
hour=t.hr;
|
||||
|
|
Loading…
Reference in New Issue