forked from letscontrolit/ESPEasyPluginPlayground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_P122_NeoPixel.ino
102 lines (86 loc) · 3.07 KB
/
_P122_NeoPixel.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
//#######################################################################################################
//#################################### Plugin 122: NeoPixel clock #######################################
//#######################################################################################################
// Command: NeoPixel <led nr>,<red>,<green>,<blue>
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel *Plugin_122_pixels;
#define PLUGIN_122
#define PLUGIN_ID_122 122
#define PLUGIN_NAME_122 "NeoPixel Basic"
#define PLUGIN_VALUENAME1_122 ""
boolean Plugin_122(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_122;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].Custom = true;
Device[deviceCount].TimerOption = false;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_122);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_122));
break;
}
case PLUGIN_WEBFORM_LOAD:
{
char tmpString[128];
sprintf_P(tmpString, PSTR("<TR><TD>Led Count:<TD><input type='text' name='plugin_122_leds' size='3' value='%u'>"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
string += tmpString;
string += F("<TR><TD>GPIO:<TD>");
addPinSelect(false, string, "taskdevicepin1", Settings.TaskDevicePin1[event->TaskIndex]);
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
String plugin1 = WebServer.arg(F("plugin_122_leds"));
Settings.TaskDevicePluginConfig[event->TaskIndex][0] = plugin1.toInt();
success = true;
break;
}
case PLUGIN_INIT:
{
if (!Plugin_122_pixels)
{
Plugin_122_pixels = new Adafruit_NeoPixel(Settings.TaskDevicePluginConfig[event->TaskIndex][0], Settings.TaskDevicePin1[event->TaskIndex], NEO_GRB + NEO_KHZ800);
Plugin_122_pixels->begin(); // This initializes the NeoPixel library.
}
success = true;
break;
}
case PLUGIN_WRITE:
{
if (Plugin_122_pixels)
{
String tmpString = string;
int argIndex = tmpString.indexOf(',');
if (argIndex)
tmpString = tmpString.substring(0, argIndex);
if (tmpString.equalsIgnoreCase(F("NeoPixel")))
{
char Line[80];
char TmpStr1[80];
TmpStr1[0] = 0;
string.toCharArray(Line, 80);
int Par4 = 0;
if (GetArgv(Line, TmpStr1, 5)) Par4 = str2int(TmpStr1);
Plugin_122_pixels->setPixelColor(event->Par1 - 1, Plugin_122_pixels->Color(event->Par2, event->Par3, Par4));
Plugin_122_pixels->show(); // This sends the updated pixel color to the hardware.
success = true;
}
}
break;
}
}
return success;
}