2019-04-25 16:20:01 +02:00
|
|
|
#include "main.h"
|
2019-04-30 11:22:16 +00:00
|
|
|
#include <defines.h>
|
2019-04-25 16:20:01 +02:00
|
|
|
|
|
|
|
// #define ESP8266
|
|
|
|
|
|
|
|
|
|
|
|
#include <EEPROM.h>
|
|
|
|
|
2019-04-30 11:22:16 +00:00
|
|
|
#include <configuration.h>
|
2019-04-25 16:20:01 +02:00
|
|
|
#include "productionMode.h"
|
|
|
|
#include "configurationMode.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool configMode = false;
|
|
|
|
|
|
|
|
uint32_t startTime = 0;
|
|
|
|
|
|
|
|
|
|
|
|
void mainSetup() {
|
|
|
|
startTime = millis();
|
|
|
|
#ifdef DEBUG
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println("Starting ...");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pinMode(CONFIG_SWITCH, INPUT_PULLUP);
|
|
|
|
|
|
|
|
|
|
|
|
EEPROM.begin(1024);
|
|
|
|
EEPROM.get(EEPROM_ADDR, configBlock);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("Magic: ");
|
|
|
|
Serial.println(configBlock.magic);
|
|
|
|
Serial.print("ConfigSwitch: ");
|
|
|
|
Serial.println(digitalRead(CONFIG_SWITCH));
|
|
|
|
|
|
|
|
|
|
|
|
configMode = ((LOW == digitalRead(CONFIG_SWITCH)) || (configBlock.magic != MAGIC));
|
|
|
|
|
|
|
|
if (configMode) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
Serial.println("Configuration mode");
|
|
|
|
#endif
|
|
|
|
setupConfigurationNetwork();
|
|
|
|
setupConfigurationServer();
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
Serial.println("Production mode");
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
showConfiguration();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
setupProduction();
|
|
|
|
setupConfigurationServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
Serial.println("Started.");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void mainLoop() {
|
|
|
|
if (configMode) {
|
|
|
|
loopConfiguration();
|
|
|
|
} else {
|
|
|
|
loopConfiguration();
|
|
|
|
loopProduction();
|
|
|
|
}
|
|
|
|
}
|