show time from RTC

This commit is contained in:
King Kévin 2016-03-23 07:50:53 +01:00
parent 3cc04f7499
commit d00c20ffb0
1 changed files with 35 additions and 11 deletions

46
main.c
View File

@ -12,7 +12,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* Copyright (c) 2016 King Kévin <kingkevin@cuvoodoo.info> */
/** @file main.c
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2016
* @brief show the time on a LED strip
* the LED strip consists of 60 WS2812b LEDs
* the time is read from a DS1307 RTC module
*/
/* standard libraries */
#include <stdint.h> // standard integer types
@ -34,21 +40,32 @@
#include "usart.h" // USART utilities
#include "usb_cdcacm.h" // USB CDC ACM utilities
#include "led_ws2812b.h" // WS2812b LEDs utilities
#include "rtc_ds1307.h" // Real Time Clock DS1307 utilities
/* flag set in interrupts to be processed in main task */
volatile bool button_flag = false; // button has been pressed
// the number of ticks in one second
/** the number of ticks in one second
* @note the other values are derived from this value @ref main_ticks
*/
#define TICKS_PER_SECOND 255
/* I can't do the following in define because how defines are stored would cause an integer overflow in the arithmetics */
const uint32_t ticks_second = TICKS_PER_SECOND; // the number of ticks in one second
const uint32_t ticks_minute = 60*TICKS_PER_SECOND; // the number of ticks in one minute
const uint32_t ticks_hour = 60*60*TICKS_PER_SECOND; // the number of ticks in one hour
const uint32_t ticks_midday = 12*60*60*TICKS_PER_SECOND; // the number of ticks in one midday (12 hours)
/** @defgroup main_ticks ticks per time units
* @note I have to use type variables because defines would be stored in signed integers, leading to an overflow it later calculations
* @{
*/
/** number of ticks in one second */
const uint32_t ticks_second = TICKS_PER_SECOND;
/** number of ticks in one minute */
const uint32_t ticks_minute = 60*TICKS_PER_SECOND;
/** number of ticks in one hour */
const uint32_t ticks_hour = 60*60*TICKS_PER_SECOND;
/** number of ticks in one midday (12 hours) */
const uint32_t ticks_midday = 12*60*60*TICKS_PER_SECOND;
/** @} */
uint8_t clock_leds[WS2812B_LEDS*3] = {0}; // RGB values for the WS2812b clock LEDs
/* default output (i.e. for printf) */
/** @brief default printf output */
int _write(int file, char *ptr, int len)
{
int i;
@ -68,7 +85,7 @@ int _write(int file, char *ptr, int len)
return -1;
}
/* switch on LED */
/** @brief switch on board LED */
void led_on(void)
{
#ifdef SYSTEM_BOARD
@ -78,7 +95,7 @@ void led_on(void)
#endif
}
/* switch off LED */
/** @brief switch off board LED */
void led_off(void)
{
#ifdef SYSTEM_BOARD
@ -88,7 +105,7 @@ void led_off(void)
#endif
}
/* toggle LED */
/** @brief toggle board LED */
void led_toggle(void)
{
gpio_toggle(LED_PORT, LED_PIN);
@ -224,12 +241,16 @@ int main(void)
nvic_enable_irq(BUTTON_IRQ); // enable interrupt
#endif
// setup WS2812b LEDs
ws2812b_setup(); // setup WS2812b LEDs
clock_hours(); // show hour markers
clock_clear(); // clear all LEDs
leds_set(); // set the colors of all LEDs
ws2812b_transmit(); // transmit set color
// setup RTC module
rtc_setup(); // setup RTC module
printf("welcome to the CuVoodoo LED clock\n"); // print welcome message
led_on(); // switch on LED to indicate setup completed
@ -254,6 +275,9 @@ int main(void)
__asm__("nop");
}
}
printf("it is now %02lu:%02lu:%02lu\n", time/ticks_hour, (time%ticks_hour)/ticks_minute, (time%ticks_minute)/ticks_second);
printf("RTC time 20%02d-%02d-%02d %02d:%02d:%02d\n", rtc_read_year(), rtc_read_month(), rtc_read_date(), rtc_read_hours(), rtc_read_minutes(), rtc_read_seconds()); // print time
printf("input commands\n");
bool action = false; // if an action has been performed don't go to sleep