/
light.c
87 lines (71 loc) · 1.41 KB
/
light.c
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
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "config.h"
uint8_t channels_active[NUM_CHANNELS];
void light_init() {
//disable all channels
for(uint8_t i; i < NUM_CHANNELS; i++)
enable_channel(i, 0);
//set switches to output
DDRA |= _BV(PA0) | _BV(PA1) | _BV(PA2) | _BV(PA3);
DDRC |= _BV(PC6) | _BV(PC7);
}
void enable_channel(uint8_t channel, uint8_t enable)
{
if (channel < NUM_CHANNELS)
{
channels_active[channel] = enable;
uint8_t *port = 0, pinmask;
//decode port/pin
switch (channel) {
//neon light
case 0:
port = &PORTA;
pinmask = _BV(PA1);
break;
//ddr light
case 1:
port = &PORTA;
pinmask = _BV(PA0);
break;
//not connected
case 2:
port = &PORTA;
pinmask = _BV(PA2);
break;
//not connected
case 3:
port = &PORTA;
pinmask = _BV(PA3);
break;
//not connected
case 4:
port = &PORTC;
pinmask = _BV(PC6);
break;
//not connected
case 5:
port = &PORTC;
pinmask = _BV(PC7);
break;
default:
break;
}
if(port)
{
if(enable)
*port |= pinmask;
else
*port &= ~pinmask;
}
send_status();
}
}
uint8_t get_channel_status() {
uint8_t i, s = 0;
for(i = 0; i < NUM_CHANNELS; i++)
if(channels_active[i])
s |= 1 << i;
return s;
}