Skip to content

Commit

Permalink
Move tallyServer loop and remove swithcer connect.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AronHetLam authored Sep 7, 2020
1 parent 5be7dc4 commit ae19246
Showing 1 changed file with 5 additions and 37 deletions.
42 changes: 5 additions & 37 deletions ATEM_tally_light/ATEM_tally_light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
//Include libraries:
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <EEPROM.h>
#include <ATEMmin.h>
#include <TallyServer.h>
Expand Down Expand Up @@ -51,11 +50,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -137,9 +125,6 @@ void setup() {

//Set state to connecting before entering loop
changeState(STATE_CONNECTING_TO_WIFI);

lastMillis = millis();
lastMicros = micros();
}

void loop() {
Expand Down Expand Up @@ -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]);
Expand All @@ -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);
Expand All @@ -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...");
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ae19246

Please sign in to comment.