rusefi/firmware/controllers/gauges/malfunction_central.cpp

63 lines
1.6 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file malfunction_central.c
* @brief This data structure holds current malfunction codes
*
2015-12-11 13:01:41 -08:00
* todo: make this a class
*
2015-07-10 06:01:56 -07:00
* @date Dec 20, 2013
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2015-07-10 06:01:56 -07:00
*/
#include "pch.h"
2015-07-10 06:01:56 -07:00
#include "malfunction_central.h"
static error_codes_set_s error_codes_set;
2023-11-03 17:53:30 -07:00
void clearWarnings(void) {
error_codes_set.count = 0;
}
// TODO: wow this is not used by real firmware?!
#if EFI_UNIT_TEST
2015-07-10 06:01:56 -07:00
/**
2023-06-26 12:49:07 -07:00
* Search if code is present
2015-07-10 06:01:56 -07:00
* @return -1 if code not found
*/
2023-06-26 12:49:07 -07:00
static int find_position(ObdCode e_code) {
2015-07-10 06:01:56 -07:00
// cycle for searching element equal seaching code
for (int t = 0; t < error_codes_set.count; t++)
if (error_codes_set.error_codes[t] == e_code)
return t; // we found position where this code is present
return -1; // -1 if code not found
}
void addError(ObdCode errorCode) {
2015-07-10 06:01:56 -07:00
if (error_codes_set.count < MAX_ERROR_CODES_COUNT && find_position(errorCode) == -1) {
error_codes_set.error_codes[error_codes_set.count] = errorCode;
error_codes_set.count++;
}
}
void removeError(ObdCode errorCode) {
2015-07-10 06:01:56 -07:00
int pos = find_position(errorCode);
if (pos >= 0) {
2021-08-27 01:07:33 -07:00
// shift all right elements to one pos left
for (int t = pos; t < error_codes_set.count - 1; t++) {
2015-07-10 06:01:56 -07:00
error_codes_set.error_codes[t] = error_codes_set.error_codes[t + 1];
2021-08-27 01:07:33 -07:00
}
error_codes_set.error_codes[--error_codes_set.count] = (ObdCode)0; // place 0
2015-07-10 06:01:56 -07:00
}
}
#endif // EFI_UNIT_TEST
2015-07-10 06:01:56 -07:00
void getErrorCodes(error_codes_set_s * copy) {
copy->count = error_codes_set.count;
copyArray(copy->error_codes, error_codes_set.error_codes);
2015-07-10 06:01:56 -07:00
}
bool hasErrorCodes(void) {
return error_codes_set.count > 0;
}