Create global 'time' variable which holds RTC value
This commit is contained in:
@@ -108,15 +108,14 @@ int8_t cmd_at_rst_handler(uint8_t mode, char* arg)
|
||||
}
|
||||
|
||||
int8_t cmd_at_time_handler(uint8_t mode, char* arg)
|
||||
{
|
||||
struct TIME_HMS time;
|
||||
{
|
||||
struct TIME_HMS n_time;
|
||||
char* val;
|
||||
char* tail;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case M_GET:
|
||||
time = rtc_read_time();
|
||||
case M_GET:
|
||||
uart_puti(time.hour, 10);
|
||||
uart_putc(':');
|
||||
uart_puti(time.minute, 10);
|
||||
@@ -125,22 +124,22 @@ int8_t cmd_at_time_handler(uint8_t mode, char* arg)
|
||||
uart_puts("\n\r");
|
||||
break;
|
||||
|
||||
case M_SET:
|
||||
case M_SET:
|
||||
if(!strlen(arg)) return -1;
|
||||
|
||||
val = strtok_r(arg, ",", &tail);
|
||||
time.hour = atoi(val);
|
||||
if(time.hour >= 24) return -1;
|
||||
n_time.hour = atoi(val);
|
||||
if(n_time.hour >= 24) return -1;
|
||||
|
||||
val = strtok_r(NULL, ",", &tail);
|
||||
time.minute = atoi(val);
|
||||
if(time.minute >= 60) return -1;
|
||||
n_time.minute = atoi(val);
|
||||
if(n_time.minute >= 60) return -1;
|
||||
|
||||
val = strtok_r(NULL, ",", &tail);
|
||||
time.second = atoi(val);
|
||||
if(time.second >= 60) return -1;
|
||||
n_time.second = atoi(val);
|
||||
if(n_time.second >= 60) return -1;
|
||||
|
||||
rtc_set_time(&time);
|
||||
rtc_set_time(&n_time);
|
||||
|
||||
uart_puts_P(PSTR("+TIM="));
|
||||
uart_puti(time.hour, 10);
|
||||
|
||||
@@ -9,20 +9,17 @@ uint8_t k_inc_hour, k_inc_minute, k_inc_second, k_inc_brightness;
|
||||
|
||||
void inc_hour(void)
|
||||
{
|
||||
led_display.hour = (led_display.hour + 1) % 24;
|
||||
rtc_set_time_part(HOUR, led_display.hour);
|
||||
rtc_set_time_part(HOUR, (time.hour + 1) % 24);
|
||||
}
|
||||
|
||||
void inc_minute(void)
|
||||
{
|
||||
led_display.minute = (led_display.minute + 1) % 60;
|
||||
rtc_set_time_part(MINUTE, led_display.minute);
|
||||
rtc_set_time_part(MINUTE, (time.minute + 1) % 60);
|
||||
}
|
||||
|
||||
void inc_second(void)
|
||||
{
|
||||
led_display.second = (led_display.second + 1) % 60;
|
||||
rtc_set_time_part(SECOND, led_display.second);
|
||||
rtc_set_time_part(SECOND, (time.second + 1) % 60);
|
||||
}
|
||||
|
||||
void inc_brightness(void)
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include <avr/interrupt.h>
|
||||
#include "config.h"
|
||||
#include "led.h"
|
||||
#include "rtc.h"
|
||||
|
||||
volatile struct TIME_HMS led_display = { 0, 0, 0 };
|
||||
volatile uint8_t led_btnes;
|
||||
|
||||
void led_init(void)
|
||||
@@ -48,15 +48,15 @@ ISR(TIMER0_OVF_vect)
|
||||
switch(curr_anode)
|
||||
{
|
||||
case 1:
|
||||
LED_PORT = ~led_display.hour;
|
||||
LED_PORT = ~time.hour;
|
||||
ANODES_PORT = led_btnes >= pwm_counter ? ~HOUR_ANODE : 0xFF;
|
||||
break;
|
||||
case 2:
|
||||
LED_PORT = ~led_display.minute;
|
||||
LED_PORT = ~time.minute;
|
||||
ANODES_PORT = led_btnes >= pwm_counter ? ~MINUTE_ANODE : 0xFF;
|
||||
break;
|
||||
case 4:
|
||||
LED_PORT = ~led_display.second;
|
||||
LED_PORT = ~time.second;
|
||||
ANODES_PORT = led_btnes >= pwm_counter ? ~SECOND_ANODE : 0xFF;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#define MINUTE_ANODE (1<<PD6)
|
||||
#define SECOND_ANODE (1<<PD7)
|
||||
|
||||
extern volatile struct TIME_HMS led_display;
|
||||
extern volatile uint8_t led_btnes;
|
||||
|
||||
void led_init(void);
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
#define I2C_BITRATE 100000UL // 100kHz
|
||||
|
||||
void update_time(void);
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -35,23 +34,6 @@ int main()
|
||||
keyboard_handle_input();
|
||||
uart_handle_event(uart_buf);
|
||||
|
||||
update_time();
|
||||
if(rtc_handle_timer()) nightm_handle();
|
||||
}
|
||||
}
|
||||
|
||||
void update_time(void)
|
||||
{
|
||||
if(!(GIFR & (1<<INTF0)))
|
||||
{
|
||||
struct TIME_HMS curr_time = rtc_read_time();
|
||||
led_display = curr_time;
|
||||
nightm_handle(&curr_time);
|
||||
}
|
||||
|
||||
GIFR |= 1<<INTF0;
|
||||
}
|
||||
|
||||
ISR(INT0_vect)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "nightm.h"
|
||||
#include "led.h"
|
||||
#include "rtc.h"
|
||||
|
||||
#define TIME2INT(TIME) ((TIME).hour*60 + (TIME).minute)
|
||||
|
||||
@@ -9,11 +10,11 @@ void nightm_config(struct NIGHTM_CFG* cfg)
|
||||
dump_ram2eem();
|
||||
}
|
||||
|
||||
void nightm_handle(struct TIME_HMS* curr_time)
|
||||
void nightm_handle(void)
|
||||
{
|
||||
if(ram_cfg.night_mode.led_btnes >= 0)
|
||||
{
|
||||
uint16_t current = TIME2INT(*curr_time);
|
||||
uint16_t current = TIME2INT(time);
|
||||
uint16_t begin = TIME2INT(ram_cfg.night_mode.begin);
|
||||
uint16_t end = TIME2INT(ram_cfg.night_mode.end);
|
||||
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
#include "time.h"
|
||||
|
||||
void nightm_config(struct NIGHTM_CFG* cfg);
|
||||
void nightm_handle(struct TIME_HMS* curr_time);
|
||||
void nightm_handle(void);
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,10 @@
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
#include "rtc.h"
|
||||
#include "i2c.h"
|
||||
|
||||
volatile struct TIME_HMS time;
|
||||
|
||||
void rtc_int0_init(void)
|
||||
{
|
||||
INT0_DIR &= ~(1<<INT0_PIN);
|
||||
@@ -40,4 +43,21 @@ struct TIME_HMS rtc_read_time(void)
|
||||
};
|
||||
|
||||
return curr_time;
|
||||
}
|
||||
|
||||
uint8_t rtc_handle_timer(void)
|
||||
{
|
||||
if(!(GIFR & (1<<INTF0)))
|
||||
{
|
||||
time = rtc_read_time();
|
||||
GIFR |= 1<<INTF0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ISR(INT0_vect)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -19,10 +19,12 @@
|
||||
#define DEC_2_BCD(dec) ((((dec) / 10) << 4) | ((dec) % 10))
|
||||
#define BCD_2_DEC(bcd) (((((bcd) >> 4) & 0x0F) * 10) + ((bcd) & 0x0F))
|
||||
|
||||
extern volatile struct TIME_HMS time;
|
||||
|
||||
void rtc_int0_init(void);
|
||||
void rtc_int1_init(void);
|
||||
void rtc_set_time(struct TIME_HMS* time);
|
||||
void rtc_set_time_part(uint8_t part, uint8_t value);
|
||||
struct TIME_HMS rtc_read_time(void);
|
||||
uint8_t rtc_handle_timer(void);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user