From cff38067f8f16385d8ebab70ec8267dd37b3d294 Mon Sep 17 00:00:00 2001 From: Angel Zaprianov Date: Sun, 27 Nov 2016 19:06:11 +0200 Subject: [PATCH] After tests ... commit --- MID/MID.ino | 27 ++-- MID/lib/CarSens.h | 58 +++----- MID/lib/EEProm.h | 267 ++++++++++++++++------------------- MID/lib/Lcd16x2.h | 4 +- MID/lib/MainFunc.h | 20 ++- MID/lib/MidMenu.h | 114 ++++++++------- MID/lib/ShutDw.h | 22 +-- MID/lib/SwrCan.h | 42 ------ MID/lib/WhlSens.h | 69 ++++++---- ~erase/MidMenu-old.h | 321 ------------------------------------------- 10 files changed, 295 insertions(+), 649 deletions(-) delete mode 100644 MID/lib/SwrCan.h delete mode 100644 ~erase/MidMenu-old.h diff --git a/MID/MID.ino b/MID/MID.ino index bcec3ab..3490d67 100644 --- a/MID/MID.ino +++ b/MID/MID.ino @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -51,12 +52,16 @@ const uint8_t SAV_PIN_DTC = A7; // Plug:16 Detect ignition key off stat // // Engine pins const uint8_t ENG_CLT_PIN = A0; // Plug:31 Engine Temp. [may be capacitor is needed] +const uint8_t BRK_LGH_PIN = 11; // Plug: Brake light detection const uint8_t RPM_SNS_PIN = 2; // Plug:6 RPM [attachInterrupt] const uint8_t SPD_SNS_PIN = 3; // Plug:12 Speed sensor hub [attachInterrupt] const uint8_t ECU_SGN_PIN = 19; // Plug:27 ECU signal // -// lpg old pin: A4 -const uint8_t LPG_LVL_PIN = A5; // None Fuel LPG switch +// 4 Pins LPG fuel switch/gauge +// Two wires are for power supply, other two wires is for displayed information. +// * Check wiring diagram in order to determine wiring +const uint8_t LPG_LVL_PIN = A5; // None Tank fuel level +const uint8_t LPG_SWT_PIN = A4; // None Fuel switcher // // Display dim pins const uint8_t DIM_PIN_VAL = A10; // Plug:7 Display back-light @@ -80,13 +85,15 @@ const uint8_t ALP_PIN_VOL = 14; // volatile Vehicle time travel //volatile float CUR_VTT = 0; float TTL_TTD; // Total travel distance -float TTL_TLC; // Total Liters per hour consumed -float TTL_CLC; // Total Consumption trip +float TTL_LPG; // Total LPG Travel Liters +float TTL_BNZ; // Total BNZ Travel Liters +float CRT_LPG; // Current LPG Consumption trip +float CRT_BNZ; // Current BNZ Consumption trip float TTL_WRD; // Total Work distance [changing the timing belt wear collection ] - // // Change state of shutdown "press to save" #define SHUTDOWN_SAVE_STATE LOW +#define SHUTDOWN_SAVE_BUTTON 9 // // LiquidCrystal library // Including from Arduino IDE @@ -159,7 +166,7 @@ void setup() { // // Shutdown setupEngine - shutDown.setup(SAV_PIN_CTR, SAV_PIN_DTC, BTN_PIN_UP, ADT_ALR_PIN); + shutDown.setup(SAV_PIN_CTR, SAV_PIN_DTC, ADT_ALR_PIN); // // Turn lcdDisplay off lcd.noDisplay(); @@ -211,10 +218,15 @@ void setup() { eepRom.loadCurrentData(); pinMode(18, INPUT_PULLUP); + + pinMode(LPG_LVL_PIN, INPUT); + pinMode(LPG_SWT_PIN, INPUT); } void loop() { + + // // Set new time every begin ampInt.setTimer(millis()); @@ -226,6 +238,7 @@ void loop() { Serial.print("Window washer value: "); Serial.println(digitalRead(18)); } + // // Listen engine carSens.listener(); @@ -314,5 +327,3 @@ static void playWelcomeScreen() { delay(1500); lcd.clear(); } - - diff --git a/MID/lib/CarSens.h b/MID/lib/CarSens.h index d2a3d6c..0cd1567 100644 --- a/MID/lib/CarSens.h +++ b/MID/lib/CarSens.h @@ -38,10 +38,11 @@ // // ECU Consumption signal mul by *10 // next 3815 -#define ECU_CORRECTION 376 // 168 || 224 || 336 || 648 +#define ENG_CORRECTION 4 // Divider pure voltage +#define ECU_CORRECTION 346 // 168 || 224 || 336 || 648 #define VSS_CORRECTION 3.767 // 3.835232 || 5 || 7.670464 || 15.340928 #define RPM_CORRECTION 33.767 // 33.767 || 50 || 67.534 || 135.068 -#define DST_CORRECTION 15400.11 // 15260.11 || 20266.66 || 30400 || 60791.24 +#define DST_CORRECTION 15600.11 // 15260.11 || 20266.66 || 30400 || 60791.24 // DST // =============== // cur test +40 = 15240.11 @@ -207,6 +208,7 @@ class CarSens { // // LPG tank int CUR_LTK; + int FUEL_STATE = 0; // unsigned long CUR_VTT,// Travel time @@ -487,15 +489,8 @@ class CarSens { } int getTnkLpgPer() { - // - // I received some additional information from the manufacturer of the fuel gauge if this changes anything: - // The fuel input is approximately 4.5V through 150 ohm. - // 73 ohm sender voltage would be 4.5*73/(150+73) = 1.5V - // 10 ohm sender voltage would be 4.5*10/(150+10) = 0.3V - // 240 ohm sender voltage would be 4.5*240/(150+240) = 2.8V - // 33 ohm sender voltage would be 4.5*33/(150+33) = 0.8V - // So in my case 20k fuel gauge - return (int) map(CUR_LTK, 10, 55, 0, 100); + + return (int) CUR_LTK;/* map(CUR_LTK, 10, 100, 0, 100)*/ } int getTnkBnz() { @@ -789,15 +784,15 @@ void CarSens::speedingAlarms() { speedAlarmCursor = ENABLE_SPEED_HW; } - if (_amp->isSec() && CUR_VSS > VSS_ALARM_CITY_SPEED && speedAlarmCursor == ENABLE_SPEED_CT) { + if (_amp->is5Seconds() && CUR_VSS > VSS_ALARM_CITY_SPEED && speedAlarmCursor == ENABLE_SPEED_CT) { tone(ADT_ALR_PIN, 4000, 200); } - if (_amp->isSec() && CUR_VSS > VSS_ALARM_VWAY_SPEED && speedAlarmCursor == ENABLE_SPEED_VW) { + if (_amp->is10Seconds() && CUR_VSS > VSS_ALARM_VWAY_SPEED && speedAlarmCursor == ENABLE_SPEED_VW) { tone(ADT_ALR_PIN, 4000, 200); } - if (_amp->isSec() && CUR_VSS > VSS_ALARM_HWAY_SPEED && speedAlarmCursor == ENABLE_SPEED_HW) { + if (_amp->isMinute() && CUR_VSS > VSS_ALARM_HWAY_SPEED && speedAlarmCursor == ENABLE_SPEED_HW) { tone(ADT_ALR_PIN, 4000, 200); } @@ -870,12 +865,16 @@ void CarSens::sensDim() { */ void CarSens::sensTnk() { + // + // LPG tank + // Full tank reading 805 + // Empty tank reading --- if (_amp->isMax()) { indexLpgTank++; int lpgTankLevel = analogRead(pinLpgTank); Serial.print("Tank level: "); Serial.println(lpgTankLevel); - lpgTankLevel = (int) ((5.00 / 1023.00) * lpgTankLevel) * 10; + lpgTankLevel = int(lpgTankLevel - 805); Serial.print("after tank level: "); @@ -884,7 +883,6 @@ void CarSens::sensTnk() { if (lpgTankLevel > 0) { containerLpgTank = containerLpgTank + lpgTankLevel; CUR_LTK = int(containerLpgTank / indexLpgTank); - CUR_LTK = lpgTankLevel; } @@ -899,34 +897,17 @@ void CarSens::sensTnk() { * Engine temperature */ void CarSens::sensEnt() { -// if (_amp->isLow()) { - - int val = analogRead(pinTemp); - if (val > 800) { - engineTempHigh++; - } - engineTempIndex++; - - if (_amp->isSens()) { - CUR_ENT = int(engineTempIndex - engineTempHigh); + int val = analogRead(pinTemp); + CUR_ENT = int(val / ENG_CORRECTION); #ifdef DEBUG_ENG_TEMP Serial.print("Engine temperature: "); Serial.print(val); - Serial.print(" / index: "); - Serial.print(engineTempIndex); - Serial.print(" / high: "); - Serial.print(engineTempHigh); Serial.print(" / result:"); Serial.println(CUR_ENT); #endif - - engineTempIndex = 0; - engineTempHigh = 0; - - } } @@ -1103,7 +1084,7 @@ void CarSens::sensCns() { } // // Convert to float - TTL_CLC = float(TTL_FL_CNS * 0.00001);// L/h, comes from the /10000*100 + CRT_LPG = float(TTL_FL_CNS * 0.00001);// L/h, comes from the /10000*100 } @@ -1136,9 +1117,10 @@ void CarSens::sensIfc() { // if maf is 0 it will just output 0 if (CUR_VSS < CONS_TGL_VSS) { - cons = long(long(maf * getIfcFuelVal()) / 1000 * 0.001); // L/h, do not use float so mul first then divide + cons = long( + long(maf * getIfcFuelVal() / 2) / 1000 * 0.001); // L/h, do not use float so mul first then divide } else { - cons = long(maf * getIfcFuelVal()) / delta_dist; // L/100kmh, 100 comes from the /10000*100 + cons = long(maf * getIfcFuelVal() / 2) / delta_dist; // L/100kmh, 100 comes from the /10000*100 } // pass // Current Instance consumption diff --git a/MID/lib/EEProm.h b/MID/lib/EEProm.h index 2695afc..07b4f24 100644 --- a/MID/lib/EEProm.h +++ b/MID/lib/EEProm.h @@ -26,20 +26,23 @@ // Saves Addresses in EEP Rom const int EEP_ADR_FTK = 0; // Fuel tank Astra G - 52 liter 14 gallons -const int EEP_ADR_TC1 = 1; // Consumption Float A -const int EEP_ADR_TC2 = 2; // Consumption Float B +const int EEP_ADR_CL1 = 1; // Consumption Float A LPG +const int EEP_ADR_Cl2 = 2; // Consumption Float B LPG + +const int EEP_ADR_CB1 = 8; // Consumption Float A BNZ +const int EEP_ADR_CB2 = 9; // Consumption Float B BNZ + const int EEP_ADR_TT1 = 3; // Total Travel distance const int EEP_ADR_TT2 = 4; // Total Travel distance + const int EEP_ADR_WD1 = 5; // Trip distance const int EEP_ADR_WD2 = 6; // Trip distance const int EEP_ADR_TRD = 7; // Trip distance -const int EEP_ADR_TTT = 4; // Total Trip Time -const int EEP_ADR_TER = 4; // Time Engine Run const int EEP_ADR_TRS = 5; // Tires size const int EEP_ADR_RMS = 6; // Rims Size -// +// AT24C256 // We’re using a 256kbit eeprom which is actually 32kbytes of space. // 262,144 bits / 8 bits in a byte = 32,768 bytes. // That’s 62 times the Arduino’s built-in storage! @@ -49,6 +52,7 @@ const int EEP_ADR_RMS = 6; // Rims Size class EepRom { CarSens *_car; + public: EepRom(CarSens *carSens); @@ -60,143 +64,28 @@ class EepRom { // Called when zeroed current data void saveZeroingData(); - void saveFuelTankLevel(unsigned int value = 0) { - WireEepRomWriteByte(EEP_ADR_FTK, value); - }; - - int loadFuelTankLevel() { - WireEepRomRead(EEP_ADR_FTK); - }; - - /** - * SAVE Travel distance - */ - void saveTravelDistance(float value = 0) { - int val[2]; - - separateFloat(value, val); - -#if defined(DEBUG_EEP_ROM) - Serial.print("EEP ROM records Travel value A: "); - Serial.print(val[0]); - Serial.print(" and value B:"); - Serial.print(val[1]); - Serial.print("\n\r"); -#endif - - WireEepRomWriteByte(EEP_ADR_TT1, val[0]); - WireEepRomWriteByte(EEP_ADR_TT2, val[1]); - } - - /** - * LOAD Travel distance - */ - float loadTravelDistance() { - int va1 = WireEepRomRead(EEP_ADR_TT1); - int va2 = WireEepRomRead(EEP_ADR_TT2); - -#if defined(DEBUG_EEP_ROM) - Serial.print("EEP ROM restore Travel value A: "); - Serial.print(va1); - Serial.print(" and value B:"); - Serial.print(va2); - Serial.print("\n\r"); -#endif - - return restoreFloat(va1, va2); - } - - /** - * Saves travel consumption - */ - void saveTravelConsumption(float value = 0) { - int val[2]; - - separateFloat(value, val); - -#if defined(DEBUG_EEP_ROM) - Serial.print("EEP ROM records value A: "); - Serial.print(val[0]); - Serial.print(" and value B:"); - Serial.print(val[1]); - Serial.print("\n\r"); -#endif - - WireEepRomWriteByte(EEP_ADR_TC1, val[0]); - WireEepRomWriteByte(EEP_ADR_TC2, val[1]); - } - - /** - * Loads travel consumption - */ - float loadTravelConsumption() { - - int va1 = WireEepRomRead(EEP_ADR_TC1); - int va2 = WireEepRomRead(EEP_ADR_TC2); + void saveCurrentData(); + void loadCurrentData(); -#if defined(DEBUG_EEP_ROM) - Serial.print("EEP ROM restore value A: "); - Serial.print(va1); - Serial.print(" and value B:"); - Serial.print(va2); - Serial.print("\n\r"); -#endif - return restoreFloat(va1, va2); - } +private: - /** - * LOAD Work distance - */ - float loadWorkDistance() { - int va1 = WireEepRomRead(EEP_ADR_WD1); - int va2 = WireEepRomRead(EEP_ADR_WD2); - -#if defined(DEBUG_EEP_ROM) - Serial.print("EEP ROM restore Work Distance value A: "); - Serial.print(va1); - Serial.print(" and value B:"); - Serial.print(va2); - Serial.print("\n\r"); -#endif - - return restoreFloat(va1, va2); - } + float loadLpgCons(); - /** - * Saves Work distance - */ - void saveWorkingDistance(float value = 0) { - int val[2]; + void saveLpgCons(float value = 0); - separateFloat(value, val); + float loadBnzCons(); -#if defined(DEBUG_EEP_ROM) - Serial.print("EEP ROM records Work Distance A: "); - Serial.print(val[0]); - Serial.print(" and value B:"); - Serial.print(val[1]); - Serial.print("\n\r"); -#endif + void saveBnzCons(float value = 0); - WireEepRomWriteByte(EEP_ADR_WD1, val[0]); - WireEepRomWriteByte(EEP_ADR_WD2, val[1]); - } + float loadWorkDistance(); + void saveWorkingDistance(float value = 0); - void saveTripDistance(unsigned int value = 0) { - WireEepRomWriteByte(EEP_ADR_TRD, value / 4); - } - - int long loadTripDistance(unsigned int value = 0) { - return WireEepRomRead(EEP_ADR_TRD) * 4; - } - - void saveCurrentData(); - - void loadCurrentData(); + float loadTravelDistance(); + void saveTravelDistance(float value = 0); void WireEepRomWriteByte(uint16_t theMemoryAddress, int u8Byte) { @@ -222,12 +111,6 @@ class EepRom { return u8retVal; } -private: - - byte noElem = 12; - unsigned int baseAddress = 0; - - }; EepRom::EepRom(CarSens *carSens) { @@ -236,37 +119,127 @@ EepRom::EepRom(CarSens *carSens) { /** - * Saves data to EepRom + * Loads travel consumption */ -void EepRom::saveCurrentData() { +float EepRom::loadLpgCons() { + int va1 = WireEepRomRead(EEP_ADR_CL1); + int va2 = WireEepRomRead(EEP_ADR_Cl2); + return restoreFloat(va1, va2); +} - TTL_TLC = TTL_TLC + TTL_CLC; - saveTravelConsumption(TTL_TLC); +/** + * Saves travel consumption + */ +void EepRom::saveLpgCons(float value = 0) { + int val[2]; + separateFloat(value, val); + WireEepRomWriteByte(EEP_ADR_CL1, val[0]); + WireEepRomWriteByte(EEP_ADR_Cl2, val[1]); +} - TTL_TTD = TTL_TTD + _car->getDst(); +/** + * Loads travel consumption + */ +float EepRom::loadBnzCons() { + int va1 = WireEepRomRead(EEP_ADR_CB1); + int va2 = WireEepRomRead(EEP_ADR_CB2); + return restoreFloat(va1, va2); +} - saveTravelDistance(TTL_TTD); +/** + * Saves travel consumption + */ +void EepRom::saveBnzCons(float value = 0) { + int val[2]; + separateFloat(value, val); + WireEepRomWriteByte(EEP_ADR_CB1, val[0]); + WireEepRomWriteByte(EEP_ADR_CB2, val[1]); +} +/** + * LOAD Travel distance + */ +float EepRom::loadTravelDistance() { + int va1 = WireEepRomRead(EEP_ADR_TT1); + int va2 = WireEepRomRead(EEP_ADR_TT2); + return restoreFloat(va1, va2); +} + +/** + * SAVE Travel distance + */ +void EepRom::saveTravelDistance(float value = 0) { + int val[2]; + separateFloat(value, val); + WireEepRomWriteByte(EEP_ADR_TT1, val[0]); + WireEepRomWriteByte(EEP_ADR_TT2, val[1]); +} + +/** + * LOAD Work distance + */ +float EepRom::loadWorkDistance() { + int va1 = WireEepRomRead(EEP_ADR_WD1); + int va2 = WireEepRomRead(EEP_ADR_WD2); + return restoreFloat(va1, va2); +} +/** + * Saves Work distance + */ +void EepRom::saveWorkingDistance(float value = 0) { + int val[2]; + separateFloat(value, val); + WireEepRomWriteByte(EEP_ADR_WD1, val[0]); + WireEepRomWriteByte(EEP_ADR_WD2, val[1]); } +/************************************************* + * public + * Combined methods + * + */ +/** + * Saves data to EepRom + */ +void EepRom::saveCurrentData() { + + TTL_LPG = TTL_LPG + CRT_LPG; + saveLpgCons(TTL_LPG); + + TTL_BNZ = TTL_BNZ + CRT_BNZ; + saveBnzCons(TTL_BNZ); + TTL_TTD = TTL_TTD + _car->getDst(); + saveTravelDistance(TTL_TTD); +} + +/** + * Load data from chip + */ void EepRom::loadCurrentData() { - TTL_TLC = loadTravelConsumption(); + TTL_LPG = loadLpgCons(); + TTL_BNZ = loadBnzCons(); + TTL_TTD = loadTravelDistance(); TTL_WRD = loadWorkDistance(); } - +/** + * Saves final data + */ void EepRom::saveZeroingData() { int assumedTravel = int(TTL_TTD); - TTL_TLC = 0; + TTL_LPG = 0; + TTL_BNZ = 0; + TTL_TTD = 0; TTL_WRD = TTL_WRD + (assumedTravel / 1000); - saveTravelConsumption(TTL_TLC); + saveLpgCons(TTL_LPG); saveTravelDistance(TTL_TTD); saveWorkingDistance(TTL_WRD); } + #endif \ No newline at end of file diff --git a/MID/lib/Lcd16x2.h b/MID/lib/Lcd16x2.h index 2d5df95..7975497 100644 --- a/MID/lib/Lcd16x2.h +++ b/MID/lib/Lcd16x2.h @@ -63,7 +63,7 @@ void displayInsTmp() { */ void displayTotalCons() { char tmp[3]; - float value = TTL_TLC + TTL_CLC; + float value = TTL_LPG + CRT_LPG; if (ampInt.isSec()) { if (ampInt.isBig()) { @@ -297,7 +297,7 @@ void displayConsumption() { lcd.setCursor(8, 2); lcd.write((uint8_t) 7); lcd.write((uint8_t) 8); - lcd.print(TTL_CLC); + lcd.print(CRT_LPG); lcd.print("L "); } } diff --git a/MID/lib/MainFunc.h b/MID/lib/MainFunc.h index 8b26a41..3c2f13f 100644 --- a/MID/lib/MainFunc.h +++ b/MID/lib/MainFunc.h @@ -131,11 +131,17 @@ void serialInjectData() { srlOutputs = "TTL_TTD "; srlOutputs += TTL_TTD; } - if (srlStrName == "tlc" || srlStrName == "ttc") { + if (srlStrName == "lpg") { // Total Liters per hour consumed - TTL_TLC = Serial.readStringUntil('\n').toInt() * 0.01; - srlOutputs = "TTL_TLC "; - srlOutputs += TTL_TLC; + TTL_LPG = Serial.readStringUntil('\n').toInt() * 0.01; + srlOutputs = "TTL_LPG "; + srlOutputs += TTL_LPG; + } + if (srlStrName == "bnz") { + // Total Liters per hour consumed + TTL_LPG = Serial.readStringUntil('\n').toInt() * 0.01; + srlOutputs = "TTL_BNZ "; + srlOutputs += TTL_BNZ; } if (srlStrName == "wrd" || srlStrName == "wrk") { // Total Liters per hour consumed @@ -146,9 +152,9 @@ void serialInjectData() { if (srlStrName == "clc") { // Total Liters consumed in trip - TTL_CLC = Serial.readStringUntil('\n').toInt() * 0.01; - srlOutputs = "TTL_CLC "; - srlOutputs += TTL_CLC; + CRT_LPG = Serial.readStringUntil('\n').toInt() * 0.01; + srlOutputs = "CRT_LPG "; + srlOutputs += CRT_LPG; } // // Show command information to human diff --git a/MID/lib/MidMenu.h b/MID/lib/MidMenu.h index c29c271..5eaf06e 100644 --- a/MID/lib/MidMenu.h +++ b/MID/lib/MidMenu.h @@ -37,7 +37,7 @@ // // #define MENU_NAME_4 "Average" - +#define AWAITING 1500 static void MidMenu_menuUsed(MenuUseEvent used); @@ -101,7 +101,7 @@ class MidMenu { MidMenu(IntAmp *amp, CarSens *car, EepRom *eep); private: - + boolean enterSub = false; // // Saves cursor between changes int savedCursor; @@ -311,6 +311,21 @@ void MidMenu::buttons(WhlSens *whl, uint8_t buttonPinUp, uint8_t buttonPinDw) { } } + if (entryDownState + AWAITING > millis() && enterSub && !digitalRead(buttonPinDw) == LOW) { + // + // + tone(pinTones, 700, 20); + delay(20); + tone(pinTones, 700, 20); + enterSub = false; + // + // Perform button is released action + lastButtonPushed = buttonPinDw; + // + // Reset entry down state + entryDownState = 0; + } + // // Detect down state button if (!digitalRead(buttonPinDw) == HIGH) { @@ -320,56 +335,22 @@ void MidMenu::buttons(WhlSens *whl, uint8_t buttonPinUp, uint8_t buttonPinDw) { whl->disable(); entryDownState = millis(); } + + + if (_amp->isLow() && !digitalRead(buttonPinDw) == HIGH) { + enterSub = true; + } + // // Hold - if (entryDownState + 1000 < millis() && !digitalRead(buttonPinDw) == HIGH) { + if (entryDownState + AWAITING < millis() && !digitalRead(buttonPinDw) == HIGH) { // // If is still high state [pressed] if (!digitalRead(buttonPinDw) == HIGH) { // // Reset entry down state entryDownState = 0; - - /*********** [SHORTCUTS] *********** *********** *********** *********** START ***********/ - // Steering button is pressed - if (whl->getCurrentState() == whl->STR_BTN_ATT) { - tone(pinTones, 1000, 10); - delay(10); - tone(pinTones, 1000, 10); - delay(10); - - tone(pinTones, 2500, 10); - delay(20); - tone(pinTones, 2500, 10); - _eep->saveZeroingData(); - delay(20); - whl->enable(); - return; - } - // - // Change Speed alarm Up - if (whl->getCurrentState() == whl->STR_BTN_VLU) { - _car->speedingAlarmsUp(); - tone(pinTones, 800, 50); - delay(50); - tone(pinTones, 2000, 80); - delay(80); - whl->enable(); - return; - } - // - // Change Speed alarm Down - if (whl->getCurrentState() == whl->STR_BTN_VLD) { - _car->speedingAlarmsDw(); - tone(pinTones, 2000, 50); - delay(50); - tone(pinTones, 800, 80); - delay(80); - whl->enable(); - return; - } - /*********** [SHORTCUTS] *********** *********** *********** *********** END ***********/ - + shortcuts(whl); // // Check for subMenu if not got inner level entry if (isInSubMenu == 0) { @@ -411,6 +392,46 @@ void MidMenu::buttons(WhlSens *whl, uint8_t buttonPinUp, uint8_t buttonPinDw) { */ void MidMenu::shortcuts(WhlSens *whl) { + /*********** [SHORTCUTS] *********** *********** *********** *********** START ***********/ + // Steering button is pressed + if (whl->getCurrentState() == whl->STR_BTN_ATT) { + tone(pinTones, 1000, 10); + delay(10); + tone(pinTones, 1000, 10); + delay(10); + + tone(pinTones, 2500, 10); + delay(20); + tone(pinTones, 2500, 10); + _eep->saveZeroingData(); + delay(20); + whl->enable(); + return; + } + // + // Change Speed alarm Up + if (whl->getCurrentState() == whl->STR_BTN_VLU) { + _car->speedingAlarmsUp(); + tone(pinTones, 800, 50); + delay(50); + tone(pinTones, 2000, 80); + delay(80); + whl->enable(); + return; + } + // + // Change Speed alarm Down + if (whl->getCurrentState() == whl->STR_BTN_VLD) { + _car->speedingAlarmsDw(); + tone(pinTones, 2000, 50); + delay(50); + tone(pinTones, 800, 80); + delay(80); + whl->enable(); + return; + } + /*********** [SHORTCUTS] *********** *********** *********** *********** END ***********/ + } @@ -424,10 +445,11 @@ void MidMenu::navigate() { if (isInSubMenu == 0) { menu.moveDown(); menu.use(); - } else { + } + /*else { menu.moveRight(); menu.use(); - } + }*/ } if (lastButtonPushed == btnPinDw) { if (lastMainMenuState != 0 && isInSubMenu == 0) { diff --git a/MID/lib/ShutDw.h b/MID/lib/ShutDw.h index 1b09318..2c8d909 100644 --- a/MID/lib/ShutDw.h +++ b/MID/lib/ShutDw.h @@ -6,6 +6,9 @@ #ifndef SHUTDOWN_SAVE_STATE #define SHUTDOWN_SAVE_STATE HIGH #endif +#ifndef SHUTDOWN_SAVE_BUTTON +#define SHUTDOWN_SAVE_BUTTON 8 +#endif #ifndef SHUTDOWN_SAVE_LOOPS #define SHUTDOWN_SAVE_LOOPS 1200 @@ -29,7 +32,7 @@ class ShutDw { CarSens *_car; private : - uint8_t pinCtrl, pinDtct, pinSaveCancel, pinTone; + uint8_t pinCtrl, pinDtct, pinTone; int indexWait = 0; int entryDisplay = 0; @@ -52,7 +55,7 @@ private : ShutDw(EepRom *eepRom, IntAmp *ampInt, CarSens *carSens); - void setup(int pinControl, int pinDetect, int pintPressSave, int pinToAlarm); + void setup(int pinControl, int pinDetect, int pinToAlarm); void listener(); @@ -84,11 +87,10 @@ ShutDw::ShutDw(EepRom *eepRom, IntAmp *ampInt, CarSens *carSens) { /** * Setup shutdown class */ -void ShutDw::setup(int pinControl, int pinDetect, int pintPressSave, int pinToAlarm) { +void ShutDw::setup(int pinControl, int pinDetect, int pinToAlarm) { pinCtrl = uint8_t(pinControl); pinDtct = uint8_t(pinDetect); - pinSaveCancel = uint8_t(pintPressSave); pinTone = uint8_t(pinToAlarm); @@ -188,11 +190,11 @@ void ShutDw::lcdDisplay(LiquidCrystal *lcd) { if (entryDisplay == 0) { lcd->clear(); lcd->setCursor(0, 0); - lcd->print("Hit \"S\" to skip"); + lcd->print("Hit \"S<\" to "); lcd->setCursor(0, 2); - lcd->print("and unsave data"); + lcd->print("skip saving data"); tone(pinTone, 3000, 500); - delay(2000); + delay(3400); lcd->clear(); lcd->setCursor(1, 0); lcd->print("Shutting down"); @@ -215,14 +217,14 @@ void ShutDw::lcdDisplay(LiquidCrystal *lcd) { lcd->print(sec); lcd->print(" sec. "); lcd->setCursor(1, 2); - lcd->print("to canceling..."); + lcd->print(" for ESC saving"); } // // Listen press button - if (digitalRead(pinSaveCancel) == SHUTDOWN_SAVE_STATE) { + if (digitalRead(SHUTDOWN_SAVE_BUTTON) == SHUTDOWN_SAVE_STATE) { delay(5); - if (digitalRead(pinSaveCancel) == SHUTDOWN_SAVE_STATE && alreadySaved == 0) { + if (digitalRead(SHUTDOWN_SAVE_BUTTON) == SHUTDOWN_SAVE_STATE && alreadySaved == 0) { displayCancel(lcd); } } diff --git a/MID/lib/SwrCan.h b/MID/lib/SwrCan.h deleted file mode 100644 index fe06113..0000000 --- a/MID/lib/SwrCan.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// Created by Angel Zaprianov on 11/6/2016. -// - -#ifndef ARDUINOM_ID_SWR_CAN_H -#define ARDUINO_MID_SWR_CAN_H - -#include - -/*String ecuPreview; - -void ISR() { - - - // - // - if (digitalRead() = LOW) { - ecuPreview += " 0"; - } - if (digitalRead() = HIGH) { - ecuPreview += " 1"; - } -} - -volatile static pFunc int0Func; -ISR(INT0_vect) { //processInjOpen by default - int0Func (); -} - -volatile static pFunc int1Func; -ISR(INT1_vect) {//processInjClosed - int1Func (); -}*/ - -// TODO lets see after first test whats happen with ECU signal then data will be moved here -// Single-Wire CAN -class SwrCan { - -}; - - -#endif //ARDUINOMID_SAECAN_H diff --git a/MID/lib/WhlSens.h b/MID/lib/WhlSens.h index 17ac0bc..769a71f 100644 --- a/MID/lib/WhlSens.h +++ b/MID/lib/WhlSens.h @@ -21,8 +21,8 @@ #include "IntAmp.h" //#define STR_DEBUG -#define STR_WHL_SEND_A -//#define STR_WHL_SEND_B +//#define STR_WHL_SEND_A +#define STR_WHL_SEND_B // // Creates test with maximum send value @@ -71,6 +71,7 @@ class WhlSens { static constexpr int STR_BTN_SKD = 4; static constexpr int STR_BTN_BCK = 5; static constexpr int STR_BTN_ATT = 6; + static constexpr int STR_BTN_MNT = 7; int getAnalogReadButtons(); @@ -152,10 +153,12 @@ void WhlSens::setButtonStateParser(int currentState) { if (currentState == STR_BTN_VLU) _setDigitalPot(95);// Volume up if (currentState == STR_BTN_VLD) _setDigitalPot(115);// Volume down if (currentState == STR_BTN_ATT) _setDigitalPot(225); // Zero + if (currentState == STR_BTN_MNT) _setDigitalPot(155);// Mute if (currentState == STR_BTN_SKU) _setDigitalPot(45);// seek up if (currentState == STR_BTN_SKD) _setDigitalPot(65);// seek down if (currentState == STR_BTN_BCK) _setDigitalPot(15);// back button if (currentState == STR_BTN_NON) _setDigitalPot(0);// return to default + } @@ -211,18 +214,19 @@ void WhlSens::listener() { Serial.println(readingSteeringButton); } #endif - - // - // Default value for sony when Steering wheel is not used - if (readingSteeringButton > 900 && readingSteeringButton < 999 && isButtonPressActive == 0) { - _setCurrentState(STR_BTN_NON); - // - // Do not enter in here next loop - isButtonPressActive = 1; -#if defined(STR_WHL_SEND_B) - digitalWrite(pinOutVoltage, HIGH); -#endif - } + _setCurrentState(STR_BTN_NON); +// +// // +// // Default value for sony when Steering wheel is not used +// if (readingSteeringButton > 900 && readingSteeringButton < 999 && isButtonPressActive == 0) { +// +// // +// // Do not enter in here next loop +// isButtonPressActive = 1; +//#if defined(STR_WHL_SEND_B) +// digitalWrite(pinOutVoltage, HIGH); +//#endif +// } // // Volume down @@ -238,6 +242,9 @@ void WhlSens::listener() { // Zero button if (readingSteeringButton > 500 && readingSteeringButton < 599) { _setCurrentState(STR_BTN_ATT); + if (_amp->isMin()) { + _setCurrentState(STR_BTN_MNT); + } // TODO long press 155 volume press button } // @@ -309,6 +316,12 @@ void WhlSens::sendRadioButtons() { #if defined(STR_WHL_SEND_B) + + if (_amp->isMid()) { + Serial.print("WHL Current State "); + Serial.println(currentState); + } + // // When is not none state if (currentState != STR_BTN_NON) { @@ -316,24 +329,24 @@ void WhlSens::sendRadioButtons() { // Open resistance to pot digitalWrite(pinOutVoltage, LOW); digitalWrite(pinDigitalOut, LOW); - // - // Check is still pressing and need to change state - if (_amp->isLow() && currentState == getCurrentState() && currentState != lastStateButton) { - lastStateButton = currentState; - setButtonStateParser(currentState); - digitalWrite(pinDigitalOut, HIGH); - } else { - // - // Close state - digitalWrite(pinDigitalOut, HIGH); - } - // - // When button is returned to none - } else { + + setButtonStateParser(currentState); + delay(1); // Some separation fix digitalWrite(pinDigitalOut, HIGH); lastStateButton = currentState; + // + // Returned to none + currentState = STR_BTN_NON; + + } else { + digitalWrite(pinOutVoltage, HIGH); + if (_amp->isMid()) { + Serial.println("WHL Current State Disable"); + + } } + #endif } diff --git a/~erase/MidMenu-old.h b/~erase/MidMenu-old.h deleted file mode 100644 index 4734864..0000000 --- a/~erase/MidMenu-old.h +++ /dev/null @@ -1,321 +0,0 @@ -// -// Created by Angel Zaprianov on 27.6.2016 г.. -// - - -#ifndef ARDUINO_MID_MENU -#define ARDUINO_MID_MENU -// -// MenuBackend library - copyright by Alexander Brevig -// Import it from: -// https://github.com/WiringProject/Wiring/tree/master/framework/libraries/MenuBackend -// -// And good example can be found here: -// https://codebender.cc/sketch:37125#MenuBackend_sample.ino -#include - -#include "lib/MainFunc.h" -#include "lib/CarSens.h" -#include "lib/WhlSens.h" - - -static void menuUsed(MenuUseEvent used); - -static void menuChanged(MenuChangeEvent changed); - -// -// -MenuBackend menu = MenuBackend(menuUsed, menuChanged); -// -// -int lastButtonPushed = LOW; -int isMainNavigationStatus = 0; -int isInSubMenu = 0; - -/* MID menu mMap - - - -Main Trip-------------------------------Trip----------------------------------------------------Fuel - | | - Item1SubItem1-----Item1SubItem2 Item2SubItem1------Item2SubItem2------Item2SubItem3 - - */ - -// -// Main menu -MenuItem mainMenu = MenuItem("Main", 1); - - -MenuItem tripMenu = MenuItem("Trip", 2); -MenuItem fuelMenu = MenuItem("Fuel", 3); -MenuItem averMenu = MenuItem("Average", 4); - -// -// Sub menu for MAIN -MenuItem dshBoardMenu = MenuItem("Panel", 11); -MenuItem testingsMenu = MenuItem("Test", 12); -// -// Sub menu for fuel -MenuItem FuelTankMenu = MenuItem("F-Tanks"); - -static void setupMenu() { - // - // Pin button mode - pinMode(BTN_PIN_UP, INPUT); - pinMode(BTN_PIN_DW, INPUT); - /* - * - menu.getRoot().add(menu1Item1); - menu1Item1.addRight(menu1Item2).addRight(menu1Item3); - menu1Item1.add(menuItem1SubItem1).addRight(menuItem1SubItem2); - menu1Item2.add(menuItem2SubItem1).addRight(menuItem2SubItem2).addRight(menuItem3SubItem3); - - */ - - menu.getRoot().add(mainMenu).add(tripMenu).add(fuelMenu).add(averMenu); - averMenu.add(mainMenu); // Create Loop menu - - // - // Main menu layers - mainMenu.addRight(dshBoardMenu).addRight(testingsMenu); - testingsMenu.addRight(dshBoardMenu); // loop - // - // add return menu - dshBoardMenu.add(mainMenu); - testingsMenu.add(mainMenu); - // - // Fuel layers - fuelMenu.addRight(FuelTankMenu); - FuelTankMenu.add(fuelMenu); - // - // Move cursor to menu - menu.moveDown(); - menu.use(); -} - -/** - * Event menu changed - */ -static void menuChanged(MenuChangeEvent changed) { - - - MenuItem newMenuItem = changed.to; //get the destination menu - lcd.clear(); - - if (newMenuItem.getName() == "Main") { - cursorMenu = 1; - } else if (newMenuItem.getName() == "Panel") { - cursorMenu = 11; - } else if (newMenuItem.getName() == "Test") { - cursorMenu = 12; - } else if (newMenuItem.getName() == "Average") { - - cursorMenu = 4; - } else if (newMenuItem.getName() == "Trip") { - cursorMenu = 2; -// } else if (newMenuItem.getName() == "Item2SubItem1") { -// lcd.print("Item2SubItem1 "); -// } -// else if (newMenuItem.getName() == "Item2SubItem2") { -// lcd.print("Item2SubItem2 "); -// } -// else if (newMenuItem.getName() == "Item2SubItem3") { -// lcd.print("Item2SubItem3 "); - } else if (newMenuItem.getName() == "Fuel") { - cursorMenu = 3; - } else if (newMenuItem.getName() == "F-Tanks") { - cursorMenu = 32; - } else { - lcd.print(newMenuItem.getName()); - } -} - -/** - * Read pin button states - */ - -unsigned long lastButtonPress = 0; - -unsigned long entryDownState = 0; - -boolean secondTone = 0; - -/** - * Lower the code - */ -void readButtons(uint8_t buttonPinUp, uint8_t buttonPinDw) { - - int OUTER_BUTTON_STATE = 0; - - lastButtonPushed = LOW; - unsigned long curTime = millis(); - // - // Detect up state button - if (!digitalRead(buttonPinUp) == HIGH) { - - if (ampInt.isLow() && !digitalRead(buttonPinUp) == HIGH) { - lastButtonPushed = buttonPinUp; - } - } - - // - // Detect down state button - if (!digitalRead(buttonPinDw) == HIGH) { - // - // Controlling start of press state - if (entryDownState == 0) { - whlSens.disable(); - entryDownState = millis(); - } - // - // Hold - if (entryDownState + 1000 < millis() && !digitalRead(buttonPinDw) == HIGH) { - // - // If is still high state [pressed] - if (!digitalRead(buttonPinDw) == HIGH) { - // - // Reset entry down state - entryDownState = 0; - - /*********** [SHORTCUTS] *********** *********** *********** *********** START ***********/ - // Steering button is pressed - if (whlSens.getCurrentState() == whlSens.STR_BTN_ATT) { - TTL_TLC = 0; - TTL_TTD = 0; - tone(ADT_ALR_PIN, 1000, 50); - delay(50); - tone(ADT_ALR_PIN, 1000, 50); - delay(50); - whlSens.enable(); - return; - } - // - // Change Speed alarm Up - if (whlSens.getCurrentState() == whlSens.STR_BTN_VLU) { - carSens.speedingAlarmsUp(); - tone(ADT_ALR_PIN, 800, 50); - delay(50); - tone(ADT_ALR_PIN, 1600, 80); - delay(80); - whlSens.enable(); - return; - } - // - // Change Speed alarm Down - if (whlSens.getCurrentState() == whlSens.STR_BTN_VLD) { - carSens.speedingAlarmsDw(); - tone(ADT_ALR_PIN, 1600, 50); - delay(50); - tone(ADT_ALR_PIN, 800, 80); - delay(80); - whlSens.enable(); - return; - } - /*********** [SHORTCUTS] *********** *********** *********** *********** END ***********/ - // - // Check for subMenu if not got inner level entry - if (isInSubMenu == 0) { - // - // Enter inner level menu - isInSubMenu = 1; - tone(ADT_ALR_PIN, 400, 100); - // - // Exit inner level menu - } else if (isInSubMenu == 1) { - isInSubMenu = 0; - tone(ADT_ALR_PIN, 400, 50); - secondTone = 1; - } - } else { - // - // Perform button is released action - lastButtonPushed = buttonPinDw; - // - // Reset entry down state - entryDownState = 0; - } - } -// } else if (entryDownState > 0 && !digitalRead(buttonPinDw) == LOW) { -// // -// // Perform button is released action -// lastButtonPushed = buttonPinDw; -// // -// // Reset entry down state -// entryDownState = 0; -// whlSens.enable(); // unlock radio -// // -// // - } else { // <- deprecated - entryDownState = 0; - whlSens.enable(); // unlock radio - } - - if (ampInt.isSec() && secondTone) { - tone(ADT_ALR_PIN, 800, 50); - secondTone = 0; - } - -} - -char lastMainMenuState = 0; - -/** - * Resolve navigation between button press - */ -void navigateMenu() { - - if (isMainNavigationStatus == 0) { - MenuItem currentMenu = menu.getCurrent(); - - switch (lastButtonPushed) { - // - // UP button - case BTN_PIN_UP: - if (isInSubMenu == 0) { - menu.moveDown(); - menu.use(); - } else { - menu.moveRight(); - menu.use(); - } - break; - - // - // Down button - case BTN_PIN_DW: - if (lastMainMenuState != 0 && isInSubMenu == 0) { - menu.moveBack(); - menu.use(); - } else if (isInSubMenu == 0) { - menu.moveUp(); - menu.use(); - } else { - lastMainMenuState = currentMenu.getShortkey(); - menu.moveLeft(); - menu.use(); - } - break; - } - } -// lastSubMenuState = isInSubMenu; - lastButtonPushed = 0; //reset the lastButtonPushed variable -} - - -static void menuUsed(MenuUseEvent used) { - lcd.clear(); - lcd.setCursor(0, 0); - lcd.print(used.item.getName()); - delay(100); - lcd.print(" Menu"); - delay(500); //delay to allow message reading - lcd.setCursor(0, 0); - lcd.clear(); - // - // fixes value peek - // reset base global vars - carSens.clearBaseData(); -} - -#endif \ No newline at end of file