-
Notifications
You must be signed in to change notification settings - Fork 1
/
WX_LED_Sectional.ino
127 lines (110 loc) · 3.93 KB
/
WX_LED_Sectional.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
#define copyright "© Aug 2022 VictorWheeler [email protected] use, modify and distribute without restrictions"
#define compiledate __DATE__
/*
* https://github.com/TiVoHomeUser/WX_LED_Sectional
* Original inspired from https://led-sectional.kyleharmon.com https://github.com/WKHarmon/led-sectional
*
*/
/*
* NOTE:
* Due to memory (ram) fragmentation and available amount *DO NOT* use Strings. Anything that will not change put in Flash Prom see F() macro
* and PROGMEM. Remember there is a Maximum of 4MB of SRAM and the WX Download needs 30,000 continuous bytes.
*
* Libraries needed are
* ESP8266mDNS (part of the esp8266 core for Arduino environment)
* ESP8266WebServer (bundled with the version of Arduino IDE)
* ESP8266WiFi (Board Manager. Type "ESP8266" in the text box to search and install the ESP8266 software for Arduino IDE.)
* - FastLED by Daniel Garica
*
* Optional:
* for autoconnect
* - WiFiManager by tzapu,tablatronix
*
* for TSL2561 light sensor
* - Adafruit TSL2561 by Adafruit
*
*/
#include "Arduino.h"
#include "user_settings.h"
#include "WX_LED_Sectional.h"
const char* ssid = STASSID;
const char* password = STAPSK;
const char* hostname = MYHOSTNAME;
ESP8266WebServer server(80);
#define NO_EVENT 0
#define MY_ID 1
#define MY_TEST 2
#define MY_WXUPDATE 3
byte my_Event = MY_TEST;
const unsigned int loop_interval = WX_REFRESH_INTERVAL * 60; // How often to run WX update converted in seconds
unsigned int loop_time = loop_interval; // Force WX update first loop
// Not really 'c' header files break up this .ino file into smaller sections still accessible by the Arduino IDE
#include "utilities.h"
#include "LEDString.h"
#include "notFoundPage.h"
#include "testPage.h"
#include "rootPage.h"
#include "stationPage.h"
#include "setup.h"
#include "metars.h"
void setup(void) {
delay(100); // some boards are unstable
setupBuiltInLED();
setupSerial();
setupBigBlock();
setupAirportString();
setupConnection();
setupmDNS();
setupServer();
setupLEDString();
}
/*
*
* Main Loop
*
*/
void loop(void) {
static unsigned int testTime = loop_time; // delay for test() leds
server.handleClient();
MDNS.update();
if ( timeElapsed() ) { // Do every second
switch(my_Event){
case MY_ID:{ // LED ID call to flash LED on or off map if from console
idLED();
}
break;
case MY_TEST:{ // Cycle colors all LEDs
// To prevent Software WD timeout test is called from loop 5 times
if(testTime <= loop_time ){
test();
testTime = loop_time + 5; // 5 seconds before next test
}
}
break;
case MY_WXUPDATE:{
server.close(); // Stop clients from locking up the 4 available connections
loop_time = loopLEDSectional(); // Return allows loop time to be adjusted for WX GET failures
server.begin(); // Restart Service
testTime = loop_time; // When loop_time overflows the next test may be delayed
my_Event = NO_EVENT;
}
break;
default: {
toggleBuiltInLED();
adjustBrightness(); // Call for light sensor
if (DO_LIGHTNING && lightningLeds.size() > 0) {
loop_time++; // cuts refresh time between WX updates in half in bad weather
doLighting();
}
if (loop_time > loop_interval){ // In default: to prevent conflicts with ID and Test
my_Event = MY_WXUPDATE;
}
}
} // switch(my_Event)
loop_time++; // count the seconds ( 1 loop = about 1 second )
}
// Test for serial data entry. So far only the Flash LED event
if (Serial.available() > 0) {
idLED(getCommand()); // process any input from terminal
}
}