diff --git a/firmware/console/binary/output_channels.txt b/firmware/console/binary/output_channels.txt index cb87460a6d..d06c11fc4e 100644 --- a/firmware/console/binary/output_channels.txt +++ b/firmware/console/binary/output_channels.txt @@ -42,7 +42,8 @@ bit sd_active_wr;SD card writing bit sd_active_rd;SD card reading bit isMapValid;MAP from sensor seems valid -! 2 unused bits left here +bit triggerPageRefreshFlag +! 1 unused bit left here uint16_t RPMValue;@@GAUGE_NAME_RPM@@;"RPM",1, 0, 0, 8000, 0 diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index 0a0deec024..90c9e6a149 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -193,7 +193,9 @@ void TunerStudio::sendErrorCode(TsChannelBase* tsChannel, uint8_t code, const ch bool validateOffsetCount(size_t offset, size_t count, TsChannelBase* tsChannel); -extern bool rebootForPresetPending; +bool wasPresetJustApplied() { + return !engine->configBurnTimer.hasElapsedSec(1); +} /** * This command is needed to make the whole transfer a bit faster @@ -218,7 +220,7 @@ void TunerStudio::handleWriteChunkCommand(TsChannelBase* tsChannel, uint16_t pag } // Skip the write if a preset was just loaded - we don't want to overwrite it - if (!rebootForPresetPending) { + if (!wasPresetJustApplied()) { uint8_t * addr = (uint8_t *) (getWorkingPageAddr() + offset); memcpy(addr, content, count); } @@ -315,11 +317,6 @@ void TunerStudio::handlePageReadCommand(TsChannelBase* tsChannel, uint16_t page, efiPrintf("TS <- Page %d read chunk offset %d count %d", page, offset, count); if (page == 0) { - if (rebootForPresetPending) { - sendErrorCode(tsChannel, TS_RESPONSE_UNRECOGNIZED_COMMAND, "reboot"); - return; - } - if (validateOffsetCount(offset, count, tsChannel)) { tunerStudioError(tsChannel, "ERROR: RD out of range"); sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE); @@ -369,7 +366,7 @@ static void handleBurnCommand(TsChannelBase* tsChannel) { validateConfigOnStartUpOrBurn(); // Skip the burn if a preset was just loaded - we don't want to overwrite it - if (!rebootForPresetPending) { + if (!wasPresetJustApplied()) { requestBurn(); } @@ -906,7 +903,7 @@ static char tsErrorBuff[80]; #endif // EFI_PROD_CODE || EFI_SIMULATOR -void startTunerStudioConnectivity(void) { +void startTunerStudioConnectivity() { // Assert tune & output channel struct sizes static_assert(sizeof(persistent_config_s) == TOTAL_CONFIG_SIZE, "TS datapage size mismatch"); // useful trick if you need to know how far off is the static_assert diff --git a/firmware/console/binary/tunerstudio.h b/firmware/console/binary/tunerstudio.h index 2ca5e559ff..05ea589bb4 100644 --- a/firmware/console/binary/tunerstudio.h +++ b/firmware/console/binary/tunerstudio.h @@ -52,7 +52,8 @@ int getSecondsSinceChannelsRequest(); void updateTunerStudioState(); -void startTunerStudioConnectivity(void); +void startTunerStudioConnectivity(); +bool wasPresetJustApplied(); typedef struct { uint16_t offset; diff --git a/firmware/console/binary/tunerstudio_commands.cpp b/firmware/console/binary/tunerstudio_commands.cpp index 3e939a01c5..999107ca0b 100644 --- a/firmware/console/binary/tunerstudio_commands.cpp +++ b/firmware/console/binary/tunerstudio_commands.cpp @@ -27,12 +27,6 @@ bool validateOffsetCount(size_t offset, size_t count, TsChannelBase* tsChannel) return false; } - -// This is used to prevent TS from reading/writing when we have just applied a preset, to prevent TS getting confused. -// At the same time an ECU reboot is forced by triggering a fatal error, informing the user to please restart -// the ECU. Forcing a reboot will force TS to re-read the tune CRC, -bool rebootForPresetPending = false; - static Timer channelsRequestTimer; int getSecondsSinceChannelsRequest() { diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index bf6a606b3b..c2e95095ac 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -727,6 +727,7 @@ void updateTunerStudioState() { tsOutputChannels->vssEdgeCounter = vehicleSpeedSensor.eventCounter; tsOutputChannels->hasCriticalError = hasFirmwareError() || hasConfigError(); + tsOutputChannels->triggerPageRefreshFlag = wasPresetJustApplied(); tsOutputChannels->isWarnNow = engine->engineState.warnings.isWarningNow(); #if EFI_HIP_9011_DEBUG diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 47d903cc32..920e815ada 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -287,6 +287,7 @@ public: RpmCalculator rpmCalculator; Timer configBurnTimer; + Timer engineTypeChangeTimer; /** * This counter is incremented every time user adjusts ECU parameters online (either via rusEfi console or other diff --git a/firmware/controllers/bench_test.cpp b/firmware/controllers/bench_test.cpp index f20fe8388e..8a624a0def 100644 --- a/firmware/controllers/bench_test.cpp +++ b/firmware/controllers/bench_test.cpp @@ -518,13 +518,9 @@ static void handleCommandX14(uint16_t index) { extern bool rebootForPresetPending; -void fatalErrorForPresetApply() { - rebootForPresetPending = true; - firmwareError(ObdCode::OBD_PCM_Processor_Fault, - "\n\nTo complete preset apply:\n" - " 1. Close TunerStudio\n" - " 2. Power cycle ECU\n" - " 3. Open TunerStudio and reconnect\n\n"); +static void applyPreset(int index) { + engine->configBurnTimer.reset(); + setEngineType(index); } PUBLIC_API_WEAK void boardTsAction(uint16_t index) { } @@ -584,8 +580,7 @@ void executeTSCommand(uint16_t subsystem, uint16_t index) { break; case TS_SET_ENGINE_TYPE: - fatalErrorForPresetApply(); - setEngineType(index); + applyPreset(index); break; case TS_BOARD_ACTION: @@ -593,8 +588,7 @@ void executeTSCommand(uint16_t subsystem, uint16_t index) { break; case TS_SET_DEFAULT_ENGINE: - fatalErrorForPresetApply(); - setEngineType((int)DEFAULT_ENGINE_TYPE); + applyPreset((int)DEFAULT_ENGINE_TYPE); break; case 0x79: diff --git a/firmware/controllers/bench_test.h b/firmware/controllers/bench_test.h index 8ae4c18af4..9814eb7b17 100644 --- a/firmware/controllers/bench_test.h +++ b/firmware/controllers/bench_test.h @@ -15,7 +15,6 @@ void onConfigurationChangeBenchTest(); bool isRunningBenchTest(); const OutputPin *getOutputOnTheBenchTest(); -void fatalErrorForPresetApply(); void fanBench(); void fan2Bench(); diff --git a/firmware/tunerstudio/tunerstudio.template.ini b/firmware/tunerstudio/tunerstudio.template.ini index 2163401691..d27e4dfe2c 100644 --- a/firmware/tunerstudio/tunerstudio.template.ini +++ b/firmware/tunerstudio/tunerstudio.template.ini @@ -5391,3 +5391,7 @@ dialog = tcuControls, "Transmission Settings" #else addTool = afrTableGenerator, "AFR Table Generator", afrTableTbl #endif + + +[EventTriggers] + triggeredPageRefresh = 1, { triggerPageRefreshFlag }