From ae19246b43124130c71a7a16e05da0e4302393db Mon Sep 17 00:00:00 2001 From: Aron het Lam Date: Tue, 8 Sep 2020 00:46:19 +0200 Subject: [PATCH] Move tallyServer loop and remove swithcer connect. Moved tallyServer loop into connected state, as else clients connected to the server will keep their tally flags up. Removed atemSwitcher.connect() as the library calls it inside it's loop function, and else it'll send multiple connect requests at once. Removed DNS server capabilities, as it really is an unnecessary drag on performance, that isn't needed and doubtfully ever being used. --- ATEM_tally_light/ATEM_tally_light.ino | 42 ++++----------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/ATEM_tally_light/ATEM_tally_light.ino b/ATEM_tally_light/ATEM_tally_light.ino index 34129f9..314c627 100644 --- a/ATEM_tally_light/ATEM_tally_light.ino +++ b/ATEM_tally_light/ATEM_tally_light.ino @@ -21,7 +21,6 @@ along with this program. If not, see . //Include libraries: #include #include -#include #include #include #include @@ -51,11 +50,7 @@ along with this program. If not, see . #define MODE_PREVIEW_STAY_ON 2 #define MODE_PROGRAM_ONLY 3 -//Define DNS port -#define DNS_PORT 53 - //Initialize global variables -DNSServer dnsServer; ESP8266WebServer server(80); ATEMmin atemSwitcher; @@ -80,11 +75,6 @@ Settings settings; bool firstRun = true; -unsigned long lastMillis; -unsigned long lastMicros; -unsigned long microsCounter; -int counter; - //Perform initial setup on power on void setup() { //Init pins for LED @@ -121,8 +111,6 @@ void setup() { Serial.println("Connecting to WiFi..."); Serial.println("Network name (SSID): " + WiFi.SSID()); - dnsServer.start(DNS_PORT, "*", IPAddress(192, 168, 4, 1)); - // Initialize and begin HTTP server for handeling the web interface server.on("/", handleRoot); server.on("/save", handleSave); @@ -137,9 +125,6 @@ void setup() { //Set state to connecting before entering loop changeState(STATE_CONNECTING_TO_WIFI); - - lastMillis = millis(); - lastMicros = micros(); } void loop() { @@ -167,7 +152,6 @@ void loop() { if (firstRun) { atemSwitcher.begin(settings.switcherIP); //atemSwitcher.serialOutput(0x80); //Makes Atem library print debug info - atemSwitcher.connect(); Serial.println("------------------------"); Serial.println("Connecting to switcher..."); Serial.println((String)"Switcher IP: " + settings.switcherIP[0] + "." + settings.switcherIP[1] + "." + settings.switcherIP[2] + "." + settings.switcherIP[3]); @@ -190,6 +174,9 @@ void loop() { tallyServer.setTallyFlag(i, atemSwitcher.getTallyByIndexTallyFlags(i)); } + //Handle Tally Server + tallyServer.runLoop(); + //Set tally light accordingly if (atemSwitcher.getTallyByIndexTallyFlags(settings.tallyNo) & 0x01) { //if tally live setLED(LED_RED); @@ -209,11 +196,10 @@ void loop() { //Force atem library to reset connection, in order for status to read correctly on website. atemSwitcher.begin(settings.switcherIP); - atemSwitcher.connect(); //Reset tally server's tally flags, They won't get the message, but it'll be reset for when the connectoin is back. tallyServer.resetTallyFlags(); - + } else if (!atemSwitcher.hasInitialized()) { // will return false if the connection was lost Serial.println("------------------------"); Serial.println("Connection to Switcher lost..."); @@ -225,26 +211,8 @@ void loop() { break; } - //Handle Tally Server - tallyServer.runLoop(); - - //Handle DNS requests - dnsServer.processNextRequest(); - //Handle web interface server.handleClient(); - - microsCounter += (micros() - lastMicros); - lastMicros = micros(); - counter++; - if(millis() - lastMillis > 10) { - Serial.print("Loop Time: "); - Serial.println((double)microsCounter / counter); - lastMillis = millis(); - microsCounter = 0; - counter = 0; - lastMicros = micros(); - } } void changeState(uint8_t stateToChangeTo) { @@ -345,7 +313,7 @@ void handleRoot() { if (atemSwitcher.hasInitialized()) html += "Connected - Initialized"; else if (atemSwitcher.isConnected()) - html += "Connected - Not initialized"; + html += "Connected - Wating for initialization - Connection might have been rejected"; else if (WiFi.status() == WL_CONNECTED) html += "Disconnected - No response from switcher"; else