Skip to content
Snippets Groups Projects
Commit bd36aa98 authored by Cyril Danilevski's avatar Cyril Danilevski
Browse files

Validate MCP port expander logic

Add poll once on start to have accurate information on webpage
parent b1331c84
No related branches found
No related tags found
No related merge requests found
Pipeline #160167 passed
...@@ -17,6 +17,8 @@ void setup() { ...@@ -17,6 +17,8 @@ void setup() {
initializeSNMP(); initializeSNMP();
start = millis(); start = millis();
poll_port_expander();
} }
......
...@@ -36,7 +36,7 @@ String buildPanel(bool sib, bool plc, bool ups, unsigned long elapsed_secs) { ...@@ -36,7 +36,7 @@ String buildPanel(bool sib, bool plc, bool ups, unsigned long elapsed_secs) {
else { page += "<span class=\"status-value status-ok\">OK</span>\n"; } else { page += "<span class=\"status-value status-ok\">OK</span>\n"; }
page += "</div>\n"; page += "</div>\n";
page += "<h3>Last INT: "; page += "<h3>Last Interrupt: ";
page += elapsed_secs; page += elapsed_secs;
page += " secs. ago"; page += " secs. ago";
page += "</h3></div></body></html>"; page += "</h3></div></body></html>";
......
...@@ -11,17 +11,16 @@ void IRAM_ATTR isr(){ ...@@ -11,17 +11,16 @@ void IRAM_ATTR isr(){
void initializeMCP() void initializeMCP()
{ {
pinMode(ISR_PIN, INPUT_PULLUP); pinMode(ISR_PIN, INPUT_PULLUP);
//attachInterrupt(digitalPinToInterrupt(ISR_PIN), isr, CHANGE); attachInterrupt(digitalPinToInterrupt(ISR_PIN), isr, CHANGE);
attachInterrupt(digitalPinToInterrupt(TRIGGER_SIGNAL), isr, CHANGE);
SPI.begin(); SPI.begin();
MCP.begin(); MCP.begin();
// Enable inputs and interrupts on pins 0-2 // Enable inputs and interrupts on pins 0-2
MCP.pinMode8(0b00000111); MCP.pinMode8(0b00000111);
MCP.enableInterrupt(0, FALLING); MCP.enableInterrupt(0, CHANGE);
MCP.enableInterrupt(1, FALLING); MCP.enableInterrupt(1, CHANGE);
MCP.enableInterrupt(2, FALLING); MCP.enableInterrupt(2, CHANGE);
Serial.println("MCP23S08 Started"); Serial.println("MCP23S08 Started");
} }
...@@ -37,23 +36,23 @@ void isr_check_loop() ...@@ -37,23 +36,23 @@ void isr_check_loop()
Serial.print("Interrupt: "); Serial.print("Interrupt: ");
uint8_t regval = MCP.getInterruptCaptureRegister(); //INTCAP uint8_t regval = MCP.getInterruptCaptureRegister(); //INTCAP
Serial.print(regval); Serial.print(regval, BIN);
uint8_t mask = 1 << 0; uint8_t mask = 1 << 0;
if (!(regval & mask)) { if ((regval & mask)) {
Serial.print("UPS"); Serial.print(" UPS");
PINS.ups = true; PINS.ups = true;
} }
mask = 1 << 1; mask = 1 << 1;
if (!(regval & mask)) { if (!(regval & mask)) {
Serial.print("PLC"); Serial.print(" PLC");
PINS.plc = true; PINS.plc = true;
} }
mask = 1 << 2; mask = 1 << 2;
if (!(regval & mask)) { if (!(regval & mask)) {
Serial.print("SIB"); Serial.print(" SIB");
PINS.sib = true; PINS.sib = true;
} }
...@@ -62,6 +61,39 @@ void isr_check_loop() ...@@ -62,6 +61,39 @@ void isr_check_loop()
} }
} }
void poll_port_expander()
{
PINS.sib = false;
PINS.plc = false;
PINS.ups = false;
PINS.last_triggered = millis();
int regval = MCP.read8();
uint8_t mask = 1 << 0;
if ((regval & mask)) {
Serial.print(" UPS");
PINS.ups = true;
}
mask = 1 << 1;
if (!(regval & mask)) {
Serial.print(" PLC");
PINS.plc = true;
}
mask = 1 << 2;
if (!(regval & mask)) {
Serial.print(" SIB");
PINS.sib = true;
}
Serial.println();
}
bool on = true; bool on = true;
unsigned long toggle_start = 0; unsigned long toggle_start = 0;
void toggle_status_led() { void toggle_status_led() {
......
...@@ -28,4 +28,5 @@ extern MCP23S08 MCP; ...@@ -28,4 +28,5 @@ extern MCP23S08 MCP;
void IRAM_ATTR isr(); void IRAM_ATTR isr();
void initializeMCP(); void initializeMCP();
void isr_check_loop(); void isr_check_loop();
void poll_port_expander();
void toggle_status_led(); void toggle_status_led();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment