Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional compilation with appDHT12, or instead with appBME280 #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion M5Stack-SAM/APPS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void appBLEBaecon(){
menuUpdate(menuidx, menulock);
}


#if defined(WS_DHT12)
void appDHT12(){
menuDrawMenu(F("DHT12"),F(""),F("ESC"),F(""),sys_menucolor,sys_windowcolor,sys_menutextcolor);
M5.Lcd.drawString(F("TEMPERATURE"),30,80,2);
Expand All @@ -60,6 +60,38 @@ void appDHT12(){
menuUpdate(menuidx, menulock);
}

#elif defined(WS_BME280)
void appBME280(){
menuDrawMenu(F("BME280"),F(""),F("ESC"),F(""),sys_menucolor,sys_windowcolor,sys_menutextcolor);
M5.Lcd.drawString(F("TEMPERATURE"),30,60,2);
M5.Lcd.drawString(F("°C"),250,60,2);
M5.Lcd.drawString(F("HUMIDITY"),30,120,2);
M5.Lcd.drawString(F("%RH"),250,120,2);
M5.Lcd.drawString(F("PRESSURE"),30,180,2);
M5.Lcd.drawString(F("hPa"),250,180,2);
menuidx = 1;
menulock = 0;
M5.Lcd.setTextColor(sys_menutextcolor, sys_windowcolor);
while(M5.BtnB.wasPressed()){
M5.update();
}
while(!M5.BtnB.wasPressed()){
M5.update();
if(millis()-tmp_tmr > 1000){
tmp_tmr = millis();
float tmp_temp = bme280.readTemperature();
float tmp_humi = bme280.readHumidity();
float tmp_pres = (bme280.readPressure()/100.0F);
//menuWindowClr(sys_windowcolor);
M5.Lcd.drawFloat(tmp_temp, 1, 140, 40, 6);
M5.Lcd.drawFloat(tmp_humi, 1, 140, 100, 6);
M5.Lcd.drawFloat(tmp_pres, 1, 140, 160, 6);
}
}
menuUpdate(menuidx, menulock);
}
#endif

void appStopky(){
boolean tmp_run = false;
float tmp_sec = 0;
Expand Down
12 changes: 10 additions & 2 deletions M5Stack-SAM/GFX_MENU.ino
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ void menuAplikaceLevel(byte inmenuidx){
case 0:
menuIsMenu = LOW;
menuWindowClr(sys_windowcolor);
windowPrintInfoText(F("DHT12"),sys_menutextcolor);
#if defined(WS_DHT12)
windowPrintInfoText(F("DHT12"),sys_menutextcolor);
#elif defined(WS_BME280)
windowPrintInfoText(F("BME280"),sys_menutextcolor);
#endif
break;
case 1:
menuIsMenu = LOW;
Expand Down Expand Up @@ -166,7 +170,11 @@ void menuRunApp(byte inmenuidx, byte inmenulock){
}

if(inmenulock==1 and inmenuidx==0){
appDHT12();
#if defined(WS_DHT12)
appDHT12();
#elif defined(WS_BME280)
appBME280();
#endif
}
if(inmenulock==1 and inmenuidx==1){
appStopky();
Expand Down
32 changes: 29 additions & 3 deletions M5Stack-SAM/M5Stack-SAM.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
#include <M5Stack.h>
#include "EEPROM.h"
#include "utility/DHT12.h"
#include <Wire.h>
#include "SimpleBeacon.h"

/*
* To let the Menu not grow to fast, both "Weather" Apps,
* appDHT12 and appBME280 use the same Menu Index.
* If you like appDHT12, use this define
* #define WEATHER_SENSOR WS_DHT12
* else if you like appBME280, use this define
* #define WEATHER_SENSOR WS_BME280
*/
#define WEATHER_SENSOR WS_BME280

#if defined(WS_DHT12)
#include "utility/DHT12.h"
DHT12 dht12;

#elif defined(WS_BME280)
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme280;
bool status;
#endif

SimpleBeacon ble;
DHT12 dht12;


#define TFT_GREY 0x5AEB
#define TFT_BROWN 0x38E0
Expand All @@ -29,7 +51,11 @@ unsigned long tmp_tmr = 0;

void setup(void) {
Serial.begin(115200);


#if defined(WS_BME280)
status = bme280.begin(0x76);
#endif

if (!EEPROM.begin(EEPROM_SIZE))
{
Serial.println("failed to initialise EEPROM");
Expand Down