-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyIR.cpp
More file actions
70 lines (59 loc) · 1.77 KB
/
Copy pathKeyIR.cpp
File metadata and controls
70 lines (59 loc) · 1.77 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
//#include "ReceiverIR.h"
#include "mbed.h"
#include "Key_Configure.h"
#include "KeyIR.h"
KeyIR::KeyIR(PinName pin,uint16_t Address,uint8_t map[],KeyName map_value[],uint8_t len): ReceiverIR(pin)
{
// ReceiverIR ir_rx(pin);
this->Address=Address;
NumKey=len;
for(int i=0; i<NumKey; i++)
{
this->map_value[i] = map_value[i];
this->map[i] = map[i];
}
//*this->map = map;
}
uint8_t KeyIR::read()
{
// return KeyIR::getState();
if(KeyIR::getState() != KeyIR::Received)
return 0;
memset(buf, 0x00, sizeof(buf));
bitlength=KeyIR::getData(&format, &buf[0], sizeof(buf) * 8);
switch(format)
{
case RemoteIR::NEC:
state = FIRST_KEY;
break;
case RemoteIR::NEC_REPEAT:
state = HOLD_KEY;
break;
default:
state = NO_KEY;
}
if(state==FIRST_KEY)
{
if(Address>>8==buf[0] && (Address&0xff)==buf[1])
{
for(int i=0; i<NumKey; i++)
{
if(map[i]==buf[2])
{
value=map_value[i];
return state;
}
}
state=NO_KEY;
value=KEY_NO_KEY;
}
else
{
state=NO_KEY;
value=KEY_NO_KEY;
}
}
else
return state;
return 0;
}