/* binwatch.c */ /* binwatch - Tiny binary wristwatch. {{{ * * Copyright (C) 2010 Nicolas Schodet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Contact : * Web: http://ni.fr.eu.org/ * Email: * }}} */ #include "io.h" #include "common/led.h" #include "common/rtc.h" #include "common/button.h" #include "common/power.h" /** Get time in leds format. */ static uint16_t binwatch_get_time (void) { uint8_t hour, minute, second; rtc_get_time (&hour, &minute, &second); hour = hour % 12; if (hour == 0) hour = 12; return hour << 6 | minute; } int main (void) { /* Initialise hardware. */ power_init (); led_init (); button_init (); /* Initialise RTC. */ uint8_t init; init = rtc_init (); if (!init) { /* Initialisation failed, blink! */ while (1) { led_display (0x3f, LED_100MS); led_display (0, 9 * LED_100MS); } } else { /* Initialisation ok, display current time. */ uint16_t time; time = binwatch_get_time (); led_display (time, 3 * LED_1S); /* If low voltage detected, wait user press to let clock go. */ if (init == RTC_LOW_VOLTAGE) { button_wait (); rtc_go (); led_display (time, 3 * LED_1S); } /* Wait user press to display time. */ while (1) { button_wait (); time = binwatch_get_time (); led_animate (time, LED_ANIMATION_TRACE_CCW, LED_100MS / 2); led_display (time, 3 * LED_1S); } } }