2023-09-18 23:26:44 -04:00
|
|
|
/************************
|
|
|
|
*
|
|
|
|
* This is the main file for the software. It contains boot up procedures, main routines and
|
|
|
|
* any diagnostic functions for development and testing.
|
|
|
|
*
|
|
|
|
*************************/
|
|
|
|
|
|
|
|
#include <P1AM.h>
|
|
|
|
#include "map.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include <Ethernet.h>
|
|
|
|
#include <LiquidCrystal.h>
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2023-11-09 14:52:08 -05:00
|
|
|
// Timer for Serial output
|
2024-03-20 12:42:15 -04:00
|
|
|
const unsigned long interval = 100; // 1000 milliseconds = 1 second
|
|
|
|
unsigned int count = 0;
|
2023-11-09 14:52:08 -05:00
|
|
|
|
2023-09-18 23:26:44 -04:00
|
|
|
/*******
|
|
|
|
*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
|
|
|
|
######*/
|
|
|
|
|
2024-05-09 15:16:30 -04:00
|
|
|
currentState = startup;
|
|
|
|
for( int i = 0; i < 16; i++) input[i] = 0;
|
|
|
|
|
|
|
|
P1.writeDiscrete(LOW,out2); //Buzzer silent
|
|
|
|
output[1] = 0;
|
|
|
|
|
2023-09-18 23:26:44 -04:00
|
|
|
// Startup input check
|
2024-05-09 15:16:30 -04:00
|
|
|
//app_Tasks();
|
2023-09-18 23:26:44 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2024-03-20 12:42:15 -04:00
|
|
|
} //unsigned long currentMillis = millis();
|
|
|
|
//if (currentMillis - previousMillis >= interval) {
|
|
|
|
//Serial.print("server is at ");
|
|
|
|
//Serial.println(Ethernet.localIP());
|
|
|
|
|
2023-09-18 23:26:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check the inputs and update the state
|
|
|
|
app_Tasks();
|
|
|
|
|
|
|
|
// Update the interfaces
|
|
|
|
app_Interfaces();
|
|
|
|
|
|
|
|
|
|
|
|
// Reset the watchdog timer
|
|
|
|
P1.petWD();
|
2023-11-09 14:52:08 -05:00
|
|
|
|
2024-03-20 12:42:15 -04:00
|
|
|
if( count % 50 == 0 ) {
|
|
|
|
|
2023-11-09 14:52:08 -05:00
|
|
|
Serial.print("State: ");
|
|
|
|
Serial.print(currentState);
|
2023-11-09 16:39:31 -05:00
|
|
|
Serial.print(";");
|
2023-11-09 14:52:08 -05:00
|
|
|
|
2023-11-09 16:39:31 -05:00
|
|
|
Serial.print("Tritium: ");
|
2023-11-09 14:52:08 -05:00
|
|
|
Serial.print(tSniffer);
|
2023-11-09 16:39:31 -05:00
|
|
|
Serial.print(" mCr;");
|
2023-11-09 14:52:08 -05:00
|
|
|
|
|
|
|
Serial.print("Vaccum: ");
|
|
|
|
Serial.print(vacuum);
|
2023-11-09 16:39:31 -05:00
|
|
|
Serial.print(" Torr;");
|
2023-11-09 14:52:08 -05:00
|
|
|
|
|
|
|
Serial.print("SubPump: ");
|
|
|
|
Serial.print(subPump);
|
2024-02-08 17:34:00 -05:00
|
|
|
Serial.print(" amp;");
|
|
|
|
|
|
|
|
for( int i = 0; i < 16; i++ ){
|
|
|
|
Serial.print(input[i]);
|
|
|
|
Serial.print(";");
|
|
|
|
}
|
|
|
|
Serial.println("");
|
2024-03-20 12:42:15 -04:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
}
|
2024-03-11 13:00:09 -04:00
|
|
|
|
|
|
|
delay(interval);
|
2024-03-20 12:42:15 -04:00
|
|
|
count ++;
|
2023-09-18 23:26:44 -04:00
|
|
|
}
|