Lua: do not sleep while TS is talking

only:small-can-board
This commit is contained in:
rusefi 2023-08-12 18:06:52 -04:00
parent 5001d93273
commit ad21014376
4 changed files with 16 additions and 5 deletions

View File

@ -32,6 +32,8 @@ void tunerStudioError(TsChannelBase* tsChannel, const char *msg);
uint8_t* getWorkingPageAddr();
void requestBurn();
// Lua script might want to know how long since last TS request to see if unit is being actively monitored
int getSecondsSinceChannelsRequest();
#if EFI_TUNER_STUDIO
#include "thread_controller.h"

View File

@ -35,7 +35,11 @@ bool validateOffsetCount(size_t offset, size_t count, TsChannelBase* tsChannel)
// the ECU. Forcing a reboot will force TS to re-read the tune CRC,
bool rebootForPresetPending = false;
static efitick_t prevRequestTimeNt = 0;
static Timer channelsRequestTimer;
int getSecondsSinceChannelsRequest() {
return channelsRequestTimer.getElapsedSeconds();
}
/**
* @brief 'Output' command sends out a snapshot of current values
@ -50,9 +54,8 @@ void TunerStudio::cmdOutputChannels(TsChannelBase* tsChannel, uint16_t offset, u
}
if (offset < BLOCKING_FACTOR) {
efitick_t nowNt = getTimeNowNt();
engine->outputChannels.outputRequestPeriod = nowNt - prevRequestTimeNt;
prevRequestTimeNt = nowNt;
engine->outputChannels.outputRequestPeriod = channelsRequestTimer.getElapsedUs();
channelsRequestTimer.reset();
}
tsState.outputChannelsCommandCounter++;

View File

@ -75,7 +75,7 @@ canRxAdd(1, 0x17C, onPOWERTRAIN_DATA)
canRxAdd(1, 0x309, onCAR_SPEED)
function onTick()
if canTimer : getElapsedSeconds() > 20 then
if canTimer : getElapsedSeconds() > 20 and secondsSinceTsActivity() > 20 then
mcu_standby()
end
end

View File

@ -8,6 +8,7 @@
#include "lua_airmass.h"
#include "value_lookup.h"
#include "can_filter.h"
#include "tunerstudio.h"
#if EFI_CAN_SUPPORT || EFI_UNIT_TEST
#include "can_msg_tx.h"
#endif // EFI_CAN_SUPPORT
@ -668,6 +669,11 @@ void configureRusefiLuaHooks(lua_State* l) {
return 1;
});
lua_register(l, "secondsSinceTsActivity", [](lua_State* l) {
lua_pushnumber(l, getSecondsSinceChannelsRequest());
return 1;
});
lua_register(l, "curve", [](lua_State* l) {
// index starting from 1
auto humanCurveIdx = luaL_checkinteger(l, 1);