Finishing BME280 page an sensor integration for BME280, BMP290, SHT21
This commit is contained in:
parent
8291631f36
commit
d0d773c8de
|
@ -6,9 +6,17 @@
|
|||
// SeaTalk
|
||||
#define OBP_SEATALK_TX 2
|
||||
#define OBP_SEATALK_RX 15
|
||||
// I2C (MCP23017)
|
||||
// I2C (MCP23017, BME280, BMP280, SHT21)
|
||||
#define OBP_I2C_SDA 21
|
||||
#define OBP_I2C_SCL 22
|
||||
// Extension Port MCP23017
|
||||
#define MCP23017_I2C_ADDR 0x20 // Addr. 0 is 0x20
|
||||
// BME280
|
||||
#define BME280_I2C_ADDR 0x76 // Addr. 0x76
|
||||
// BMP280
|
||||
#define BMP280_I2C_ADDR 0x77 // Addr. 0x77
|
||||
// SHT21
|
||||
#define SHT21_I2C_ADDR 0x40 // Addr. 0x40
|
||||
// SPI (E-Ink display, Extern Bus)
|
||||
#define OBP_SPI_CS 5
|
||||
#define OBP_SPI_DC 17
|
||||
|
@ -43,8 +51,6 @@
|
|||
#define OBP_ANALOG2 39 // Analog In 2
|
||||
#define MIN_VOLTAGE 9.0 // Min voltage for under voltage detection (then goto deep sleep)
|
||||
#define POWER_FAIL_TIME 2 // in [ms] Accept min voltage until 2 x 1ms (for under voltage gaps by engine start)
|
||||
// Extension Port MCP23017
|
||||
#define MCP23017_I2C_ADDR 0x20 // Addr. 0 is 0x20
|
||||
// Extension Port PA
|
||||
#define PA0 0 // Digital Out 1
|
||||
#define PA1 1 // Digital Out 2
|
||||
|
|
|
@ -0,0 +1,208 @@
|
|||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
|
||||
class PageBME280 : public Page
|
||||
{
|
||||
bool keylock = false; // Keylock
|
||||
|
||||
public:
|
||||
PageBME280(CommonData &comon){
|
||||
comon.logger->logDebug(GwLog::LOG,"Show PageThreeValue");
|
||||
}
|
||||
|
||||
virtual int handleKey(int key){
|
||||
if(key == 11){ // Code for keylock
|
||||
keylock = !keylock; // Toggle keylock
|
||||
return 0; // Commit the key
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
virtual void displayPage(CommonData &commonData, PageData &pageData){
|
||||
GwConfigHandler *config = commonData.config;
|
||||
GwLog *logger=commonData.logger;
|
||||
|
||||
double value1 = 0;
|
||||
double value2 = 0;
|
||||
double value3 = 0;
|
||||
|
||||
// Get config data
|
||||
String tempformat = config->getString(config->tempFormat);
|
||||
bool simulation = config->getBool(config->useSimuData);
|
||||
String displaycolor = config->getString(config->displaycolor);
|
||||
String flashLED = config->getString(config->flashLED);
|
||||
String backlightMode = config->getString(config->backlight);
|
||||
|
||||
// Get sensor values #1
|
||||
String name1 = "Temp"; // Value name
|
||||
name1 = name1.substring(0, 6); // String length limit for value name
|
||||
if(simulation == false){
|
||||
value1 = commonData.data.airTemperature; // Value as double in SI unit
|
||||
}
|
||||
else{
|
||||
value1 = 23.0 + float(random(0, 10)) / 10.0;
|
||||
}
|
||||
String svalue1 = String(value1, 1); // Formatted value as string including unit conversion and switching decimal places
|
||||
String unit1 = "Deg C"; // Unit of value
|
||||
|
||||
// Get sensor values #2
|
||||
String name2 = "Humid"; // Value name
|
||||
name2 = name2.substring(0, 6); // String length limit for value name
|
||||
if(simulation == false){
|
||||
value2 = commonData.data.airHumidity; // Value as double in SI unit
|
||||
}
|
||||
else{
|
||||
value2 = 43 + float(random(0, 4));
|
||||
}
|
||||
String svalue2 = String(value2, 0); // Formatted value as string including unit conversion and switching decimal places
|
||||
String unit2 = "%"; // Unit of value
|
||||
|
||||
// Get sensor values #3
|
||||
String name3 = "Press"; // Value name
|
||||
name3 = name3.substring(0, 6); // String length limit for value name
|
||||
if(simulation == false){
|
||||
value3 = commonData.data.airPressure; // Value as double in SI unit
|
||||
}
|
||||
else{
|
||||
value3 = 1006 + float(random(0, 5));
|
||||
}
|
||||
String svalue3 = String(value3, 0); // Formatted value as string including unit conversion and switching decimal places
|
||||
String unit3 = "mBar"; // Unit of value
|
||||
|
||||
// Optical warning by limit violation (unused)
|
||||
if(String(flashLED) == "Limit Violation"){
|
||||
setBlinkingLED(false);
|
||||
setPortPin(OBP_FLASH_LED, false);
|
||||
}
|
||||
|
||||
// Logging boat values
|
||||
LOG_DEBUG(GwLog::LOG,"Drawing at PageBME280, %s: %f, %s: %f, %s: %f", name1, value1, name2, value2, name3, value3);
|
||||
|
||||
// Draw page
|
||||
//***********************************************************
|
||||
|
||||
// Set background color and text color
|
||||
int textcolor = GxEPD_BLACK;
|
||||
int pixelcolor = GxEPD_BLACK;
|
||||
if(displaycolor == "Normal"){
|
||||
textcolor = GxEPD_BLACK;
|
||||
pixelcolor = GxEPD_BLACK;
|
||||
}
|
||||
else{
|
||||
textcolor = GxEPD_WHITE;
|
||||
pixelcolor = GxEPD_WHITE;
|
||||
}
|
||||
// Clear display by call in obp60task.cpp in main loop
|
||||
|
||||
// ############### Value 1 ################
|
||||
|
||||
// Show name
|
||||
display.setTextColor(textcolor);
|
||||
display.setFont(&Ubuntu_Bold20pt7b);
|
||||
display.setCursor(20, 55);
|
||||
display.print(name1); // Page name
|
||||
|
||||
// Show unit
|
||||
display.setTextColor(textcolor);
|
||||
display.setFont(&Ubuntu_Bold12pt7b);
|
||||
display.setCursor(20, 90);
|
||||
display.print(unit1); // Unit
|
||||
|
||||
// Switch font if format for any values
|
||||
display.setFont(&DSEG7Classic_BoldItalic30pt7b);
|
||||
display.setCursor(180, 90);
|
||||
|
||||
// Show bus data
|
||||
display.print(svalue1); // Real value as formated string
|
||||
|
||||
// ############### Horizontal Line ################
|
||||
|
||||
// Horizontal line 3 pix
|
||||
display.fillRect(0, 105, 400, 3, pixelcolor);
|
||||
|
||||
// ############### Value 2 ################
|
||||
|
||||
// Show name
|
||||
display.setTextColor(textcolor);
|
||||
display.setFont(&Ubuntu_Bold20pt7b);
|
||||
display.setCursor(20, 145);
|
||||
display.print(name2); // Page name
|
||||
|
||||
// Show unit
|
||||
display.setTextColor(textcolor);
|
||||
display.setFont(&Ubuntu_Bold12pt7b);
|
||||
display.setCursor(20, 180);
|
||||
display.print(unit2); // Unit
|
||||
|
||||
// Switch font if format for any values
|
||||
display.setFont(&DSEG7Classic_BoldItalic30pt7b);
|
||||
display.setCursor(180, 180);
|
||||
|
||||
// Show bus data
|
||||
display.print(svalue2); // Real value as formated string
|
||||
|
||||
// ############### Horizontal Line ################
|
||||
|
||||
// Horizontal line 3 pix
|
||||
display.fillRect(0, 195, 400, 3, pixelcolor);
|
||||
|
||||
// ############### Value 3 ################
|
||||
|
||||
// Show name
|
||||
display.setTextColor(textcolor);
|
||||
display.setFont(&Ubuntu_Bold20pt7b);
|
||||
display.setCursor(20, 235);
|
||||
display.print(name3); // Page name
|
||||
|
||||
// Show unit
|
||||
display.setTextColor(textcolor);
|
||||
display.setFont(&Ubuntu_Bold12pt7b);
|
||||
display.setCursor(20, 270);
|
||||
display.print(unit3); // Unit
|
||||
|
||||
// Switch font if format for any values
|
||||
display.setFont(&DSEG7Classic_BoldItalic30pt7b);
|
||||
display.setCursor(180, 270);
|
||||
|
||||
// Show bus data
|
||||
display.print(svalue3); // Real value as formated string
|
||||
|
||||
// ############### Key Layout ################
|
||||
|
||||
// Key Layout
|
||||
display.setTextColor(textcolor);
|
||||
display.setFont(&Ubuntu_Bold8pt7b);
|
||||
display.setCursor(115, 290);
|
||||
if(keylock == false){
|
||||
display.print(" [ <<<<<< >>>>>> ]");
|
||||
if(String(backlightMode) == "Control by Key"){ // Key for illumination
|
||||
display.setCursor(343, 290);
|
||||
display.print("[ILUM]");
|
||||
}
|
||||
}
|
||||
else{
|
||||
display.print(" [ Keylock active ]");
|
||||
}
|
||||
|
||||
// Update display
|
||||
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast)
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
static Page *createPage(CommonData &common){
|
||||
return new PageBME280(common);
|
||||
}/**
|
||||
* with the code below we make this page known to the PageTask
|
||||
* we give it a type (name) that can be selected in the config
|
||||
* we define which function is to be called
|
||||
* and we provide the number of user parameters we expect
|
||||
* this will be number of BoatValue pointers in pageData.values
|
||||
*/
|
||||
PageDescription registerPageBME280(
|
||||
"BME280", // Page name
|
||||
createPage, // Action
|
||||
0, // Number of bus values depends on selection in Web configuration
|
||||
{}, // Names of bus values undepends on selection in Web configuration (refer GwBoatData.h)
|
||||
true // Show display header on/off
|
||||
);
|
|
@ -12,10 +12,32 @@ typedef struct{
|
|||
ValueList values;
|
||||
} PageData;
|
||||
|
||||
typedef struct{
|
||||
double batteryVoltage = 0;
|
||||
double batteryCurrent = 0;
|
||||
double batteryPower = 0;
|
||||
double solarVoltage = 0;
|
||||
double solarCurrent = 0;
|
||||
double solarPower = 0;
|
||||
double generatorVoltage = 0;
|
||||
double generatorCurrent = 0;
|
||||
double generatorPower = 0;
|
||||
double airTemperature = 21.3;
|
||||
double airHumidity = 43.2;
|
||||
double airPressure = 1018.8;
|
||||
double onewireTemp1 = 0;
|
||||
double onewireTemp2 = 0;
|
||||
double onewireTemp3 = 0;
|
||||
double onewireTemp4 = 0;
|
||||
double onewireTemp5 = 0;
|
||||
double onewireTemp6 = 0;
|
||||
} SensorData;
|
||||
|
||||
typedef struct{
|
||||
GwApi::Status status;
|
||||
GwLog *logger=NULL;
|
||||
GwConfigHandler *config=NULL;
|
||||
SensorData data;
|
||||
} CommonData;
|
||||
|
||||
//a base class that all pages must inherit from
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
"default": "0",
|
||||
"check": "checkMinMax",
|
||||
"min": -12,
|
||||
"max": 12,
|
||||
"description": "Time zone [UTC -12...+12]",
|
||||
"max": 14,
|
||||
"description": "Time zone [UTC -12...+14]",
|
||||
"category": "OBP60 Settings",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
|
@ -238,32 +238,47 @@
|
|||
},
|
||||
{
|
||||
"name": "useGPS",
|
||||
"label": "GPS NEO-6M",
|
||||
"type": "boolean",
|
||||
"default": "false",
|
||||
"description": "Using internal GPS modul NEO-6M",
|
||||
"label": "GPS Sensor",
|
||||
"type": "list",
|
||||
"default": "off",
|
||||
"description": "Using internal GPS modul NEO-6M or NEO-M8N",
|
||||
"list": [
|
||||
"off",
|
||||
"NEO-6M",
|
||||
"NEO-M8N"
|
||||
],
|
||||
"category": "OBP60 Hardware",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "useBME280",
|
||||
"label": "BME280",
|
||||
"type": "boolean",
|
||||
"default": "false",
|
||||
"description": "Using internal BME280 modul",
|
||||
"name": "useEnvSensor",
|
||||
"label": "Env. Sensor",
|
||||
"type": "list",
|
||||
"default": "off",
|
||||
"description": "Using internal or external environment sensors BME280, BMP280 or SHT21",
|
||||
"list": [
|
||||
"off",
|
||||
"BME280",
|
||||
"BMP280",
|
||||
"SHT21"
|
||||
],
|
||||
"category": "OBP60 Hardware",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "use1Wire",
|
||||
"label": "1Wire",
|
||||
"name": "useTempSensor",
|
||||
"label": "Temp. Sensor",
|
||||
"type": "boolean",
|
||||
"default": "false",
|
||||
"default": "off",
|
||||
"description": "Using external 1Wirew devices (DS18B20)",
|
||||
"list": [
|
||||
"off",
|
||||
"DS18B20"
|
||||
],
|
||||
"category": "OBP60 Hardware",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
|
@ -492,7 +507,7 @@
|
|||
"type": "list",
|
||||
"default": "Voltage",
|
||||
"description": "Type of page for page 1",
|
||||
"list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage"],
|
||||
"list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280"],
|
||||
"category": "OBP60 Page 1",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
|
@ -552,7 +567,7 @@
|
|||
"type": "list",
|
||||
"default": "apparantWind",
|
||||
"description": "Type of page for page 2",
|
||||
"list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage"],
|
||||
"list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280"],
|
||||
"category": "OBP60 Page 2",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
|
@ -613,7 +628,7 @@
|
|||
"type": "list",
|
||||
"default": "oneValue",
|
||||
"description": "Type of page for page 3",
|
||||
"list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage"],
|
||||
"list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280"],
|
||||
"category": "OBP60 Page 3",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
|
@ -674,7 +689,7 @@
|
|||
"type": "list",
|
||||
"default": "oneValue",
|
||||
"description": "Type of page for page 4",
|
||||
"list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage"],
|
||||
"list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280"],
|
||||
"category": "OBP60 Page 4",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
#include <Ticker.h> // Timer Lib for timer interrupts
|
||||
#include <Wire.h> // I2C connections
|
||||
#include <MCP23017.h> // MCP23017 extension Port
|
||||
#include <Adafruit_Sensor.h> // Adafruit Lib for sensors
|
||||
#include <Adafruit_BME280.h> // Adafruit Lib for BME280
|
||||
#include <Adafruit_BMP280.h> // Adafruit Lib for BMP280
|
||||
#include <HTU21D.h> // Lib for SHT21/HTU21
|
||||
#include <N2kTypes.h> // NMEA2000
|
||||
#include <N2kMessages.h>
|
||||
#include <NMEA0183.h> // NMEA0183
|
||||
|
@ -27,10 +31,20 @@
|
|||
tNMEA0183Msg NMEA0183Msg;
|
||||
tNMEA0183 NMEA0183;
|
||||
|
||||
Adafruit_BME280 bme280; // Evironment sensor BME280
|
||||
Adafruit_BMP280 bmp280; // Evironment sensor BMEP280
|
||||
HTU21D sht21(HTU21D_RES_RH12_TEMP14); // Environment sensor SHT21 identical to HTU21
|
||||
|
||||
// Global vars
|
||||
bool initComplete = false; // Initialization complete
|
||||
int taskRunCounter = 0; // Task couter for loop section
|
||||
bool gps_ready = false; // GPS initialized and ready to use
|
||||
bool BME280_ready = false; // BME280 initialized and ready to use
|
||||
bool BMP280_ready = false; // BMP20 initialized and ready to use
|
||||
bool SHT21_ready = false; // SHT21 initialized and ready to use
|
||||
double airhumidity = 0; // Air Humitity value from environment sensor
|
||||
double airtemperature = 0; // Air Temperature value from environment sensor
|
||||
double airpressure = 0; // Ais pressure value from environment sensor
|
||||
|
||||
// Timer Interrupts for hardware functions
|
||||
void underVoltageDetection();
|
||||
|
@ -95,15 +109,6 @@ void OBP60Init(GwApi *api){
|
|||
// Init extension port
|
||||
MCP23017Init();
|
||||
|
||||
// Settings for 1Wire
|
||||
bool enable1Wire = api->getConfig()->getConfigItem(api->getConfig()->use1Wire,true)->asBoolean();
|
||||
if(enable1Wire == true){
|
||||
api->getLogger()->logDebug(GwLog::DEBUG,"1Wire Mode is On");
|
||||
}
|
||||
else{
|
||||
api->getLogger()->logDebug(GwLog::DEBUG,"1Wire Mode is Off");
|
||||
}
|
||||
|
||||
// Settings for NMEA0183
|
||||
String nmea0183Mode = api->getConfig()->getConfigItem(api->getConfig()->serialDirection,true)->asString();
|
||||
api->getLogger()->logDebug(GwLog::DEBUG,"NMEA0183 Mode is: %s", nmea0183Mode);
|
||||
|
@ -136,8 +141,8 @@ void OBP60Init(GwApi *api){
|
|||
}
|
||||
|
||||
// Start serial stream and take over GPS data stream form internal GPS
|
||||
bool gpsOn=api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asBoolean();
|
||||
if(gpsOn == true){
|
||||
String gpsOn=api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asString();
|
||||
if(String(gpsOn) == "NEO-6M"){
|
||||
Serial2.begin(9600, SERIAL_8N1, OBP_GPS_TX, -1); // GPS RX unused in hardware (-1)
|
||||
if (!Serial2) {
|
||||
api->getLogger()->logDebug(GwLog::ERROR,"GPS modul NEO-6M not found, check wiring");
|
||||
|
@ -150,6 +155,19 @@ void OBP60Init(GwApi *api){
|
|||
gps_ready = true;
|
||||
}
|
||||
}
|
||||
if(String(gpsOn) == "NEO-M8N"){
|
||||
Serial2.begin(9600, SERIAL_8N1, OBP_GPS_TX, -1); // GPS RX unused in hardware (-1)
|
||||
if (!Serial2) {
|
||||
api->getLogger()->logDebug(GwLog::ERROR,"GPS modul NEO-M8N not found, check wiring");
|
||||
gps_ready = false;
|
||||
}
|
||||
else{
|
||||
api->getLogger()->logDebug(GwLog::DEBUG,"GPS modul NEO-M8N found");
|
||||
NMEA0183.SetMessageStream(&Serial2);
|
||||
NMEA0183.Open();
|
||||
gps_ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Marker for init complete
|
||||
// Used in OBP60Task()
|
||||
|
@ -161,6 +179,54 @@ void OBP60Init(GwApi *api){
|
|||
|
||||
}
|
||||
|
||||
// Settings for temperature sensors
|
||||
String tempSensor = api->getConfig()->getConfigItem(api->getConfig()->useTempSensor,true)->asString();
|
||||
if(String(tempSensor) == "DS18B20"){
|
||||
api->getLogger()->logDebug(GwLog::DEBUG,"1Wire Mode is On");
|
||||
}
|
||||
else{
|
||||
api->getLogger()->logDebug(GwLog::DEBUG,"1Wire Mode is Off");
|
||||
}
|
||||
|
||||
// Settings for environment sensors on I2C bus
|
||||
String envSensors=api->getConfig()->getConfigItem(api->getConfig()->useEnvSensor,true)->asString();
|
||||
|
||||
if(String(envSensors) == "BME280"){
|
||||
if (!bme280.begin(BME280_I2C_ADDR)) {
|
||||
api->getLogger()->logDebug(GwLog::ERROR,"Modul BME280 not found, check wiring");
|
||||
}
|
||||
else{
|
||||
api->getLogger()->logDebug(GwLog::DEBUG,"Modul BME280 found");
|
||||
airtemperature = bme280.readTemperature();
|
||||
airpressure = bme280.readPressure()/100;
|
||||
airhumidity = bme280.readHumidity();
|
||||
BME280_ready = true;
|
||||
}
|
||||
}
|
||||
else if(String(envSensors) == "BMP280"){
|
||||
if (!bmp280.begin(BMP280_I2C_ADDR)) {
|
||||
api->getLogger()->logDebug(GwLog::ERROR,"Modul BMP280 not found, check wiring");
|
||||
}
|
||||
else{
|
||||
api->getLogger()->logDebug(GwLog::DEBUG,"Modul BMP280 found");
|
||||
airtemperature = bmp280.readTemperature();
|
||||
airpressure =bmp280.readPressure()/100;
|
||||
BMP280_ready = true;
|
||||
}
|
||||
}
|
||||
else if(String(envSensors) == "SHT21"){
|
||||
if (!sht21.begin()) {
|
||||
api->getLogger()->logDebug(GwLog::ERROR,"Modul SHT21 not found, check wiring");
|
||||
}
|
||||
else{
|
||||
api->getLogger()->logDebug(GwLog::DEBUG,"Modul SHT21 found");
|
||||
airhumidity = sht21.readCompensatedHumidity();
|
||||
airtemperature = sht21.readTemperature();
|
||||
SHT21_ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
@ -288,6 +354,8 @@ void registerAllPages(PageList &list){
|
|||
list.add(®isterPageClock);
|
||||
extern PageDescription registerPageWhite;
|
||||
list.add(®isterPageWhite);
|
||||
extern PageDescription registerPageBME280;
|
||||
list.add(®isterPageBME280);
|
||||
}
|
||||
|
||||
// OBP60 Task
|
||||
|
@ -415,7 +483,7 @@ void OBP60Task(GwApi *api){
|
|||
|
||||
// Configuration values for main loop
|
||||
String gpsFix = api->getConfig()->getConfigItem(api->getConfig()->flashLED,true)->asString();
|
||||
bool gps = api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asBoolean();
|
||||
String gps = api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asString();
|
||||
String backlight = api->getConfig()->getConfigItem(api->getConfig()->backlight,true)->asString();
|
||||
// refreshmode defined in init section
|
||||
// displaycolor defined in init section
|
||||
|
@ -441,6 +509,8 @@ void OBP60Task(GwApi *api){
|
|||
long starttime2 = millis(); // Full display refresh after 5 min
|
||||
long starttime3 = millis(); // Display update all 1s
|
||||
long starttime4 = millis(); // Delayed display update after 2s when select a new page
|
||||
long starttime5 = millis(); // Voltage update all 1s
|
||||
long starttime6 = millis(); // Environment sensor update all 1s
|
||||
|
||||
while (true){
|
||||
Timer1.update(); // Update for Timer1
|
||||
|
@ -449,7 +519,7 @@ void OBP60Task(GwApi *api){
|
|||
starttime0 = millis();
|
||||
|
||||
// Send NMEA0183 GPS data on several bus systems all 1000ms
|
||||
if(gps == true){ // If config enabled
|
||||
if(String(gps) == "NEO-6M" || String(gps) == "NEO-M8N"){ // If config enabled
|
||||
if(gps_ready = true){
|
||||
tNMEA0183Msg NMEA0183Msg;
|
||||
while(NMEA0183.GetMessage(NMEA0183Msg)){
|
||||
|
@ -489,16 +559,18 @@ void OBP60Task(GwApi *api){
|
|||
if (keyboardMessage == 9)
|
||||
{
|
||||
pageNumber++;
|
||||
if (pageNumber >= numPages)
|
||||
if (pageNumber >= numPages){
|
||||
pageNumber = 0;
|
||||
}
|
||||
}
|
||||
// #10 Swipe left
|
||||
if (keyboardMessage == 10)
|
||||
{
|
||||
pageNumber--;
|
||||
if (pageNumber < 0)
|
||||
if (pageNumber < 0){
|
||||
pageNumber = numPages - 1;
|
||||
}
|
||||
}
|
||||
/*
|
||||
// #9 or #10 Refresh display befor start a new page if reshresh is enabled
|
||||
if(refreshmode == true && (keyboardMessage == 9 || keyboardMessage == 10)){
|
||||
|
@ -538,12 +610,61 @@ void OBP60Task(GwApi *api){
|
|||
}
|
||||
|
||||
// Send supplay voltage value
|
||||
if(millis() > starttime3 + 1000){
|
||||
if(millis() > starttime5 + 1000){
|
||||
starttime5 = millis();
|
||||
batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20
|
||||
commonData.data.batteryVoltage = batteryVoltage; // Data take over to page
|
||||
// Send to NMEA200 bus
|
||||
SetN2kDCBatStatus(N2kMsg, 0, batteryVoltage, N2kDoubleNA, N2kDoubleNA, 1);
|
||||
api->sendN2kMessage(N2kMsg);
|
||||
}
|
||||
|
||||
// Send data from environment sensor
|
||||
if(millis() > starttime6 + 1000){
|
||||
starttime6 = millis();
|
||||
unsigned char TempSource = 2; // Inside temperature
|
||||
unsigned char PressureSource = 0; // Atmospheric pressure
|
||||
unsigned char HumiditySource=0; // Inside humidity
|
||||
LOG_DEBUG(GwLog::LOG,"Ready status BME280 %d", BME280_ready);
|
||||
if(BME280_ready == true){
|
||||
airtemperature = bme280.readTemperature();
|
||||
commonData.data.airTemperature = airtemperature; // Data take over to page
|
||||
airpressure = bme280.readPressure()/100;
|
||||
commonData.data.airPressure = airpressure; // Data take over to page
|
||||
airhumidity = bme280.readHumidity();
|
||||
commonData.data.airHumidity = airhumidity; // Data take over to page
|
||||
// Send to NMEA200 bus
|
||||
SetN2kPGN130312(N2kMsg, 0, 0,(tN2kTempSource) TempSource, CToKelvin(airtemperature), N2kDoubleNA);
|
||||
api->sendN2kMessage(N2kMsg);
|
||||
SetN2kPGN130313(N2kMsg, 0, 0,(tN2kHumiditySource) HumiditySource, airhumidity, N2kDoubleNA);
|
||||
api->sendN2kMessage(N2kMsg);
|
||||
SetN2kPGN130314(N2kMsg, 0, 0, (tN2kPressureSource) mBarToPascal(PressureSource), airpressure);
|
||||
api->sendN2kMessage(N2kMsg);
|
||||
}
|
||||
else if(BMP280_ready == true){
|
||||
airtemperature = bmp280.readTemperature();
|
||||
commonData.data.airTemperature = airtemperature; // Data take over to page
|
||||
airpressure =bmp280.readPressure()/100;
|
||||
commonData.data.airPressure = airpressure; // Data take over to page
|
||||
// Send to NMEA200 bus
|
||||
SetN2kPGN130312(N2kMsg, 0, 0,(tN2kTempSource) TempSource, CToKelvin(airtemperature), N2kDoubleNA);
|
||||
api->sendN2kMessage(N2kMsg);
|
||||
SetN2kPGN130314(N2kMsg, 0, 0, (tN2kPressureSource) mBarToPascal(PressureSource), airpressure);
|
||||
api->sendN2kMessage(N2kMsg);
|
||||
}
|
||||
else if(BME280_ready == true){
|
||||
airhumidity = sht21.readCompensatedHumidity();
|
||||
commonData.data.airHumidity = airhumidity; // Data take over to page
|
||||
airtemperature = sht21.readTemperature();
|
||||
commonData.data.airTemperature = airtemperature; // Data take over to page
|
||||
// Send to NMEA200 bus
|
||||
SetN2kPGN130312(N2kMsg, 0, 0,(tN2kTempSource) TempSource, CToKelvin(airtemperature), N2kDoubleNA);
|
||||
api->sendN2kMessage(N2kMsg);
|
||||
SetN2kPGN130313(N2kMsg, 0, 0,(tN2kHumiditySource) HumiditySource, airhumidity, N2kDoubleNA);
|
||||
api->sendN2kMessage(N2kMsg);
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh display data all 1s
|
||||
if(millis() > starttime3 + 1000){
|
||||
starttime3 = millis();
|
||||
|
|
|
@ -13,6 +13,9 @@ lib_deps =
|
|||
adafruit/Adafruit BusIO@1.5.0
|
||||
zinggjm/GxEPD@3.1.0
|
||||
sstaub/Ticker@4.4.0
|
||||
adafruit/Adafruit BMP280 Library@2.6.2
|
||||
adafruit/Adafruit BME280 Library@2.2.2
|
||||
enjoyneering/HTU21D@1.2.1
|
||||
build_flags=
|
||||
-D BOARD_NODEMCU32S_OBP60
|
||||
${env.build_flags}
|
||||
|
|
|
@ -7,12 +7,9 @@
|
|||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[platformio]
|
||||
default_envs=
|
||||
m5stack-atom
|
||||
m5stack-atom-canunit
|
||||
m5stickc-atom-canunit
|
||||
nodemcu-homberger
|
||||
default_envs = nodemcu32s_obp60
|
||||
extra_configs =
|
||||
lib/*task*/platformio.ini
|
||||
|
||||
|
@ -44,7 +41,11 @@ build_flags =
|
|||
|
||||
[env:m5stack-atom]
|
||||
board = m5stack-atom
|
||||
lib_deps = ${env.lib_deps}
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
adafruit/Adafruit BMP280 Library@2.6.2
|
||||
adafruit/Adafruit BME280 Library@2.2.2
|
||||
enjoyneering/HTU21D@1.2.1
|
||||
build_flags =
|
||||
-D BOARD_M5ATOM
|
||||
${env.build_flags}
|
||||
|
@ -53,7 +54,11 @@ upload_protocol = esptool
|
|||
|
||||
[env:m5stack-atom-canunit]
|
||||
board = m5stack-atom
|
||||
lib_deps = ${env.lib_deps}
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
adafruit/Adafruit BMP280 Library@2.6.2
|
||||
adafruit/Adafruit BME280 Library@2.2.2
|
||||
enjoyneering/HTU21D@1.2.1
|
||||
build_flags =
|
||||
-D BOARD_M5ATOM_CANUNIT
|
||||
${env.build_flags}
|
||||
|
@ -62,7 +67,11 @@ upload_protocol = esptool
|
|||
|
||||
[env:m5stickc-atom-canunit]
|
||||
board = m5stick-c
|
||||
lib_deps = ${env.lib_deps}
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
adafruit/Adafruit BMP280 Library@2.6.2
|
||||
adafruit/Adafruit BME280 Library@2.2.2
|
||||
enjoyneering/HTU21D@1.2.1
|
||||
build_flags =
|
||||
-D BOARD_M5STICK_CANUNIT -D HAS_RTC -D HAS_M5LCD
|
||||
${env.build_flags}
|
||||
|
@ -71,9 +80,45 @@ upload_protocol = esptool
|
|||
|
||||
[env:nodemcu-homberger]
|
||||
board = nodemcu-32s
|
||||
lib_deps = ${env.lib_deps}
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
adafruit/Adafruit BMP280 Library@2.6.2
|
||||
adafruit/Adafruit BME280 Library@2.2.2
|
||||
enjoyneering/HTU21D@1.2.1
|
||||
build_flags =
|
||||
-D BOARD_HOMBERGER
|
||||
${env.build_flags}
|
||||
upload_port = /dev/esp32
|
||||
upload_protocol = esptool
|
||||
|
||||
[env:testboard]
|
||||
board = m5stack-atom
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
own_lib
|
||||
enjoyneering/HTU21D@1.2.1
|
||||
build_flags =
|
||||
-D BOARD_TEST
|
||||
${env.build_flags}
|
||||
upload_port = /dev/esp32
|
||||
upload_protocol = esptool
|
||||
|
||||
[env:nodemcu32s_obp60]
|
||||
board_build.partitions = lib/obp60task/partitions_obp60.csv
|
||||
board = nodemcu-32s
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
lib_deps =
|
||||
blemasle/MCP23017@2.0.0
|
||||
adafruit/Adafruit BusIO@1.5.0
|
||||
zinggjm/GxEPD@3.1.0
|
||||
sstaub/Ticker@4.4.0
|
||||
adafruit/Adafruit BMP280 Library@2.6.2
|
||||
adafruit/Adafruit BME280 Library@2.2.2
|
||||
enjoyneering/HTU21D@1.2.1
|
||||
build_flags =
|
||||
-D BOARD_NODEMCU32S_OBP60
|
||||
${env.build_flags}
|
||||
upload_port = COM3
|
||||
upload_protocol = esptool
|
||||
monitor_speed = 115200
|
||||
|
|
Loading…
Reference in New Issue