forked from NHGmaniac/loungeled
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloungeled.ino
194 lines (164 loc) · 4.6 KB
/
loungeled.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <GPNBadge.hpp>
#include <FS.h>
#include "rboot.h"
#include "rboot-api.h"
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include "url-encode.h"
const static int bufferSize = 12;
char packetBuffer[bufferSize];
unsigned int localPort = 8888;
WiFiUDP UDP;
boolean udpConnected = false;
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Badge badge;
void setup() {
badge.init();
badge.setBacklight(true);
tft.fillScreen(BLACK);
tft.setCursor(0,0);
pixels.setPixelColor(1, 0, 255, 0);
pixels.show();
delay(100);
pixels.show();
Serial.begin(115200);
rboot_config rboot_config = rboot_get_config();
SPIFFS.begin();
File f = SPIFFS.open("/rom"+String(rboot_config.current_rom),"w");
f.println("LOUNGELED\n");
setup_wifi();
UDP.begin(localPort);
tft.fillScreen(BLACK);
tft.setCursor(0,0);
tft.println("LoungeLed");
tft.writeFramebuffer();
}
void loop() {
int packetSize = UDP.parsePacket();
if(packetSize)
{
if(packetSize == bufferSize){
UDP.read(packetBuffer, bufferSize);
for (int i = 0; i < 12; i = i+3){
unsigned char r = packetBuffer[i];
unsigned char g = packetBuffer[i+1];
unsigned char b = packetBuffer[i+2];
pixels.setPixelColor(i/3, pixels.Color(r, g, b));
//tft.printf("%d, %d, %d\n", r, g, b);
//tft.println(i);
}
pixels.show();
//tft.writeFramebuffer();
}
}
}
void setup_wifi() {
int ledVal = 0;
bool up = true;
tft.setFont();
tft.setTextSize(1);
tft.setTextColor(RED);
tft.setCursor(0, 2);
tft.println("Reading wifi.conf...");
tft.writeFramebuffer();
tft.setTextColor(WHITE);
File wifiConf = SPIFFS.open("/wifi.conf", "r");
if (!wifiConf) {
tft.println("File not found!");
tft.writeFramebuffer();
delay(5000);
}
String configString;
while (wifiConf.available()) {
configString += char(wifiConf.read());
}
wifiConf.close();
UrlDecode confParse(configString.c_str());
Serial.println(configString);
configString = String();
char* ssid = confParse.getKey("ssid");
char* pw = confParse.getKey("pw");
ssid = "loungeled";
pw = "thisiswhythewifiisslow";
Serial.printf("Connecting to wifi '%s' with password '%s'...\n", ssid, pw);
tft.println("Connecting to SSID:");
tft.println(ssid);
tft.writeFramebuffer();
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
delay(400);
WiFi.mode(WIFI_AP);
delay(400);
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
delay(400);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pw);
unsigned long startTime = millis();
//delete[] pw;
while (WiFi.status() != WL_CONNECTED) {
pixels.setPixelColor(1, pixels.Color(0, 0, ledVal));
pixels.setPixelColor(2, pixels.Color(0, 0, ledVal));
pixels.setPixelColor(3, pixels.Color(0, 0, ledVal));
pixels.setPixelColor(0, pixels.Color(0, 0, ledVal));
pixels.show();
if (ledVal == 100) {
up = false;
}
if (ledVal == 0) {
up = true;
}
if (up) {
//ui->root->setSub("Connecting...");
//ui->draw();
ledVal++;
} else {
ledVal--;
}
if (millis() - startTime > 30 * 1000) {
pixels.setPixelColor(1, pixels.Color(50, 0, 0));
pixels.setPixelColor(2, pixels.Color(50, 0, 0));
pixels.setPixelColor(3, pixels.Color(50, 0, 0));
pixels.setPixelColor(0, pixels.Color(50, 0, 0));
pixels.show();
tft.setTextColor(RED);
tft.println("");
tft.println("WiFi connect failed!");
delay(2000);
ESP.reset();
}
delay(10);
}
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0, 0, 0));
pixels.setPixelColor(3, pixels.Color(0, 0, 0));
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show();
//delete[] ssid;
tft.setTextColor(GREEN);
tft.println("");
tft.println("WiFi connected!");
tft.setTextColor(WHITE);
tft.println(WiFi.localIP().toString());
tft.writeFramebuffer();
Serial.println("WiFi connected");
Serial.println("");
Serial.println(WiFi.localIP());
pixels.show();
delay(2000);
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0, 0, 0));
pixels.setPixelColor(3, pixels.Color(0, 0, 0));
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show();
tft.fillScreen(BLACK);
tft.setCursor(0, 0);
tft.writeFramebuffer();
}