2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file malfunction_indicator.cpp
|
|
|
|
* @brief We can blink out OBD-II error codes using Malfunction Indicator Light (MIL)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @date Dec 20, 2013
|
|
|
|
* @author Konstantin Nikonenko
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
* we show 4 digit error code - 1,5sec * (4xxx+1) digit + 0,4sec * (x3xxx+1) + ....
|
|
|
|
* ATTENTION!!! 0 = 1 blink, 1 = 2 blinks, ...., 9 = 10 blinks
|
|
|
|
* sequence is the constant!!!
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This file is part of rusEfi - see http://rusefi.com
|
|
|
|
*
|
|
|
|
* rusEfi is free software; you can redistribute it and/or modify it under the terms of
|
|
|
|
* the GNU General Public License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
|
|
|
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with this program.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
2019-04-09 20:00:17 -07:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_MALFUNCTION_INDICATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "malfunction_central.h"
|
|
|
|
#include "malfunction_indicator.h"
|
2022-09-07 12:56:45 -07:00
|
|
|
|
2019-07-08 00:35:41 -07:00
|
|
|
#include "periodic_thread_controller.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-02-10 20:54:41 -08:00
|
|
|
#define TEST_MIL_CODE FALSE
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#define MFI_LONG_BLINK 1500
|
|
|
|
#define MFI_SHORT_BLINK 400
|
|
|
|
#define MFI_BLINK_SEPARATOR 400
|
|
|
|
#define MFI_CHECKENGINE_LIGHT 10000
|
|
|
|
|
|
|
|
static void blink_digits(int digit, int duration) {
|
|
|
|
for (int iter = 0; iter < digit; iter++) {
|
2019-08-18 12:53:38 -07:00
|
|
|
// todo: why we set LOW and then HIGH? not the other way around?
|
2016-09-13 22:01:57 -07:00
|
|
|
enginePins.checkEnginePin.setValue(0);
|
2015-07-10 06:01:56 -07:00
|
|
|
chThdSleepMilliseconds(duration);
|
2016-09-13 22:01:57 -07:00
|
|
|
enginePins.checkEnginePin.setValue(1);
|
2015-07-10 06:01:56 -07:00
|
|
|
chThdSleepMilliseconds(MFI_BLINK_SEPARATOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate how many digits our code have
|
|
|
|
static int DigitLength(int digit) {
|
|
|
|
int i = 0;
|
|
|
|
while (digit > 0) {
|
|
|
|
digit = digit / 10;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// display code
|
|
|
|
static void DisplayErrorCode(int length, int code) {
|
|
|
|
// todo: I suggest we use 'itoa' method to simplify this logic
|
|
|
|
for (int iter = length - 1; iter >= 0; iter--) {
|
|
|
|
int ourDigit = (int) efiPow10(iter); // 10^0 = 1, 10^1 = 10, 10^2=100, 10^3 = 1000, ....
|
|
|
|
int digit = 1; // as we remember "0" we show as one blink
|
|
|
|
while (code >= ourDigit) {
|
|
|
|
code = code - ourDigit;
|
|
|
|
digit++;
|
|
|
|
}
|
|
|
|
if (iter % 2 == 0)
|
|
|
|
blink_digits(digit, MFI_SHORT_BLINK); // even 2,0 - long blink
|
|
|
|
else
|
|
|
|
blink_digits(digit, MFI_LONG_BLINK); // odd 3,1 - short blink
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-10 20:54:41 -08:00
|
|
|
class MILController : public PeriodicController<UTILITY_THREAD_STACK_SIZE> {
|
|
|
|
public:
|
|
|
|
MILController() : PeriodicController("MFIndicator") { }
|
|
|
|
private:
|
2019-12-21 18:11:09 -08:00
|
|
|
void PeriodicTask(efitick_t nowNt) override {
|
2019-02-21 02:44:45 -08:00
|
|
|
UNUSED(nowNt);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2023-06-24 23:16:31 -07:00
|
|
|
assertStackVoid("MIL", ObdCode::STACK_USAGE_MIL, EXPECTED_REMAINING_STACK);
|
2022-04-16 14:04:35 -07:00
|
|
|
#if EFI_SHAFT_POSITION_INPUT
|
2019-12-21 18:18:38 -08:00
|
|
|
if (nowNt - engine->triggerCentral.triggerState.mostRecentSyncTime < MS2NT(500)) {
|
2019-08-18 12:53:38 -07:00
|
|
|
enginePins.checkEnginePin.setValue(1);
|
|
|
|
chThdSleepMilliseconds(500);
|
|
|
|
enginePins.checkEnginePin.setValue(0);
|
|
|
|
}
|
2023-06-26 13:05:30 -07:00
|
|
|
#endif // EFI_SHAFT_POSITION_INPUT
|
2019-08-18 12:53:38 -07:00
|
|
|
|
|
|
|
static error_codes_set_s localErrorCopy;
|
|
|
|
// todo: why do I not see this on a real vehicle? is this whole blinking logic not used?
|
2015-07-10 06:01:56 -07:00
|
|
|
getErrorCodes(&localErrorCopy);
|
|
|
|
for (int p = 0; p < localErrorCopy.count; p++) {
|
|
|
|
// Calculate how many digits in this integer and display error code from start to end
|
2023-04-11 17:01:34 -07:00
|
|
|
int code = (int)localErrorCopy.error_codes[p];
|
2015-07-10 06:01:56 -07:00
|
|
|
DisplayErrorCode(DigitLength(code), code);
|
|
|
|
}
|
|
|
|
}
|
2019-02-10 20:54:41 -08:00
|
|
|
};
|
|
|
|
|
2021-11-24 12:22:10 -08:00
|
|
|
static MILController instance;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-02-10 20:54:41 -08:00
|
|
|
#if TEST_MIL_CODE
|
2021-11-15 04:02:34 -08:00
|
|
|
static void testMil() {
|
2023-04-11 17:01:34 -07:00
|
|
|
addError(ObdCode::OBD_Engine_Coolant_Temperature_Circuit_Malfunction);
|
|
|
|
addError(ObdCode::OBD_Intake_Air_Temperature_Circuit_Malfunction);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2019-02-10 20:54:41 -08:00
|
|
|
#endif /* TEST_MIL_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-12-27 21:02:03 -08:00
|
|
|
bool isMilEnabled() {
|
2021-11-17 00:54:21 -08:00
|
|
|
return isBrainPinValid(engineConfiguration->malfunctionIndicatorPin);
|
2016-12-27 21:02:03 -08:00
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
void initMalfunctionIndicator(void) {
|
2016-12-27 21:02:03 -08:00
|
|
|
if (!isMilEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-18 12:53:38 -07:00
|
|
|
instance.setPeriod(10 /*ms*/);
|
2022-07-21 12:17:32 -07:00
|
|
|
instance.start();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-02-10 20:54:41 -08:00
|
|
|
#if TEST_MIL_CODE
|
2015-07-10 06:01:56 -07:00
|
|
|
addConsoleAction("testmil", testMil);
|
2019-02-10 20:54:41 -08:00
|
|
|
#endif /* TEST_MIL_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* EFI_MALFUNCTION_INDICATOR */
|