summaryrefslogtreecommitdiffhomepage
path: root/digital/beacon/src/led.c
blob: 0f82ba786cb3bef6b00e732d68c3fec9c33f8eed (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* led.c */
/* Led management. {{{
 *
 * Copyright (C) 2012 Florent Duchon
 *
 * APBTeam:
 *        Web: http://apbteam.org/
 *      Email: team AT apbteam DOT org
 *
 * 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.
 *
 * }}} */

#include <appTimer.h>
#include "led.h"

static HAL_AppTimer_t delayTimer;


/* This function display a combination of led according the the given state */
void led_display_state(int state)
{
	switch(state)
	{
		case APP_INITIAL_STATE:
		case APP_NETWORK_JOINING_STATE:
			led_on(1);
			led_off(2);
			break;
		case APP_NETWORK_JOINED_STATE:
			led_on(1);
			led_on(2);
		default:
			break;
	}
}


/* This function initializes the leds*/
void init_led(void)
{
	/*D5/D6/D7 are configured in output */
	DDRD = 0xE0;
}

/* This function activates a specific led */
void led_on(int number)
{
	switch(number)
	{
		case 1:
			PORTD|=0x20;
			break;
		case 2:
			PORTD|=0x40;
			break;
		case 3:
			PORTD|=0x80;
			break;
		default:
			break;
	}
}

/* This function deactivates a specific led*/
void led_off(int number)
{
	switch(number)
	{
		case 1:
			PORTD&=0xDF;
			break;
		case 2:
			PORTD&=0xBF;
			break;
		case 3:
			PORTD&=0x7F;
			break;
		default:
			break;
	}
}

/* This function inverse the state of a specific led*/
void led_inverse(int number)
{
	switch(number)
	{
		case 1:
 			PORTD^=0x20;
			break;
		case 2:
 			PORTD^=0x40;
			break;
		case 3:
 			PORTD^=0x80;
			break;
		default:
			break;
	}
}

/* This function enables the timer used by the network blink status led */
void led_start_blink(void)
{
	delayTimer.interval = APP_JOINING_INDICATION_PERIOD;
	delayTimer.mode     = TIMER_REPEAT_MODE;
	delayTimer.callback = led_network_status_blink_callback;
	HAL_StartAppTimer(&delayTimer);
}

/* This function disables the timer used by the network blink status led */
void led_stop_blink(void)
{
	HAL_StopAppTimer(&delayTimer);
	led_on(1);
}

/*  Led blink callback*/
void led_network_status_blink_callback(void)
{
	led_inverse(1);
}