-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialRx.h
More file actions
73 lines (69 loc) · 1.06 KB
/
serialRx.h
File metadata and controls
73 lines (69 loc) · 1.06 KB
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
void update_leds(int status);
void update_servo(uint8_t status);
union
{
uint16_t IntVar;
unsigned char Bytes[2];
} Data;
unsigned char rx( void )
{
while ( !(UCSR0A & (1<<RXC0)) );
return UDR0;
}
void handleRx()
{
//leest Data en neemt de bijbehorede acties
uint8_t command = Data.Bytes[0];
uint8_t payload = Data.Bytes[1];
switch(command)
{
case 11:
eeprom_write_byte(&tempOn, payload);
break;
case 12:
eeprom_write_byte(&tempOff, payload);
break;
case 13:
eeprom_write_byte(&lightOn, payload);
break;
case 14:
eeprom_write_byte(&lightOff, payload);
break;
case 15:
eeprom_write_byte(&servoLaag, payload);
break;
case 16:
eeprom_write_byte(&servoHoog, payload);
break;
case 51:
update_leds(1);
break;
case 52:
update_leds(0);
break;
case 53:
manual = payload;
break;
}
}
int id = 0;
int pid = 0;
void buffer(uint8_t data)
{
if (data == 0xff)
{
id = 1;
}
else if (id)
{
id = 0;
pid = data;
}
else if (pid)
{
Data.Bytes[0] = pid;
Data.Bytes[1] = data;
pid = 0;
handleRx();
}
}