diff --git a/firmware/controllers/core/le_functions.cpp b/firmware/controllers/core/le_functions.cpp index d64fbaff06..585c713bd9 100644 --- a/firmware/controllers/core/le_functions.cpp +++ b/firmware/controllers/core/le_functions.cpp @@ -19,6 +19,7 @@ static LENameOrdinalPair leFan(LE_METHOD_FAN, "fan"); static LENameOrdinalPair leCoolant(LE_METHOD_COOLANT, "coolant"); static LENameOrdinalPair leFanOnSetting(LE_METHOD_FAN_ON_SETTING, "fan_on_setting"); static LENameOrdinalPair leFanOffSetting(LE_METHOD_FAN_OFF_SETTING, "fan_off_setting"); +static LENameOrdinalPair leTimeSinceBoot(LE_METHOD_TIME_SINCE_BOOT, "time_since_boot"); #if EFI_PROD_CODE || EFI_SIMULATOR diff --git a/firmware/controllers/core/logic_expression.cpp b/firmware/controllers/core/logic_expression.cpp index 84206b05b6..984ab45b0b 100644 --- a/firmware/controllers/core/logic_expression.cpp +++ b/firmware/controllers/core/logic_expression.cpp @@ -56,6 +56,24 @@ void LECalculator::reset() { stack.reset(); } +void LECalculator::reset(LEElement *element) { + first = NULL; + stack.reset(); + add(element); +} + +void LECalculator::add(LEElement *element) { + if (first == NULL) { + first = element; + } else { + LEElement *last = first; + while (last->next != NULL) { + last = last->next; + } + last->next = element; + } +} + static bool float2bool(float v) { return v != 0; } @@ -138,18 +156,6 @@ float LECalculator::getValue() { return stack.pop(); } -void LECalculator::add(LEElement *element) { - if (first == NULL) { - first = element; - } else { - LEElement *last = first; - while (last->next != NULL) { - last = last->next; - } - last->next = element; - } -} - LEElementPool::LEElementPool() { reset(); } @@ -159,6 +165,10 @@ void LEElementPool::reset() { } LEElement *LEElementPool::next() { + if (index == LE_ELEMENT_POOL_SIZE - 1) { + firmwareError("LE_ELEMENT_POOL_SIZE overflow"); + return NULL; + } return &pool[index++]; } diff --git a/firmware/controllers/core/logic_expression.h b/firmware/controllers/core/logic_expression.h index 570136ca13..571a5549b1 100644 --- a/firmware/controllers/core/logic_expression.h +++ b/firmware/controllers/core/logic_expression.h @@ -52,7 +52,7 @@ public: LEElement *next; }; -#define LE_ELEMENT_POOL_SIZE 64 +#define LE_ELEMENT_POOL_SIZE 256 class LEElementPool { public: @@ -73,6 +73,7 @@ public: float getValue(); void add(LEElement *element); void reset(); + void reset(LEElement *element); private: void doJob(LEElement *element); diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index a6aab10d6c..15455f09c9 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -52,6 +52,15 @@ #include "ec2.h" #include "PwmTester.h" #include "engine.h" +#include "logic_expression.h" + +#define FUEL_PUMP_LOGIC "time_since_boot 4 less rpm 0 > OR" + +LECalculator calc; + +LEElementPool lePool; +LEElement * fuelPumpLogic; +LEElement * radiatorFanLogic; extern board_configuration_s *boardConfiguration; @@ -337,5 +346,7 @@ void initEngineContoller(void) { } #endif + fuelPumpLogic = parseExpression(&lePool, FUEL_PUMP_LOGIC); + addConsoleAction("analoginfo", printAnalogInfo); } diff --git a/unit_tests/test_logic_expression.cpp b/unit_tests/test_logic_expression.cpp index 2101ef732d..a5d033c5df 100644 --- a/unit_tests/test_logic_expression.cpp +++ b/unit_tests/test_logic_expression.cpp @@ -106,7 +106,7 @@ void testLogicExpressions(void) { /** * fuel_pump = (time_since_boot < 4 seconds) OR (rpm > 0) - * fuel_pump = time_since_boot 4 less rpm 0 more OR + * fuel_pump = time_since_boot 4 less rpm 0 > OR */ c.reset();