641 {
644
646 lua_register(lState, "random", [](lua_State* l) {
648 lua_pushnumber(l, random);
649 return 1;
650 });
651
652 LuaClass<Timer> luaTimer(lState, "Timer");
653 luaTimer
654 .ctor()
655 .fun("reset", static_cast<void (Timer::*)() >(&Timer::reset ))
656 .fun("getElapsedSeconds", static_cast<float(Timer::*)()const>(&Timer::getElapsedSeconds));
657
658 LuaClass<LuaSensor> luaSensor(lState, "Sensor");
659 luaSensor
660 .ctor<lua_State*, const char*>()
661 .fun("set", &LuaSensor::set)
662 .fun("setRedundant", &LuaSensor::setRedundant)
663 .fun("setTimeout", &LuaSensor::setTimeout)
664 .fun("invalidate", &LuaSensor::invalidate);
665
666#ifndef WITH_LUA_PID
667#define WITH_LUA_PID TRUE
668#endif
669
670#if WITH_LUA_PID
671 LuaClass<LuaBiQuad> biQuard(lState, "Biquad");
672 biQuard
673 .ctor()
676
677 LuaClass<LuaPid> luaPid(lState, "Pid");
678 luaPid
683
684 LuaClass<LuaIndustrialPid> luaIndustrialPid(lState, "IndustrialPid");
685 luaIndustrialPid
692#endif
693
695
697#if EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT
698 lua_register(lState, "startCrankingEngine", [](lua_State* l) {
700 return 0;
701 });
702#endif
703 lua_register(lState,
"vin",
lua_vin);
704
710
711#ifndef WITH_LUA_CONSUMPTION
712#define WITH_LUA_CONSUMPTION TRUE
713#endif
714
715#if EFI_VEHICLE_SPEED && WITH_LUA_CONSUMPTION && defined (MODULE_ODOMETER)
716 lua_register(lState, "getConsumedGrams", [](lua_State* l) {
718 return 1;
719 });
720 lua_register(lState, "getConsumedGramsRemainder", [](lua_State* l) {
722 return 1;
723 });
724 lua_register(lState, "getConsumptionGramPerSecond", [](lua_State* l) {
726 return 1;
727 });
728 lua_register(lState, "resetOdometer", [](lua_State*) {
730 return 0;
731 });
732#endif
733 lua_register(lState, "table3d", [](lua_State* l) {
734 auto humanTableIdx = luaL_checkinteger(l, 1);
735 auto x = luaL_checknumber(l, 2);
736 auto y = luaL_checknumber(l, 3);
737
738
740
741 lua_pushnumber(l, result);
742 return 1;
743 });
744
745 lua_register(lState, "secondsSinceTsActivity", [](lua_State* l) {
747 return 1;
748 });
749
750 lua_register(lState, "curve", [](lua_State* l) {
751
752 auto humanCurveIdx = luaL_checkinteger(l, 1);
753 auto x = luaL_checknumber(l, 2);
754
755 auto result =
getCurveValue(humanCurveIdx - HUMAN_OFFSET, x);
756
757 lua_pushnumber(l, result);
758 return 1;
759 });
760
761#if EFI_PROD_CODE || EFI_SIMULATOR
763
764 lua_register(lState, "getTsButtonCount",
765 [](lua_State* l) {
766 auto humanIndex = luaL_checkinteger(l, 1);
767 if (humanIndex < 1 || humanIndex > LUA_BUTTON_COUNT) {
768 luaL_error(l, "Invalid button index: %d", humanIndex);
769 return 0;
770 }
772 return 1;
773 });
774#endif
775
776#if EFI_PROD_CODE && EFI_SENT_SUPPORT
777 lua_register(lState, "getSentValue",
778 [](lua_State* l) {
779 auto humanIndex = luaL_checkinteger(l, 1);
781 lua_pushnumber(l, value);
782 return 1;
783 });
784
785 lua_register(lState, "getSentValues",
786 [](lua_State* l) {
787 uint16_t sig0;
788 uint16_t sig1;
789 auto humanIndex = luaL_checkinteger(l, 1);
791 lua_pushinteger(l, sig0);
792 lua_pushinteger(l, sig1);
793 return 2;
794 });
795#endif
796
797#if EFI_LAUNCH_CONTROL
798 lua_register(lState, "setSparkSkipRatio", [](lua_State* l) {
799 auto targetSkipRatio = luaL_checknumber(l, 1);
802 return 0;
803 });
804 lua_register(lState, "setSparkHardSkipRatio", [](lua_State* l) {
805 auto targetSkipRatio = luaL_checknumber(l, 1);
808 return 0;
809 });
810 lua_register(lState, "setLaunchTrigger", [](lua_State* l) {
811 auto value = luaL_checkinteger(l, 1);
813 return 0;
814 });
815#endif
816#if EFI_ANTILAG_SYSTEM
817 lua_register(lState, "setRollingIdleTrigger", [](lua_State* l) {
818 auto value = luaL_checkinteger(l, 1);
820 return 0;
821 });
822#endif
823
824#if EFI_EMULATE_POSITION_SENSORS && !EFI_UNIT_TEST
825 lua_register(lState, "selfStimulateRPM", [](lua_State* l) {
826 auto rpm = luaL_checkinteger(l, 1);
827 if (rpm < 1) {
829 return 0;
830 }
833 }
835 return 0;
836 });
837#endif
838
839
840
841
842 lua_register(lState, "setLuaGauge", [](lua_State* l) {
843 auto index = luaL_checkinteger(l, 1) - 1;
844 auto value = luaL_checknumber(l, 2);
845 if (index < 0 || index >= LUA_GAUGE_COUNT)
846 return 0;
849 return 0;
850 });
851
852 lua_register(lState, "enableCanTx", [](lua_State* l) {
854 return 0;
855 });
856
857 lua_register(lState, "enableCanRxWorkaround", [](lua_State*) {
858
860 return 0;
861 });
862
863#if !defined(STM32F4)
864#if EFI_CAN_SUPPORT
865 lua_register(lState, "getCanRxDropped", [](lua_State* l) {
867 lua_pushinteger(l,
count);
868 return 1;
869 });
870#endif
871 lua_register(lState, "disableExtendedCanBroadcast", [](lua_State*) {
872
874 return 0;
875 });
876 lua_register(lState, "getCanBaudRate", [](lua_State* l) {
877 auto index = luaL_checkinteger(l, 1);
878 if (index == 1) {
880 } else {
882 }
883 return 1;
884 });
885
886 lua_register(lState, "setEngineTorque", [](lua_State* l) {
888 return 0;
889 });
890#endif
891
892#if !defined(STM32F4) || defined(WITH_LUA_GET_GPPWM_STATE)
893 lua_register(lState, "getGpPwm", [](lua_State* l) {
894 auto index = luaL_checkinteger(l, 1);
895
897 lua_pushnumber(l, result);
898 return 1;
899 });
900#endif
901
902#if EFI_ELECTRONIC_THROTTLE_BODY && EFI_PROD_CODE
903 lua_register(lState, "getEtbTarget", [](lua_State* l) {
905 assertNotNull(controller, 0);
906 auto result = controller->getCurrentTarget();
907 lua_pushnumber(l, result);
908 return 1;
909 });
910 lua_register(lState, "restartEtb", [](lua_State*) {
911
912
914 return 0;
915 });
916#endif
917
918
919 lua_register(lState, "crc8_j1850", [](lua_State* l) {
920 uint8_t data[8];
921 uint32_t length =
getLuaArray(l, 1, data,
sizeof(data));
922 auto trimLength = luaL_checkinteger(l, 2);
923 int crc = crc8(data, minI(length, trimLength));
924
925 lua_pushinteger(l, crc);
926 return 1;
927 });
928
929#if EFI_BOOST_CONTROL
930 lua_register(lState, "setBoostTargetAdd", [](lua_State* l) {
932 return 0;
933 });
934 lua_register(lState, "setBoostTargetMult", [](lua_State* l) {
936 return 0;
937 });
938 lua_register(lState, "setBoostDutyAdd", [](lua_State* l) {
940 return 0;
941 });
942#endif
943#if EFI_IDLE_CONTROL
944 lua_register(lState, "setIdleAdd", [](lua_State* l) {
946 return 0;
947 });
948 lua_register(lState, "setIdleRpm", [](lua_State* l) {
949 auto rpm = luaL_checknumber(l, 1);
951 return 0;
952 });
953#endif
954 lua_register(lState, "setTimingAdd", [](lua_State* l) {
956 return 0;
957 });
958#ifndef DISABLE_LUA_SET_TIMING_MULT
959 lua_register(lState, "setTimingMult", [](lua_State* l) {
961 return 0;
962 });
963#endif
964#ifndef DISABLE_LUA_SET_FUEL_ADD
965 lua_register(lState, "setFuelAdd", [](lua_State* l) {
967 return 0;
968 });
969#endif
970 lua_register(lState, "setFuelMult", [](lua_State* l) {
972 return 0;
973 });
974#if EFI_ELECTRONIC_THROTTLE_BODY && EFI_PROD_CODE
975 lua_register(lState, "setEtbAdd", [](lua_State* l) {
977
979
980 return 0;
981 });
982 lua_register(lState, "setEwgAdd", [](lua_State* l) {
984
986
987 return 0;
988 });
989 lua_register(lState, "setEtbDisabled", [](lua_State* l) {
991 return 0;
992 });
993#endif
994#if EFI_PROD_CODE
995 lua_register(lState, "setIgnDisabled", [](lua_State* l) {
997 return 0;
998 });
999 lua_register(lState, "setFuelDisabled", [](lua_State* l) {
1001 return 0;
1002 });
1003 lua_register(lState, "setDfcoDisabled", [](lua_State* l) {
1005 return 0;
1006 });
1007#endif
1008
1009 lua_register(lState, "setClutchUpState", [](lua_State* l) {
1011 return 0;
1012 });
1013 lua_register(lState, "setClutchDownState", [](lua_State* l) {
1015 return 0;
1016 });
1017 lua_register(lState, "setBrakePedalState", [](lua_State* l) {
1019 return 0;
1020 });
1021
1022 lua_register(lState, "setAcRequestState", [](lua_State* l) {
1024 return 0;
1025 });
1026
1027#if !defined(STM32F4)
1028 lua_register(lState, "getTorque", [](lua_State* l) {
1031
1032
1033 auto result = interpolate3d(
1037 );
1038 lua_pushnumber(l, result);
1039 return 1;
1040 });
1041#endif
1042
1043 lua_register(lState, "setTorqueReductionState", [](lua_State* l) {
1045 return 0;
1046 });
1047
1048 lua_register(lState, "getCalibration", [](lua_State* l) {
1049 auto propertyName = luaL_checklstring(l, 1, nullptr);
1051 lua_pushnumber(l, result);
1052 return 1;
1053 });
1054
1055#if EFI_TUNER_STUDIO && (EFI_PROD_CODE || EFI_SIMULATOR)
1056 lua_register(lState, "getOutput", [](lua_State* l) {
1057 auto propertyName = luaL_checklstring(l, 1, nullptr);
1058
1061 lua_pushnumber(l, result);
1062 return 1;
1063 });
1064#endif
1065
1066#if EFI_SHAFT_POSITION_INPUT
1067 lua_register(lState, "getEngineState", [](lua_State* l) {
1069 int luaStateCode;
1071 luaStateCode = 0;
1073 luaStateCode = 2;
1074 } else {
1075
1076 luaStateCode = 1;
1077 }
1078 lua_pushinteger(l, luaStateCode);
1079 return 1;
1080 });
1081#endif
1082
1083 lua_register(lState, "setCalibration", [](lua_State* l) {
1084 auto propertyName = luaL_checklstring(l, 1, nullptr);
1085 auto value = luaL_checknumber(l, 2);
1086 auto incrementVersion = lua_toboolean(l, 3);
1088 if (isGoodName) {
1089 efiPrintf("LUA: applying [%s][%f]", propertyName, value);
1090 } else {
1091 efiPrintf("LUA: invalid calibration key [%s]", propertyName);
1092 }
1093 if (incrementVersion) {
1095 }
1096 return 0;
1097 });
1098 lua_register(lState, CMD_BURNCONFIG, [](lua_State*) {
1100 return 0;
1101 });
1102
1103 lua_register(lState, "getGlobalConfigurationVersion", [](lua_State* l) {
1105 return 1;
1106 });
1107
1108 lua_register(lState, "setAcDisabled", [](lua_State* l) {
1109 auto value = lua_toboolean(l, 1);
1111 return 0;
1112 });
1113 lua_register(lState, "getTimeSinceAcToggleMs", [](lua_State* l) {
1115 lua_pushnumber(l, result);
1116 return 1;
1117 });
1118
1119#if !EFI_UNIT_TEST
1123 lua_register(lState, "getFan", [](lua_State* l) {
1125 return 1;
1126 });
1127 lua_register(lState, "getFan2", [](lua_State* l) {
1129 return 1;
1130 });
1131 lua_register(lState, "getAcRelay", [](lua_State* l) {
1133 return 1;
1134 });
1138#if EFI_ENGINE_CONTROL
1141#endif
1142
1143
1144#ifndef WITH_LUA_STOP_ENGINE
1145#define WITH_LUA_STOP_ENGINE TRUE
1146#endif
1147
1148#if WITH_LUA_STOP_ENGINE
1149 lua_register(lState, "isFirmwareError", [](lua_State* l) {
1150 lua_pushboolean(l, hasFirmwareError());
1151 return 1;
1152 });
1153#if EFI_SHAFT_POSITION_INPUT
1154 lua_register(lState, "stopEngine", [](lua_State*) {
1156 return 0;
1157 });
1158 lua_register(lState, "isEngineStopRequested", [](lua_State* l) {
1160 lua_pushboolean(l, result);
1161 return 1;
1162 });
1163 lua_register(lState, "getTimeSinceTriggerEventMs", [](lua_State* l) {
1165 lua_pushinteger(l, result);
1166 return 1;
1167 });
1168#endif
1169#endif
1170
1171#if EFI_CAN_SUPPORT
1174#endif
1175#endif
1176
1177#if EFI_CAN_SUPPORT || EFI_UNIT_TEST
1178 lua_register(lState,
"txCan",
lua_txCan);
1179#endif
1180
1181#if EFI_PROD_CODE
1182
1183
1184
1185
1186
1187
1188
1189#endif
1190
1191#if EFI_PROD_CODE && HW_HELLEN
1192 lua_register(lState, "hellenEnablePower", [](lua_State*) {
1194 return 0;
1195 });
1196 lua_register(lState, "hellenDisablePower", [](lua_State*) {
1198 return 0;
1199 });
1200#endif
1201
1202#if EFI_DAC
1203 lua_register(lState, "setDacVoltage", [](lua_State* l) {
1204 auto channel = luaL_checkinteger(l, 1);
1205 auto voltage = luaL_checknumber(l, 2);
1207 return 0;
1208 });
1209#endif
1210
1211 LuaClass<SignalDebounce> luaDebounce(lState, "SignalDebounce");
1212 luaDebounce
1213 .ctor<float>()
1216
1217#if EFI_UNIT_TEST
1218 lua_register(lState, "advanceTimeUs", [](lua_State *l){
1219 auto us = luaL_checknumber(l, 1);
1221 return 0;
1222 });
1223#endif
1224}
int luaCommandCounters[LUA_BUTTON_COUNT]
Timer timeSinceStateChange
TriggerCentral triggerCentral
int getGlobalConfigurationVersion() const
IgnitionState ignitionState
LaunchControlBase launchController
RpmCalculator rpmCalculator
AntilagSystemBase antilagController
IEtbController * etbControllers[ETB_COUNT]
TunerStudioOutputChannels outputChannels
constexpr auto & module()
RegisteredOutputPin fanRelay
RegisteredOutputPin fanRelay2
RegisteredOutputPin acRelay
ShutdownController shutdownController
bool getLogicValue() const
spinning_state_e getState() const
static float getOrZero(SensorType type)
bool isEngineStop(efitick_t nowNt) const
Base class for sensors that compute a value on one thread, and want to make it available to consumers...
void setValidValue(float value, efitick_t timestamp)
bool directSelfStimulation
float getConsumedGramsRemainder() const
float getConsumptionGramPerSecond() const
uint32_t getConsumedGrams() const
virtual float getValue(float xColumn, float yRow) const =0
void setDacVoltage(int channel, float voltage)
void advanceTimeUs(int us)
void setEtbLuaAdjustment(percent_t pos)
void setEwgLuaAdjustment(percent_t pos)
void doInitElectronicThrottle(bool isStartupInit)
LimpManager * getLimpManager()
static EngineAccessor engine
void incrementGlobalConfigurationVersion(const char *msg)
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
void hellenEnableEn(const char *msg)
void hellenDisableEn(const char *msg)
StoredValueSensor luaGauges[]
size_t getLuaCanRxDropped()
static int lua_setPwmFreq(lua_State *l)
static int lua_readpin(lua_State *l)
PUBLIC_API_WEAK void boardConfigureLuaHooks(lua_State *lState)
int lua_canRxAddMask(lua_State *l)
static int lua_txCan(lua_State *l)
uint32_t getLuaArray(lua_State *l, int paramIndex, uint8_t *data, uint32_t size)
static int lua_setAirmass(lua_State *l)
static int lua_getDigital(lua_State *l)
static int lua_getAuxDigital(lua_State *l)
static int lua_getAuxAnalog(lua_State *l)
static int lua_getSensorByIndex(lua_State *l)
static int lua_hasSensor(lua_State *l)
static int lua_getSensorByName(lua_State *l)
static int lua_getAirmass(lua_State *l)
static int lua_setPwmDuty(lua_State *l)
static int lua_getSensorRaw(lua_State *l)
int lua_canRxAdd(lua_State *l)
static int lua_setDebug(lua_State *l)
static int lua_startPwm(lua_State *l)
static int lua_vin(lua_State *l)
void configureRusefiLuaHooksExt(lua_State *)
void configureRusefiLuaUtilHooks(lua_State *lState)
float getOutputValueByName(const char *name)
float getCurveValue(int index, float key)
ValueProvider3D * getscriptTable(int index)
state("state", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1890, 1.0, -1.0, -1.0, "")
luaAdjustment("ETB: luaAdjustment", SensorCategory.SENSOR_INPUTS, FieldType.INT, 1848, 1.0, -100.0, 100.0, "%")
float getSentValue(SentInput input)
int getSentValues(SentInput input, uint16_t *sig0, uint16_t *sig1)
void doScheduleStopEngine(StopRequestedReason reason)
bool disableDecelerationFuelCutOff
bool torqueReductionState
void configureLowpass(float samplingFrequency, float cutoffFrequency)
float filter(float input)
void setOffset(float offset)
void setDerivativeFilterLoss(float derivativeFilterLoss)
void setAntiwindupFreq(float antiwindupFreq)
float get(float target, float input)
float get(float target, float input)
void setOffset(float offset)
scaled_channel< int16_t, 2, 1 > luaTargetAdd
can_baudrate_e canBaudRate
can_baudrate_e can2BaudRate
bool enableExtendedCanBroadcast
scaled_channel< uint8_t, 2, 1 > gppwmOutput[4]
uint16_t torqueLoadBins[TORQUE_CURVE_SIZE]
uint16_t torqueRpmBins[TORQUE_CURVE_RPM_SIZE]
scaled_channel< uint8_t, 1, 10 > torqueTable[TORQUE_CURVE_SIZE][TORQUE_CURVE_RPM_SIZE]
scaled_channel< uint8_t, 1, 20 > cltIdleRpm[CLT_CURVE_SIZE]
void setLinearCurve(TValue(&array)[TSize], float from, float to, float precision=0.01f)
void tinymt32_init(tinymt32_t *random, uint32_t seed)
static float tinymt32_generate_float(tinymt32_t *random)
void disableTriggerStimulator()
void setTriggerEmulatorRPM(int rpm)
void enableTriggerStimulator(bool incGlobalConfiguration)
void updateTunerStudioState()
int getSecondsSinceChannelsRequest()
bool setConfigValueByName(const char *name, float value)
float getConfigValueByName(const char *name)