Update WaterishOS-core2.0.ino

This commit is contained in:
Siwat Sirichai 2019-08-12 20:29:58 +07:00
parent b2317ed21a
commit 714eebdcb5
1 changed files with 10 additions and 5 deletions

View File

@ -35,6 +35,9 @@ Thread mqttupdater = Thread();
Thread datacollector = Thread(); Thread datacollector = Thread();
Thread lcdmanager = Thread(); Thread lcdmanager = Thread();
boolean online = true; boolean online = true;
boolean sensorstate[12];
boolean lastsensorstate[12];
boolean firstrun = true;
FlowMeter sensorA[6] = FlowMeter(14); FlowMeter sensorA[6] = FlowMeter(14);
FlowMeter sensorB[6] = FlowMeter(3); FlowMeter sensorB[6] = FlowMeter(3);
volatile boolean awakenByInterrupt = false; volatile boolean awakenByInterrupt = false;
@ -55,13 +58,15 @@ void updatelcd()
void ICACHE_RAM_ATTR readA() { void ICACHE_RAM_ATTR readA() {
uint8_t pin = mcp.getLastInterruptPin(); uint8_t pin = mcp.getLastInterruptPin();
uint8_t val = mcp.getLastInterruptPinValue(); uint8_t val = mcp.getLastInterruptPinValue();
for (int sid = 0; sid <= 5; sid++)sensorA[sid].count(); sensorA[pin].count();
mqtt.publish("/waterishos/debug","Aterupted"); mqtt.publish("/waterishos/debug", "Aterupt");
for (int counter=0; counter <= 15; counter++)mcp.digitalRead(counter);
} }
void ICACHE_RAM_ATTR readB() { void ICACHE_RAM_ATTR readB() {
uint8_t pin = mcp.getLastInterruptPin(); uint8_t pin = mcp.getLastInterruptPin();
uint8_t val = mcp.getLastInterruptPinValue(); uint8_t val = mcp.getLastInterruptPinValue();
for (int sid = 8; sid < 13; sid++)sensorB[sid - 8].count(); for (int sid = 8; sid < 13; sid++)sensorB[sid - 8].count();
for (int counter=0; counter <= 15; counter++)mcp.digitalRead(counter);
} }
void collectdata() { void collectdata() {
for (int sid = 0; sid <= 5; sid++)sensorA[sid].tick(1000); for (int sid = 0; sid <= 5; sid++)sensorA[sid].tick(1000);
@ -100,12 +105,12 @@ void setup() {
pinMode(1, INPUT); pinMode(1, INPUT);
pinMode(3, INPUT); pinMode(3, INPUT);
pinMode(14, INPUT); pinMode(14, INPUT);
attachInterrupt(digitalPinToInterrupt(14), readA, FALLING); attachInterrupt(digitalPinToInterrupt(14), readA, RISING);
attachInterrupt(digitalPinToInterrupt(3), readB, FALLING); attachInterrupt(digitalPinToInterrupt(3), readB, RISING);
delay(1000); delay(1000);
writelcd("Boot Sequence P3","Waking Processor"); writelcd("Boot Sequence P3","Waking Processor");
mcp.begin(); mcp.begin();
mcp.setupInterrupts(true, false, LOW); mcp.setupInterrupts(false, false, HIGH);
for (int i = 0; i <= 15; i++) for (int i = 0; i <= 15; i++)
{ {
mcp.pinMode(i, INPUT); mcp.pinMode(i, INPUT);