From 1b4470a970141c5151c6ea5f9086ff0bab380f99 Mon Sep 17 00:00:00 2001 From: Bouletmarc Date: Fri, 4 Dec 2020 09:06:00 -0500 Subject: [PATCH] Add files via upload --- BMDatalogger/BMDatalogger.ino | 659 +++++++++++++++++++++++++++++ BMDatalogger/ButtonsManager.ino | 453 ++++++++++++++++++++ BMDatalogger/CustomCharacter.ino | 397 +++++++++++++++++ BMDatalogger/DatalogProtocol.ino | 546 ++++++++++++++++++++++++ BMDatalogger/FileList.txt | 13 + BMDatalogger/OptionPage.ino | 598 ++++++++++++++++++++++++++ BMDatalogger/PeakValues.ino | 86 ++++ BMDatalogger/ScreenDisplay.ino | 268 ++++++++++++ BMDatalogger/ScreenJ12.ino | 15 + BMDatalogger/ScreenMain.ino | 50 +++ BMDatalogger/ScreenTexts.ino | 376 ++++++++++++++++ BMDatalogger/SettingPage.ino | 168 ++++++++ BMDatalogger/SettingPageCursor.ino | 287 +++++++++++++ BMDatalogger/SpeedCounter.ino | 35 ++ BMDatalogger/Version.txt | 2 +- BMDatalogger/Warnings.ino | 31 ++ 16 files changed, 3983 insertions(+), 1 deletion(-) create mode 100644 BMDatalogger/BMDatalogger.ino create mode 100644 BMDatalogger/ButtonsManager.ino create mode 100644 BMDatalogger/CustomCharacter.ino create mode 100644 BMDatalogger/DatalogProtocol.ino create mode 100644 BMDatalogger/FileList.txt create mode 100644 BMDatalogger/OptionPage.ino create mode 100644 BMDatalogger/PeakValues.ino create mode 100644 BMDatalogger/ScreenDisplay.ino create mode 100644 BMDatalogger/ScreenJ12.ino create mode 100644 BMDatalogger/ScreenMain.ino create mode 100644 BMDatalogger/ScreenTexts.ino create mode 100644 BMDatalogger/SettingPage.ino create mode 100644 BMDatalogger/SettingPageCursor.ino create mode 100644 BMDatalogger/SpeedCounter.ino create mode 100644 BMDatalogger/Warnings.ino diff --git a/BMDatalogger/BMDatalogger.ino b/BMDatalogger/BMDatalogger.ino new file mode 100644 index 0000000..5a861e5 --- /dev/null +++ b/BMDatalogger/BMDatalogger.ino @@ -0,0 +1,659 @@ +//##################################################### +//##################################################### +//##################################################### +/* + THIS IS THE BM DEVS DATALOGGER + + THIS WORKS BY DATALOGGING BMTUNE ISR V3 PROTOCOL ON + THE TX/RX SERIAL PORT. THIS WORKS WITH 2X BUTTONS + NAVIGATION ONLY. IT ONLY WORKS FOR THE 20X04 LCD + + IF YOUR SCREEN DOESNT DISPLAY ANY CHARACTERS : + FIND THE LINE 'LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);' + AND REPLACE 0x3F BY 0x20 OR 0x27 OR 0x30 + + #################################################### + ALL CREDITS GOES TO : + -Bouletmarc (BM Devs) +*/ +//##################################################### +//##################################################### +//##################################################### + +#include "Wire.h" +//#include +#include +#include +//#include +//#include +#include +#include + +//##################################################### +//##################################################### +//#include +//LiquidCrystal_I2C lcd(I2CByte, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); + +// initialize the library by associating any needed LCD interface pin +// with the arduino pin number it is connected to +#include +const int rs = 37, en = 39, d4 = 41, d5 = 42, d6 = 43, d7 = 44; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + + +void noBacklight() { + digitalWrite(46, LOW); +} + +void backlight() { + RefreshBackLight(); +} +//##################################################### +//##################################################### + + +//0x20-0x27 - 0x30 - 0x3F +//byte I2CByte = 0x27; +const int NextButton = 29; //Atmega644P=20; //Atmega328P=8 +const int BackButton = 28; //Atmega644P=19; //Atmega328P=9 +const int BackLightPin = A1; //Atmega644P=12; //Atmega328P=10 +const int ContrastPin = A0; //Atmega644P=13; //Atmega328P=None +const int ChipSelectPin = 8; //Atmega644P=4; //Atmega328P=None CS Pin for SD Card +const int StatusLEDPin = 4; //Atmega644P=1; //Atmega328P=None LED Pin for Status + +byte Brightness = 255; +byte BrightnessNight = 110; +bool NightMode = false; +byte ContrastLevel = 150; + +byte ScreenCurrentPage = 1; +byte ScreenCurrentPeak = 0; +byte ScreenCurrentMenu = 0; +byte ScreenSettingSelected = 0; +byte ScreenOptionSelected = 0; +byte ThisScreenIndex = 0; //current display index number +byte XPos = 0; +byte YPos = 0; +char StringBuffer[20]; +const int MaxDataValue = 79; +//bool EcuConnected = false; +bool InMain = true; +bool EngineRunning = false; +unsigned long last_datalog_time = 0; +bool Sleeping = false; +//bool J12Cut = true; +//bool ShowJ12 = false; +//bool WasAvailable = false; + +int ScreenPage1[8] = {100, 0, 1, 2, 3, 9, 5, 11}; +int ScreenPage2[8] = {200, 0, 7, 8, 14, 15, 28, 30}; +int ScreenPage3[8] = {300, 0, 13, 20, 18, 19, 4, 5}; +int ScreenPage4[8] = {100, 0, 100, 0, 18, 11, 19, 9}; +int ScreenPage5[8] = {100, 0, 100, 0, 107, 0, 8, 16}; +int ScreenPage6[8] = {100, 0, 61, 9, 53, 4, 57, 59}; +int ScreenPage7[8] = {100, 0, 3, 12, 6, 4, 13, 26}; +int ScreenPage8[8] = {41, 37, 35, 24, 25, 23, 17, 21}; + +const String BoardVersionStr = "2.0"; +const String FirmwareVersionStr = "2.01"; +byte ProgressBarMode = 2; +byte ProgressBarLeft = 0; +int Timeout = 150; +int Injectors_Size = 240; +byte O2Input = 0; +byte MapValue = 0; +byte UseCelcius = 1; +byte UseKMH = 1; +byte O2Type = 0; +double WBConversion[4] = {0, 1.3, 1, 0.71}; +int WBModel = 0; +byte MapByte[4] = {186, 127, 254, 134}; +byte Tranny[4] = {72, 113, 178, 214}; +int TrannyModel = 0; +int MapModel = 0; +int Warning_RPM = 7600; +int Warning_IAT = 65; +int Warning_ECT = 107; + +int mBarMin = -70; +int mBarMax = 1790; +int TempMin = -40; +int TempMax = 140; + +int WaitingDelay = 0; +bool WaitingQuick = false; + +const int SettingVersion = 3; +//int TimeoutCount = 0; +byte LastChecksum = 0; +const long AutoSaveTime = 120000; +unsigned long last_save_time = 0; + +bool SDDetected = true; +bool SDLogging = true; + +File myFile; +unsigned int SDFileCount = 0; + +//##################################################### + +void setup() { + FirstLoadEEPROM(); + + pinMode(BackButton, INPUT_PULLUP); + pinMode(NextButton, INPUT_PULLUP); + + pinMode(StatusLEDPin, OUTPUT); + digitalWrite(StatusLEDPin, HIGH); + + pinMode(BackLightPin, OUTPUT); + RefreshBackLight(); + //pinMode(ContrastPin,OUTPUT); + //analogWrite(ContrastPin, ContrastLevel); // PWM values from 0 to 255 (0% – 100% duty cycle) + + //####################################################### + //Atmega644 Interrupt + //enableInterrupt(BackButton, pin_ISR1, CHANGE); + //enableInterrupt(NextButton, pin_ISR2, CHANGE); + + digitalWrite(38, LOW); //RW Pins on Atmega64A + //####################################################### + + ReCalcValueRange(); + + //################### + //screen start + lcd.begin(20, 4); + lcd.clear(); + ResetBufferIndex(); + GetInfosString(20); + PrintTextAnimated(20, 4, 0); + + //delay(200); + ResetBufferIndex(); + Add_String(BoardVersionStr); + //PrintTextAnimated(3, 15, 0); + writeBigStringAnimated(6, 1); + + //delay(200); + ResetBufferIndex(); + Add_String("Firmware V" + FirmwareVersionStr); + PrintTextAnimated(20, 3, 3); + + /*delay(200); + ResetBufferIndex(); + Add_String(FirmwareVersionStr); + PrintTextAnimated(20, 8, 2);*/ + + /*delay(200); + ResetBufferIndex(); + GetInfosString(21); + PrintTextAnimated(20, 3, 3);*/ + + delay(700); + //lcd.clear(); + //################### + + Serial.begin(38400); + Serial1.begin(38400); + //ScanForI2C(); + //ScanForSD(); + + digitalWrite(StatusLEDPin, LOW); + lcd.clear(); +} + +void ScanForSD() { + if (!SD.begin(ChipSelectPin)) { + SDDetected = false; + Serial.println("Card failed, or not present"); + } + + if (SDDetected) { + SDFileCount = 0; + /*while (SD.exists("BMDatalogger" + SDFileCount + ".bml")) { + SDFileCount++; + Serial.println("BMDatalogger" + SDFileCount + ".bml already exists!"); + }*/ + } +} + +void ReCalcValueRange() { + mBarMin = (int) ((((long) MapByte[1] * 256) + (long) MapByte[0]) - 32768); + mBarMax = (int) ((((long) MapByte[3] * 256) + (long) MapByte[2]) - 32768); + + if (UseCelcius == 0) { + TempMin = TempMin * 1.8 + 32.0; + TempMax = TempMax * 1.8 + 32.0; + Warning_IAT = Warning_IAT * 1.8 + 32.0; + Warning_ECT = Warning_ECT * 1.8 + 32.0; + } +} + +//##################################################### + +void loop() { + RefreshBackLight(); + //analogWrite(ContrastPin, ContrastLevel); // PWM values from 0 to 255 (0% – 100% duty cycle) + //ConnectBT(); + //CheckButtons(); + + if (millis() - last_save_time > AutoSaveTime) { + AutoSaveEEPROM(); + } + + //############################ + while (WaitingDelay > 0) { + if (InMain && WaitingQuick) ScreenMain(); + if (!InMain && WaitingQuick) Display(); + delay(1); + WaitingDelay--; + CheckButtons(); + if (WaitingDelay <= 0) { + //if (!WaitingQuick) lcd.clear(); + //if (WaitingQuick) WaitingQuick = false; + WaitingQuick = false; + } + //if (WaitingQuick) WaitingQuick = false; + } + //############################ + + if (millis() - last_datalog_time > Timeout) { + //if (TimeoutCount >= Timeout) { + /*if (!J12Cut) { + ScreenJ12(); + } + else {*/ + GetData(); + SetEngineRunning(); + ApplyPeak(); + //TimeoutCount = 0; + //} + last_datalog_time = millis(); + } + + //if (!ShowJ12) { + SetSpeedTime(); + GetWarnings(); + + if (InMain) ScreenMain(); + if (!InMain) Display(); + //} + + CheckButtons(); + + //_delay_us(100); + //TimeoutCount++; +} + +//##################################################### + +/*void ScanForI2C() { + // Leonardo: wait for serial port to connect + while (!Serial) { } + + //scan + byte count = 0; + Wire.begin(); + for (byte i = 1; i < 120; i++) + { + Wire.beginTransmission (i); + if (Wire.endTransmission () == 0) + { + if (i != I2CByte) + { + I2CByte = i; + + Serial.println (); + Serial.print ("I2CByte Address not set correctly, please set to: "); + Serial.print ("0x"); + Serial.print (i, HEX); + + //Enless Loop + //while(true) { } //desactivated due to New AutoConnect + } + count++; + } + } +}*/ + +//##################################################### + +void FirstLoadEEPROM() { + if (EEPROM.read(0) != SettingVersion) { + SaveLoadEEPROM(true); //save (never create this version settings) + } + SaveLoadEEPROM(false); //load + LastChecksum = GetSettingsSum(); +} + +void AutoSaveEEPROM() { + last_save_time = millis(); + + byte NewChecksum = GetSettingsSum(); + if (NewChecksum != LastChecksum) { + if (EEPROM.read(1) != NewChecksum) { + EEPROM.write(0, SettingVersion); + EEPROM.write(1, NewChecksum); + SaveLoadEEPROM(true); //save + LastChecksum = GetSettingsSum(); + } + } + + //SaveLoadEEPROM(false); //load + //LastChecksum = GetSettingsSum(); +} + +byte GetSettingsSum() { + byte num = 0; + num = (byte) (num + SettingVersion); + num = (byte) (num + ScreenCurrentPage); + num = (byte) (num + ScreenCurrentPeak); + num = (byte) (num + ScreenCurrentMenu); + if (Sleeping) num = (byte) (num + 1); + if (InMain) num = (byte) (num + 1); + num = (byte) (num + Brightness); + num = (byte) (num + BrightnessNight); + if (NightMode) num = (byte) (num + 1); + num = (byte) (num + ScreenSettingSelected); + num = (byte) (num + ScreenOptionSelected); + for (byte i = 1; i < 8; i++) { + num = (byte) (num + GetMSBFromInt(ScreenPage1[i])); + num = (byte) (num + GetLSBFromInt(ScreenPage1[i])); + } + for (byte i = 1; i < 8; i++) { + num = (byte) (num + GetMSBFromInt(ScreenPage2[i])); + num = (byte) (num + GetLSBFromInt(ScreenPage2[i])); + } + for (byte i = 1; i < 8; i++) { + num = (byte) (num + GetMSBFromInt(ScreenPage3[i])); + num = (byte) (num + GetLSBFromInt(ScreenPage3[i])); + } + for (byte i = 1; i < 8; i++) { + num = (byte) (num + GetMSBFromInt(ScreenPage4[i])); + num = (byte) (num + GetLSBFromInt(ScreenPage4[i])); + } + for (byte i = 1; i < 8; i++) { + num = (byte) (num + GetMSBFromInt(ScreenPage5[i])); + num = (byte) (num + GetLSBFromInt(ScreenPage5[i])); + } + for (byte i = 1; i < 8; i++) { + num = (byte) (num + GetMSBFromInt(ScreenPage6[i])); + num = (byte) (num + GetLSBFromInt(ScreenPage6[i])); + } + for (byte i = 1; i < 8; i++) { + num = (byte) (num + GetMSBFromInt(ScreenPage7[i])); + num = (byte) (num + GetLSBFromInt(ScreenPage7[i])); + } + for (byte i = 1; i < 8; i++) { + num = (byte) (num + GetMSBFromInt(ScreenPage8[i])); + num = (byte) (num + GetLSBFromInt(ScreenPage8[i])); + } + num = (byte) (num + ProgressBarMode); + num = (byte) (num + ProgressBarLeft); + + num = (byte) (num + GetMSBFromInt(Timeout)); + num = (byte) (num + GetLSBFromInt(Timeout)); + num = (byte) (num + GetMSBFromInt(Injectors_Size)); + num = (byte) (num + GetLSBFromInt(Injectors_Size)); + + num = (byte) (num + O2Input); + num = (byte) (num + MapValue); + num = (byte) (num + UseCelcius); + num = (byte) (num + UseKMH); + num = (byte) (num + O2Type); + //missing WB table + for (byte i = 1; i < 4; i++) { + //(int) (ThisDouble * 100) + num = (byte) (num + GetMSBFromInt((int) (WBConversion[i] * 100))); + num = (byte) (num + GetLSBFromInt((int) (WBConversion[i] * 100))); + //num = (byte) (num + GetMSBFromDouble(WBConversion[i])); + //num = (byte) (num + GetLSBFromDouble(WBConversion[i])); + } + num = (byte) (num + WBModel); + for (byte i = 1; i < 4; i++) num = (byte) (num + MapByte[i]); + for (byte i = 1; i < 4; i++) num = (byte) (num + Tranny[i]); + num = (byte) (num + TrannyModel); + num = (byte) (num + MapModel); + + num = (byte) (num + GetMSBFromInt(Warning_RPM)); + num = (byte) (num + GetLSBFromInt(Warning_RPM)); + num = (byte) (num + GetMSBFromInt(Warning_IAT + 40)); + num = (byte) (num + GetLSBFromInt(Warning_IAT + 40)); + num = (byte) (num + GetMSBFromInt(Warning_ECT + 40)); + num = (byte) (num + GetLSBFromInt(Warning_ECT + 40)); + num = (byte) (num + GetMSBFromInt(mBarMin + 300)); + num = (byte) (num + GetLSBFromInt(mBarMin + 300)); + num = (byte) (num + GetMSBFromInt(mBarMax)); + num = (byte) (num + GetLSBFromInt(mBarMax)); + num = (byte) (num + GetMSBFromInt(TempMin + 40)); + num = (byte) (num + GetLSBFromInt(TempMin + 40)); + num = (byte) (num + GetMSBFromInt(TempMax + 40)); + num = (byte) (num + GetLSBFromInt(TempMax + 40)); + + return num; +} + +/*byte GetMSBFromDouble(double ThisDouble) { + int ThisInt = (int) (ThisDouble * 100); + return GetMSBFromInt(int ThisInt); + } + + byte GetLSBFromDouble(double ThisDouble) { + int ThisInt = (int) (ThisDouble * 100); + return GetLSBFromInt(int ThisInt); + }*/ + +byte GetMSBFromInt(int ThisInt) { + byte MSB = (byte) (ThisInt / 256); + return MSB; +} + +byte GetLSBFromInt(int ThisInt) { + byte MSB = (byte) (ThisInt / 256); + byte LSB = (byte) (ThisInt - MSB); + return LSB; +} + +void SaveLoadEEPROM(bool IsSaving) { + int CurrAddr = 5; + + if (IsSaving) EEPROM.write(CurrAddr, ScreenCurrentPage); + else ScreenCurrentPage = EEPROM.read(CurrAddr); + + ScreenCurrentPeak = CheckThisByte(IsSaving, CurrAddr, ScreenCurrentPeak); + CurrAddr++; + ScreenCurrentMenu = CheckThisByte(IsSaving, CurrAddr, ScreenCurrentMenu); + CurrAddr++; + Sleeping = CheckThisBool(IsSaving, CurrAddr, Sleeping); + CurrAddr++; + InMain = CheckThisBool(IsSaving, CurrAddr, InMain); + CurrAddr++; + Brightness = CheckThisByte(IsSaving, CurrAddr, Brightness); + CurrAddr++; + BrightnessNight = CheckThisByte(IsSaving, CurrAddr, BrightnessNight); + CurrAddr++; + NightMode = CheckThisBool(IsSaving, CurrAddr, NightMode); + CurrAddr++; + ScreenSettingSelected = CheckThisByte(IsSaving, CurrAddr, ScreenSettingSelected); + CurrAddr++; + ScreenOptionSelected = CheckThisByte(IsSaving, CurrAddr, ScreenOptionSelected); + CurrAddr++; + + //##################################################################### + for (byte i = 1; i < 8; i++) { + ScreenPage1[i] = CheckThisInt(IsSaving, CurrAddr, ScreenPage1[i]); + CurrAddr++; + CurrAddr++; + } + for (byte i = 1; i < 8; i++) { + ScreenPage2[i] = CheckThisInt(IsSaving, CurrAddr, ScreenPage2[i]); + CurrAddr++; + CurrAddr++; + } + for (byte i = 1; i < 8; i++) { + ScreenPage3[i] = CheckThisInt(IsSaving, CurrAddr, ScreenPage3[i]); + CurrAddr++; + CurrAddr++; + } + for (byte i = 1; i < 8; i++) { + ScreenPage4[i] = CheckThisInt(IsSaving, CurrAddr, ScreenPage4[i]); + CurrAddr++; + CurrAddr++; + } + for (byte i = 1; i < 8; i++) { + ScreenPage5[i] = CheckThisInt(IsSaving, CurrAddr, ScreenPage5[i]); + CurrAddr++; + CurrAddr++; + } + for (byte i = 1; i < 8; i++) { + ScreenPage6[i] = CheckThisInt(IsSaving, CurrAddr, ScreenPage6[i]); + CurrAddr++; + CurrAddr++; + } + for (byte i = 1; i < 8; i++) { + ScreenPage7[i] = CheckThisInt(IsSaving, CurrAddr, ScreenPage7[i]); + CurrAddr++; + CurrAddr++; + } + for (byte i = 1; i < 8; i++) { + ScreenPage8[i] = CheckThisInt(IsSaving, CurrAddr, ScreenPage8[i]); + CurrAddr++; + CurrAddr++; + } + //##################################################################### + + ProgressBarMode = CheckThisByte(IsSaving, CurrAddr, ProgressBarMode); + CurrAddr++; + ProgressBarLeft = CheckThisByte(IsSaving, CurrAddr, ProgressBarLeft); + CurrAddr++; + + Timeout = CheckThisInt(IsSaving, CurrAddr, Timeout); + CurrAddr++; + CurrAddr++; + Injectors_Size = CheckThisInt(IsSaving, CurrAddr, Injectors_Size); + CurrAddr++; + CurrAddr++; + + O2Input = CheckThisByte(IsSaving, CurrAddr, O2Input); + CurrAddr++; + MapValue = CheckThisByte(IsSaving, CurrAddr, MapValue); + CurrAddr++; + UseCelcius = CheckThisByte(IsSaving, CurrAddr, UseCelcius); + CurrAddr++; + UseKMH = CheckThisByte(IsSaving, CurrAddr, UseKMH); + CurrAddr++; + O2Type = CheckThisByte(IsSaving, CurrAddr, O2Type); + CurrAddr++; + + //Missing WB Conversion (double here) + for (byte i = 1; i < 4; i++) { + WBConversion[i] = CheckThisDouble(IsSaving, CurrAddr, WBConversion[i]); + CurrAddr++; + CurrAddr++; + } + + WBModel = CheckThisByte(IsSaving, CurrAddr, WBModel); + CurrAddr++; + + for (byte i = 1; i < 4; i++) { + MapByte[i] = CheckThisByte(IsSaving, CurrAddr, MapByte[i]); + CurrAddr++; + } + for (byte i = 1; i < 4; i++) { + Tranny[i] = CheckThisByte(IsSaving, CurrAddr, Tranny[i]); + CurrAddr++; + } + + TrannyModel = CheckThisByte(IsSaving, CurrAddr, TrannyModel); + CurrAddr++; + MapModel = CheckThisByte(IsSaving, CurrAddr, MapModel); + CurrAddr++; + + Warning_RPM = CheckThisInt(IsSaving, CurrAddr, Warning_RPM); + CurrAddr++; + CurrAddr++; + Warning_IAT = CheckThisInt(IsSaving, CurrAddr, Warning_IAT + 40) - 40; + CurrAddr++; + CurrAddr++; + Warning_ECT = CheckThisInt(IsSaving, CurrAddr, Warning_ECT + 40) - 40; + CurrAddr++; + CurrAddr++; + mBarMin = CheckThisInt(IsSaving, CurrAddr, mBarMin + 300) - 300; + CurrAddr++; + CurrAddr++; + mBarMax = CheckThisInt(IsSaving, CurrAddr, mBarMax); + CurrAddr++; + CurrAddr++; + TempMin = CheckThisInt(IsSaving, CurrAddr, TempMin + 40) - 40; + CurrAddr++; + CurrAddr++; + TempMax = CheckThisInt(IsSaving, CurrAddr, TempMax + 40) - 40; + CurrAddr++; + CurrAddr++; +} + +//################################################################## + +double CheckThisDouble(bool IsSaving, int CurrAddr, double ThisDouble) { + if (IsSaving) { + int ThisInt = (int) (ThisDouble * 100); + CheckThisInt(IsSaving, CurrAddr, ThisInt); + } + else { + return (double) ((double) CheckThisInt(IsSaving, CurrAddr, 9999) / 100.0); + } + return ThisDouble; +} + +int CheckThisInt(bool IsSaving, int CurrAddr, int ThisInt) { + if (IsSaving) { + byte MSB = (byte) (ThisInt / 256); + byte LSB = (byte) (ThisInt - MSB); + WriteSingleByte(CurrAddr, MSB); + CurrAddr++; + WriteSingleByte(CurrAddr, LSB); + } + else { + byte MSB = ReadSingleByte(CurrAddr); + CurrAddr++; + byte LSB = ReadSingleByte(CurrAddr); + return ((int) LSB + ((int) MSB * 256)); + } + return ThisInt; +} + + +bool CheckThisBool(bool IsSaving, int CurrAddr, bool ThisBool) { + if (IsSaving) { + if (ThisBool) WriteSingleByte(CurrAddr, 1); + else WriteSingleByte(CurrAddr, 0); + } + else { + if (ReadSingleByte(CurrAddr) == 1) return true; + else return false; + //return ReadSingleByte(CurrAddr); + } + return ThisBool; +} + +byte CheckThisByte(bool IsSaving, int CurrAddr, byte ThisByte) { + if (IsSaving) { + WriteSingleByte(CurrAddr, ThisByte); + } + else { + return ReadSingleByte(CurrAddr); + } + return ThisByte; +} + +void WriteSingleByte(int CurrAddr, byte ThisByte) { + CurrAddr++; + EEPROM.write(CurrAddr, ThisByte); +} + +byte ReadSingleByte(int CurrAddr) { + CurrAddr++; + return EEPROM.read(CurrAddr); +} +//################################################################### diff --git a/BMDatalogger/ButtonsManager.ino b/BMDatalogger/ButtonsManager.ino new file mode 100644 index 0000000..f2c5ede --- /dev/null +++ b/BMDatalogger/ButtonsManager.ino @@ -0,0 +1,453 @@ +#define ON 1 +#define OFF 0 +volatile int buttonBack = 0; +volatile int buttonNext = 0; +volatile int buttonDual = 0; +unsigned long last_interrupt_time=0; +const int debouncing = 60; +volatile bool ButtonsPressed = false; +int BrightnessBuffer = 255; +int BrightnessBufferNight = 150; + +void CheckButtons() { + + //################### + //Atmega64A + pin_ISR1(); + pin_ISR2(); + //################### + + if (ButtonsPressed) { + if (millis() - last_interrupt_time > debouncing) { + ButtonsPressed = false; + last_interrupt_time = millis(); + GetButtonStates(); + + buttonBack=OFF; + buttonNext=OFF; + buttonDual=OFF; + + //last_interrupt_time = millis(); + } + } +} + +void pin_ISR1() +{ + if (digitalRead(BackButton) == LOW) { + buttonBack=ON; + ButtonsPressed = true; + ResetButtonTime(); + } + CheckDualButton(); +} + +void pin_ISR2() +{ + if (digitalRead(NextButton) == LOW) { + buttonNext=ON; + ButtonsPressed = true; + ResetButtonTime(); + } + CheckDualButton(); +} + +void CheckDualButton() { + if (digitalRead(NextButton) == LOW && digitalRead(BackButton) == LOW) { + buttonBack=OFF; + buttonNext=OFF; + buttonDual=ON; + ButtonsPressed = true; + ResetButtonTime(); + } + + //ResetButtonTime(); +} + +void ResetButtonTime() { + last_interrupt_time = millis(); + WaitingQuick = true; + WaitingDelay = debouncing*2; +} + +void GetButtonStates() { + if (buttonBack == ON) { + /*if (ShowJ12) { + BypassJ12(); + } + else {*/ + if (!InMain) { + if (ScreenCurrentMenu >= 4 && ScreenCurrentMenu < 12) { + SettingMenuNext(); + } + else if (ScreenCurrentMenu >= 13 && ScreenCurrentMenu <= 32) { + SettingMenuNext(); + } + else if (ScreenCurrentMenu == 32) { + MainMenu(); + } + else if (ScreenCurrentMenu == 33) { + OptionMenuNext(); + } + else if (ScreenCurrentMenu == 12) { + SettingPageNext(); + } + else { + MainMenu(); //Return to Main Menu + } + } else { + if (!Sleeping) { + MainMenuNext(); + } + else { + SleepDevice(); //disable sleeping + } + } + //} + + //AutoSaveEEPROM(); + } + + if (buttonNext == ON) { + /*if (ShowJ12) { + BypassJ12(); + } + else {*/ + if (!InMain) { + if (ScreenCurrentMenu >= 4) { + if (ScreenCurrentMenu >= 4 && ScreenCurrentMenu < 12) { + SettingMenu(1); + } + else if (ScreenCurrentMenu >= 13 && ScreenCurrentMenu < 32) { + SettingMenu(2); + } + else if (ScreenCurrentMenu == 12) { + IncreaseScreenIndex(); + } + else if (ScreenCurrentMenu == 32) { + MainMenu(); + } + else if (ScreenCurrentMenu == 33) { + if (ScreenOptionSelected == 0) DecreaseOption(); + if (ScreenOptionSelected == 1) IncreaseOption(); + if (ScreenOptionSelected == 2) SettingMenu(0); + } + else { + //settings menu (secondary page) + + } + } + else { + if(ScreenCurrentMenu != 2) { + NextDisplay(); + } + else { + ResetMilCodes(); + } + } + } + else { + if(ScreenCurrentMenu == 3) { + SleepDevice(); + } + else if(ScreenCurrentMenu == 4) { + SettingMenu(0); + } + else if(ScreenCurrentMenu == 5) { + SetNightMode(); + } + else { + MainMenu(); //Select Current Menu + } + } + //} + + //AutoSaveEEPROM(); + } + + //Dual buttons + if (buttonDual == ON) { + if (!InMain) { + if (ScreenCurrentMenu == 0) { + NextDisplay(); + } + else if (ScreenCurrentMenu == 1) { + ResetPeaks(); + } + else if (ScreenCurrentMenu == 2) { + ResetMilCodes(); + } + else if (ScreenCurrentMenu >= 4 && ScreenCurrentMenu < 12) { + MainMenu(); + } + else if (ScreenCurrentMenu == 12) { + SettingMenu(0); + } + else if (ScreenCurrentMenu >= 13 && ScreenCurrentMenu <= 32) { + MainMenu(); + } + else { + MainMenu(); + } + } + else { + if (ScreenCurrentMenu != 3) { + SettingMenu(0); + } + else { + SleepDevice(); + } + } + + //AutoSaveEEPROM(); + } +} + +/*void BypassJ12() { + J12Cut = true; + ShowJ12 = false; + WasAvailable = true; + + lcd.clear(); + ResetBufferIndex(); +}*/ + +void ResetMilCodes() { + lcd.clear(); + ResetBufferIndex(); + GetInfosString(11); + writeBigString(0, 0); + ResetBufferIndex(); + bool Resetted = ResetMil(); + if (Resetted) GetInfosString(12); + if (!Resetted) GetInfosString(13); + writeBigString(0, 2); + + delay(1000); + lcd.clear(); +} + +void ResetPeaks() { + lcd.clear(); + ResetBufferIndex(); + GetInfosString(11); + writeBigString(0, 0); + ResetBufferIndex(); + InitPeak(); + + GetInfosString(8); + writeBigString(2, 2); + + delay(1000); + lcd.clear(); + ResetBufferIndex(); + GetInfosString(12); + writeBigString(0, 0); + //writeBigString(0, 2); + + delay(1000); + lcd.clear(); +} + +void NextDisplay() { + if(ScreenCurrentMenu == 0) { + ScreenCurrentPage++; + if(ScreenCurrentPage > 8) ScreenCurrentPage = 1; + } + if(ScreenCurrentMenu == 1) { + ScreenCurrentPeak++; + if(ScreenCurrentPeak >= MaxDataValue) ScreenCurrentPeak = 0; + } + + //SaveLoadEEPROM(true); //save + ShowPage(); +} + +void MainMenu() { + if (InMain) InMain = false; + else InMain = true; + if (ScreenCurrentMenu > 3) ScreenCurrentMenu = 0; + + //SaveLoadEEPROM(true); //save + lcd.clear(); + + if (InMain) AutoSaveEEPROM(); + + //delay(40); + WaitingDelay = 40; + WaitingQuick = false; + //SetWait(); +} + +/*void SetWait() { + WaitingQuick = true; + WaitingDelay = debouncing*2; +}*/ + +void SettingMenu(int PartMenu) { + InMain = false; + if (PartMenu == 0) { + if (ScreenCurrentMenu == 33) { + ScreenCurrentMenu = ScreenSettingSelected; + } + else if (ScreenCurrentMenu == 12) { + ScreenCurrentMenu = ScreenCurrentPage + 3; + } + else { + ScreenCurrentMenu = 4; + } + } + else if (PartMenu == 1) { + ScreenCurrentPage = ScreenCurrentMenu - 3; + ScreenSettingSelected = 0; + ScreenCurrentMenu = 12; + } + else if (PartMenu == 2) { + ScreenSettingSelected = ScreenCurrentMenu; + ScreenOptionSelected = 0; + ScreenCurrentMenu = 33; + } + lcd.clear(); + //delay(40); + WaitingDelay = 40; + WaitingQuick = false; + //SetWait(); +} + +void SettingMenuNext() { + int PartMenu = 0; + if (ScreenCurrentMenu == 12) PartMenu = 1; + + ScreenCurrentMenu++; + //if(ScreenCurrentMenu > 11 && PartMenu == 0) ScreenCurrentMenu = 4; + if(ScreenCurrentMenu == 12 && PartMenu == 0) ScreenCurrentMenu++; + if(ScreenCurrentMenu > 32 && PartMenu == 0) ScreenCurrentMenu = 4; + + if(ScreenCurrentMenu != 12 && PartMenu == 1) ScreenCurrentMenu = 12; + + //delay(40); + WaitingDelay = 40; + WaitingQuick = false; + //SetWait(); +} + +void OptionMenuNext() { + ScreenOptionSelected++; + if (ScreenOptionSelected > 2) ScreenOptionSelected = 0; + + //delay(40); + WaitingDelay = 40; + WaitingQuick = false; + //SetWait(); +} + +void SettingPageNext() { + ScreenSettingSelected++; + if (ScreenSettingSelected > 15) ScreenSettingSelected = 0; + + //delay(40); + WaitingDelay = 40; + WaitingQuick = false; + //SetWait(); +} + +void SleepDevice() { + if (!Sleeping) { + BrightnessBuffer = Brightness; + BrightnessBufferNight = BrightnessNight; + Brightness = 0; + BrightnessNight = 0; + analogWrite(BackLightPin, 0); // PWM values from 0 to 255 (0% – 100% duty cycle) + //lcd.noBacklight(); + noBacklight(); + Sleeping = true; + Serial1.end(); + } else { + Brightness = BrightnessBuffer; + BrightnessNight = BrightnessBufferNight; + RefreshBackLight(); + //lcd.backlight(); + backlight(); + Sleeping = false; + Serial1.begin(38400); + } + //SaveLoadEEPROM(true); //save +} + +void SetNightMode() { + if (!NightMode) { + NightMode = true; + } + else { + NightMode = false; + } + RefreshBackLight(); + + //delay(40); + WaitingDelay = 40; + WaitingQuick = false; + //SetWait(); +} + +void RefreshBackLight() { + if (!NightMode) analogWrite(BackLightPin, Brightness); // PWM values from 0 to 255 (0% – 100% duty cycle) + if (NightMode) analogWrite(BackLightPin, BrightnessNight); // PWM values from 0 to 255 (0% – 100% duty cycle) +} + +void MainMenuNext() { + ScreenCurrentMenu++; + if(ScreenCurrentMenu > 5) ScreenCurrentMenu = 0; + //if(ScreenCurrentMenu > 3) ScreenCurrentMenu = 0; + + //SaveLoadEEPROM(true); //save + + //delay(40); + WaitingDelay = 40; + WaitingQuick = false; + //SetWait(); +} + +void ShowPage() { + lcd.clear(); + + ResetBufferIndex(); + GetInfosString(5); + writeBigString(3, 0); + + ResetBufferIndex(); + if(ScreenCurrentMenu == 0) Add_String(String(ScreenCurrentPage)); + if(ScreenCurrentMenu == 1) Add_String(String(ScreenCurrentPeak)); + writeBigString(7, 2); + + WaitingDelay = 500; + WaitingQuick = false; + //_delay_ms(500); + //lcd.clear(); +} + +/*void ShowMenu() { + lcd.clear(); + ResetBufferIndex(); + GetInfosString(6); + writeBigString(3, 0); + + ResetBufferIndex(); + int XOffset = 0; + if (ScreenCurrentMenu == 0) GetInfosString(7); + if (ScreenCurrentMenu == 1) { + GetInfosString(8); + XOffset = 2; + } + if (ScreenCurrentMenu == 2) { + GetInfosString(9); + XOffset = 5; + } + if (ScreenCurrentMenu == 4) GetInfosString(24); + + writeBigString(XOffset, 2); + + WaitingDelay = 700; + WaitingQuick = false; + //_delay_ms(1000); + //lcd.clear(); +}*/ diff --git a/BMDatalogger/CustomCharacter.ino b/BMDatalogger/CustomCharacter.ino new file mode 100644 index 0000000..11a43fe --- /dev/null +++ b/BMDatalogger/CustomCharacter.ino @@ -0,0 +1,397 @@ +const char Progbar2_START[][8] PROGMEM = { + { B01111, B11000, B10000, B10000, B10000, B10000, B11000, B01111 }, + { B01111, B11000, B10011, B10111, B10111, B10011, B11000, B01111 } +}; + +const char Progbar2_MIDDLE[][8] PROGMEM = { + { B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111 }, + { B11111, B00000, B11000, B11000, B11000, B11000, B00000, B11111 }, + { B11111, B00000, B11011, B11011, B11011, B11011, B00000, B11111 }, + { B11111, B00000, B00011, B00011, B00011, B00011, B00000, B11111 } +}; + +const char Progbar2_END[][8] PROGMEM = { + { B11110, B00011, B00001, B00001, B00001, B00001, B00011, B11110 }, + { B11110, B00011, B11001, B11101, B11101, B11001, B00011, B11110 } +}; + +const char Progbar3[][8] PROGMEM = { + { B10101, B00000, B00000, B00000, B00000, B00000, B00000, B10101 }, + { B10101, B10000, B10000, B10000, B10000, B10000, B10000, B10101 }, + { B10101, B10100, B10100, B10100, B10100, B10100, B10100, B10101 }, + { B10101, B10101, B10101, B10101, B10101, B10101, B10101, B10101 }, + { B10101, B00100, B00100, B00100, B00100, B00100, B00100, B10101 }, + { B10101, B00001, B00001, B00001, B00001, B00001, B00001, B10101 } +}; + +const char Progbar4[][8] PROGMEM = { + { B11111, B10000, B10000, B10000, B10000, B10000, B10000, B11111 }, + { B11111, B01000, B01000, B01000, B01000, B01000, B01000, B11111 }, + { B11111, B00100, B00100, B00100, B00100, B00100, B00100, B11111 }, + { B11111, B00010, B00010, B00010, B00010, B00010, B00010, B11111 }, + { B11111, B00001, B00001, B00001, B00001, B00001, B00001, B11111 }, + { B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111 } +}; + +const char custom[][8] PROGMEM = { + { 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00 }, // char 1 + { 0x18, 0x1C, 0x1E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F }, // char 2 + { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0F, 0x07, 0x03 }, // char 3 + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F }, // char 4 + { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1E, 0x1C, 0x18 }, // char 5 + { 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x1F, 0x1F }, // char 6 + { 0x1F, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F }, // char 7 + { 0x03, 0x07, 0x0F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F } // char 8 +}; + +const char *bigChars[][2] = { + {"\024", "\024"}, // Space + {"\024", "\004"}, // . + {"\010\001\002", "\003\004\005"}, // 0 + {"\001\002", "\024\377"}, // 1 + {"\006\006\002", "\003\007\007"}, // 2 + {"\006\006\002", "\007\007\005"}, // 3 + {"\003\004\002", "\024\024\377"}, // 4 + {"\377\006\006", "\007\007\005"}, // 5 + {"\010\006\006", "\003\007\005"}, // 6 + {"\001\001\002", "\024\010\024"}, // 7 + {"\010\006\002", "\003\007\005"}, // 8 + {"\010\006\002", "\024\024\377"}, // 9 + {"\004", "\001"}, // : + {"\010\006\002", "\377\024\377"}, // A + {"\377\006\005", "\377\007\002"}, // B + {"\010\001\001", "\003\004\004"}, // C + {"\377\001\002", "\377\004\005"}, // D + {"\377\006\006", "\377\007\007"}, // E + {"\377\006\006", "\377\024\024"}, // F + {"\010\001\001", "\003\004\002"}, // G + {"\377\004\377", "\377\024\377"}, // H + {"\001\377\001", "\004\377\004"}, // I + {"\024\024\377", "\004\004\005"}, // J + {"\377\004\005", "\377\024\002"}, // K + {"\377\024\024", "\377\004\004"}, // L + {"\010\003\005\002", "\377\024\024\377"}, // M + {"\010\002\024\377", "\377\024\003\005"}, // N + {"\010\001\002", "\003\004\005"}, // 0 + {"\377\006\002", "\377\024\024"}, // P + {"\010\001\002\024", "\003\004\377\004"}, // Q + {"\377\006\002", "\377\024\002"}, // R + {"\010\006\006", "\007\007\005"}, // S + {"\001\377\001", "\024\377\024"}, // T + {"\377\024\377", "\003\004\005"}, // U + {"\003\024\024\005", "\024\002\010\024"}, // V + {"\377\024\024\377", "\003\010\002\005"}, // W + {"\003\004\005", "\010\024\002"}, // X + {"\003\004\005", "\024\377\024"}, // Y + {"\001\006\005", "\010\007\004"}, // Z +}; + +byte InitMode = 99; + +void CharacterInit(byte bank) { + if (InitMode != bank) { + uint8_t ThisArray[8]; + + switch (bank) { + case 0: + for (int i=0; i<5; i++ ) { + byte ThisByte = 0x00; + if (ProgressBarMode == 0) { + if (i == 0) ThisByte = 0x1F; + if (i == 1) ThisByte = 0x10; + if (i == 2) ThisByte = 0x18; + if (i == 3) ThisByte = 0x1C; + if (i == 4) ThisByte = 0x1E; + } + if (ProgressBarMode == 1) { + if (i == 0) ThisByte = 0x01; + if (i == 1) ThisByte = 0x10; + if (i == 2) ThisByte = 0x08; + if (i == 3) ThisByte = 0x04; + if (i == 4) ThisByte = 0x02; + } + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) ThisByte; + lcd.createChar (i, ThisArray); + } + break; + + case 1: + for (int i=0; i<8; i++ ) { + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &custom[i][i2] ); + lcd.createChar (i+1, ThisArray); + } + break; + + case 2: + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar2_START[0][i2] ); lcd.createChar (1, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar2_START[1][i2] ); lcd.createChar (2, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar2_MIDDLE[0][i2] ); lcd.createChar (3, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar2_MIDDLE[1][i2] ); lcd.createChar (4, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar2_MIDDLE[2][i2] ); lcd.createChar (5, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar2_END[0][i2] ); lcd.createChar (6, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar2_END[1][i2] ); lcd.createChar (7, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar2_MIDDLE[3][i2] ); lcd.createChar (8, ThisArray); + break; + + case 3: + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar3[0][i2] ); lcd.createChar (0, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar3[1][i2] ); lcd.createChar (1, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar3[2][i2] ); lcd.createChar (2, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar3[3][i2] ); lcd.createChar (3, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar3[4][i2] ); lcd.createChar (4, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar3[5][i2] ); lcd.createChar (5, ThisArray); + break; + + case 4: + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar4[0][i2] ); lcd.createChar (0, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar4[1][i2] ); lcd.createChar (1, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar4[2][i2] ); lcd.createChar (2, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar4[3][i2] ); lcd.createChar (3, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar4[4][i2] ); lcd.createChar (4, ThisArray); + for (int i2=0; i2<8; i2++) ThisArray[i2]= (uint8_t) pgm_read_byte( &Progbar4[5][i2] ); lcd.createChar (5, ThisArray); + break; + } + + InitMode = bank; + } +} + + +void DrawProgressBar(const int value, const int Lenght) { + + int percent = GetPeakPercent(value); + DrawProgressBarPercent(percent, Lenght); +} + +void DrawProgressBarPercent(const int value, const int Lenght) { + int StyleMode = 1; + if (ProgressBarMode == 2 | ProgressBarMode == 3) StyleMode = 2; + if (ProgressBarMode == 4 | ProgressBarMode == 5) StyleMode = 3; + if (ProgressBarMode == 6) StyleMode = 4; + + int WhiteMode = 0; + if (ProgressBarMode == 1| ProgressBarMode == 3 | ProgressBarMode == 5) WhiteMode = 1; + + if (StyleMode == 1) CharacterInit(0); + if (StyleMode == 2) CharacterInit(2); + if (StyleMode == 3) CharacterInit(3); + if (StyleMode == 4) CharacterInit(4); + + int percent = value; + //int nb_columns = map(percent, 0, 100, 0, Lenght * 2 * 4 - 2 * 4); + //int nb_columns = (percent * ((Lenght * 8) - 8)) / 100; + int nb_columns = (percent * ((Lenght * 2) - 2)) / 100; + double RowsNumber = ((double) Lenght / 100) * (double) percent; + int RowsDone = 0; + + lcd.setCursor(XPos, YPos); + + //ProgBar Style #1 + if (StyleMode == 1) { + if (RowsNumber >= 1) { + for (int i=1; i < RowsNumber; i++) { + if (WhiteMode == 0) lcd.write((uint8_t)0); + if (WhiteMode == 1) lcd.write(' '); + RowsDone++; + } + } + + RowsNumber = RowsNumber - RowsDone; + unsigned int peace = RowsNumber * 5; + + switch (peace) { + case 0: + if (WhiteMode == 1) { + lcd.write((uint8_t)1); + RowsDone++; + } + break; + case 1: + lcd.write((uint8_t)1); RowsDone++; + break; + case 2: + lcd.write((uint8_t)2); RowsDone++; + break; + case 3: + lcd.write((uint8_t)3); RowsDone++; + break; + case 4: + lcd.write((uint8_t)4); RowsDone++; + break; + case 5: + lcd.write((uint8_t)0); RowsDone++; + break; + } + + for (int i =0; i < (Lenght - RowsDone); i++) lcd.write(' '); + } + + //ProgBar Style #2 + if (StyleMode == 2) { + for (byte i = 0; i < Lenght; ++i) { + if (i == 0) { + if ((nb_columns > 0 && WhiteMode == 0) | (nb_columns == 1 && WhiteMode == 1)) { + lcd.write(2); + nb_columns -= 1; + } else { + lcd.write((uint8_t)1); + } + } else if (i == Lenght -1) { + if (nb_columns > 0) lcd.write(7); + if (nb_columns == 0) lcd.write(6); + } else { + if ((nb_columns >= 2 && WhiteMode == 0) | (nb_columns == 2 && WhiteMode == 1)) { + if (WhiteMode == 0) lcd.write(5); + if (WhiteMode == 1) lcd.write(8); + nb_columns -= 2; + } else if (nb_columns == 1) { + lcd.write(4); + nb_columns -= 1; + } else { + lcd.write(3); + if (WhiteMode == 1 && nb_columns > 2) nb_columns -= 2; + } + } + } + } + + //ProgBar Style #3 + if (StyleMode == 3) { + if (RowsNumber >= 1) { + for (int i=1; i < RowsNumber; i++) { + if (RowsDone < Lenght - 1) { + if (WhiteMode == 0) lcd.write((uint8_t)3); + if (WhiteMode == 1) lcd.write((uint8_t)0); + RowsDone++; + } + } + } + + RowsNumber = RowsNumber - RowsDone; + unsigned int peace = RowsNumber * 5; + + switch (peace) { + case 0: + if (RowsDone == 0) { + lcd.write((uint8_t)0); RowsDone++; + } + break; + case 1: + lcd.write((uint8_t)1); RowsDone++; + break; + case 2: + if (WhiteMode == 0) lcd.write((uint8_t)2); + if (WhiteMode == 1) lcd.write((uint8_t)4); + RowsDone++; + break; + case 3: + if (WhiteMode == 0) lcd.write((uint8_t)2); + if (WhiteMode == 1) lcd.write((uint8_t)4); + RowsDone++; + break; + case 4: + if (WhiteMode == 0) lcd.write((uint8_t)3); + if (WhiteMode == 1) lcd.write((uint8_t)5); + RowsDone++; + break; + case 5: + if (WhiteMode == 0) lcd.write((uint8_t)3); + if (WhiteMode == 1) lcd.write((uint8_t)5); + RowsDone++; + break; + } + + for (int i =0; i < (Lenght - RowsDone); i++) lcd.write((uint8_t)0); + } + + //ProgBar Style #4 + if (StyleMode == 4) { + if (RowsNumber >= 1) { + for (int i=1; i < RowsNumber; i++) { + if (RowsDone < Lenght - 1) { + lcd.write((uint8_t)5); RowsDone++; + } + } + } + + RowsNumber = RowsNumber - RowsDone; + unsigned int peace = RowsNumber * 5; + + switch (peace) { + case 0: + if (RowsDone == 0) { + lcd.write((uint8_t)0); RowsDone++; + } + break; + case 1: + lcd.write((uint8_t)0); RowsDone++; + break; + case 2: + lcd.write((uint8_t)1); RowsDone++; + break; + case 3: + lcd.write((uint8_t)2); RowsDone++; + break; + case 4: + lcd.write((uint8_t)3); RowsDone++; + break; + case 5: + lcd.write((uint8_t)4); RowsDone++; + break; + } + + for (int i =0; i < (Lenght - RowsDone); i++) lcd.write((uint8_t)5); + } +} + +int writeBigChar(const char ch, const int x, const int y) { + const char *(*blocks)[2] = NULL; + + if (ch < ' ' || ch > 'Z') return 0; + if (ch >= '!' && ch <= '-') return 0; + if (ch == '/') return 0; + if (ch >= ';' && ch <= '@') return 0; + + int Index = (int) ch - (int) ' '; + if (ch > '!') Index -= 13; + if (ch > '/') Index -= 1; + if (ch > ';') Index -= 6; + + blocks = &bigChars[Index]; + + for (int half = 0; half <=1; half++) { + int t = x; + for (const char *cp = (*blocks)[half]; *cp; cp++) { + if (t < 20) { + lcd.setCursor(t, y+half); + lcd.write(*cp); + t = (t+1) % 40; + } + } + //lcd.setCursor(t, y+half); + //lcd.write(' '); + } + + return strlen((*blocks)[0]); +} + +void writeBigString(int x, int y) { + CharacterInit(1); + for (int i=0; i < 20; i++) { + char c = StringBuffer[i]; + //if ((int) c != 0) x += writeBigChar(c, x, y) + 1; + if ((int) c >= 20) x += writeBigChar(c, x, y); + if ((int) c < 20) i += 20; + } +} + +void writeBigStringAnimated(int x, int y) { + CharacterInit(1); + for (int i=0; i < 20; i++) { + char c = StringBuffer[i]; + //if ((int) c != 0) x += writeBigChar(c, x, y) + 1; + if ((int) c >= 20) x += writeBigChar(c, x, y); + if ((int) c < 20) i += 20; + delay(20); + } +} diff --git a/BMDatalogger/DatalogProtocol.ino b/BMDatalogger/DatalogProtocol.ino new file mode 100644 index 0000000..7b32832 --- /dev/null +++ b/BMDatalogger/DatalogProtocol.ino @@ -0,0 +1,546 @@ +const int Array_Size = 52; +byte Datalog_Bytes[Array_Size]; +unsigned long CurrentSDWrite = 0; + +// ect, iat, o2, baro, map +// tps, rpmlo, rpmhi, vtec, locam +// hicam, column, vss, injlo, injhi +// ign, knonk, (crank|batt) (crank for crome 1.2, batt for crome 1.4) + +//Crome 1.2 Protocol +const byte Crome12_Bytes[18] = { + 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, + 0x1A, 0x1B, 0x20, 0x21, 0x08, + 0x23, 0x24, 0x25 +}; + +//Crome 1.4 QD2 Protocol +const byte Crome14_Bytes[18] = { + 0x1D, 0x1B, 0x20, 0x1E, 0x14, + 0x15, 0x10, 0x11, 0x22, 0x12, + 0x13, 0x16, 0x1C, 0x17, 0x18, + 0x19, 0x1A, 0x22 //0x22 or 0x1F for Batt +}; + +//################################################ + +// ect, iat, map, baro, tps +// o2, rpmlo, rpmhi, rows, column +// vtec, vss, err1, err2, err3 +// (fuello, fuelhi, gear, eld, ign) (NG63++) + +//NG60-NG62 Protocol +const byte NG60_Bytes[15] = { + 0x30, 0x32, 0xF8, 0x34, 0x39, + 0xFB, 0xFA, 0x47, 0xFE, 0xFD, + 0x18, 0x6C, 0x2B, 0x2C, 0x2D, +}; + +//NG63 Protocol +const byte NG63_Bytes[20] = { + 0x30, 0x32, 0xF8, 0x34, 0x39, + 0xFB, 0xFA, 0x47, 0x3B, 0xFD, + 0x18, 0x6C, 0x2B, 0x2C, 0x2D, + 0x70, 0x6F, 0xFE, 0xFC, 0x63 +}; + +/*void GetJ12Cut() { + J12Cut = false; + WasAvailable = false; + Serial.write((byte) 16); + _delay_ms(500); + if (Serial.available()) { + WasAvailable = true; + if (Serial.read() == 0xcd) J12Cut = true; + } +}*/ + +void WriteToSD() { + unsigned long FLenght = ((CurrentSDWrite * 72) + 14); + unsigned long long_2 = ((int)((FLenght - 0x7b) - 0x10L)) / (0x7b + 1); + //this.long_3 = struct12_1.long_3; + + myFile = SD.open("BMDatalogger.bml", FILE_WRITE); + //myFile = SD.open("BMDatalogger" + SDFileCount + ".bml", FILE_WRITE); + if (CurrentSDWrite == 0) + { + myFile.write((const uint8_t *) 0x42, 1); + myFile.write((const uint8_t *) 0x4d, 1); + myFile.write((const uint8_t *) 0x54, 1); + myFile.write((const uint8_t *) 0x75, 1); + myFile.write((const uint8_t *) 0x6e, 1); + myFile.write((const uint8_t *) 0x65, 1); + myFile.write((const uint8_t *) 0x2e, 1); + myFile.write((const uint8_t *) 0x62, 1); + myFile.write((const uint8_t *) 0x6d, 1); + myFile.write((const uint8_t *) 0x6c, 1); + myFile.write((const uint8_t *) 0x06, 1); + myFile.write((const uint8_t *) 0x00, 1); + myFile.write((const uint8_t *) 0x7b, 1); + myFile.write((const uint8_t *) 0x00, 1); + } + + myFile.write((const uint8_t *) Datalog_Bytes[0], 1); + myFile.write((const uint8_t *) Datalog_Bytes[1], 1); + myFile.write((const uint8_t *) Datalog_Bytes[2], 1); + myFile.write((const uint8_t *) Datalog_Bytes[3], 1); + myFile.write((const uint8_t *) Datalog_Bytes[4], 1); + myFile.write((const uint8_t *) Datalog_Bytes[5], 1); + + myFile.write((const uint8_t *) Datalog_Bytes[6], 1); + myFile.write((const uint8_t *) Datalog_Bytes[7], 1); + + myFile.write((const uint8_t *) Datalog_Bytes[8], 1); + myFile.write((const uint8_t *) Datalog_Bytes[9], 1); + myFile.write((const uint8_t *) Datalog_Bytes[10], 1); + myFile.write((const uint8_t *) Datalog_Bytes[11], 1); + myFile.write((const uint8_t *) Datalog_Bytes[12], 1); + myFile.write((const uint8_t *) Datalog_Bytes[13], 1); + myFile.write((const uint8_t *) Datalog_Bytes[14], 1); + myFile.write((const uint8_t *) Datalog_Bytes[15], 1); + myFile.write((const uint8_t *) Datalog_Bytes[16], 1); + + myFile.write((const uint8_t *) Datalog_Bytes[17], 1); + myFile.write((const uint8_t *) Datalog_Bytes[18], 1); + + myFile.write((const uint8_t *) Datalog_Bytes[19], 1); + myFile.write((const uint8_t *) Datalog_Bytes[20], 1); + myFile.write((const uint8_t *) Datalog_Bytes[21], 1); + myFile.write((const uint8_t *) Datalog_Bytes[22], 1); + myFile.write((const uint8_t *) Datalog_Bytes[23], 1); + myFile.write((const uint8_t *) Datalog_Bytes[24], 1); + myFile.write((const uint8_t *) Datalog_Bytes[25], 1); + + myFile.write((const uint8_t *) GetByte1(CurrentSDWrite + 1), 1); + myFile.write((const uint8_t *) GetByte2(CurrentSDWrite + 1), 1); + + myFile.write((const uint8_t *) GetByte1(Timeout), 1); + myFile.write((const uint8_t *) GetByte2(Timeout), 1); + + myFile.write((const uint8_t *) Datalog_Bytes[26], 1); + + myFile.write((const uint8_t *) Datalog_Bytes[27], 1); + myFile.write((const uint8_t *) Datalog_Bytes[28], 1); + myFile.write((const uint8_t *) Datalog_Bytes[29], 1); + myFile.write((const uint8_t *) Datalog_Bytes[30], 1); + myFile.write((const uint8_t *) Datalog_Bytes[31], 1); + myFile.write((const uint8_t *) Datalog_Bytes[32], 1); + + myFile.write((const uint8_t *) Datalog_Bytes[33], 1); + myFile.write((const uint8_t *) Datalog_Bytes[34], 1); + myFile.write((const uint8_t *) Datalog_Bytes[35], 1); + myFile.write((const uint8_t *) Datalog_Bytes[36], 1); + myFile.write((const uint8_t *) Datalog_Bytes[37], 1); + myFile.write((const uint8_t *) Datalog_Bytes[38], 1); + myFile.write((const uint8_t *) Datalog_Bytes[39], 1); + myFile.write((const uint8_t *) Datalog_Bytes[40], 1); + myFile.write((const uint8_t *) Datalog_Bytes[41], 1); + myFile.write((const uint8_t *) Datalog_Bytes[42], 1); + myFile.write((const uint8_t *) Datalog_Bytes[43], 1); + myFile.write((const uint8_t *) Datalog_Bytes[44], 1); + myFile.write((const uint8_t *) Datalog_Bytes[45], 1); + myFile.write((const uint8_t *) Datalog_Bytes[46], 1); + myFile.write((const uint8_t *) Datalog_Bytes[47], 1); + myFile.write((const uint8_t *) Datalog_Bytes[48], 1); + + myFile.write((const uint8_t *) Datalog_Bytes[49], 1); + myFile.write((const uint8_t *) Datalog_Bytes[50], 1); + + myFile.write((const uint8_t *) GetWBByte(), 1); + + myFile.write((const uint8_t *) Datalog_Bytes[8], 1); + myFile.write((const uint8_t *) Datalog_Bytes[9], 1); + myFile.write((const uint8_t *) Datalog_Bytes[10], 1); + myFile.write((const uint8_t *) Datalog_Bytes[11], 1); + + //NOT FINISHED HERE //float_0 in bmtune + + //myFile.write((const uint8_t *)&Datalog_Bytes, sizeof(Datalog_Bytes)); + myFile.close(); + + CurrentSDWrite++; +} + +byte GetByte1(long ThisNumber) { + int Divider = ThisNumber / 255; + return ThisNumber - (Divider * 255); +} + +byte GetByte2(long ThisNumber) { + return ThisNumber / 255; +} + +void GetData(){ + //digitalWrite(StatusLEDPin, HIGH); + if(Serial1.available()) { + int Tries = 0; + while (Serial1.available() < 52 && Tries < 50) { + //delayMicroseconds(1); + delay(1); + Tries++; + } + for (int i = 0; i < Array_Size; i++) { + Datalog_Bytes[i] = Serial1.read(); + } + } + + Serial1.flush(); + Serial1.write(" "); + //digitalWrite(StatusLEDPin, LOW); + + //FakeValue += 1; + //if (FakeValue >= 180) FakeValue = 0; +} + +bool ResetMil() { + bool MilResetted = false; + Serial1.write((byte) 80); + delay(500); + if (Serial1.available()) { + byte MilReadByte[4] = {0,0,0,0}; + for (int i = 0; i < 4; i++) MilReadByte[i] = Serial1.read(); + if (MilReadByte[1] == 80) MilResetted = true; + } + return MilResetted; +} + +void GetMil() { + int Displayed = 0; + for (int i = 1; i <= 8; i++) { + if (Displayed < 4) { + if (GetActivated(Datalog_Bytes[12], i - 1, false) == 1) { + ResetBufferIndex(); + GetErrorString(FixMil(i)); + DisplayMil(Displayed); + Displayed++; + } + } + } + for (int j = 1; j <= 8; j++) { + if (Displayed < 4) { + if (GetActivated(Datalog_Bytes[13], j - 1, false) == 1) { + ResetBufferIndex(); + GetErrorString(FixMil(j + 8)); + DisplayMil(Displayed); + Displayed++; + } + } + } + for (int k = 1; k <= 8; k++) { + if (Displayed < 4) { + if (GetActivated(Datalog_Bytes[14], k - 1, false) == 1) { + ResetBufferIndex(); + GetErrorString(FixMil((k + 8) + 8)); + DisplayMil(Displayed); + Displayed++; + } + } + } + for (int m = 1; m <= 8; m++) { + if (Displayed < 4) { + if (GetActivated(Datalog_Bytes[15], m - 1, false) == 1) { + ResetBufferIndex(); + GetErrorString(FixMil(((m + 8) + 8) + 8)); + DisplayMil(Displayed); + Displayed++; + } + } + } + + //Nothing Displayed + if (Displayed == 0) { + ResetBufferIndex(); + GetInfosString(10); + writeBigString(0, 2); + } + + //Reset Overlay if displayed + if (Displayed == 1) { + ResetBufferIndex(); + PrintText(10, 10, 2); + } + if (Displayed == 2) { + ResetBufferIndex(); + PrintTextLenght(0, 3); + } + if (Displayed == 3) { + ResetBufferIndex(); + PrintText(10, 10, 3); + } +} + +int FixMil(int Value) { + switch (Value) { + case 0x18: + return 30; + case 0x19: + return 0x1f; + case 0x1a: + return 0x24; + case 0x1b: + return 0x29; + case 0x1c: + return 0x2b; + } + //if (Value >= 0x18) return 0; + return Value; +} + +long Long2Bytes(const byte ThisByte1, const byte ThisByte2) { + return ((long) ThisByte2 * 256) + (long) ThisByte1; +} + +float GetTemperature(const byte ThisByte) { + float ThisTemp = (float) ThisByte / 51; + ThisTemp = (0.1423*pow(ThisTemp,6)) - (2.4938*pow(ThisTemp,5)) + (17.837*pow(ThisTemp,4)) - (68.698*pow(ThisTemp,3)) + (154.69*pow(ThisTemp,2)) - (232.75*ThisTemp) + 284.24; + ThisTemp = ((ThisTemp - 32)*5)/9; + + if (UseCelcius == 0) + ThisTemp = ThisTemp * 1.8 + 32.0; + + return ThisTemp; +} + +double GetVolt(const byte ThisByte) { + return (double) ThisByte * 0.0196078438311815; +} + +float GetDuration(const int ThisInt) { + return ((float) ThisInt * 3.20000004768372) / 1000.0; +} + +byte GetActivated(byte ThisByte, const int ThisPos, const bool Reversed) { + int bitArray[8]; + for (int i=0; i < 8; ++i ) { + bitArray[i] = ThisByte & 1; + ThisByte = ThisByte >> 1; + } + + if (Reversed) + return bitArray[ThisPos] ? (byte) 0 : (byte) 1; + return bitArray[ThisPos] ? (byte) 1 : (byte) 0; +} + +float GetInstantConsumption(){ + if (GetVssKMH() == 0) return 0; + //float hundredkm = ((60 / GetVssKMH()) * 100) / 60; //minutes needed to travel 100km (OLD) + float hundredkm = 6000 / GetVssKMH(); //minutes needed to travel 100km + float fuelc = (hundredkm * ((Injectors_Size / 100) * GetDuty())) / 1000; + return constrain(fuelc * 4, 0.0, 50.0); //Vary between 0-50 L/100km +} + +float GetDuty(){ + return ((float) GetRpm() * (float) GetInjDurr()) / 1200; +} + +int GetInjDurr(){ + //return (int) (Long2Bytes(Datalog_Bytes[17], Datalog_Bytes[18]) / 352); + return GetDuration((int) Long2Bytes(Datalog_Bytes[17], Datalog_Bytes[18])); +} + +int GetEct(){ + return constrain(GetTemperature(Datalog_Bytes[0]), TempMin, TempMax); +} + +int GetIat(){ + return constrain(GetTemperature(Datalog_Bytes[1]), TempMin, TempMax); +} + +byte GetWBByte(){ + byte WBByte = 0; + if (O2Input == 0) WBByte = Datalog_Bytes[2]; + if (O2Input == 1) WBByte = Datalog_Bytes[24]; + if (O2Input == 2) WBByte = Datalog_Bytes[44]; + if (O2Input == 3) WBByte = Datalog_Bytes[45]; + return WBByte; +} + +double GetO2(){ + byte WBByte = 0; + if (O2Input == 0) WBByte = Datalog_Bytes[2]; + if (O2Input == 1) WBByte = Datalog_Bytes[24]; + if (O2Input == 2) WBByte = Datalog_Bytes[44]; + if (O2Input == 3) WBByte = Datalog_Bytes[45]; + double RTND = 0.0; + if (O2Type == 0) RTND = constrain((double) InterpolateWB(GetVolt(WBByte)) * 14.7, 10, 20); + if (O2Type == 1) RTND = constrain((double) InterpolateWB(GetVolt(WBByte)), 0, 5); + if (O2Type == 2) RTND = constrain((double) GetVolt(WBByte), 0, 16); + + //return RoundThis(1, RTND); + return RTND; +} + +double InterpolateWB(double ThisDouble) { + if (ThisDouble < WBConversion[0]) return WBConversion[1]; + if (ThisDouble > WBConversion[2]) return WBConversion[3]; + return (WBConversion[1] + (((ThisDouble - WBConversion[0]) * (WBConversion[3] - WBConversion[1])) / (WBConversion[2] - WBConversion[0]))); +} + +int GetMBar() { + long Value = (long) Datalog_Bytes[4]; + long MapLow = (long) mBarMin + 32768; + long MapHigh = (long) mBarMax + 32768; + + return (int) ((((Value * (MapHigh - MapLow)) / 255) + MapLow) - 32768); +} + +int GetMap(){ + int mBar = GetMBar(); + if (MapValue == 0) return constrain(mBar, mBarMin, mBarMax); + else if (MapValue == 1) { + if (mBar <= 1013) return 0; + else return constrain((int) (((float) mBar - 1013) * 0.01450377), 0, 40); //GetValuePSI(ThisInt); + } + else if (MapValue == 2) return constrain((int) round((double) mBar * 0.1), 0, 105); //GetValueKPa(ThisInt); + else return 0; +} + +double GetBoost(){ + int ThisInt = GetMBar(); + if (ThisInt <= 1013) return 0; + else return (double) (((double) ThisInt - 1013) * 0.0145037695765495); +} + +unsigned int GetTps(){ + return constrain((int) round(((double) Datalog_Bytes[5] - 25.0) / 2.04), 0, 100); + //return constrain((0.4716 * Datalog_Bytes[5]) - 11.3184, 0, 100); +} + +unsigned int GetRpm(){ + //return (int) (1875000/Long2Bytes(Datalog_Bytes[6], Datalog_Bytes[7])); //unused + + int rpm = (int) (1851562/Long2Bytes(Datalog_Bytes[6], Datalog_Bytes[7])); + return constrain(rpm, 0, 11000); +} + +void SetEngineRunning() { + if (GetRpm() < 400) EngineRunning = false; + else EngineRunning = true; +} + +unsigned int GetVss(){ + if (UseKMH == 1) return (int) Datalog_Bytes[16]; + return (int) round((float) Datalog_Bytes[16] / 1.6f); +} + +unsigned int GetVssKMH(){ + return (unsigned int) Datalog_Bytes[16]; +} + +double GetInjFV() { + return (double) Long2Bytes(Datalog_Bytes[17], Datalog_Bytes[18]) / 4.0; +} + +int GetIgn(){ + return constrain((0.25 * Datalog_Bytes[19]) - 6, -6, 60); +} + +float GetBattery(){ + return constrain((26.0 * Datalog_Bytes[25]) / 270.0, 0, 18); +} + +int GetIACVDuty(){ + return constrain((int) (Long2Bytes(Datalog_Bytes[49], Datalog_Bytes[50]) / 327.68) - 100, -100, 100); +} + +double GetMapVolt(){ + return constrain(GetVolt(Datalog_Bytes[4]), 0, 5); +} + +double GetTPSVolt(){ + return constrain(GetVolt(Datalog_Bytes[5]), 0, 5); +} + +//############################### + +double GetELDVolt(){ + return GetVolt(Datalog_Bytes[24]); +} + + +unsigned int GetGear(){ + long VSS = (long) GetVssKMH(); + long FAKERPM = Long2Bytes(Datalog_Bytes[6], Datalog_Bytes[7]); + if (VSS == 0 | GetRpm() == 0) return 0; + long num = ((VSS * 256) * FAKERPM) / 65535; + for (int i = 0; i < 4; i++) if (num < (long) Tranny[i]) return i + 1; + return 5; +} + +int GetIgnTable(){ + return (0.25 * Datalog_Bytes[20]) - 6; +} + +//############################### + +bool GetSensorsActived(int ThisB, int ThisI){ + return (bool) GetActivated(Datalog_Bytes[ThisB], ThisI, false); +} + +//############################### + +int GetBaro(){ + return (int) round((double) ((int) Datalog_Bytes[3] / 2 + 24) * 7.221 - 59.0); +} + +double GetECTFC(){ + return GetFC(Datalog_Bytes[26], 128); +} + +double GetO2Short(){ + return (double) GetFC(Long2Bytes(Datalog_Bytes[27], Datalog_Bytes[28]), 32768); +} + +double GetO2Long(){ + return (double) GetFC(Long2Bytes(Datalog_Bytes[29], Datalog_Bytes[30]), 32768); +} + +double GetIATFC(){ + return (double) GetFC(Long2Bytes(Datalog_Bytes[31], Datalog_Bytes[32]), 32768); +} + +double GetVEFC(){ + return GetFC(Datalog_Bytes[33], 128); +} + +float GetIATIC(){ + return GetIC(Datalog_Bytes[34]); +} + +float GetECTIC(){ + return GetIC(Datalog_Bytes[35]); +} + +float GetGEARIC(){ + return GetIC(Datalog_Bytes[36]); +} + +double GetEBCBaseDuty(){ + return GetEBC(Datalog_Bytes[40]); +} + +double GetEBCDuty(){ + return GetEBC(Datalog_Bytes[41]); +} + +float GetIC(byte ThisByte) { + if ((int) ThisByte == 128) + return 0.0f; + if ((int) ThisByte < 128) + return (float) (128 - (int) ThisByte) * -0.25f; + return (float) ((int) ThisByte - 128) * 0.25f; +} + +double GetFC(long ThisByte, long ThisLong) { + double num = (double) ThisByte / (double) ThisLong; + //if (CorrectionUnits == "multi") + return round((num) * 100) / 100; + //return round(num * 100.0 - 100.0); +} + +double GetEBC(byte ThisByte) { + double num = (double) ThisByte / 2.0; + if (num > 100.0) num = 100.0; + return round((num * 10)) / 10; +} diff --git a/BMDatalogger/FileList.txt b/BMDatalogger/FileList.txt new file mode 100644 index 0000000..6175ce8 --- /dev/null +++ b/BMDatalogger/FileList.txt @@ -0,0 +1,13 @@ +BMDatalogger.ino +ButtonsManager.ino +CustomCharacter.ino +DatalogProtocol.ino +PeakValues.ino +ScreenDisplay.ino +ScreenJ12.ino +ScreenStart.ino +ScreenTexts.ino +SpeedCounter.ino +UNUSEDDISPLAY.ino +Warnings.ino +Version.txt \ No newline at end of file diff --git a/BMDatalogger/OptionPage.ino b/BMDatalogger/OptionPage.ino new file mode 100644 index 0000000..66b3402 --- /dev/null +++ b/BMDatalogger/OptionPage.ino @@ -0,0 +1,598 @@ +unsigned long last_shown_option_time=0; +const int SpawnTimeoutOption = 1200; +int CurrentShowOption = 0; + +void DisplayOptionPage() { + if (millis() - last_shown_option_time > SpawnTimeoutOption) { + CurrentShowOption++; + if (CurrentShowOption > 3) CurrentShowOption = 0; + last_shown_option_time = millis(); + } + + ResetBufferIndex(); + GetOptionString(ScreenSettingSelected); + GetInfosString(39); + PrintText(20, 0, 0); + + //########################### + //Option Value + ResetBufferIndex(); + if (ScreenSettingSelected == 13) { + Add_String(String(Timeout)); + Add_String("ms"); + } + if (ScreenSettingSelected == 14) { + Add_String(String(Brightness)); + //int Percent = (Brightness * 100) / 255; + //Add_String(String(Percent)); + //Add_String("%"); + NightMode = false; + RefreshBackLight(); + } + if (ScreenSettingSelected == 15) { + Add_String(String((int) ProgressBarMode)); + XPos = 10; + YPos = 1; + DrawProgressBarPercent(50, 10); + } + if (ScreenSettingSelected == 16) { + Add_String(String((int) ProgressBarLeft)); + if (ProgressBarLeft == 0) Add_String(" (right)"); + if (ProgressBarLeft == 1) Add_String(" (left)"); + } + if (ScreenSettingSelected == 17) { + Add_String(String(Injectors_Size)); + Add_String("cc"); + } + if (ScreenSettingSelected == 18) { + Add_String(String((int) O2Input)); + if (O2Input == 0) Add_String(" (O2)"); + if (O2Input == 1) Add_String(" (EGR)"); + if (O2Input == 2) Add_String(" (ELD)"); + if (O2Input == 3) Add_String(" (B6)"); + } + if (ScreenSettingSelected == 19) { + Add_String(String((int) UseCelcius)); + Add_String(" ("); + GetTempCelcius(); + Add_String(")"); + } + if (ScreenSettingSelected == 20) { + Add_String(String((int) UseKMH)); + if (UseKMH == 0) Add_String(" (mph)"); + if (UseKMH == 1) Add_String(" (kmh)"); + } + if (ScreenSettingSelected == 21) { + Add_String(String((int) O2Type)); + if (O2Type == 0) Add_String(" (AFR)"); + if (O2Type == 1) Add_String(" (Lambda)"); + if (O2Type == 2) Add_String(" (Voltage)"); + } + if (ScreenSettingSelected == 22) { + Add_String(String((int) Warning_RPM)); + Add_String("rpm"); + } + if (ScreenSettingSelected == 23) { + Add_String(String((int) Warning_ECT)); + GetTempCelcius(); + } + if (ScreenSettingSelected == 24) { + Add_String(String((int) Warning_IAT)); + GetTempCelcius(); + } + if (ScreenSettingSelected == 25) { + Add_String(String((int) mBarMin)); + Add_String("mBar"); + } + if (ScreenSettingSelected == 26) { + Add_String(String((int) mBarMax)); + Add_String("mBar"); + } + if (ScreenSettingSelected == 27) { + Add_String(String((int) TempMin)); + GetTempCelcius(); + } + if (ScreenSettingSelected == 28) { + Add_String(String((int) TempMax)); + GetTempCelcius(); + } + if (ScreenSettingSelected == 29) { + if (CurrentShowOption == 0) { + Add_String("Volt:"); + Add_String(String((double) WBConversion[0]) + "/" + String((double) WBConversion[2])); + } + if (CurrentShowOption == 1) { + Add_String("Lambda:"); + Add_String(String((double) WBConversion[1]) + "/" + String((double) WBConversion[3])); + } + if (CurrentShowOption == 2) { + Add_String("AFR:"); + Add_String(String((double) (WBConversion[1] * 14.7)) + "/" + String((double) (WBConversion[3] * 14.7))); + } + if (CurrentShowOption == 3) { + Add_String("Sensor:"); + if (WBModel == 0) Add_String("OEM"); + if (WBModel == 1) Add_String("AEM"); + if (WBModel == 2) Add_String("PLX-M"); + if (WBModel == 3) Add_String("FJO"); + if (WBModel == 4) Add_String("LC1/LM1"); + if (WBModel == 5) Add_String("Techedge"); + if (WBModel == 6) Add_String("Zeitronix"); + if (WBModel == 7) Add_String("Motec PLM"); + if (WBModel == 8) Add_String("JAW"); + //if (WBModel == 9) Add_String("Custom"); + } + } + if (ScreenSettingSelected == 30) { + if (CurrentShowOption == 0) { + long Value = (((long) MapByte[1] * 256) + (long) MapByte[0]) - 32768; + Add_String("mBar Min:" + String(Value)); + } + if (CurrentShowOption == 1) { + long Value = (((long) MapByte[3] * 256) + (long) MapByte[2]) - 32768; + Add_String("mBar Max:" + String(Value)); + } + if (CurrentShowOption == 2 || CurrentShowOption == 3) { + Add_String("Sensor:"); + if (MapModel == 0) Add_String("OEM"); + if (MapModel == 1) Add_String("GM 2"); + if (MapModel == 2) Add_String("GM 3"); + if (MapModel == 3) Add_String("Motorola 2.5"); + if (MapModel == 4) Add_String("AEM 3.5"); + if (MapModel == 5) Add_String("Xenocron 3"); + if (MapModel == 6) Add_String("Xenocron 4"); + if (MapModel == 7) Add_String("AEM 5"); + if (MapModel == 8) Add_String("Omni/Hondata4"); + } + } + if (ScreenSettingSelected == 31) { + if (CurrentShowOption == 0) { + Add_String("Gear1-2:"); + Add_String(String((int) Tranny[0]) + "/" + String((int) Tranny[1])); + } + if (CurrentShowOption == 1) { + Add_String("Gear2-3:"); + Add_String(String((int) Tranny[1]) + "/" + String((int) Tranny[2])); + } + if (CurrentShowOption == 2) { + Add_String("Gear3-4:"); + Add_String(String((int) Tranny[2]) + "/" + String((int) Tranny[3])); + } + if (CurrentShowOption == 3) { + Add_String("Box:"); + if (TrannyModel == 0) Add_String("Y21/Y80/S80 EDM"); + if (TrannyModel == 1) Add_String("ITR S80 JDM96-97"); + if (TrannyModel == 2) Add_String("ITR S80 JDM98-01"); + if (TrannyModel == 3) Add_String("ITR S80 USDM97+"); + if (TrannyModel == 4) Add_String("Z6/Y8"); + if (TrannyModel == 5) Add_String("GSR USDM 94+"); + if (TrannyModel == 6) Add_String("GSR JDM 93+ SIR"); + if (TrannyModel == 7) Add_String("LS/RS/GS/SE 94+"); + if (TrannyModel == 8) Add_String("H22 USDM 92-96"); + if (TrannyModel == 9) Add_String("H22 JDM 92-96"); + if (TrannyModel == 10) Add_String("H23 USDM 92-96"); + if (TrannyModel == 11) Add_String("H23 JDM 92-96"); + if (TrannyModel == 12) Add_String("D16Y7"); + } + } + + if (ScreenSettingSelected == 15) { + PrintText(10, 0, 1); + } + else { + PrintText(20, 0, 1); + } + //########################### + + ResetBufferIndex(); + GetInfosString(41); + PrintText(9, 1, 2); + + ResetBufferIndex(); + GetInfosString(40); + PrintText(9, 11, 2); + + ResetBufferIndex(); + GetInfosString(34); + PrintText(19, 1, 3); + + //########################### + //reset empty indicator + ResetBufferIndex(); + if (ScreenOptionSelected != 0) PrintText(1, 0, 2); + if (ScreenOptionSelected != 1) PrintText(1, 10, 2); + if (ScreenOptionSelected != 2) PrintText(1, 0, 3); + + //Set Indicator + StringBuffer[0] = '>'; + if (ScreenOptionSelected == 0) PrintText(1, 0, 2); + if (ScreenOptionSelected == 1) PrintText(1, 10, 2); + if (ScreenOptionSelected == 2) PrintText(1, 0, 3); +} + +//#################################################################################################### +//#################################################################################################### +//#################################################################################################### + +void GetOptionString(int ThisOptionIndex) { + //Timeout, backlight, Bar Type, Bar Side + if (ThisOptionIndex == 13) { + GetInfosString(27); + } + else if (ThisOptionIndex == 14) { + GetInfosString(28); + } + else if (ThisOptionIndex == 15) { + GetInfosString(29); + AddThisChar(' '); + GetInfosString(30); + } + else if (ThisOptionIndex == 16) { + GetInfosString(29); + AddThisChar(' '); + GetInfosString(31); + } + //Inj_Size, O2_Input, Temp, Speed + else if (ThisOptionIndex == 17) { + GetInfosString(32); + AddThisChar(' '); + GetInfosString(33); + } + else if (ThisOptionIndex == 18) { + GetSensorString(4); + AddThisChar(' '); + GetInfosString(35); + } + else if (ThisOptionIndex == 19) { + GetInfosString(37); + } + else if (ThisOptionIndex == 20) { + GetInfosString(38); + } + //O2 Type, Warning_Max_RPM, Warning_Max_ECT, Warning_Max_IAT + else if (ThisOptionIndex == 21) { + GetSensorString(4); + AddThisChar(' '); + GetInfosString(30); + } + else if (ThisOptionIndex == 22) { + GetInfosString(16); + AddThisChar(' '); + GetSensorString(0); + } + else if (ThisOptionIndex == 23) { + GetInfosString(16); + AddThisChar(' '); + GetSensorString(1); + } + else if (ThisOptionIndex == 24) { + GetInfosString(16); + AddThisChar(' '); + GetSensorString(2); + } + //MAP_Min, MAP_Max, Temp_Min, Temp_Max + else if (ThisOptionIndex == 25) { + GetInfosString(15); + AddThisChar(' '); + GetSensorString(9); + } + else if (ThisOptionIndex == 26) { + GetInfosString(16); + AddThisChar(' '); + GetSensorString(9); + } + else if (ThisOptionIndex == 27) { + GetInfosString(15); + AddThisChar(' '); + GetInfosString(37); + } + else if (ThisOptionIndex == 28) { + GetInfosString(16); + AddThisChar(' '); + GetInfosString(37); + } + //WBConversion, MapByte, Tranny + else if (ThisOptionIndex == 29) { + GetInfosString(42); + AddThisChar(' '); + GetInfosString(43); + } + else if (ThisOptionIndex == 30) { + GetSensorString(9); + AddThisChar(' '); + GetInfosString(43); + } + else if (ThisOptionIndex == 31) { + GetInfosString(44); + GetInfosString(43); + } +} + +//#################################################################################################### +//#################################################################################################### +//#################################################################################################### + +void DecreaseOption() { + CurrentShowOption = 3; + last_shown_option_time = millis(); + + if (ScreenSettingSelected == 13) { + Timeout -= 25; + if (Timeout < 50) Timeout = 600; + } + if (ScreenSettingSelected == 14) { + if (Brightness == 255) Brightness = 250; + Brightness -= 25; + if (Brightness < 0) Brightness = 255; + RefreshBackLight(); + } + if (ScreenSettingSelected == 15) { + ProgressBarMode -= 1; + if (ProgressBarMode < 0 || ProgressBarMode > 6) ProgressBarMode = 6; + } + if (ScreenSettingSelected == 16) { + ProgressBarLeft -= 1; + if (ProgressBarLeft < 0 || ProgressBarLeft > 1) ProgressBarLeft = 1; + } + if (ScreenSettingSelected == 17) { + Injectors_Size -= 10; + if (Injectors_Size < 180) Injectors_Size = 2000; + } + if (ScreenSettingSelected == 18) { + O2Input -= 1; + if (O2Input < 0 || O2Input > 3) O2Input = 3; + } + if (ScreenSettingSelected == 19) { + UseCelcius -= 1; + if (UseCelcius < 0 || UseCelcius > 1) UseCelcius = 1; + } + if (ScreenSettingSelected == 20) { + UseKMH -= 1; + if (UseKMH < 0 || UseKMH > 1) UseKMH = 1; + } + if (ScreenSettingSelected == 21) { + O2Type -= 1; + if (O2Type < 0 || O2Type > 2) O2Type = 2; + } + if (ScreenSettingSelected == 22) { + Warning_RPM -= 50; + if (Warning_RPM < 5000) Warning_RPM = 11000; + } + if (ScreenSettingSelected == 23) { + if (UseCelcius == 0) { + Warning_ECT -= 5; + if (Warning_ECT < -40) Warning_ECT = 290; + } + else { + Warning_ECT -= 1; + if (Warning_ECT < -40) Warning_ECT = 141; + } + } + if (ScreenSettingSelected == 24) { + if (UseCelcius == 0) { + Warning_IAT -= 5; + if (Warning_IAT < -40) Warning_IAT = 290; + } + else { + Warning_IAT -= 1; + if (Warning_IAT < -40) Warning_IAT = 141; + } + } + if (ScreenSettingSelected == 25) { + mBarMin -= 10; + if (mBarMin < -70) mBarMin = 250; + } + if (ScreenSettingSelected == 26) { + if (mBarMax == 1790) mBarMax = 1800; + mBarMax -= 100; + if (mBarMax < 1000) mBarMax = 5000; + if (mBarMax == 1800) mBarMax = 1790; + } + if (ScreenSettingSelected == 27) { + if (UseCelcius == 0) { + TempMin -= 5; + if (TempMin < -40) TempMin = 290; + } + else { + TempMin -= 1; + if (TempMin < -40) TempMin = 141; + } + } + if (ScreenSettingSelected == 28) { + if (UseCelcius == 0) { + TempMax -= 5; + if (TempMax < -40) TempMax = 290; + } + else { + TempMax -= 1; + if (TempMax < -40) TempMax = 141; + } + } + if (ScreenSettingSelected == 29) { + WBModel -= 1; + if (WBModel < 0) WBModel = 8; + SetWB(); + } + if (ScreenSettingSelected == 30) { + MapModel -= 1; + if (MapModel < 0) MapModel = 8; + SetMap(); + } + if (ScreenSettingSelected == 31) { + TrannyModel -= 1; + if (TrannyModel < 0) TrannyModel = 12; + SetTranny(); + } + + delay(40); + //SetWait(); + last_shown_option_time = millis(); +} + +//#################################################################################################### +//#################################################################################################### +//#################################################################################################### + +void SetWB() { + if (WBModel == 0) { WBConversion[0] = 0; WBConversion[1] = 1.3; WBConversion[2] = 1; WBConversion[3] = 0.71; } + if (WBModel == 1) { WBConversion[0] = 0.5; WBConversion[1] = 0.75; WBConversion[2] = 3.38; WBConversion[3] = 1.14; } + if (WBModel == 2) { WBConversion[0] = 0; WBConversion[1] = 0.68; WBConversion[2] = 5; WBConversion[3] = 1.36; } + if (WBModel == 3) { WBConversion[0] = 0.85; WBConversion[1] = 0.68; WBConversion[2] = 5; WBConversion[3] = 1.36; } + if (WBModel == 4) { WBConversion[0] = 0; WBConversion[1] = 0.51; WBConversion[2] = 5; WBConversion[3] = 1.52; } + if (WBModel == 5) { WBConversion[0] = 0; WBConversion[1] = 0.61; WBConversion[2] = 5; WBConversion[3] = 1.29; } + if (WBModel == 6) { WBConversion[0] = 0.15; WBConversion[1] = 0.65; WBConversion[2] = 3.47; WBConversion[3] = 1.51; } + if (WBModel == 7) { WBConversion[0] = 1; WBConversion[1] = 0.73; WBConversion[2] = 4.5; WBConversion[3] = 1.5; } + if (WBModel == 8) { WBConversion[0] = 1.02; WBConversion[1] = 0.69; WBConversion[2] = 2.21; WBConversion[3] = 1.5; } +} + +void SetTranny() { + if (TrannyModel == 0) { Tranny[0] = 0x46; Tranny[1] = 0x67; Tranny[2] = 0x8E; Tranny[3] = 0xB8; } + if (TrannyModel == 1) { Tranny[0] = 0x46; Tranny[1] = 0x67; Tranny[2] = 0x8E; Tranny[3] = 0xB8; } + if (TrannyModel == 2) { Tranny[0] = 0x42; Tranny[1] = 0x5D; Tranny[2] = 0x87; Tranny[3] = 0xB6; } + if (TrannyModel == 3) { Tranny[0] = 0x46; Tranny[1] = 0x64; Tranny[2] = 0x91; Tranny[3] = 0xB8; } + if (TrannyModel == 4) { Tranny[0] = 0x48; Tranny[1] = 0x71; Tranny[2] = 0xAA; Tranny[3] = 0xE3; } + if (TrannyModel == 5) { Tranny[0] = 0x46; Tranny[1] = 0x6E; Tranny[2] = 0x9A; Tranny[3] = 0xC4; } + if (TrannyModel == 6) { Tranny[0] = 0x46; Tranny[1] = 0x6E; Tranny[2] = 0x9A; Tranny[3] = 0xC4; } + if (TrannyModel == 7) { Tranny[0] = 0x48; Tranny[1] = 0x71; Tranny[2] = 0xB2; Tranny[3] = 0xD6; } + if (TrannyModel == 8) { Tranny[0] = 0x47; Tranny[1] = 0x6E; Tranny[2] = 0x9E; Tranny[3] = 0xC3; } + if (TrannyModel == 9) { Tranny[0] = 0x47; Tranny[1] = 0x6E; Tranny[2] = 0x9E; Tranny[3] = 0xC9; } + if (TrannyModel == 10) { Tranny[0] = 0x47; Tranny[1] = 0x6E; Tranny[2] = 0x9E; Tranny[3] = 0xC9; } + if (TrannyModel == 11) { Tranny[0] = 0x4A; Tranny[1] = 0x7B; Tranny[2] = 0xAF; Tranny[3] = 0xE0; } + if (TrannyModel == 12) { Tranny[0] = 0x4B; Tranny[1] = 0x7D; Tranny[2] = 0xBC; Tranny[3] = 0xED; } +} + +void SetMap() { + if (MapModel == 0) { MapByte[0] = 0xba; MapByte[1] = 0x7f; MapByte[2] = 0xfe; MapByte[3] = 0x86; } + if (MapModel == 1) { MapByte[0] = 0x08; MapByte[1] = 0x80; MapByte[2] = 0xf9; MapByte[3] = 0x87; } + if (MapModel == 2) { MapByte[0] = 0x0b; MapByte[1] = 0x80; MapByte[2] = 0x53; MapByte[3] = 0x8c; } + if (MapModel == 3) { MapByte[0] = 0x46; MapByte[1] = 0x80; MapByte[2] = 0x1e; MapByte[3] = 0x8a; } + if (MapModel == 4) { MapByte[0] = 0x51; MapByte[1] = 0x7e; MapByte[2] = 0x04; MapByte[3] = 0x8f; } + if (MapModel == 5) { MapByte[0] = 0x0b; MapByte[1] = 0x80; MapByte[2] = 0xe0; MapByte[3] = 0x8b; } + if (MapModel == 6) { MapByte[0] = 0x23; MapByte[1] = 0x80; MapByte[2] = 0x54; MapByte[3] = 0x90; } + if (MapModel == 7) { MapByte[0] = 0x8f; MapByte[1] = 0x7d; MapByte[2] = 0xf9; MapByte[3] = 0x95; } + if (MapModel == 8) { MapByte[0] = 0x23; MapByte[1] = 0x80; MapByte[2] = 0x54; MapByte[3] = 0x90; } + + mBarMin = (int) ((((long) MapByte[1] * 256) + (long) MapByte[0]) - 32768); + mBarMax = (int) ((((long) MapByte[3] * 256) + (long) MapByte[2]) - 32768); +} + +//#################################################################################################### +//#################################################################################################### +//#################################################################################################### +void IncreaseOption() { + CurrentShowOption = 3; + last_shown_option_time = millis(); + + if (ScreenSettingSelected == 13) { + Timeout += 25; + if (Timeout > 600) Timeout = 50; + } + if (ScreenSettingSelected == 14) { + if (Brightness == 255) Brightness = 250; + Brightness += 25; + if (Brightness == 250) Brightness = 255; + if (Brightness > 255) Brightness = 0; + RefreshBackLight(); + } + if (ScreenSettingSelected == 15) { + ProgressBarMode += 1; + if (ProgressBarMode > 6) ProgressBarMode = 0; + } + if (ScreenSettingSelected == 16) { + ProgressBarLeft += 1; + if (ProgressBarLeft > 1) ProgressBarLeft = 0; + } + if (ScreenSettingSelected == 17) { + Injectors_Size += 10; + if (Injectors_Size > 2000) Injectors_Size = 180; + } + if (ScreenSettingSelected == 18) { + O2Input += 1; + if (O2Input > 3) O2Input = 0; + } + if (ScreenSettingSelected == 19) { + UseCelcius += 1; + if (UseCelcius > 1) UseCelcius = 0; + } + if (ScreenSettingSelected == 20) { + UseKMH += 1; + if (UseKMH > 1) UseKMH = 0; + } + if (ScreenSettingSelected == 21) { + O2Type += 1; + if (O2Type > 2) O2Type = 0; + } + if (ScreenSettingSelected == 22) { + Warning_RPM += 50; + if (Warning_RPM > 11000) Warning_RPM = 5000; + } + if (ScreenSettingSelected == 23) { + if (UseCelcius == 0) { + Warning_ECT += 5; + if (Warning_ECT > 190) Warning_ECT = -40; + } + else { + Warning_ECT += 1; + if (Warning_ECT > 141) Warning_ECT = -40; + } + } + if (ScreenSettingSelected == 24) { + if (UseCelcius == 0) { + Warning_IAT += 5; + if (Warning_IAT > 190) Warning_IAT = -40; + } + else { + Warning_IAT += 1; + if (Warning_IAT > 141) Warning_IAT = -40; + } + } + if (ScreenSettingSelected == 25) { + mBarMin += 10; + if (mBarMin > 250) mBarMin = -70; + } + if (ScreenSettingSelected == 26) { + if (mBarMax == 1790) mBarMax = 1800; + mBarMax += 100; + if (mBarMax > 5000) mBarMax = 1000; + if (mBarMax == 1800) mBarMax = 1790; + } + if (ScreenSettingSelected == 27) { + if (UseCelcius == 0) { + TempMin += 5; + if (TempMin > 290) TempMin = -40; + } + else { + TempMin += 1; + if (TempMin > 141) TempMin = -40; + } + } + if (ScreenSettingSelected == 28) { + if (UseCelcius == 0) { + TempMax += 5; + if (TempMax > 290) TempMax = -40; + } + else { + TempMax += 1; + if (TempMax > 141) TempMax = -40; + } + } + if (ScreenSettingSelected == 29) { + WBModel += 1; + if (WBModel > 8) WBModel = 0; + SetWB(); + } + if (ScreenSettingSelected == 30) { + MapModel += 1; + if (MapModel > 8) MapModel = 0; + SetMap(); + } + if (ScreenSettingSelected == 31) { + TrannyModel += 1; + if (TrannyModel > 12) TrannyModel = 0; + SetTranny(); + } + + delay(40); + //SetWait(); + last_shown_option_time = millis(); +} diff --git a/BMDatalogger/PeakValues.ino b/BMDatalogger/PeakValues.ino new file mode 100644 index 0000000..876ba3c --- /dev/null +++ b/BMDatalogger/PeakValues.ino @@ -0,0 +1,86 @@ +int PeakValuesMin[MaxDataValue]; +int PeakValuesMax[MaxDataValue]; +int PeakMinValue = 0; +int PeakMaxValue = 1; +byte PeakInitialized = 0; +bool PeakSet = false; + +void InitPeak() { + for (int i=0; i < MaxDataValue; i++) { + ThisScreenIndex = i; + int Value = (int) GetInt(); + PeakValuesMin[i] = Value; + PeakValuesMax[i] = Value; + } + PeakInitialized = 1; +} + +void SetPeakValue(const int minValue, const int maxValue) { + if (PeakInitialized == 0) InitPeak(); + PeakMinValue = minValue; + PeakMaxValue = maxValue; + + PeakSet = true; +} + +void ApplyPeak() { + for (int i=0; i < MaxDataValue; i++) { + ThisScreenIndex = i; + SetPeak(); + int ThisValue = (int) GetInt(); + if (ThisValue < PeakValuesMin[ThisScreenIndex]) PeakValuesMin[ThisScreenIndex] = ThisValue; + if (ThisValue > PeakValuesMax[ThisScreenIndex]) PeakValuesMax[ThisScreenIndex] = ThisValue; + } +} + +void SetPeak() { + PeakSet = false; + if (ThisScreenIndex == 0) SetPeakValue(0,11000); + if (ThisScreenIndex == 1) SetPeakValue(TempMin, TempMax); + if (ThisScreenIndex == 1) SetPeakValue(TempMin, TempMax); + if (ThisScreenIndex == 3) SetPeakValue(0,100); + if (ThisScreenIndex == 4) SetPeakValue(10,20); + if (ThisScreenIndex == 5) SetPeakValue(-6,60); + if (ThisScreenIndex == 6) SetPeakValue(0,20); + if (ThisScreenIndex == 7) SetPeakValue(0,50); + if (ThisScreenIndex == 8) SetPeakValue(-100,100); + if (ThisScreenIndex == 9) SetPeakValue(mBarMin, mBarMax); + if (ThisScreenIndex == 10) SetPeakValue(0,40); + if (ThisScreenIndex == 11) SetPeakValue(0,300); + if (ThisScreenIndex == 13) SetPeakValue(0,18); + if (ThisScreenIndex == 16) SetPeakValue(0,3000); + if (ThisScreenIndex == 18) SetPeakValue(2,18); + if (ThisScreenIndex == 19) SetPeakValue(2,18); + if (ThisScreenIndex == 22) SetPeakValue(0,18); + if (ThisScreenIndex == 26) SetPeakValue(0,5); + if (ThisScreenIndex == 59) SetPeakValue(-6,60); + if (ThisScreenIndex == 68) SetPeakValue(114, 3800); + if (ThisScreenIndex == 69) SetPeakValue(0, 100); + if (ThisScreenIndex == 70) SetPeakValue(0, 255); + if (ThisScreenIndex == 71) SetPeakValue(0, 255); + if (ThisScreenIndex == 72) SetPeakValue(0, 255); + if (ThisScreenIndex == 73) SetPeakValue(0, 255); + if (ThisScreenIndex == 74) SetPeakValue(0, 255); + if (ThisScreenIndex == 75) SetPeakValue(0, 60); + if (ThisScreenIndex == 76) SetPeakValue(0, 60); + if (ThisScreenIndex == 77) SetPeakValue(0, 60); + if (ThisScreenIndex == 78) SetPeakValue(0, 100); + if (ThisScreenIndex == 79) SetPeakValue(0, 100); + + if (!PeakSet) SetPeakValue(0,1); +} + +double GetPeakPercent(int value) { + SetPeak(); + if (value < PeakMinValue) return 0.0; + if (value > PeakMaxValue) return 100.0; + return map((double) value, (double) PeakMinValue, (double) PeakMaxValue, (double) 0, (double) 100); +} + +int GetPeakMin() { + return PeakValuesMin[ThisScreenIndex]; +} + +int GetPeakMax() { + return PeakValuesMax[ThisScreenIndex]; +} diff --git a/BMDatalogger/ScreenDisplay.ino b/BMDatalogger/ScreenDisplay.ino new file mode 100644 index 0000000..5907e76 --- /dev/null +++ b/BMDatalogger/ScreenDisplay.ino @@ -0,0 +1,268 @@ +void Display() { + if (ScreenCurrentMenu == 2) { + //Mil Menu + ResetBufferIndex(); + GetInfosString(9); + writeBigString(5, 0); + GetMil(); + } + else if (ScreenCurrentMenu >= 4 && ScreenCurrentMenu < 12) { + DisplaySettingPage(); + } + else if (ScreenCurrentMenu >= 13 && ScreenCurrentMenu <= 32) { + DisplaySettingPageOption(); + } + else if (ScreenCurrentMenu == 33) { + DisplayOptionPage(); + } + else { + for (int i=0; i<8; i++) { + ThisScreenIndex = 0; + if (ScreenCurrentPage == 0) ScreenCurrentPage = 1; + if (ScreenCurrentPage == 1) ThisScreenIndex = ScreenPage1[i]; + if (ScreenCurrentPage == 2) ThisScreenIndex = ScreenPage2[i]; + if (ScreenCurrentPage == 3) ThisScreenIndex = ScreenPage3[i]; + if (ScreenCurrentPage == 4) ThisScreenIndex = ScreenPage4[i]; + if (ScreenCurrentPage == 5) ThisScreenIndex = ScreenPage5[i]; + if (ScreenCurrentPage == 6) ThisScreenIndex = ScreenPage6[i]; + if (ScreenCurrentPage == 7) ThisScreenIndex = ScreenPage7[i]; + if (ScreenCurrentPage == 8) ThisScreenIndex = ScreenPage8[i]; + + int ThisScreenMode = 0; //normal + if (ThisScreenIndex >= 100) ThisScreenMode = 1; //progressbar + if (ThisScreenIndex >= 200) ThisScreenMode = 2; //big + if (ThisScreenIndex >= 300) ThisScreenMode = 3; //big2 + + //peak values + if (ScreenCurrentMenu == 1) { + ThisScreenMode = 4; + ThisScreenIndex = ScreenCurrentPeak; + } + + //setting page menu '>' indicator + if (ScreenCurrentMenu == 12) { + SetCursor(); + } + //#### + + + while (ThisScreenIndex >= 100) { + ThisScreenIndex -= 100; + } + /*if (ThisScreenIndex >= 100) ThisScreenIndex -= 100; + else if (ThisScreenIndex >= 200) ThisScreenIndex -= 200; + else if (ThisScreenIndex >= 300) ThisScreenIndex -= 300;*/ + + ResetBufferIndex(); + + //Only Run 'reconized' data values + if (ThisScreenIndex <= MaxDataValue) { + GetSensorString(ThisScreenIndex); + GetInfosString(39); + + if (ThisScreenMode < 2) { + SetValueToBuffer(); + Add_Sensor_Desc(); + } + + SetPos(i); + if (ThisScreenMode >= 1) XPos = 0; + if (ThisScreenMode >= 3) YPos = 0; + + //normal + if (ThisScreenMode == 0) { + PrintText(10, XPos, YPos); + } + + //progressbar + if (ThisScreenMode == 1) { + if (ProgressBarLeft == 0) XPos = 10; + PrintText(10, XPos, YPos); + if (ProgressBarLeft == 0) XPos = 0; + if (ProgressBarLeft == 1) XPos = 10; + DrawProgressBar((int) GetInt(), 10); + i++; + } + + //big font + if (ThisScreenMode == 2) { + PrintTextLenght(XPos, YPos); + PrintTextLenghtEmpty(XPos, YPos + 1); + int StartAt = GetBufferLenght(); + ResetBufferIndex(); + SetValueToBuffer(); + writeBigString(StartAt, YPos); + i += 3; + } + + //big font #2 + if (ThisScreenMode == 3) { + writeBigString(XPos, YPos); + ResetBufferIndex(); + SetValueToBuffer(); + writeBigString(XPos, YPos+2); + i += 8; + } + + //peak + if (ThisScreenMode == 4) { + writeBigString(XPos, YPos); + ResetBufferIndex(); + GetInfosString(15); + GetInfosString(39); + Add_String(String(GetPeakMin())); + Add_Sensor_Desc(); + PrintText(10, XPos, YPos + 2); + + ResetBufferIndex(); + GetInfosString(17); + GetInfosString(39); + SetValueToBuffer(); + Add_Sensor_Desc(); + PrintText(10, XPos + 10, YPos + 2); + + ResetBufferIndex(); + GetInfosString(16); + GetInfosString(39); + Add_String(String(GetPeakMax())); + Add_Sensor_Desc(); + PrintText(20, XPos, YPos + 3); + + i += 8; + } + } + } + } +} + +void SetPos(const int ThisLine) { + XPos = 0; + YPos = ThisLine; + + if (ThisLine == 1) { + XPos = 10; + YPos = 0; + } + if (ThisLine == 2) YPos = 1; + if (ThisLine == 3) { + XPos = 10; + YPos = 1; + } + if (ThisLine == 4) YPos = 2; + if (ThisLine == 5) { + XPos = 10; + YPos = 2; + } + if (ThisLine == 6) YPos = 3; + if (ThisLine == 7) { + XPos = 10; + YPos = 3; + } +} + +double GetInt() { + if (ThisScreenIndex == 0) return (double) GetRpm(); + if (ThisScreenIndex == 1) return (double) GetEct(); + if (ThisScreenIndex == 2) return (double) GetIat(); + if (ThisScreenIndex == 3) return (double) GetTps(); + if (ThisScreenIndex == 4) return (double) GetO2(); + if (ThisScreenIndex == 5) return (double) GetIgn(); + if (ThisScreenIndex == 6) return (double) GetInjDurr(); + if (ThisScreenIndex == 7) return (double) GetInstantConsumption(); + if (ThisScreenIndex == 8) return (double) GetIACVDuty(); + if (ThisScreenIndex == 9) return (double) GetMap(); + if (ThisScreenIndex == 10) return (double) GetBoost(); + if (ThisScreenIndex == 11) return (double) GetVss(); + if (ThisScreenIndex == 12) return (double) GetSensorsActived(39, 6); + if (ThisScreenIndex == 13) return (double) GetBattery(); + if (ThisScreenIndex == 14) return (double) GetSensorsActived(8, 2); + if (ThisScreenIndex == 15) return (double) GetSensorsActived(8, 4); + if (ThisScreenIndex == 16) return (double) GetInjFV(); + if (ThisScreenIndex == 17) return (double) GetSensorsActived(39, 5); + if (ThisScreenIndex == 18) return (double) GetSpeedTime(); + if (ThisScreenIndex == 19) return (double) GetBestSpeedTime(); + if (ThisScreenIndex == 20) return (double) GetSensorsActived(23, 7); + if (ThisScreenIndex == 21) return (double) GetSensorsActived(21, 3); + if (ThisScreenIndex == 22) return (double) GetELDVolt(); + if (ThisScreenIndex == 23) return (double) GetSensorsActived(23, 6); + if (ThisScreenIndex == 24) return (double) GetSensorsActived(22, 7); + if (ThisScreenIndex == 25) return (double) GetSensorsActived(22, 5); + if (ThisScreenIndex == 26) return (double) GetGear(); + + if (ThisScreenIndex == 27) return (double) GetSensorsActived(39, 7); + if (ThisScreenIndex == 28) return (double) GetSensorsActived(39, 0); + if (ThisScreenIndex == 29) return (double) GetSensorsActived(39, 1); + if (ThisScreenIndex == 30) return (double) GetSensorsActived(39, 2); + if (ThisScreenIndex == 31) return (double) GetSensorsActived(39, 4); + if (ThisScreenIndex == 32) return (double) GetSensorsActived(39, 3); + if (ThisScreenIndex == 33) return (double) GetSensorsActived(43, 7); + if (ThisScreenIndex == 34) return (double) GetSensorsActived(21, 0); + if (ThisScreenIndex == 35) return (double) GetSensorsActived(21, 1); + if (ThisScreenIndex == 36) return (double) GetSensorsActived(21, 2); + if (ThisScreenIndex == 37) return (double) GetSensorsActived(21, 4); + if (ThisScreenIndex == 38) return (double) GetSensorsActived(21, 5); + if (ThisScreenIndex == 39) return (double) GetSensorsActived(8, 5); + if (ThisScreenIndex == 40) return (double) GetSensorsActived(21, 7); + if (ThisScreenIndex == 41) return (double) GetSensorsActived(22, 0); + if (ThisScreenIndex == 42) return (double) GetSensorsActived(22, 2); + if (ThisScreenIndex == 43) return (double) GetSensorsActived(22, 6); + if (ThisScreenIndex == 44) return (double) GetSensorsActived(43, 0); + if (ThisScreenIndex == 45) return (double) GetSensorsActived(43, 1); + if (ThisScreenIndex == 46) return (double) GetSensorsActived(43, 2); + if (ThisScreenIndex == 47) return (double) GetSensorsActived(43, 3); + if (ThisScreenIndex == 48) return (double) GetSensorsActived(43, 4); + if (ThisScreenIndex == 49) return (double) GetSensorsActived(43, 5); + + if (ThisScreenIndex == 50) return (double) GetSensorsActived(8, 0); + if (ThisScreenIndex == 51) return (double) GetSensorsActived(8, 1); + if (ThisScreenIndex == 52) return (double) GetSensorsActived(8, 3); + if (ThisScreenIndex == 53) return (double) GetSensorsActived(8, 6); + if (ThisScreenIndex == 54) return (double) GetSensorsActived(8, 7); + if (ThisScreenIndex == 55) return (double) GetSensorsActived(21, 6); + if (ThisScreenIndex == 56) return (double) GetSensorsActived(22, 4); + if (ThisScreenIndex == 57) return (double) GetSensorsActived(23, 5); + if (ThisScreenIndex == 58) return (double) GetSensorsActived(43, 6); + if (ThisScreenIndex == 59) return (double) GetIgnTable(); + + if (ThisScreenIndex == 60) return (double) GetSensorsActived(38, 0); + if (ThisScreenIndex == 61) return (double) GetSensorsActived(38, 1); + if (ThisScreenIndex == 62) return (double) GetSensorsActived(38, 2); + if (ThisScreenIndex == 63) return (double) GetSensorsActived(38, 3); + if (ThisScreenIndex == 64) return (double) GetSensorsActived(38, 4); + if (ThisScreenIndex == 65) return (double) GetSensorsActived(38, 5); + if (ThisScreenIndex == 66) return (double) GetSensorsActived(38, 6); + if (ThisScreenIndex == 67) return (double) GetSensorsActived(38, 7); + if (ThisScreenIndex == 68) return (double) GetBaro(); + if (ThisScreenIndex == 69) return (double) GetDuty(); + if (ThisScreenIndex == 70) return (double) GetECTFC(); + if (ThisScreenIndex == 71) return (double) GetO2Short(); + if (ThisScreenIndex == 72) return (double) GetO2Long(); + if (ThisScreenIndex == 73) return (double) GetIATFC(); + if (ThisScreenIndex == 74) return (double) GetVEFC(); + if (ThisScreenIndex == 75) return (double) GetIATIC(); + if (ThisScreenIndex == 76) return (double) GetECTIC(); + if (ThisScreenIndex == 77) return (double) GetGEARIC(); + if (ThisScreenIndex == 78) return (double) GetEBCBaseDuty(); + if (ThisScreenIndex == 79) return (double) GetEBCDuty(); +} + +void SetValueToBuffer() { + if (ThisScreenIndex == 4 || ThisScreenIndex == 5 || ThisScreenIndex == 6 || ThisScreenIndex == 7 + || ThisScreenIndex == 10 || ThisScreenIndex == 13 || ThisScreenIndex == 16 || ThisScreenIndex == 18 + || ThisScreenIndex == 19 || ThisScreenIndex == 22 || ThisScreenIndex == 59 || ThisScreenIndex == 69 + || ThisScreenIndex == 70 || ThisScreenIndex == 71 || ThisScreenIndex == 72 || ThisScreenIndex == 73 + || ThisScreenIndex == 74 || ThisScreenIndex == 75 || ThisScreenIndex == 76 || ThisScreenIndex == 77 + || ThisScreenIndex == 78 || ThisScreenIndex == 79) + { + Add_String(String(GetInt())); + } + else Add_String(String((int) GetInt())); + + //remake double into 1decimal + if (ThisScreenIndex == 4) RemoveLastChar(); + if (ThisScreenIndex == 7) RemoveLastChar(); + if (ThisScreenIndex == 10) RemoveLastChar(); + if (ThisScreenIndex == 13) RemoveLastChar(); + if (ThisScreenIndex == 18) RemoveLastChar(); + if (ThisScreenIndex == 19) RemoveLastChar(); +} diff --git a/BMDatalogger/ScreenJ12.ino b/BMDatalogger/ScreenJ12.ino new file mode 100644 index 0000000..1be99b9 --- /dev/null +++ b/BMDatalogger/ScreenJ12.ino @@ -0,0 +1,15 @@ +/*void ScreenJ12() { + GetJ12Cut(); + + if (WasAvailable && !J12Cut) { + ShowJ12 = true; + ResetBufferIndex(); + GetInfosString(23); + writeBigString(2, 0); + + ResetBufferIndex(); + GetInfosString(13); + writeBigString(0, 2); + } +}*/ + diff --git a/BMDatalogger/ScreenMain.ino b/BMDatalogger/ScreenMain.ino new file mode 100644 index 0000000..30bfbf4 --- /dev/null +++ b/BMDatalogger/ScreenMain.ino @@ -0,0 +1,50 @@ +void ScreenMain(){ + ResetBufferIndex(); + GetInfosString(6); + writeBigString(3, 0); + + if (ScreenCurrentMenu >= 0 && ScreenCurrentMenu < 4) { + ResetBufferIndex(); + GetInfosString(7); + PrintText(9, 1, 2); + + ResetBufferIndex(); + GetInfosString(8); + PrintText(9, 11, 2); + + ResetBufferIndex(); + GetInfosString(25); + PrintText(9, 1, 3); + + ResetBufferIndex(); + GetInfosString(22); + PrintText(9, 11, 3); + } + else if (ScreenCurrentMenu >= 4 && ScreenCurrentMenu < 8) { + ResetBufferIndex(); + GetInfosString(24); + PrintText(9, 1, 2); + + ResetBufferIndex(); + GetInfosString(46); + PrintText(9, 11, 2); + + ResetBufferIndex(); + PrintText(9, 1, 3); + PrintText(9, 11, 3); + } + + //reset empty indicator + ResetBufferIndex(); + if (ScreenCurrentMenu != 0 && ScreenCurrentMenu != 4) PrintText(1, 0, 2); + if (ScreenCurrentMenu != 1 && ScreenCurrentMenu != 5) PrintText(1, 10, 2); + if (ScreenCurrentMenu != 2) PrintText(1, 0, 3); + if (ScreenCurrentMenu != 3) PrintText(1, 10, 3); + + //Set Indicator + StringBuffer[0] = '>'; + if (ScreenCurrentMenu == 0 || ScreenCurrentMenu == 4) PrintText(1, 0, 2); + if (ScreenCurrentMenu == 1 || ScreenCurrentMenu == 5) PrintText(1, 10, 2); + if (ScreenCurrentMenu == 2) PrintText(1, 0, 3); + if (ScreenCurrentMenu == 3) PrintText(1, 10, 3); +} diff --git a/BMDatalogger/ScreenTexts.ino b/BMDatalogger/ScreenTexts.ino new file mode 100644 index 0000000..85575c4 --- /dev/null +++ b/BMDatalogger/ScreenTexts.ino @@ -0,0 +1,376 @@ +const char sensor_0[] PROGMEM = "RPM"; +const char sensor_1[] PROGMEM = "ECT"; +const char sensor_2[] PROGMEM = "IAT"; +const char sensor_3[] PROGMEM = "TPS"; +const char sensor_4[] PROGMEM = "O2"; +const char sensor_5[] PROGMEM = "IGN"; +const char sensor_6[] PROGMEM = "INJ"; +const char sensor_7[] PROGMEM = "FUEL"; +const char sensor_8[] PROGMEM = "IACV"; +const char sensor_9[] PROGMEM = "MAP"; +const char sensor_10[] PROGMEM = "BST"; +const char sensor_11[] PROGMEM = "VSS"; +const char sensor_12[] PROGMEM = "FAN"; +const char sensor_13[] PROGMEM = "BATT"; +const char sensor_14[] PROGMEM = "ICUT"; +const char sensor_15[] PROGMEM = "FCUT"; +const char sensor_16[] PROGMEM = "INJFV"; +const char sensor_17[] PROGMEM = "2MAP"; +const char sensor_18[] PROGMEM = "TIME"; +const char sensor_19[] PROGMEM = "BTIME"; +const char sensor_20[] PROGMEM = "VTS"; +const char sensor_21[] PROGMEM = "VTP"; +const char sensor_22[] PROGMEM = "ELDV"; +const char sensor_23[] PROGMEM = "O2H"; +const char sensor_24[] PROGMEM = "AC"; +const char sensor_25[] PROGMEM = "ALT"; +const char sensor_26[] PROGMEM = "GEAR"; + +const char sensor_27[] PROGMEM = "BST"; +const char sensor_28[] PROGMEM = "FTL"; +const char sensor_29[] PROGMEM = "ATLG"; +const char sensor_30[] PROGMEM = "FTS"; +const char sensor_31[] PROGMEM = "EBC"; +const char sensor_32[] PROGMEM = "BSTCT"; +const char sensor_33[] PROGMEM = "LEAN"; +const char sensor_34[] PROGMEM = "PARK"; +const char sensor_35[] PROGMEM = "BKSW"; +const char sensor_36[] PROGMEM = "ACC"; +const char sensor_37[] PROGMEM = "START"; +const char sensor_38[] PROGMEM = "SCC"; +const char sensor_39[] PROGMEM = "FCUT2"; +const char sensor_40[] PROGMEM = "PSP"; +const char sensor_41[] PROGMEM = "FPMP"; +const char sensor_42[] PROGMEM = "IAB"; +const char sensor_43[] PROGMEM = "PURGE"; +const char sensor_44[] PROGMEM = "GPO1"; +const char sensor_45[] PROGMEM = "GPO2"; +const char sensor_46[] PROGMEM = "GPO3"; +const char sensor_47[] PROGMEM = "BSTS2"; +const char sensor_48[] PROGMEM = "BSTS3"; +const char sensor_49[] PROGMEM = "BSTS4"; + +const char sensor_50[] PROGMEM = "PSTF"; +const char sensor_51[] PROGMEM = "SCCCK"; +const char sensor_52[] PROGMEM = "VTSM"; +const char sensor_53[] PROGMEM = "ATS1"; +const char sensor_54[] PROGMEM = "ATS2"; +const char sensor_55[] PROGMEM = "VTSFB"; +const char sensor_56[] PROGMEM = "FANC"; +const char sensor_57[] PROGMEM = "MIL"; +const char sensor_58[] PROGMEM = "OHEAT"; +const char sensor_59[] PROGMEM = "IGNT"; +const char sensor_60[] PROGMEM = "IFTL"; +const char sensor_61[] PROGMEM = "IFTS"; +const char sensor_62[] PROGMEM = "IEBC"; +const char sensor_63[] PROGMEM = "IGPO1"; +const char sensor_64[] PROGMEM = "IGPO2"; +const char sensor_65[] PROGMEM = "IGPO3"; +const char sensor_66[] PROGMEM = "IBST"; +const char sensor_67[] PROGMEM = "BARO"; + +const char sensor_68[] PROGMEM = "INJD"; +const char sensor_69[] PROGMEM = "ECTFC"; +const char sensor_70[] PROGMEM = "O2SHT"; +const char sensor_71[] PROGMEM = "O2LNG"; +const char sensor_72[] PROGMEM = "IATFC"; +const char sensor_73[] PROGMEM = "VEFC"; +const char sensor_74[] PROGMEM = "IATIC"; +const char sensor_75[] PROGMEM = "ECTIC"; +const char sensor_76[] PROGMEM = "GEARI"; +const char sensor_77[] PROGMEM = "EBCBD"; +const char sensor_78[] PROGMEM = "EBCDT"; +const char sensor_79[] PROGMEM = "EBCDT"; + + +const char inf_0[] PROGMEM = "kmh"; +const char inf_1[] PROGMEM = "mph"; +const char inf_2[] PROGMEM = "%"; +const char inf_3[] PROGMEM = "ms"; +const char inf_4[] PROGMEM = "L"; +const char inf_5[] PROGMEM = "PAGE"; +const char inf_6[] PROGMEM = "MENU"; +const char inf_7[] PROGMEM = "SENSORS"; +const char inf_8[] PROGMEM = "PEAKS"; +const char inf_9[] PROGMEM = "MIL"; +const char inf_10[] PROGMEM = "NO CODE"; +const char inf_11[] PROGMEM = " RESET"; +const char inf_12[] PROGMEM = " DONE"; +const char inf_13[] PROGMEM = "FAILED"; +const char inf_14[] PROGMEM = "START"; +const char inf_15[] PROGMEM = "Min"; +const char inf_16[] PROGMEM = "Max"; +const char inf_17[] PROGMEM = "Curr"; +const char inf_18[] PROGMEM = "Off"; +const char inf_19[] PROGMEM = "On"; +const char inf_20[] PROGMEM = "BMDatalogger"; +const char inf_21[] PROGMEM = "By Bouletmarc"; +const char inf_22[] PROGMEM = "SLEEP"; +const char inf_23[] PROGMEM = "J12"; +const char inf_24[] PROGMEM = "SETUP"; +const char inf_25[] PROGMEM = "CODES"; + +const char inf_26[] PROGMEM = "Page"; +const char inf_27[] PROGMEM = "Timeout"; +const char inf_28[] PROGMEM = "DAYLight"; +const char inf_29[] PROGMEM = "Bar"; +const char inf_30[] PROGMEM = "Type"; +const char inf_31[] PROGMEM = "Side"; +const char inf_32[] PROGMEM = "Inj"; +const char inf_33[] PROGMEM = "Size"; +const char inf_34[] PROGMEM = "Back"; +const char inf_35[] PROGMEM = "Input"; +const char inf_36[] PROGMEM = "B6"; +const char inf_37[] PROGMEM = "Temp"; +const char inf_38[] PROGMEM = "Speed"; +const char inf_39[] PROGMEM = ":"; +const char inf_40[] PROGMEM = "Increase"; +const char inf_41[] PROGMEM = "Decrease"; +const char inf_42[] PROGMEM = "WB"; +const char inf_43[] PROGMEM = "Tbl"; +const char inf_44[] PROGMEM = "Gearbx"; +const char inf_45[] PROGMEM = "NIGTLight"; +const char inf_46[] PROGMEM = "NightMode"; +//const char inf_45[] PROGMEM = ""; +//ProgressBarMode +//ProgressBarLeft +//Injectors_Size +//O2Input +//MapValue +//UseCelcius +//UseKMH +//O2Type +//Warning_RPM +//Warning_IAT +//Warning_ECT +//mBarMin = -70; +//mBarMax = 1790; +//TempMin = -40; +//TempMax = 140; + +const char err_0[] PROGMEM = "UKNW"; +const char err_1[] PROGMEM = "O2A"; +const char err_2[] PROGMEM = "O2B"; +const char err_3[] PROGMEM = "MAP"; +const char err_4[] PROGMEM = "CKP"; +const char err_5[] PROGMEM = "MAP"; +const char err_6[] PROGMEM = "ECT"; +const char err_7[] PROGMEM = "TPS"; +const char err_8[] PROGMEM = "TDC"; +const char err_9[] PROGMEM = "CYP"; +const char err_10[] PROGMEM = "IAT"; + +const char err_12[] PROGMEM = "EGR"; +const char err_13[] PROGMEM = "BARO"; +const char err_14[] PROGMEM = "IACV"; +const char err_15[] PROGMEM = "ICM"; +const char err_16[] PROGMEM = "INJ"; +const char err_17[] PROGMEM = "VSS"; + +const char err_19[] PROGMEM = "AUTO"; +const char err_20[] PROGMEM = "ELD"; +const char err_21[] PROGMEM = "VTS"; +const char err_22[] PROGMEM = "VTP"; +const char err_23[] PROGMEM = "KNCK"; + +const char err_30[] PROGMEM = "AUTOA"; +const char err_31[] PROGMEM = "AUTOB"; + +const char err_36[] PROGMEM = "TRAC"; +const char err_41[] PROGMEM = "PO2H"; +const char err_43[] PROGMEM = "FUELS"; +const char err_45[] PROGMEM = "FUEL"; + +const char* const SensorVars[] PROGMEM = { + sensor_0, sensor_1, sensor_2, sensor_3, sensor_4, + sensor_5, sensor_6, sensor_7, sensor_8, sensor_9, + sensor_10, sensor_11, sensor_12, sensor_13, sensor_14, + sensor_15, sensor_16, sensor_17, sensor_18, sensor_19, + sensor_20, sensor_21, sensor_22, sensor_23, sensor_24, + sensor_25, sensor_26, sensor_27, sensor_28, sensor_29, + sensor_30, sensor_31, sensor_32, sensor_33, sensor_34, + sensor_35, sensor_36, sensor_37, sensor_38, sensor_39, + sensor_40, sensor_41, sensor_42, sensor_43, sensor_44, + sensor_45, sensor_46, sensor_47, sensor_48, sensor_49, + sensor_50, sensor_51, sensor_52, sensor_53, sensor_54, + sensor_55, sensor_56, sensor_57, sensor_58, sensor_59, + sensor_60, sensor_61, sensor_62, sensor_63, sensor_64, + sensor_65, sensor_66, sensor_67, sensor_68, sensor_69, + sensor_70, sensor_71, sensor_72, sensor_73, sensor_74, + sensor_75, sensor_76, sensor_77, sensor_78, sensor_79 +}; + +const char* const StringInfos[] PROGMEM = { + inf_0, inf_1, inf_2, inf_3, inf_4, + inf_5, inf_6, inf_7, inf_8, inf_9, + inf_10, inf_11, inf_12, inf_13, inf_14, + inf_15, inf_16, inf_17, inf_18, inf_19, + inf_20, inf_21, inf_22, inf_23, inf_24, + inf_25, inf_26, inf_27, inf_28, inf_29, + inf_30, inf_31, inf_32, inf_33, inf_34, + inf_35, inf_36, inf_37, inf_38, inf_39, + inf_40, inf_41, inf_42, inf_43, inf_44, + inf_45, inf_46 +}; + +const char* const ErrorsVars[] PROGMEM = { + err_0, err_1, err_2, err_3, err_4, + err_5, err_6, err_7, err_8, err_9, + err_10, err_12, err_13, err_14, + err_15, err_16, err_17, err_19, + err_20, err_21, err_22, err_23, + err_30, err_31, + err_36, err_41, err_43, err_45 +}; + +int CurrentBufferIndex = 0; //which index we are now doing into the Buffer (0-10 or 0-20) + +//################################################################################################ +//################################################################################################ +//################################################################################################ + +void ResetBufferIndex() { + CurrentBufferIndex = 0; + for (int i=0; i < 20; i++) StringBuffer[i] = ' '; +} + +void Add_String(String ThisStr) { + for (int i=0; i < ThisStr.length(); i++) { + char c = ThisStr.charAt(i); + AddThisChar(c); + } + + /*for (int i=0; i < 20; i++) { + char c = ThisStr.charAt(i); + if ((int) c >= 20) AddThisChar(c); + if ((int) c < 20) i += 20; + }*/ + + //int Size = ThisStr.length() + 1; + //int Size = strlen(ThisStr); + //if (Size > 20) Size = 20; + //for (int i=0; i 23 & Addr < 30) Addr = 0; + if (Addr > 31 & Addr < 36) Addr = 0; + if (Addr > 36 & Addr < 41) Addr = 0; + if (Addr == 42 | Addr == 44 | Addr > 45) Addr = 0; + + int Remover = 0; + if (Addr > 11) Remover = 1; + if (Addr > 18) Remover = 2; + if (Addr > 29) Remover = 8; + if (Addr > 35) Remover = 12; + if (Addr > 40) Remover = 16; + if (Addr > 42) Remover = 17; + if (Addr > 44) Remover = 18; + if (Addr > 11) Addr -= Remover; + + GetStringsChar((unsigned int) pgm_read_word(&ErrorsVars[Addr])); +} + +void GetStringsChar(unsigned int flash_address) { + for (int i=0; i < 20; i++) { + char c = (char) pgm_read_byte(flash_address++); + if ((int) c >= 20) AddThisChar(c); + if ((int) c < 20) i += 20; + } +} + +void AddThisChar(char This) { + if (CurrentBufferIndex < 20) { + StringBuffer[CurrentBufferIndex] = This; + CurrentBufferIndex++; + } +} + +//used to remake double into 1 decimal +void RemoveLastChar() { + if (CurrentBufferIndex > 0) CurrentBufferIndex--; + StringBuffer[CurrentBufferIndex] = ' '; +} + +void PrintText(int Lenght, int PosX, int PosY) { + for (int i=0; i < Lenght; i++) { + lcd.setCursor(PosX + i, PosY); + lcd.print(StringBuffer[i]); + } +} + +void PrintTextAnimated(int Lenght, int PosX, int PosY) { + for (int i=0; i < Lenght; i++) { + lcd.setCursor(PosX + i, PosY); + lcd.print(StringBuffer[i]); + delay(20); + } +} + +void PrintTextLenght(int PosX, int PosY) { + for (int i=0; i < CurrentBufferIndex; i++) { + lcd.setCursor(PosX + i, PosY); + lcd.print(StringBuffer[i]); + } +} + +void PrintTextLenghtEmpty(int PosX, int PosY) { + for (int i=0; i < CurrentBufferIndex; i++) { + lcd.setCursor(PosX + i, PosY); + lcd.print(" "); + } +} + +void PrintTextFrom(int Lenght, int From, int PosX, int PosY) { + for (int i=0; i < Lenght; i++) { + lcd.setCursor(PosX + i, PosY); + lcd.print(StringBuffer[i + From]); + } +} + +int GetBufferLenght() { + return CurrentBufferIndex; +} + +void DisplayMil(int Displayed) { + int PosX = 0; + int PosY = 2; + if (Displayed == 1 | Displayed == 3) PosX = 10; + if (Displayed >= 2) PosY = 3; + PrintText(10, PosX, PosY); +} diff --git a/BMDatalogger/SettingPage.ino b/BMDatalogger/SettingPage.ino new file mode 100644 index 0000000..6e06423 --- /dev/null +++ b/BMDatalogger/SettingPage.ino @@ -0,0 +1,168 @@ +void DisplaySettingPage() { + //Settings Menu + ResetBufferIndex(); + PrintText(2, 0, 0); + PrintText(2, 0, 1); + PrintText(3, 17, 0); + PrintText(3, 17, 1); + GetInfosString(24); + writeBigString(2, 0); + //########################### + ResetBufferIndex(); + GetInfosString(5); + if (ScreenCurrentMenu < 8) Add_String("1"); + else Add_String("5"); + PrintText(9, 1, 2); + + ResetBufferIndex(); + GetInfosString(5); + if (ScreenCurrentMenu < 8) Add_String("2"); + else Add_String("6"); + PrintText(9, 11, 2); + + ResetBufferIndex(); + GetInfosString(5); + if (ScreenCurrentMenu < 8) Add_String("3"); + else Add_String("7"); + PrintText(9, 1, 3); + + ResetBufferIndex(); + GetInfosString(5); + if (ScreenCurrentMenu < 8) Add_String("4"); + else Add_String("8"); + PrintText(9, 11, 3); + + //########################### + //reset empty indicator + ResetBufferIndex(); + if (ScreenCurrentMenu != 4 && ScreenCurrentMenu != 8) PrintText(1, 0, 2); + if (ScreenCurrentMenu != 5 && ScreenCurrentMenu != 9) PrintText(1, 10, 2); + if (ScreenCurrentMenu != 6 && ScreenCurrentMenu != 10) PrintText(1, 0, 3); + if (ScreenCurrentMenu != 7 && ScreenCurrentMenu != 11) PrintText(1, 10, 3); + + //Set Indicator + StringBuffer[0] = '>'; + if (ScreenCurrentMenu == 4 || ScreenCurrentMenu == 8) PrintText(1, 0, 2); + if (ScreenCurrentMenu == 5 || ScreenCurrentMenu == 9) PrintText(1, 10, 2); + if (ScreenCurrentMenu == 6 || ScreenCurrentMenu == 10) PrintText(1, 0, 3); + if (ScreenCurrentMenu == 7 || ScreenCurrentMenu == 11) PrintText(1, 10, 3); +} + +void DisplaySettingPageOption() { + //AddThisChar(' '); + //Settings Menu + ResetBufferIndex(); + PrintText(2, 0, 0); + PrintText(2, 0, 1); + PrintText(3, 17, 0); + PrintText(3, 17, 1); + GetInfosString(24); + writeBigString(2, 0); + //########################### + if (ScreenCurrentMenu >= 13 && ScreenCurrentMenu < 17) { + //Timeout, backlight, Bar Type, Bar Side + ResetBufferIndex(); + GetOptionString(13); + PrintText(9, 1, 2); + + ResetBufferIndex(); + GetOptionString(14); + PrintText(9, 11, 2); + + ResetBufferIndex(); + GetOptionString(15); + PrintText(9, 1, 3); + + ResetBufferIndex(); + GetOptionString(16); + PrintText(9, 11, 3); + } + else if (ScreenCurrentMenu >= 17 && ScreenCurrentMenu < 21) { + //Inj_Size, O2_Input, Temp, Speed + ResetBufferIndex(); + GetOptionString(17); + PrintText(9, 1, 2); + + ResetBufferIndex(); + GetOptionString(18); + PrintText(9, 11, 2); + + ResetBufferIndex(); + GetOptionString(19); + PrintText(9, 1, 3); + + ResetBufferIndex(); + GetOptionString(20); + PrintText(9, 11, 3); + } + else if (ScreenCurrentMenu >= 21 && ScreenCurrentMenu < 25) { + //O2 Type, Warning_Max_RPM, Warning_Max_ECT, Warning_Max_IAT + ResetBufferIndex(); + GetOptionString(21); + PrintText(9, 1, 2); + + ResetBufferIndex(); + GetOptionString(22); + PrintText(9, 11, 2); + + ResetBufferIndex(); + GetOptionString(23); + PrintText(9, 1, 3); + + ResetBufferIndex(); + GetOptionString(24); + PrintText(9, 11, 3); + } + else if (ScreenCurrentMenu >= 25 && ScreenCurrentMenu < 29) { + //MAP_Min, MAP_Max, Temp_Min, Temp_Max + ResetBufferIndex(); + GetOptionString(25); + PrintText(9, 1, 2); + + ResetBufferIndex(); + GetOptionString(26); + PrintText(9, 11, 2); + + ResetBufferIndex(); + GetOptionString(27); + PrintText(9, 1, 3); + + ResetBufferIndex(); + GetOptionString(28); + PrintText(9, 11, 3); + } + + else if (ScreenCurrentMenu >= 29 && ScreenCurrentMenu < 33) { + //WBConversion, MapByte, Tranny, Back + ResetBufferIndex(); + GetOptionString(29); + PrintText(9, 1, 2); + + ResetBufferIndex(); + GetOptionString(30); + PrintText(9, 11, 2); + + ResetBufferIndex(); + GetOptionString(31); + PrintText(9, 1, 3); + + //Back + ResetBufferIndex(); + GetInfosString(34); + PrintText(9, 11, 3); + } + + //reset empty indicator + ResetBufferIndex(); + if (ScreenCurrentMenu != 13 && ScreenCurrentMenu != 17 && ScreenCurrentMenu != 21 && ScreenCurrentMenu != 25 && ScreenCurrentMenu != 29) PrintText(1, 0, 2); + if (ScreenCurrentMenu != 14 && ScreenCurrentMenu != 18 && ScreenCurrentMenu != 22 && ScreenCurrentMenu != 26 && ScreenCurrentMenu != 30) PrintText(1, 10, 2); + if (ScreenCurrentMenu != 15 && ScreenCurrentMenu != 19 && ScreenCurrentMenu != 23 && ScreenCurrentMenu != 27 && ScreenCurrentMenu != 31) PrintText(1, 0, 3); + if (ScreenCurrentMenu != 16 && ScreenCurrentMenu != 20 && ScreenCurrentMenu != 24 && ScreenCurrentMenu != 28 && ScreenCurrentMenu != 32) PrintText(1, 10, 3); + + //Set Indicator + StringBuffer[0] = '>'; + if (ScreenCurrentMenu == 13 || ScreenCurrentMenu == 17 || ScreenCurrentMenu == 21 || ScreenCurrentMenu == 25 || ScreenCurrentMenu == 29) PrintText(1, 0, 2); + if (ScreenCurrentMenu == 14 || ScreenCurrentMenu == 18 || ScreenCurrentMenu == 22 || ScreenCurrentMenu == 26 || ScreenCurrentMenu == 30) PrintText(1, 10, 2); + if (ScreenCurrentMenu == 15 || ScreenCurrentMenu == 19 || ScreenCurrentMenu == 23 || ScreenCurrentMenu == 27 || ScreenCurrentMenu == 31) PrintText(1, 0, 3); + if (ScreenCurrentMenu == 16 || ScreenCurrentMenu == 20 || ScreenCurrentMenu == 24 || ScreenCurrentMenu == 28 || ScreenCurrentMenu == 32) PrintText(1, 10, 3); +} diff --git a/BMDatalogger/SettingPageCursor.ino b/BMDatalogger/SettingPageCursor.ino new file mode 100644 index 0000000..95e1f7c --- /dev/null +++ b/BMDatalogger/SettingPageCursor.ino @@ -0,0 +1,287 @@ +//int Showing = 0; +unsigned long last_shown_time=0; +const int SpawnTimeout = 600; + +void SetCursor() { + //Showing++; + //if (Showing > 40) Showing = 0; + //if (Showing <= 15) { + if (millis() - last_shown_time > SpawnTimeout) { + StringBuffer[0] = '>'; + if (ScreenSettingSelected == 0) { + PrintText(1, 0, 0); + StringBuffer[0] = '<'; + PrintText(1, 9, 0); + } + if (ScreenSettingSelected == 1) { + PrintText(1, 10, 0); + StringBuffer[0] = '<'; + PrintText(1, 19, 0); + } + if (ScreenSettingSelected == 2) { + PrintText(1, 0, 0); + StringBuffer[0] = '<'; + PrintText(1, 19, 0); + } + //######################################## + if (ScreenSettingSelected == 3) { + PrintText(1, 0, 1); + StringBuffer[0] = '<'; + PrintText(1, 9, 1); + } + if (ScreenSettingSelected == 4) { + PrintText(1, 10, 1); + StringBuffer[0] = '<'; + PrintText(1, 19, 1); + } + if (ScreenSettingSelected == 5) { + PrintText(1, 0, 1); + StringBuffer[0] = '<'; + PrintText(1, 19, 1); + } + if (ScreenSettingSelected == 6) { + PrintText(1, 0, 0); + StringBuffer[0] = '<'; + PrintText(1, 19, 1); + } + //######################################## + if (ScreenSettingSelected == 7) { + PrintText(1, 0, 2); + StringBuffer[0] = '<'; + PrintText(1, 9, 2); + } + if (ScreenSettingSelected == 8) { + PrintText(1, 10, 2); + StringBuffer[0] = '<'; + PrintText(1, 19, 2); + } + if (ScreenSettingSelected == 9) { + PrintText(1, 0, 2); + StringBuffer[0] = '<'; + PrintText(1, 19, 2); + } + if (ScreenSettingSelected == 10) { + PrintText(1, 0, 1); + StringBuffer[0] = '<'; + PrintText(1, 19, 2); + } + //######################################## + if (ScreenSettingSelected == 11) { + PrintText(1, 0, 3); + StringBuffer[0] = '<'; + PrintText(1, 9, 3); + } + if (ScreenSettingSelected == 12) { + PrintText(1, 10, 3); + StringBuffer[0] = '<'; + PrintText(1, 19, 3); + } + if (ScreenSettingSelected == 13) { + PrintText(1, 0, 3); + StringBuffer[0] = '<'; + PrintText(1, 19, 3); + } + if (ScreenSettingSelected == 14) { + PrintText(1, 0, 2); + StringBuffer[0] = '<'; + PrintText(1, 19, 3); + } + if (ScreenSettingSelected == 15) { + PrintText(1, 0, 0); + StringBuffer[0] = '<'; + PrintText(1, 19, 3); + } + + if (millis() - last_shown_time > (SpawnTimeout * 2)) last_shown_time = millis(); + } +} + +void IncreaseScreenIndex() { + //ScreenSettingSelected + //ScreenCurrentPage + + int ThisPageeeIndex = 0; + if (ScreenSettingSelected == 1) ThisPageeeIndex = 1; + if (ScreenSettingSelected == 2) ThisPageeeIndex = 0; + + if (ScreenSettingSelected == 3) ThisPageeeIndex = 2; + if (ScreenSettingSelected == 4) ThisPageeeIndex = 3; + if (ScreenSettingSelected == 5) ThisPageeeIndex = 2; + if (ScreenSettingSelected == 6) ThisPageeeIndex = 0; + + if (ScreenSettingSelected == 7) ThisPageeeIndex = 4; + if (ScreenSettingSelected == 8) ThisPageeeIndex = 5; + if (ScreenSettingSelected == 9) ThisPageeeIndex = 4; + if (ScreenSettingSelected == 10) ThisPageeeIndex = 2; + + if (ScreenSettingSelected == 11) ThisPageeeIndex = 6; + if (ScreenSettingSelected == 12) ThisPageeeIndex = 7; + if (ScreenSettingSelected == 13) ThisPageeeIndex = 6; + if (ScreenSettingSelected == 14) ThisPageeeIndex = 4; + if (ScreenSettingSelected == 15) ThisPageeeIndex = 0; + + int ThisScreenIndex = GetScreenIndex(ThisPageeeIndex); + + int ThisScreenMode = 0; //normal + if (ThisScreenIndex >= 100) ThisScreenMode = 1; //progressbar + if (ThisScreenIndex >= 200) ThisScreenMode = 2; //big + if (ThisScreenIndex >= 300) ThisScreenMode = 3; //big2 + + int ThisScreenModeSuposed = 0; + if (ScreenSettingSelected == 2 || ScreenSettingSelected == 5 || ScreenSettingSelected == 9 || ScreenSettingSelected == 13) ThisScreenModeSuposed = 1; + if (ScreenSettingSelected == 6 || ScreenSettingSelected == 10 || ScreenSettingSelected == 14) ThisScreenModeSuposed = 2; + if (ScreenSettingSelected == 15) ThisScreenModeSuposed = 3; + + //put to index to '0-MaxSensors' Range + ThisScreenIndex = ReRangeIndex(ThisScreenIndex); + + //increase by 1 + if (ThisScreenMode == ThisScreenModeSuposed) { + ThisScreenIndex++; + if (ThisScreenIndex >= MaxDataValue) ThisScreenIndex = 0; + } + + //set proper index + if (ThisScreenModeSuposed == 1) ThisScreenIndex = ThisScreenIndex + 100; + if (ThisScreenModeSuposed == 2) ThisScreenIndex = ThisScreenIndex + 200; + if (ThisScreenModeSuposed == 3) ThisScreenIndex = ThisScreenIndex + 300; + + //set index + SetScreenIndex(ThisPageeeIndex, ThisScreenIndex); + + if (ThisScreenModeSuposed == 1) ReRangeScreenIndexMode(ThisPageeeIndex + 1); //SetScreenIndex(ThisPageeeIndex + 1, 0); + if (ThisScreenModeSuposed == 2) { + for (int i = 0; i < 3; i++) { + ReRangeScreenIndexMode(ThisPageeeIndex + 1 + i); //SetScreenIndex(ThisPageeeIndex + 1, 0); + } + } + if (ThisScreenModeSuposed == 3) { + for (int i = 0; i < 7; i++) { + ReRangeScreenIndexMode(ThisPageeeIndex + 1 + i); //SetScreenIndex(ThisPageeeIndex + 1, 0); + } + } + + //super big font remover + if (ThisScreenModeSuposed != 3 && HasSuperBigFont()) ReRangeScreenIndexMode(0); + + //progbar remover + if (ThisPageeeIndex == 1 || ThisPageeeIndex == 3 || ThisPageeeIndex == 5 || ThisPageeeIndex == 7) { + if (ThisScreenModeSuposed != 1 && HasProgBarAt(ThisPageeeIndex - 1)) { + ReRangeScreenIndexMode(ThisPageeeIndex - 1); + } + } + + if (ThisScreenModeSuposed == 2 && HasProgBar()) { + for (int i = 0; i < 8; i++) { + if (HasProgBarAt(i)) { + ReRangeScreenIndexMode(i); + } + } + } + + //big font remover + if (ThisScreenModeSuposed != 2) { + if (((ThisPageeeIndex == 1 || ThisPageeeIndex == 2 || ThisPageeeIndex == 3) && HasBigFontAt(0)) + || ((ThisPageeeIndex == 3 || ThisPageeeIndex == 4 || ThisPageeeIndex == 5) && HasBigFontAt(2)) + || ((ThisPageeeIndex == 5 || ThisPageeeIndex == 6 || ThisPageeeIndex == 7) && HasBigFontAt(4))) { + + if (ThisPageeeIndex == 1 || ThisPageeeIndex == 2 || ThisPageeeIndex == 3) ReRangeScreenIndexMode(0); + if (ThisPageeeIndex == 3 || ThisPageeeIndex == 4 || ThisPageeeIndex == 5) ReRangeScreenIndexMode(2); + if (ThisPageeeIndex == 5 || ThisPageeeIndex == 6 || ThisPageeeIndex == 7) ReRangeScreenIndexMode(4); + } + } + + if (ThisScreenModeSuposed == 1 && HasBigFont()) { + for (int i = 0; i < 8; i++) { + if (HasBigFontAt(i)) { + ReRangeScreenIndexMode(i); + } + } + } +} + +bool HasProgBar() { + bool HasProgBarPage = false; + for (int i = 0; i < 8; i++) { + if (HasProgBarAt(i)) { + HasProgBarPage = true; + i = 8; + } + } + return HasProgBarPage; +} + +bool HasProgBarAt(int ThisPageeeIndex) { + bool HasProgBarPage = false; + int TestIndex = GetScreenIndex(ThisPageeeIndex); + if (TestIndex >= 100 && TestIndex < 200) HasProgBarPage = true; + return HasProgBarPage; +} + +bool HasBigFont() { + bool HasBigFontPage = false; + for (int i = 0; i < 8; i++) { + if (HasBigFontAt(i)) { + HasBigFontPage = true; + i = 8; + } + } + return HasBigFontPage; +} + +bool HasBigFontAt(int ThisPageeeIndex) { + bool HasBigFontPage = false; + int TestIndex = GetScreenIndex(ThisPageeeIndex); + if (TestIndex >= 200 && TestIndex < 300) HasBigFontPage = true; + return HasBigFontPage; +} + +bool HasSuperBigFont() { + bool HasBigFontPage = false; + int TestIndex = GetScreenIndex(0); + if (TestIndex >= 300 && TestIndex < 400) { + HasBigFontPage = true; + } + return HasBigFontPage; +} + +void SetScreenIndex(int ThisPageeeIndex, int ThisScreenIndex) { + if (ScreenCurrentPage == 0) ScreenCurrentPage = 1; + if (ScreenCurrentPage == 1) ScreenPage1[ThisPageeeIndex] = ThisScreenIndex; + if (ScreenCurrentPage == 2) ScreenPage2[ThisPageeeIndex] = ThisScreenIndex; + if (ScreenCurrentPage == 3) ScreenPage3[ThisPageeeIndex] = ThisScreenIndex; + if (ScreenCurrentPage == 4) ScreenPage4[ThisPageeeIndex] = ThisScreenIndex; + if (ScreenCurrentPage == 5) ScreenPage5[ThisPageeeIndex] = ThisScreenIndex; + if (ScreenCurrentPage == 6) ScreenPage6[ThisPageeeIndex] = ThisScreenIndex; + if (ScreenCurrentPage == 7) ScreenPage7[ThisPageeeIndex] = ThisScreenIndex; + if (ScreenCurrentPage == 8) ScreenPage8[ThisPageeeIndex] = ThisScreenIndex; +} + +int GetScreenIndex(int ThisPageeeIndex) { + int ThisScreenIndex = 0; + if (ScreenCurrentPage == 0) ScreenCurrentPage = 1; + if (ScreenCurrentPage == 1) ThisScreenIndex = ScreenPage1[ThisPageeeIndex]; + if (ScreenCurrentPage == 2) ThisScreenIndex = ScreenPage2[ThisPageeeIndex]; + if (ScreenCurrentPage == 3) ThisScreenIndex = ScreenPage3[ThisPageeeIndex]; + if (ScreenCurrentPage == 4) ThisScreenIndex = ScreenPage4[ThisPageeeIndex]; + if (ScreenCurrentPage == 5) ThisScreenIndex = ScreenPage5[ThisPageeeIndex]; + if (ScreenCurrentPage == 6) ThisScreenIndex = ScreenPage6[ThisPageeeIndex]; + if (ScreenCurrentPage == 7) ThisScreenIndex = ScreenPage7[ThisPageeeIndex]; + if (ScreenCurrentPage == 8) ThisScreenIndex = ScreenPage8[ThisPageeeIndex]; + + return ThisScreenIndex; +} + +int ReRangeIndex(int ThisScreenIndex) { + //put to index to '0-MaxSensors' Range + while (ThisScreenIndex >= 100) { + ThisScreenIndex -= 100; + } + return ThisScreenIndex; +} + +void ReRangeScreenIndexMode(int ThisPageeeIndex) { + int ThisScreenIndex = GetScreenIndex(ThisPageeeIndex); + ThisScreenIndex = ReRangeIndex(ThisScreenIndex); + SetScreenIndex(ThisPageeeIndex, ThisScreenIndex); +} diff --git a/BMDatalogger/SpeedCounter.ino b/BMDatalogger/SpeedCounter.ino new file mode 100644 index 0000000..6cdfb95 --- /dev/null +++ b/BMDatalogger/SpeedCounter.ino @@ -0,0 +1,35 @@ +double TimeVal = 99.99; +double BestTimeVal = 99.99; +unsigned long last_zero_time=0; +bool CheckDone = false; + +void SetSpeedTime() { + unsigned int Speed = GetVssKMH(); + + if (Speed < 3) { + TimeVal = 99.99; + last_zero_time = millis(); + CheckDone = false; + } + if (!CheckDone) { + if (Speed >= 3 && Speed < 100) { + TimeVal = ((double)(((long) millis() - (long) last_zero_time)) / 1000) + 0.1; + if (TimeVal > 20) { + TimeVal = 99.99; + CheckDone = true; + } + } + if (Speed >= 100) { + if (TimeVal < BestTimeVal) BestTimeVal = TimeVal; + CheckDone = true; + } + } +} + +double GetSpeedTime() { + return TimeVal; +} + +double GetBestSpeedTime() { + return BestTimeVal; +} diff --git a/BMDatalogger/Version.txt b/BMDatalogger/Version.txt index 0638160..5f7a5d5 100644 --- a/BMDatalogger/Version.txt +++ b/BMDatalogger/Version.txt @@ -1 +1 @@ -V2.0.0 +V2.0.0 \ No newline at end of file diff --git a/BMDatalogger/Warnings.ino b/BMDatalogger/Warnings.ino new file mode 100644 index 0000000..7f51222 --- /dev/null +++ b/BMDatalogger/Warnings.ino @@ -0,0 +1,31 @@ +bool IsWarning = false; + +void GetWarnings() { + bool Warning = false; + if (EngineRunning) { + if (GetRpm() > Warning_RPM) Warning = true; + if (GetIat() > Warning_IAT) Warning = true; + if (GetEct() > Warning_ECT) Warning = true; + + //Disable (not warning) + if (!Warning && IsWarning) { + //lcd.backlight(); + backlight(); + IsWarning = false; + } + + //Warning (Trigger Flash) + if (Warning) { + if (!IsWarning) { + //lcd.noBacklight(); + noBacklight(); + IsWarning = true; + } + else { + //lcd.backlight(); + backlight(); + IsWarning = false; + } + } + } +}