migate lcdcontrol.h to waterish core
This commit is contained in:
parent
c6d4e288c1
commit
3f6b18b2e2
|
@ -25,74 +25,100 @@
|
||||||
#include <Adafruit_MCP23017.h>
|
#include <Adafruit_MCP23017.h>
|
||||||
#include <Thread.h>
|
#include <Thread.h>
|
||||||
#include <ThreadController.h>
|
#include <ThreadController.h>
|
||||||
#include "lcdcontrol.h"
|
|
||||||
Adafruit_MCP23017 mcp;
|
Adafruit_MCP23017 mcp;
|
||||||
long tslr=0;
|
long tslr = 0;
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
PubSubClient client("siwatsystem.com", 1883, espClient);
|
PubSubClient client("siwatsystem.com", 1883, espClient);
|
||||||
PubSubClientTools mqtt(client);
|
PubSubClientTools mqtt(client);
|
||||||
ThreadController threadControl = ThreadController();
|
ThreadController threadControl = ThreadController();
|
||||||
Thread mqttupdater = Thread();
|
Thread mqttupdater = Thread();
|
||||||
Thread datacollector = Thread();
|
Thread datacollector = Thread();
|
||||||
boolean online=true;
|
boolean online = true;
|
||||||
FlowMeter sensorA[6]= FlowMeter(1);
|
FlowMeter sensorA[6] = FlowMeter(1);
|
||||||
FlowMeter sensorB[6]= FlowMeter(3);
|
FlowMeter sensorB[6] = FlowMeter(3);
|
||||||
volatile boolean awakenByInterrupt = false;
|
volatile boolean awakenByInterrupt = false;
|
||||||
void readA(){
|
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
||||||
uint8_t pin=mcp.getLastInterruptPin();
|
int menu;
|
||||||
uint8_t val=mcp.getLastInterruptPinValue();
|
void drawmenu()
|
||||||
for(int sid=0;sid<=5;sid++)sensorA[sid].count();
|
{
|
||||||
|
switch (this->menu)
|
||||||
|
case: '1':
|
||||||
|
lcd.print(" Waterish OS OK ");
|
||||||
|
|
||||||
}
|
}
|
||||||
void readB(){
|
};
|
||||||
uint8_t pin=mcp.getLastInterruptPin();
|
class disp {
|
||||||
uint8_t val=mcp.getLastInterruptPinValue();
|
public:
|
||||||
for(int sid=8;sid<13;sid++)sensorB[sid-8].count();
|
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
||||||
|
int menu;
|
||||||
|
void setmenu(int mnp) {
|
||||||
|
this->menu = mnp;
|
||||||
|
}
|
||||||
|
void drawmenu()
|
||||||
|
{
|
||||||
|
switch (this->menu)
|
||||||
|
case: '1':
|
||||||
|
this->lcd.print(" Waterish OS OK ");
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void readA() {
|
||||||
|
uint8_t pin = mcp.getLastInterruptPin();
|
||||||
|
uint8_t val = mcp.getLastInterruptPinValue();
|
||||||
|
for (int sid = 0; sid <= 5; sid++)sensorA[sid].count();
|
||||||
}
|
}
|
||||||
void collectdata(){
|
void readB() {
|
||||||
for(int sid=0;sid<=5;sid++)sensorA[sid].tick(1000);
|
uint8_t pin = mcp.getLastInterruptPin();
|
||||||
for(int sid=8;sid<13;sid++)sensorB[sid-8].tick(1000);
|
uint8_t val = mcp.getLastInterruptPinValue();
|
||||||
|
for (int sid = 8; sid < 13; sid++)sensorB[sid - 8].count();
|
||||||
}
|
}
|
||||||
void updatemqtt(){
|
void collectdata() {
|
||||||
for(int counter;counter<=6;counter++)mqtt.publish("/waterishos/node"+nodename+"/flowrateA/"+counter,String(sensorA[counter].getCurrentFlowrate()));
|
for (int sid = 0; sid <= 5; sid++)sensorA[sid].tick(1000);
|
||||||
for(int counter;counter<=6;counter++)mqtt.publish("/waterishos/node"+nodename+"/volumeA/"+counter,String(sensorA[counter].getTotalVolume()));
|
for (int sid = 8; sid < 13; sid++)sensorB[sid - 8].tick(1000);
|
||||||
for(int counter;counter<=6;counter++)mqtt.publish("/waterishos/node"+nodename+"/flowrateB/"+counter,String(sensorB[counter].getCurrentFlowrate()));
|
}
|
||||||
for(int counter;counter<=6;counter++)mqtt.publish("/waterishos/node"+nodename+"/volumeB/"+counter,String(sensorB[counter].getTotalVolume()));}
|
void updatemqtt() {
|
||||||
void setup(){
|
for (int counter; counter <= 6; counter++)mqtt.publish("/waterishos/node" + nodename + "/flowrateA/" + counter, String(sensorA[counter].getCurrentFlowrate()));
|
||||||
|
for (int counter; counter <= 6; counter++)mqtt.publish("/waterishos/node" + nodename + "/volumeA/" + counter, String(sensorA[counter].getTotalVolume()));
|
||||||
|
for (int counter; counter <= 6; counter++)mqtt.publish("/waterishos/node" + nodename + "/flowrateB/" + counter, String(sensorB[counter].getCurrentFlowrate()));
|
||||||
|
for (int counter; counter <= 6; counter++)mqtt.publish("/waterishos/node" + nodename + "/volumeB/" + counter, String(sensorB[counter].getTotalVolume()));
|
||||||
|
}
|
||||||
|
void setup() {
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
int connectionattempt=0;
|
int connectionattempt = 0;
|
||||||
while(WiFi.status() != WL_CONNECTED)
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
{
|
{
|
||||||
//wait for it ... (Wait for Wifi Connection)
|
//wait for it ... (Wait for Wifi Connection)
|
||||||
connectionattempt++;
|
connectionattempt++;
|
||||||
delay(500);
|
delay(500);
|
||||||
if(connectionattempt>=20){
|
if (connectionattempt >= 20) {
|
||||||
online=false;
|
online = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
attachInterrupt(digitalPinToInterrupt(1),readA,FALLING);
|
attachInterrupt(digitalPinToInterrupt(1), readA, FALLING);
|
||||||
attachInterrupt(digitalPinToInterrupt(3),readB,FALLING);
|
attachInterrupt(digitalPinToInterrupt(3), readB, FALLING);
|
||||||
pinMode(1, FUNCTION_3);
|
pinMode(1, FUNCTION_3);
|
||||||
pinMode(3, FUNCTION_3);
|
pinMode(3, FUNCTION_3);
|
||||||
pinMode(1,INPUT);
|
pinMode(1, INPUT);
|
||||||
pinMode(3,INPUT);
|
pinMode(3, INPUT);
|
||||||
mcp.begin();
|
mcp.begin();
|
||||||
mcp.setupInterrupts(true,false,LOW);
|
mcp.setupInterrupts(true, false, LOW);
|
||||||
for(int i=0;i<=15;i++)
|
for (int i = 0; i <= 15; i++)
|
||||||
{
|
{
|
||||||
mcp.pinMode(i, INPUT);
|
mcp.pinMode(i, INPUT);
|
||||||
mcp.setupInterruptPin(i,RISING);
|
mcp.setupInterruptPin(i, RISING);
|
||||||
}
|
}
|
||||||
datacollector.onRun(collectdata);
|
datacollector.onRun(collectdata);
|
||||||
datacollector.setInterval(1000);
|
datacollector.setInterval(1000);
|
||||||
mqttupdater.onRun(updatemqtt);
|
mqttupdater.onRun(updatemqtt);
|
||||||
mqttupdater.setInterval(1000);
|
mqttupdater.setInterval(1000);
|
||||||
threadControl.add(&datacollector);
|
threadControl.add(&datacollector);
|
||||||
threadControl.add(&mqttupdater);
|
threadControl.add(&mqttupdater);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop() {
|
||||||
client.loop();
|
client.loop();
|
||||||
threadControl.run();
|
threadControl.run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,5 @@ const String password = "";
|
||||||
const byte InteruptPinA=1;
|
const byte InteruptPinA=1;
|
||||||
const byte InteruptPinB=3;
|
const byte InteruptPinB=3;
|
||||||
const byte arduinoInterrupt=1;
|
const byte arduinoInterrupt=1;
|
||||||
|
const byte buttonPin = 0;
|
||||||
const String nodename="devkit";
|
const String nodename="devkit";
|
||||||
#define LCD_I2C '0x27'
|
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
class disp {
|
class disp {
|
||||||
public:
|
public:
|
||||||
LiquidCrystal_I2C lcd(LCD_I2C, 16, 2);
|
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
||||||
int menu();
|
int menu;
|
||||||
|
void setmenu(int mnp){
|
||||||
}
|
this->menu = mnp;
|
||||||
|
}
|
||||||
|
void drawmenu()
|
||||||
|
{
|
||||||
|
switch(this->menu)
|
||||||
|
case: '1':
|
||||||
|
this->lcd.print(" Waterish OS OK ");
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue