forked from enesbcs/ESPEasyPluginPlayground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_P180_Mux.ino
133 lines (126 loc) · 5.04 KB
/
_P180_Mux.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
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
//#######################################################################################################
//#################################### Plugin 180: Analog ###############################################
//#######################################################################################################
#define PLUGIN_180
#define PLUGIN_ID_180 180
#define PLUGIN_NAME_180 "Mux Analog input - 74151/74152/74153 [TESTING]"
#define PLUGIN_VALUENAME1_180 "Analog"
boolean Plugin_180(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_180;
Device[deviceCount].Type = DEVICE_TYPE_TRIPLE;
Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
Device[deviceCount].Ports = 8;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].GlobalSyncOption = true;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_180);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_180));
break;
}
case PLUGIN_INIT:
{
int availablePorts=1;
if (Settings.TaskDevicePin1[event->TaskIndex] != -1)
{
pinMode(Settings.TaskDevicePin1[event->TaskIndex], OUTPUT);
availablePorts*=2;
}
if (Settings.TaskDevicePin2[event->TaskIndex] != -1)
{
pinMode(Settings.TaskDevicePin2[event->TaskIndex], OUTPUT);
availablePorts*=2;
}
if (Settings.TaskDevicePin3[event->TaskIndex] != -1)
{
pinMode(Settings.TaskDevicePin3[event->TaskIndex], OUTPUT);
availablePorts*=2;
}
String log = F("Mux available ports : ");
log += availablePorts;
addLog(LOG_LEVEL_INFO,log);
success = true;
break;
}
case PLUGIN_READ:
{
String log = F("ADC : Analog port ");
log += Settings.TaskDevicePort[event->TaskIndex];
log += F(" mux address: ");
switch( Settings.TaskDevicePort[event->TaskIndex] )
{
case 1:
digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], LOW);
digitalWrite(Settings.TaskDevicePin2[event->TaskIndex], LOW);
digitalWrite(Settings.TaskDevicePin3[event->TaskIndex], HIGH);
log += " 001 ";
break;
case 2:
digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], LOW);
digitalWrite(Settings.TaskDevicePin2[event->TaskIndex], HIGH);
digitalWrite(Settings.TaskDevicePin3[event->TaskIndex], LOW);
log += " 010 ";
break;
case 3:
digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], LOW);
digitalWrite(Settings.TaskDevicePin2[event->TaskIndex], HIGH);
digitalWrite(Settings.TaskDevicePin3[event->TaskIndex], HIGH);
log += " 011 ";
break;
case 4:
digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], HIGH);
digitalWrite(Settings.TaskDevicePin2[event->TaskIndex], LOW);
digitalWrite(Settings.TaskDevicePin3[event->TaskIndex], LOW);
log += " 100 ";
break;
case 5:
digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], HIGH);
digitalWrite(Settings.TaskDevicePin2[event->TaskIndex], LOW);
digitalWrite(Settings.TaskDevicePin3[event->TaskIndex], HIGH);
log += " 101 ";
break;
case 6:
digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], HIGH);
digitalWrite(Settings.TaskDevicePin2[event->TaskIndex], HIGH);
digitalWrite(Settings.TaskDevicePin3[event->TaskIndex], LOW);
log += " 110 ";
break;
case 7:
digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], HIGH);
digitalWrite(Settings.TaskDevicePin2[event->TaskIndex], HIGH);
digitalWrite(Settings.TaskDevicePin3[event->TaskIndex], HIGH);
log += " 111 ";
break;
default :
digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], LOW);
digitalWrite(Settings.TaskDevicePin2[event->TaskIndex], LOW);
digitalWrite(Settings.TaskDevicePin3[event->TaskIndex], LOW);
log += " 000 ";
}
UserVar[event->BaseVarIndex] = analogRead(A0);
log += F("value: ");
log += UserVar[event->BaseVarIndex];
addLog(LOG_LEVEL_INFO,log);
success = true;
break;
}
}
return success;
}