Skip to content

Commit

Permalink
Merge pull request #164 from kike-canaries/fix_issue_sl_102
Browse files Browse the repository at this point in the history
DeviceType Refactor
  • Loading branch information
hpsaturn authored Dec 8, 2021
2 parents cf0a4b2 + 10e8aa3 commit 88ec1b2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
16 changes: 8 additions & 8 deletions lib/gui-utils-oled/src/GUIUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ void GUIUtils::displayCenterBig(String msg) {
u8g2.print(msg.c_str());
#else
if (dw > 64) {
if (_deviceType <= 3) { // PM
if (_deviceType <= 1) { // PM
u8g2.setCursor(dw - 64, 6);
u8g2.setFont(u8g2_font_inb24_mn);
} else { // CO2
u8g2.setCursor(dw - 62, 10);
u8g2.setFont(u8g2_font_inb19_mn);
}
} else {
if (_deviceType <= 3) { // PM
if (_deviceType <= 1) { // PM
u8g2.setCursor(dw - 28, 7);
u8g2.setFont(u8g2_font_9x18B_tf);
} else { // CO2
Expand All @@ -131,9 +131,9 @@ void GUIUtils::displayCenterBig(String msg) {
u8g2.print(msg.c_str());
u8g2.setCursor(94, 34);
u8g2.setFont(u8g2_font_6x13_tf);
if (_deviceType == -1)
if (_deviceType == 0)
u8g2.print("PAX");
else if (_deviceType == 3)
else if (_deviceType == 1)
u8g2.print("ug/m3");
else
u8g2.print("ppm");
Expand Down Expand Up @@ -208,7 +208,7 @@ void GUIUtils::displaySensorAverage(int average) {
}
#endif
#else
if (_deviceType <= 3) { //PM sensors
if (_deviceType <= 1) { //PM sensors and PAX
if (average < 13) {
#ifdef TTGO_TQ
u8g2.drawXBM(1, 0, 32, 32, SmileFaceGood);
Expand Down Expand Up @@ -335,10 +335,10 @@ void GUIUtils::displaySensorAverage(int average) {
void GUIUtils::displayMainValues() {
displaySensorAverage(_average);
char output[50];
if (_deviceType <= 4)
sprintf(output, "%04d E%02d H%02d%% T%02d°C", _mainValue, 0, (int)_humi, (int)_temp);
else
if (_deviceType <= 1) // PM sensors and PAX
sprintf(output, "%03d E%02d H%02d%% T%02d°C", _mainValue, 0, (int)_humi, (int)_temp);
else
sprintf(output, "%04d E%02d H%02d%% T%02d°C", _mainValue, 0, (int)_humi, (int)_temp);
displayBottomLine(String(output));

#ifdef EMOTICONS
Expand Down
6 changes: 3 additions & 3 deletions lib/gui-utils-tft/src/TFTUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,9 @@ void TFTUtils::displayMainValues(){
displayCenterBig(output);


if (_deviceType == -1)
if (_deviceType == 0)
displayMainUnit("PAX");
else if (_deviceType <= 3)
else if (_deviceType == 1)
displayMainUnit("PM2.5");
else
displayMainUnit("PPM");
Expand Down Expand Up @@ -606,7 +606,7 @@ void TFTUtils::displayGUIStatusFlags() {
}

uint32_t TFTUtils::getAQIColor(uint32_t value) {
if (_deviceType <= 3) {
if (_deviceType <= 1) {

if (value <= 13) return 0;
else if (value <= 35) return 1;
Expand Down
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ framework = arduino
upload_speed = 1500000
monitor_speed = 115200
version = 0.4.9
revision = 869
revision = 873
target = prod
monitor_filters = time
extra_scripts = pre:prebuild.py
Expand All @@ -28,7 +28,7 @@ lib_deps =
bblanchon/ArduinoJson @ 6.18.5
tobiasschuerg/ESP8266 Influxdb @ 3.9.0
chrisjoyce911/esp32FOTA @ 0.1.5
hpsaturn/CanAirIO Air Quality Sensors Library @ 0.4.0
hpsaturn/CanAirIO Air Quality Sensors Library @ 0.4.1
https://github.com/256dpi/arduino-mqtt.git

[esp32_common]
Expand Down
4 changes: 2 additions & 2 deletions src/bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bool oldDeviceConnected = false;

String getNotificationData() {
StaticJsonDocument<40> doc; // notification capacity is reduced, only main value
int deviceType = sensors.getPmDeviceTypeSelected();
int deviceType = sensors.getUARTDeviceTypeSelected();
if (deviceType <= 3) {
doc["P25"] = sensors.getPM25();
} else {
Expand All @@ -40,7 +40,7 @@ String getSensorData() {
doc["pre"] = sensors.getPressure();
doc["bat"] = gui.getBatteryLevel();
doc["PAX"] = getPaxCount();
doc["dsl"] = sensors.getPmDeviceSelected();
doc["dsl"] = sensors.getMainDeviceSelected();
String json;
serializeJson(doc, json);
return json;
Expand Down
30 changes: 16 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,33 @@
#include <bluetooth.hpp>
#include <wifi.hpp>

void refreshGUIData() {
gui.displaySensorLiveIcon(); // all sensors read are ok
int deviceType = sensors.getPmDeviceTypeSelected();
uint16_t getMainValue() {
uint16_t mainValue = 0;

if (deviceType == -1) {
if (sensors.getMainDeviceSelected().isEmpty()) {
mainValue = getPaxCount();
} else if (deviceType <= 3) {
} else if (sensors.getMainSensorTypeSelected() == Sensors::SENSOR_PM) {
mainValue = sensors.getPM25();
} else {
} else if (sensors.getMainSensorTypeSelected() == Sensors::SENSOR_CO2) {
mainValue = sensors.getCO2();
}
return mainValue;
}

void refreshGUIData() {
gui.displaySensorLiveIcon(); // all sensors read are ok

float humi = sensors.getHumidity();
if (humi == 0.0) humi = sensors.getCO2humi();

float temp = sensors.getTemperature();
if (temp == 0.0) temp = sensors.getCO2temp();
if (temp == 0.0) temp = sensors.getCO2temp(); // TODO: temp could be 0.0

gui.setSensorData(
mainValue,
getMainValue(),
humi,
temp,
getWifiRSSI(),
deviceType);
sensors.getMainSensorTypeSelected());

gui.setInfoData(getDeviceInfo());
}
Expand Down Expand Up @@ -118,10 +120,10 @@ void startingSensors() {
// For more information about the supported sensors,
// please see the canairio_sensorlib documentation.

if(sensors.isPmSensorConfigured()){
if(!sensors.getMainDeviceSelected().isEmpty()) {
Serial.print("-->[INFO] PM/CO2 sensor detected: ");
Serial.println(sensors.getPmDeviceSelected());
gui.welcomeAddMessage(sensors.getPmDeviceSelected());
Serial.println(sensors.getMainDeviceSelected());
gui.welcomeAddMessage(sensors.getMainDeviceSelected());
}
else {
Serial.println("-->[INFO] Detection sensors FAIL!");
Expand Down
2 changes: 1 addition & 1 deletion src/wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ String getDeviceInfo () {
String info = getHostId() + "\n";
info = info + String(FLAVOR) + "\n";
info = info + "Rev" + String(REVISION) +" v" + String(VERSION) + "\n";
info = info + "MS: "+sensors.getPmDeviceSelected() + "\n";
info = info + "MS: "+sensors.getMainDeviceSelected() + "\n";
info = info + "" + cfg.getStationName() + "\n";
info = info + "IP: " + WiFi.localIP().toString() + "\n";
info = info + "OTA: " + String(TARGET) + " channel\n";
Expand Down

0 comments on commit 88ec1b2

Please sign in to comment.