Skip to content

Commit

Permalink
rev944 Sensorlib BME680 fix, improved GUI and stype CLI command
Browse files Browse the repository at this point in the history
  • Loading branch information
hpsaturn committed Apr 12, 2023
1 parent e18e022 commit dd214f6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/gui-utils-tft/src/TFTUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ void guiTask(void* pvParameters) {
Serial.println("-->[TGUI] starting task loop");
while (1) {
gui.pageStart();
gui.checkButtons();
gui.displayMainValues();
gui.pageEnd();
vTaskDelay(80 / portTICK_PERIOD_MS);
Expand Down Expand Up @@ -808,7 +809,6 @@ void TFTUtils::pageStart() {
if (wstate == 3 ) displayMainHeader();
}
/// fast interactions (80ms)
checkButtons();
if(sensorLive) drawFanIcon();
updateCalibrationField();
displayGUIStatusFlags();
Expand Down
4 changes: 2 additions & 2 deletions lib/gui-utils-tft/src/TFTUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class TFTUtils {

void pageStart();

void checkButtons();

void pageEnd();

void clearScreen();
Expand Down Expand Up @@ -330,8 +332,6 @@ class TFTUtils {

void showWindowBike();

void checkButtons();

void suspend();

void setupGUITask();
Expand Down
6 changes: 4 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

[platformio]
default_envs = TTGO_TDISPLAY
extra_configs = ../canairio_sensorlib/unified-lib-deps.ini ; only for local tests of sensorslib

[common]
platform = espressif32 @ 4.4.0
framework = arduino
upload_speed = 1500000
monitor_speed = 115200
version = 0.5.8
revision = 943
revision = 944
# OTA remote update target (change it to none, if you want prevent CanAirIO updates)
target = dev
monitor_filters =
Expand All @@ -39,7 +40,8 @@ lib_deps =
hpsaturn/ESP32 Wifi CLI @ 0.2.1
https://github.com/256dpi/arduino-mqtt.git#7afcfb1
https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino.git#8e5f051
hpsaturn/CanAirIO Air Quality Sensors Library @ 0.6.6
; hpsaturn/CanAirIO Air Quality Sensors Library @ 0.6.6
${commonlibs.lib_deps}

[esp32_common]
platform = ${common.platform}
Expand Down
23 changes: 17 additions & 6 deletions src/cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,24 @@ void wcli_stime(String opts) {
Serial.println("invalid sample time");
}

void wcli_stype_error(){
Serial.println("invalid UART sensor type! Choose one into 0-7:");
for (int i=0; i<=7 ;i++)Serial.printf("%i\t%s\r\n",i,sensors.getSensorName((SENSORS)i));
}

void wcli_stype(String opts) {
maschinendeck::Pair<String, String> operands = maschinendeck::SerialTerminal::ParseCommand(opts);
int stype = operands.first().toInt();
if (stype > 7 || stype < 0) Serial.println("invalid UART sensor type. Choose one into 0-7");
String stype = operands.first();
if(stype.length()==0){
wcli_stype_error();
return;
}
int type = stype.toInt();
if (type > 7 || type < 0) wcli_stype_error();
else {
cfg.saveSensorType(stype);
Serial.printf("\nselected UART sensor model\t: %s\r\n", sensors.getSensorName((SENSORS)cfg.stype));
cfg.saveSensorType(type);
Serial.printf("\nselected UART sensor model\t: %s\r\n", sensors.getSensorName((SENSORS)type));
Serial.println("Please reboot to changes apply");
}
}

Expand Down Expand Up @@ -211,7 +222,7 @@ class mESP32WifiCLICallbacks : public ESP32WifiCLICallbacks {
void cliTask(void *param) {
for ( ; ; ) {
wcli.loop();
vTaskDelay(50);
vTaskDelay(120 / portTICK_PERIOD_MS);
}
vTaskDelete( NULL );
}
Expand All @@ -220,7 +231,7 @@ void cliTaskInit() {
xTaskCreate(
cliTask, /* Task function. */
"cliTask", /* String with name of task. */
10000, /* Stack size in bytes. */
3000, /* Stack size in bytes. */
NULL, /* Parameter passed as input of the task */
1, /* Priority of the task. */
NULL /* Task handle. */
Expand Down
44 changes: 23 additions & 21 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ void loadGUIData() {
data.onSelectionUnit = nextUnit;
}

void refreshGUIData() {
void refreshGUIData(bool onUnitSelection) {
loadGUIData();
gui.displaySensorLiveIcon(); // all sensors read are ok
if (!onUnitSelection) {
gui.displaySensorLiveIcon(); // all sensors read are ok
gui.setInfoData(getDeviceInfo());
printWifiRSSI();
}
gui.setSensorData(data);
gui.setInfoData(getDeviceInfo());
printWifiRSSI();
logMemory ("LOOP");
}

Expand Down Expand Up @@ -118,7 +120,7 @@ class MyGUIUserPreferencesCallbacks : public GUIUserPreferencesCallbacks {
if (nextUnit == UNIT::NUNIT ) {
nextUnit = sensors.getNextUnit();
}
refreshGUIData();
refreshGUIData(true);
};
void onUnitSelectionConfirm() {
Serial.print("-->[MAIN] Unit selected \t: ");
Expand Down Expand Up @@ -165,13 +167,13 @@ class MyBatteryUpdateCallbacks : public BatteryUpdateCallbacks {
/// sensors data callback
void onSensorDataOk() {
log_i("[MAIN] onSensorDataOk");
refreshGUIData();
refreshGUIData(false);
}

/// sensors error callback
void onSensorDataError(const char * msg){
log_w("[MAIN] onSensorDataError %s", msg);
refreshGUIData();
refreshGUIData(false);
}

void printSensorsDetected() {
Expand Down Expand Up @@ -201,7 +203,6 @@ void startingSensors() {
sensors.init(mUART); // start all sensors (board predefined pins)
else
sensors.init(mUART, mRX, mTX); // start all sensors and custom pins via setup.

// For more information about the supported sensors,
// please see the canairio_sensorlib documentation.
if(sensors.getSensorsRegisteredCount()==0){
Expand Down Expand Up @@ -242,10 +243,10 @@ void setup() {
Serial.flush();
Serial.println("\n== CanAirIO Setup ==\r\n");
logMemory("INIT");

powerInit();
// init app preferences and load settings
cfg.init("canairio");
logMemory("CONF");
logMemory("CONF");
// init graphic user interface
gui.setBrightness(cfg.getBrightness());
gui.setWifiMode(cfg.isWifiEnable());
Expand All @@ -257,32 +258,32 @@ void setup() {
gui.setCallbacks(new MyGUIUserPreferencesCallbacks());
gui.showWelcome();
logMemory("GLIB");
// CanAirIO CLI init and first setup (safe mode)
if (cfg.getBool(CONFKEYS::KFAILSAFE, true)) {
gui.welcomeAddMessage("wait for setup..");
Serial.println("\n-->[INFO] == Waiting for safe mode setup (10s) ==");
}
cliInit();
logMemory("CLI ");
// init battery monitor
if (FAMILY != "ESP32-C3") {
battery.setUpdateCallbacks(new MyBatteryUpdateCallbacks());
battery.init(cfg.devmode);
battery.update();
logMemory("BATT");
}
powerInit();
// device wifi mac addres and firmware version
Serial.println("-->[INFO] ESP32MAC\t\t: " + cfg.deviceId);
Serial.println("-->[INFO] Hostname\t\t: " + getHostId());
Serial.println("-->[INFO] Revision\t\t: " + gui.getFirmwareVersionCode());
Serial.println("-->[INFO] Firmware\t\t: " + String(VERSION));
Serial.println("-->[INFO] Flavor \t\t: " + String(FLAVOR));
Serial.println("-->[INFO] Target \t\t: " + String(TARGET));
logMemory("GPIO");

if (cfg.getBool(CONFKEYS::KFAILSAFE, true))
gui.welcomeAddMessage("wait for setup..");
// CanAirIO CLI init and first setup (safe mode)
Serial.println("\n-->[INFO] == Waiting for safe mode setup (10s) ==");
cliInit();
logMemory("GPIO");
// Sensors library initialization
Serial.println("-->[INFO] == Detecting Sensors ==");
Serial.println("-->[INFO] Sensorslib version\t: " + sensors.getLibraryVersion());
Serial.println("-->[INFO] enable sensor GPIO\t: " + String(MAIN_HW_EN_PIN));
logMemory("CLI");
startingSensors();
logMemory("SLIB");
// Setting callback for remote commands via Bluetooth config
Expand Down Expand Up @@ -318,7 +319,7 @@ void setup() {
delay(600);
gui.showMain();
gui.loop();
refreshGUIData();
refreshGUIData(false);
logMemory("GLIB");
Serial.printf("-->[INFO] sensors units count\t: %d\r\n", sensors.getUnitsRegisteredCount());
Serial.printf("-->[INFO] show unit selected \t: %s\r\n",sensors.getUnitName(selectUnit).c_str());
Expand All @@ -330,6 +331,7 @@ void setup() {
cfg.saveString("kdevid",cfg.getDeviceId());
// enabling CLI interface
cliTaskInit();
logMemory("CLITASK");
}

void loop() {
Expand All @@ -341,7 +343,7 @@ void loop() {
wd.loop(); // watchdog for check loop blockers
// update GUI flags:
gui.setGUIStatusFlags(WiFi.isConnected(), true, bleIsConnected());
gui.loop();
gui.loop(); // Only for OLED

battery.loop(); // refresh battery level and voltage
powerLoop(); // check power status and manage power saving
Expand Down

0 comments on commit dd214f6

Please sign in to comment.