-
Notifications
You must be signed in to change notification settings - Fork 30
/
_P016_IR.ino
87 lines (78 loc) · 2.55 KB
/
_P016_IR.ino
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
//#######################################################################################################
//#################################### Plugin 016: Input IR #############################################
//#######################################################################################################
#include <IRremoteESP8266.h>
IRrecv *irReceiver;
decode_results results;
#define PLUGIN_016
#define PLUGIN_ID_016 16
#define PLUGIN_NAME_016 "Infrared Receive - TSOP4838"
#define PLUGIN_VALUENAME1_016 "IR"
boolean Plugin_016(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_016;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = SENSOR_TYPE_LONG;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = true;
Device[deviceCount].InverseLogicOption = true;
Device[deviceCount].FormulaOption = false;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = false;
Device[deviceCount].GlobalSyncOption = true;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_016);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_016));
break;
}
case PLUGIN_INIT:
{
int irPin = Settings.TaskDevicePin1[event->TaskIndex];
if (irReceiver == 0 && irPin != -1)
{
Serial.println("IR Init");
irReceiver= new IRrecv(irPin);
irReceiver->enableIRIn(); // Start the receiver
}
if (irReceiver != 0 && irPin == -1)
{
Serial.println("IR Removed");
irReceiver->disableIRIn();
delete irReceiver;
irReceiver=0;
}
success = true;
break;
}
case PLUGIN_TEN_PER_SECOND:
{
if (irReceiver->decode(&results))
{
unsigned long IRcode = results.value;
irReceiver->resume();
UserVar[event->BaseVarIndex] = (IRcode & 0xFFFF);
UserVar[event->BaseVarIndex + 1] = ((IRcode >> 16) & 0xFFFF);
String log = F("IR : Code ");
log += String(IRcode, HEX);
addLog(LOG_LEVEL_INFO, log);
sendData(event);
}
success = true;
break;
}
}
return success;
}