summaryrefslogtreecommitdiff
path: root/src/binwatch/binwatch.c
blob: 268a9ee8b69e760666480c2a353c6eaca094b082 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* 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: <nico at ni.fr.eu.org>
 * }}} */
#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);
	  }
      }
}