From ceec907c74bb8ae8dccbeefec0a640af9fc6973b Mon Sep 17 00:00:00 2001 From: Lubos Petrovic Date: Mon, 28 Dec 2020 22:57:58 +0100 Subject: [PATCH] code cleaning --- Board320_240.cpp | 38 ++++++++++++++++++++++++-------------- BoardInterface.cpp | 4 ++-- menu.h | 17 ++--------------- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/Board320_240.cpp b/Board320_240.cpp index 0782972..c492f20 100644 --- a/Board320_240.cpp +++ b/Board320_240.cpp @@ -1141,25 +1141,25 @@ void Board320_240::menuItemClick() { case 3064: liveData->settings.defaultScreen = 4; showParentMenu = true; break; case 3065: liveData->settings.defaultScreen = 5; showParentMenu = true; break; // SleepMode off/on - case MENU_SLEEP_MODE: liveData->settings.sleepModeEnabled = (liveData->settings.sleepModeEnabled == 1) ? 0 : 1; showMenu(); return; break; - case MENU_SCREEN_BRIGHTNESS: liveData->settings.lcdBrightness += 20; if (liveData->settings.lcdBrightness > 100) liveData->settings.lcdBrightness = 0; + case MENU_SLEEP_MODE: liveData->settings.sleepModeEnabled = (liveData->settings.sleepModeEnabled == 1) ? 0 : 1; showMenu(); return; break; + case MENU_SCREEN_BRIGHTNESS: liveData->settings.lcdBrightness += 20; if (liveData->settings.lcdBrightness > 100) liveData->settings.lcdBrightness = 0; setBrightness((liveData->settings.lcdBrightness == 0) ? 100 : liveData->settings.lcdBrightness); showMenu(); return; break; // Pre-drawn charg.graphs off/on - case MENU_PREDRAWN_GRAPHS: liveData->settings.predrawnChargingGraphs = (liveData->settings.predrawnChargingGraphs == 1) ? 0 : 1; showMenu(); return; break; - case MENU_HEADLIGHTS_REMINDER: liveData->settings.headlightsReminder = (liveData->settings.headlightsReminder == 1) ? 0 : 1; showMenu(); return; break; - case MENU_GPRS: liveData->settings.gprsHwSerialPort = (liveData->settings.gprsHwSerialPort == 2) ? 255 : liveData->settings.gprsHwSerialPort + 1; showMenu(); return; break; - case MENU_GPS: liveData->settings.gpsHwSerialPort = (liveData->settings.gpsHwSerialPort == 2) ? 255 : liveData->settings.gpsHwSerialPort + 1; showMenu(); return; break; - case MENU_SERIAL_CONSOLE: liveData->settings.serialConsolePort = (liveData->settings.serialConsolePort == 0) ? 255 : liveData->settings.serialConsolePort + 1; showMenu(); return; break; - case MENU_DEBUG_LEVEL: liveData->settings.debugLevel = (liveData->settings.debugLevel == 3) ? 0 : liveData->settings.debugLevel + 1; syslog->setDebugLevel(liveData->settings.debugLevel); showMenu(); return; break; + case MENU_PREDRAWN_GRAPHS: liveData->settings.predrawnChargingGraphs = (liveData->settings.predrawnChargingGraphs == 1) ? 0 : 1; showMenu(); return; break; + case MENU_HEADLIGHTS_REMINDER: liveData->settings.headlightsReminder = (liveData->settings.headlightsReminder == 1) ? 0 : 1; showMenu(); return; break; + case MENU_GPRS: liveData->settings.gprsHwSerialPort = (liveData->settings.gprsHwSerialPort == 2) ? 255 : liveData->settings.gprsHwSerialPort + 1; showMenu(); return; break; + case MENU_GPS: liveData->settings.gpsHwSerialPort = (liveData->settings.gpsHwSerialPort == 2) ? 255 : liveData->settings.gpsHwSerialPort + 1; showMenu(); return; break; + case MENU_SERIAL_CONSOLE: liveData->settings.serialConsolePort = (liveData->settings.serialConsolePort == 0) ? 255 : liveData->settings.serialConsolePort + 1; showMenu(); return; break; + case MENU_DEBUG_LEVEL: liveData->settings.debugLevel = (liveData->settings.debugLevel == 3) ? 0 : liveData->settings.debugLevel + 1; syslog->setDebugLevel(liveData->settings.debugLevel); showMenu(); return; break; // Wifi menu - case MENU_WIFI_ENABLED: liveData->settings.wifiEnabled = (liveData->settings.wifiEnabled == 1) ? 0 : 1; showMenu(); return; break; - case MENU_WIFI_SSID: return; break; - case MENU_WIFI_PASSWORD: return; break; + case MENU_WIFI_ENABLED: liveData->settings.wifiEnabled = (liveData->settings.wifiEnabled == 1) ? 0 : 1; showMenu(); return; break; + case MENU_WIFI_SSID: return; break; + case MENU_WIFI_PASSWORD: return; break; // Sdcard - case MENU_SDCARD_ENABLED: liveData->settings.sdcardEnabled = (liveData->settings.sdcardEnabled == 1) ? 0 : 1; showMenu(); return; break; + case MENU_SDCARD_ENABLED: liveData->settings.sdcardEnabled = (liveData->settings.sdcardEnabled == 1) ? 0 : 1; showMenu(); return; break; case MENU_SDCARD_AUTOSTARTLOG: liveData->settings.sdcardAutstartLog = (liveData->settings.sdcardAutstartLog == 1) ? 0 : 1; showMenu(); return; break; case MENU_SDCARD_MOUNT_STATUS: sdcardMount(); break; - case MENU_SDCARD_REC: sdcardToggleRecording(); showMenu(); return; break; + case MENU_SDCARD_REC: sdcardToggleRecording(); showMenu(); return; break; // Distance case 4011: liveData->settings.distanceUnit = 'k'; showParentMenu = true; break; case 4012: liveData->settings.distanceUnit = 'm'; showParentMenu = true; break; @@ -1170,7 +1170,17 @@ void Board320_240::menuItemClick() { case 4031: liveData->settings.pressureUnit = 'b'; showParentMenu = true; break; case 4032: liveData->settings.pressureUnit = 'p'; showParentMenu = true; break; // Pair ble device - case 2: scanDevices = true; liveData->menuCurrent = 9999; commInterface->scanDevices(); return; + case 2: + if (liveData->settings.commType == COMM_TYPE_OBD2CAN) { + displayMessage("Not supported", "in CAN mode"); + delay(3000); + hideMenu(); + return; + } + scanDevices = true; + liveData->menuCurrent = 9999; + commInterface->scanDevices(); + return; // Reset settings case 8: resetSettings(); hideMenu(); return; // Save settings diff --git a/BoardInterface.cpp b/BoardInterface.cpp index c710f78..a8f059a 100644 --- a/BoardInterface.cpp +++ b/BoardInterface.cpp @@ -96,7 +96,7 @@ void BoardInterface::loadSettings() { // Default settings liveData->settings.initFlag = 183; - liveData->settings.settingsVersion = 5; + liveData->settings.settingsVersion = 6; liveData->settings.carType = CAR_KIA_ENIRO_2020_64; tmpStr = "00:00:00:00:00:00"; // Pair via menu (middle button) tmpStr.toCharArray(liveData->settings.obdMacAddress, tmpStr.length() + 1); @@ -198,7 +198,7 @@ void BoardInterface::loadSettings() { if (liveData->tmpSettings.settingsVersion == 5) { liveData->tmpSettings.settingsVersion = 6; liveData->tmpSettings.serialConsolePort = 0; // hwuart0 - liveData->tmpSettings.debugLevel = 1; // 1 - debug communication (BLE/CAN) + liveData->tmpSettings.debugLevel = 0; // show all liveData->tmpSettings.sdcardLogIntervalSec = 2; liveData->tmpSettings.gprsLogIntervalSec = 60; } diff --git a/menu.h b/menu.h index 00b0ee5..2a482da 100644 --- a/menu.h +++ b/menu.h @@ -29,7 +29,7 @@ MENU_ITEM menuItemsSource[100] = { {MENU_ADAPTER_BLE4-1, MENU_ADAPTER_TYPE, 0, "<- parent menu"}, {MENU_ADAPTER_BLE4, MENU_ADAPTER_TYPE, -1, "Bluetooth 4 (BLE4)"}, {MENU_ADAPTER_CAN, MENU_ADAPTER_TYPE, -1, "CAN bus (MCP2515-1/SO)"}, - {MENU_ADAPTER_BT3, MENU_ADAPTER_TYPE, -1, "Bluetooth 3 (dev)"}, + //{MENU_ADAPTER_BT3, MENU_ADAPTER_TYPE, -1, "Bluetooth 3 (dev)"}, {300, 3, 0, "<- parent menu"}, // {MENU_WIFI, 3, -1, "[dev] WiFi network"}, @@ -47,19 +47,6 @@ MENU_ITEM menuItemsSource[100] = { {MENU_HEADLIGHTS_REMINDER, 3, -1, "Headlight reminder"}, {MENU_SLEEP_MODE, 3, -1, "SleepMode"}, -/* - // NTP - byte ntpEnabled; // 0/1 - byte ntpTimezone; - byte ntpDaySaveTime; // 0/1 - // GPRS SIM800L - byte gprsEnabled; // 0/1 - char gprsApn[64]; - // Remote upload - byte remoteUploadEnabled; // 0/1 - char remoteApiUrl[64]; - char remoteApiKey[32];*/ - {400, 4, 0, "<- parent menu"}, {MENU_DISTANCE_UNIT, 4, -1, "Distance"}, {MENU_TEMPERATURE_UNIT, 4, -1, "Temperature"}, @@ -75,7 +62,7 @@ MENU_ITEM menuItemsSource[100] = { {MENU_SDCARD_AUTOSTARTLOG, MENU_SDCARD, -1, "Autostart log enabled"}, {MENU_SDCARD_MOUNT_STATUS, MENU_SDCARD, -1, "Status"}, {MENU_SDCARD_REC, MENU_SDCARD, -1, "Record"}, - {MENU_SDCARD_INTERVAL, MENU_SDCARD, -1, "Log interval sec."}, + //{MENU_SDCARD_INTERVAL, MENU_SDCARD, -1, "Log interval sec."}, {3060, 306, 3, "<- parent menu"}, {3061, 306, -1, "Auto mode"},