/************************ * * This is the main file for the software. It contains boot up procedures, main routines and * any diagnostic functions for development and testing. * *************************/ #include #include "map.h" #include "config.h" #include #include // Network configuration IPAddress ip(128, 186, 111, 180); EthernetServer server(80); // LCD display configuration LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // Timer variables unsigned long printerPace = 0; unsigned long heartBeat = 0; unsigned long lcdTimer = 0; unsigned long lcdReset = 0; // LCD display variable int lcdLooper = 0; int lcdLine2 = 16; // Timer for Serial output const unsigned long interval = 100; // 1000 milliseconds = 1 second unsigned int count = 0; /******* *Setup function runs once on startup *******/ void setup() { // Start LCD display and initial message lcd.begin(16, 2); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Rebooting..."); // Flash LED during initialization of modules while (!P1.init()) { digitalWrite(heartbeat, !digitalRead(heartbeat)); delay(250); } // Initialize analog module settings const char P1_04ADL_2_CONFIG[] = { 0x40, 0x02 }; //only 3 setup at the moment // Serial begin for any readouts Serial.begin(9600); // Prints the modules connected to the bus Serial.println(P1.rollCall(RollCall, 4)); // Watchdog timer resets the system if it stalls for 5 seconds without being pet P1.configWD(5000, TOGGLE); P1.startWD(); // Configure pin modes pinMode(LED_BUILTIN,OUTPUT); pinMode(SWITCH_BUILTIN,INPUT); // Ethernet setup and print info to serial Ethernet.init(5); Ethernet.begin(mac, ip); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); // Interrupts for future use to streamline important input changes //attachInterrupt(digitalPinToInterrupt(pin),ISR,mode); //attachInterrupt(digitalPinToInterrupt(pin),ISR,mode); /*###### * Send start-up notice to logging server ######*/ currentState = startup; for( int i = 0; i < 16; i++) input[i] = 0; P1.writeDiscrete(LOW,out2); //Buzzer silent output[1] = 0; // Startup input check //app_Tasks(); } void loop() { // Read button on front panel if (P1.readDiscrete(in1) == CLOSED) { acknowledge(); //Acknowledge alarm and silence buzzer delay(2000); if (P1.readDiscrete(in1) == CLOSED){ //Reset to normal condition newState = normal; } //unsigned long currentMillis = millis(); //if (currentMillis - previousMillis >= interval) { //Serial.print("server is at "); //Serial.println(Ethernet.localIP()); } // Check the inputs and update the state app_Tasks(); // Update the interfaces app_Interfaces(); // Reset the watchdog timer P1.petWD(); if( count % 50 == 0 ) { Serial.print("State: "); Serial.print(currentState); Serial.print(";"); Serial.print("Tritium: "); Serial.print(tSniffer); Serial.print(" mCr;"); Serial.print("Vaccum: "); Serial.print(vacuum); Serial.print(" Torr;"); Serial.print("SubPump: "); Serial.print(subPump); Serial.print(" amp;"); for( int i = 0; i < 16; i++ ){ Serial.print(input[i]); Serial.print(";"); } Serial.println(""); count = 0; } delay(interval); count ++; }