1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/projects/watch/clock_app.c

59 lines
1.4 KiB
C
Raw Normal View History

#include <stdio.h>
#include <time.h>
#include <thread.h>
#include <msg.h>
#include <rtc.h>
#include "clock_app.h"
#include "watch.h"
void time_print(struct tm *time) {
printf("%02i %02i%02i\n", time->tm_sec, time->tm_hour, time->tm_min);
}
static char clock_stack[KERNEL_CONF_STACKSIZE_DEFAULT];
static void clock_thread(void) {
2011-03-08 10:54:40 +01:00
msg_t m;
int active = 0;
rtc_second_pid = thread_getpid();
while(1) {
msg_receive(&m);
switch (m.type) {
case RTC_SECOND:
{
if (! active) break;
}
case MSG_ACTIVATE:
{
active = 1;
struct tm now;
rtc_get_localtime(&now);
time_print(&now);
break;
}
case MSG_DEACTIVATE:
{
active = 0;
break;
}
case MSG_BUTTON_HASH:
{
printf("hashclock\n");
break;
}
default:
{
printf("def clock\n");
}
}
}
}
int clock_app_init() {
return thread_create(clock_stack, sizeof(clock_stack), PRIORITY_MAIN-1, CREATE_STACKTEST, clock_thread, "clock");
}