From 1f9dcf4ab0e210d72ef0a513db7d61033ca14d8e Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 3 Jun 2017 21:09:04 -0400 Subject: [PATCH 01/36] clean-up --- firmware/util/datalogging.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/firmware/util/datalogging.cpp b/firmware/util/datalogging.cpp index 2e8617cf4a..eaebaf57fb 100644 --- a/firmware/util/datalogging.cpp +++ b/firmware/util/datalogging.cpp @@ -58,7 +58,7 @@ static ALWAYS_INLINE bool validateBuffer(Logging *logging, uint32_t extraLen) { if (remainingSize(logging) < extraLen + 1) { #if EFI_PROD_CODE warning(CUSTOM_LOGGING_BUFFER_OVERFLOW, "output overflow %s", logging->name); -#endif +#endif /* EFI_PROD_CODE */ return true; } return false; @@ -67,8 +67,8 @@ static ALWAYS_INLINE bool validateBuffer(Logging *logging, uint32_t extraLen) { void append(Logging *logging, const char *text) { efiAssertVoid(text != NULL, "append NULL"); uint32_t extraLen = efiStrlen(text); - bool isError = validateBuffer(logging, extraLen); - if (isError) { + bool isCapacityProblem = validateBuffer(logging, extraLen); + if (isCapacityProblem) { return; } strcpy(logging->linePointer, text); @@ -83,12 +83,7 @@ void append(Logging *logging, const char *text) { */ void appendFast(Logging *logging, const char *text) { // todo: fix this implementation? this would be a one-pass implementation instead of a two-pass -// char c; -// char *s = (char *) text; -// do { -// c = *s++; -// *logging->linePointer++ = c; -// } while (c != '\0'); + register char *s; for (s = (char *) text; *s; ++s) ; From 2e70c3915e5a2667f6a66c6ae1bf1051cac54b8c Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 3 Jun 2017 21:59:58 -0400 Subject: [PATCH 02/36] tiny improvement --- firmware/util/datalogging.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/firmware/util/datalogging.cpp b/firmware/util/datalogging.cpp index eaebaf57fb..5d751950c9 100644 --- a/firmware/util/datalogging.cpp +++ b/firmware/util/datalogging.cpp @@ -82,19 +82,11 @@ void append(Logging *logging, const char *text) { * @note This method if fast because it does not validate much, be sure what you are doing */ void appendFast(Logging *logging, const char *text) { -// todo: fix this implementation? this would be a one-pass implementation instead of a two-pass - register char *s; - for (s = (char *) text; *s; ++s) - ; - int extraLen = (s - text); - s = logging->linePointer; while ((*s++ = *text++) != 0) ; - -// strcpy(logging->linePointer, text); - logging->linePointer += extraLen; + logging->linePointer = s - 1; } // todo: look into chsnprintf once on Chibios 3 From e6e75ab888dd7bff6763e1bd82671c51642784fd Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 3 Jun 2017 22:12:44 -0400 Subject: [PATCH 03/36] reducing complexity just a bit --- firmware/util/datalogging.cpp | 8 ++------ firmware/util/datalogging.h | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/firmware/util/datalogging.cpp b/firmware/util/datalogging.cpp index 5d751950c9..9f24a01285 100644 --- a/firmware/util/datalogging.cpp +++ b/firmware/util/datalogging.cpp @@ -212,11 +212,6 @@ void printWithLength(char *line) { consoleOutputBuffer((const uint8_t *) line, p - line); } -void printLine(Logging *logging) { - printWithLength(logging->buffer); - resetLogging(logging); -} - void appendMsgPrefix(Logging *logging) { append(logging, "msg" DELIMETER); } @@ -250,7 +245,8 @@ void printMsg(Logging *logger, const char *fmt, ...) { va_end(ap); append(logger, DELIMETER); - printLine(logger); + printWithLength(logger->buffer); + resetLogging(logger); } /** diff --git a/firmware/util/datalogging.h b/firmware/util/datalogging.h index 87d8cfb89b..1999dc5af5 100644 --- a/firmware/util/datalogging.h +++ b/firmware/util/datalogging.h @@ -56,7 +56,6 @@ void debugFloat(Logging *logging, const char *text, float value, int precision); void appendFloat(Logging *logging, float value, int precision); void resetLogging(Logging *logging); -void printLine(Logging *logging); void appendMsgPrefix(Logging *logging); void appendMsgPostfix(Logging *logging); From 382f28daf1ffd1fff013a50c6ef4e2c957d4a22d Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 3 Jun 2017 22:27:05 -0400 Subject: [PATCH 04/36] minor improvements --- firmware/console/status_loop.cpp | 5 ++++- firmware/util/loggingcentral.cpp | 10 ++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index c607f4d343..a5f41dc5fd 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -432,6 +432,7 @@ static void printInfo(systime_t nowSeconds) { static systime_t timeOfPreviousReport = (systime_t) -1; extern fatal_msg_t errorMessageBuffer; +extern bool consoleInBinaryMode; /** * @brief Sends all pending data to dev console @@ -442,7 +443,9 @@ void updateDevConsoleState(void) { } // looks like this is not needed anymore // checkIfShouldHalt(); - printPending(); + if (!consoleInBinaryMode) { + printPending(); + } /** * this should go before the firmware error so that console can detect connection diff --git a/firmware/util/loggingcentral.cpp b/firmware/util/loggingcentral.cpp index c905021f55..84f0c68046 100644 --- a/firmware/util/loggingcentral.cpp +++ b/firmware/util/loggingcentral.cpp @@ -73,7 +73,7 @@ char * swapOutputBuffers(int *actualOutputBufferSize) { int expectedOutputSize; #endif /* EFI_ENABLE_ASSERTS */ { // start of critical section - lockOutputBuffer(); + bool alreadyLocked = lockOutputBuffer(); /** * we cannot output under syslock, we simply rotate which buffer is which */ @@ -88,7 +88,9 @@ char * swapOutputBuffers(int *actualOutputBufferSize) { accumulatedSize = 0; accumulationBuffer[0] = 0; - unlockOutputBuffer(); + if (!alreadyLocked) { + unlockOutputBuffer(); + } } // end of critical section *actualOutputBufferSize = efiStrlen(outputBuffer); @@ -104,16 +106,12 @@ char * swapOutputBuffers(int *actualOutputBufferSize) { return outputBuffer; } -extern bool consoleInBinaryMode; - /** * This method actually sends all the pending data to the communication layer. * This method is invoked by the main thread - that's the only thread which should be sending * actual data to console in order to avoid concurrent access to serial hardware. */ void printPending(void) { - if (consoleInBinaryMode) - return; int actualOutputBufferSize; char *output = swapOutputBuffers(&actualOutputBufferSize); From 0816278de29cf81d35b68ceecaadaf368911e0d7 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 3 Jun 2017 22:43:05 -0400 Subject: [PATCH 05/36] minor fix --- firmware/controllers/error_handling.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/controllers/error_handling.cpp b/firmware/controllers/error_handling.cpp index 1b47996135..3f7c4fe011 100644 --- a/firmware/controllers/error_handling.cpp +++ b/firmware/controllers/error_handling.cpp @@ -171,9 +171,9 @@ void onUnlockHook(void) { if (lockedDuration > maxLockedDuration) { maxLockedDuration = lockedDuration; } -// if (t > 2800) { +// if (lockedDuration > 2800) { // // un-comment this if you want a nice stop for a breakpoint -// maxLockTime = t + 1; +// maxLockedDuration = lockedDuration + 1; // } } From fc17b7f12ded4dc15ed268eb23df25e26149a2f4 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 3 Jun 2017 23:36:34 -0400 Subject: [PATCH 06/36] docs --- firmware/controllers/system/event_queue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/controllers/system/event_queue.cpp b/firmware/controllers/system/event_queue.cpp index 4581488e1f..9c669018f5 100644 --- a/firmware/controllers/system/event_queue.cpp +++ b/firmware/controllers/system/event_queue.cpp @@ -50,7 +50,7 @@ bool EventQueue::insertTask(scheduling_s *scheduling, efitime_t timeX, schfunc_t #if EFI_UNIT_TEST || defined(__DOXYGEN__) printf("Already scheduled was %d\r\n", (int)scheduling->momentX); printf("Already scheduled now %d\r\n", (int)timeX); -#endif /* EFI_UNIT_TEST || EFI_SIMULATOR */ +#endif /* EFI_UNIT_TEST */ return false; } From e88598d324d73f84f8739b525ed9f2264b87e3eb Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 4 Jun 2017 15:48:53 +0300 Subject: [PATCH 07/36] stopTsPort() needed by Bluetooth setup code --- firmware/console/binary/tunerstudio_io.cpp | 30 ++++++++++++++++++++++ firmware/console/binary/tunerstudio_io.h | 1 + 2 files changed, 31 insertions(+) diff --git a/firmware/console/binary/tunerstudio_io.cpp b/firmware/console/binary/tunerstudio_io.cpp index b18e2e4883..79d3bbbb79 100644 --- a/firmware/console/binary/tunerstudio_io.cpp +++ b/firmware/console/binary/tunerstudio_io.cpp @@ -124,6 +124,36 @@ void startTsPort(ts_channel_s *tsChannel) { #endif /* EFI_PROD_CODE */ } +bool stopTsPort(ts_channel_s *tsChannel) { +#if EFI_PROD_CODE || defined(__DOXYGEN__) +#if EFI_USB_SERIAL || defined(__DOXYGEN__) + if (isCommandLineConsoleOverTTL()) { +#if 0 + usb_serial_stop(); +#endif + // don't stop USB! + return false; + } else +#endif + { + if (boardConfiguration->useSerialPort) { + // todo: disable Rx/Tx pads? +#if TS_UART_DMA_MODE + uartStop(TS_DMA_UART_DEVICE); +#else + sdStop(TS_SERIAL_UART_DEVICE); +#endif /* TS_UART_DMA_MODE */ + } + } + + tsChannel->channel = (BaseChannel *) NULL; + return true; +#else /* EFI_PROD_CODE */ + // don't stop simulator! + return false; +#endif /* EFI_PROD_CODE */ +} + void sr5WriteData(ts_channel_s *tsChannel, const uint8_t * buffer, int size) { efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 64, "tunerStudioWriteData"); #if EFI_SIMULATOR || defined(__DOXYGEN__) diff --git a/firmware/console/binary/tunerstudio_io.h b/firmware/console/binary/tunerstudio_io.h index d7e2bd69b2..b34a3ae9b1 100644 --- a/firmware/console/binary/tunerstudio_io.h +++ b/firmware/console/binary/tunerstudio_io.h @@ -90,6 +90,7 @@ typedef struct { void startTsPort(ts_channel_s *tsChannel); +bool stopTsPort(ts_channel_s *tsChannel); // that's 1 second #define BINARY_IO_TIMEOUT MS2ST(1000) From 06b345c9ef472e23e166a5e9d7ef187836676848 Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 4 Jun 2017 15:50:31 +0300 Subject: [PATCH 08/36] Bluetooth setup code integration --- firmware/config/stm32f4ems/efifeatures.h | 5 +++++ firmware/console/binary/tunerstudio.cpp | 19 +++++++++++++++++++ firmware/console/binary/tunerstudio.mk | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/firmware/config/stm32f4ems/efifeatures.h b/firmware/config/stm32f4ems/efifeatures.h index d64b9c31ba..29512c5bbb 100644 --- a/firmware/config/stm32f4ems/efifeatures.h +++ b/firmware/config/stm32f4ems/efifeatures.h @@ -56,6 +56,11 @@ */ #define EFI_TUNER_STUDIO TRUE +/** + * Bluetooth UART setup support. + */ +#define EFI_BLUETOOTH_SETUP FALSE + /** * TunerStudio debug output */ diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index 8f3e603417..d0377c59a3 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -73,6 +73,7 @@ #include "console_io.h" #include "crc.h" #include "fl_protocol.h" +#include "bluetooth.h" #include #include "engine_configuration.h" @@ -167,6 +168,13 @@ static void setTsSpeed(int value) { printTsStats(); } +#if EFI_BLUETOOTH_SETUP || defined(__DOXYGEN__) +// Bluetooth HC-06 module initialization start (it waits for disconnect and then communicates to the module) +static void bluetoothHC06(const char *baudRate, const char *name, const char *pinCode) { + bluetoothStart(&tsChannel, BLUETOOTH_HC_06, baudRate, name, pinCode); +} +#endif /* EFI_BLUETOOTH_SETUP */ + void tunerStudioDebug(const char *msg) { #if EFI_TUNER_STUDIO_VERBOSE || defined(__DOXYGEN__) scheduleMsg(&tsLogger, "%s", msg); @@ -452,6 +460,10 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel, bool isConsoleRedirect) { if (received != 1) { // tunerStudioError("ERROR: no command"); +#if EFI_BLUETOOTH_SETUP || defined(__DOXYGEN__) + // assume there's connection loss and notify the bluetooth init code + bluetoothSoftwareDisconnectNotify(); +#endif /* EFI_BLUETOOTH_SETUP */ continue; } onDataArrived(); @@ -828,6 +840,13 @@ void startTunerStudioConnectivity(void) { addConsoleAction("tsinfo", printTsStats); addConsoleAction("reset_ts", resetTs); addConsoleActionI("set_ts_speed", setTsSpeed); + +#if EFI_BLUETOOTH_SETUP || defined(__DOXYGEN__) + // Usage: "bluetooth_hc06 " + // Example: "bluetooth_hc06 38400 rusefi 1234" + addConsoleActionSSS("bluetooth_hc06", bluetoothHC06); + addConsoleAction("bluetooth_cancel", bluetoothCancel); +#endif /* EFI_BLUETOOTH_SETUP */ chThdCreateStatic(tsThreadStack, sizeof(tsThreadStack), NORMALPRIO, (tfunc_t)tsThreadEntryPoint, NULL); } diff --git a/firmware/console/binary/tunerstudio.mk b/firmware/console/binary/tunerstudio.mk index 6620966dd2..0126d71c85 100644 --- a/firmware/console/binary/tunerstudio.mk +++ b/firmware/console/binary/tunerstudio.mk @@ -1,3 +1,4 @@ TUNERSTUDIO_SRC_CPP = $(PROJECT_DIR)/console/binary/tunerstudio_io.cpp \ - $(PROJECT_DIR)/console/binary/tunerstudio.cpp + $(PROJECT_DIR)/console/binary/tunerstudio.cpp \ + $(PROJECT_DIR)/console/binary/bluetooth.cpp From e7bc494c5335b94458170640532ff9d271318133 Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 4 Jun 2017 15:52:44 +0300 Subject: [PATCH 09/36] Bluetooth setup, initial code --- firmware/console/binary/bluetooth.cpp | 263 +++++++++++++++++++ firmware/console/binary/bluetooth.h | 45 ++++ firmware/console/binary/bluetooth_readme.txt | 38 +++ 3 files changed, 346 insertions(+) create mode 100644 firmware/console/binary/bluetooth.cpp create mode 100644 firmware/console/binary/bluetooth.h create mode 100644 firmware/console/binary/bluetooth_readme.txt diff --git a/firmware/console/binary/bluetooth.cpp b/firmware/console/binary/bluetooth.cpp new file mode 100644 index 0000000000..8f83f97f7a --- /dev/null +++ b/firmware/console/binary/bluetooth.cpp @@ -0,0 +1,263 @@ +#include "main.h" + +#include "engine_state.h" +#include "tunerstudio.h" + +#include "tunerstudio_io.h" +#include "bluetooth.h" +#include "engine_configuration.h" + +#if EFI_BLUETOOTH_SETUP || defined(__DOXYGEN__) + +static bool btProcessIsStarted = false; +static bool btProcessIsRunning = false; +static const char *commands[5]; +static int numCommands = 0; +static int setBaudIdx = -1; + +static char cmdBaud[10]; +static char cmdName[30]; +static char cmdPin[16]; + +static const int baudRates[] = { 0, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, -1 }; +static const int baudRateIndexList[] = { 4 /*9600*/, 6 /*38400*/, 8 /*115200*/, 7, 5, 3, 2, 1, -1 }; +static const int btModuleTimeout = MS2ST(1000); + +static ts_channel_s *tsChannel; + + +static THD_WORKING_AREA(btThreadStack, UTILITY_THREAD_STACK_SIZE); +static thread_t *btThread = NULL; +static thread_reference_t btThreadRef = NULL; // used by thread suspend/resume as a flag + +static LoggingWithStorage btLogger("bluetooth"); + + +EXTERN_ENGINE +; + + +// Main communication code +// We assume that the user has disconnected the software before starting the code. +static void runCommands() { + uint8_t buffer[2]; + + if (!btProcessIsStarted) + return; + + // Store current serial port speed - we're going to change it + int savedSerialSpeed = boardConfiguration->tunerStudioSerialSpeed; + + int prevBaudIdx = -1, baudIdx = -1, baudListIdx = 0; + int cmdIdx = 0; + + // run all commands + while (true) { + if (baudIdx < 0) { + // try all available baud rates, in order of preference + baudIdx = baudRateIndexList[baudListIdx++]; + // we've tried all baud rates? + if (baudIdx < 0) + break; + } + + bool restoreAndExit = (cmdIdx >= numCommands || baudIdx < 0); + + // if the baud rate is changed, reinit the UART + if (baudIdx != prevBaudIdx || restoreAndExit) { + // deinit UART + if (!stopTsPort(tsChannel)) { + scheduleMsg(&btLogger, "Failed! Cannot restart serial port connection!"); + return; + } + chThdSleepMilliseconds(10); // safety + // change the port speed + boardConfiguration->tunerStudioSerialSpeed = restoreAndExit ? savedSerialSpeed : baudRates[baudIdx]; + // init UART + startTsPort(tsChannel); + chThdSleepMilliseconds(10); // safety + prevBaudIdx = baudIdx; + } + + // exit if all commands were sent + if (restoreAndExit) + break; + + // send current command + sr5WriteData(tsChannel, (uint8_t *)commands[cmdIdx], strlen(commands[cmdIdx])); + + // waiting for an answer + bool wasAnswer = false; + if (sr5ReadDataTimeout(tsChannel, buffer, 2, btModuleTimeout) == 2) { + wasAnswer = (buffer[0] == 'O' && buffer[1] == 'K'); + } + + // wait 1 second and skip all remaining response bytes from the bluetooth module + while (true) { + if (sr5ReadDataTimeout(tsChannel, buffer, 1, btModuleTimeout) < 1) + break; + } + + if (wasAnswer) { + // if we changed the baud rate + if (commands[cmdIdx] == cmdBaud) { + // this is what we've set + baudIdx = setBaudIdx; + // if we fail somehow, try all other baud rates + baudListIdx = 0; + } + // move to the next command + cmdIdx++; + } else { + // try other baud rate + baudIdx = -1; + } + } + + // the connection is already restored to the current baud rate, so print the result + if (cmdIdx == numCommands) + scheduleMsg(&btLogger, "SUCCESS! All commands (%d of %d) passed to the Bluetooth module!", cmdIdx, numCommands); + else + scheduleMsg(&btLogger, "FAIL! Only %d commands (of %d total) were passed to the Bluetooth module!", cmdIdx, numCommands); +} + +static THD_FUNCTION(btThreadEntryPoint, arg) { + (void) arg; + chRegSetThreadName("bluetooth thread"); + + scheduleMsg(&btLogger, "*** Bluetooth module setup procedure ***"); + scheduleMsg(&btLogger, "!Warning! Please make sure you're not currently using the BT module for communication (not paired)!"); + scheduleMsg(&btLogger, "TO START THE PROCEDURE: PLEASE DISCONNECT YOUR PC COM-PORT FROM THE BOARD NOW!"); + scheduleMsg(&btLogger, "After that please don't turn off the board power and wait for ~15 seconds to complete. Then reconnect to the board!"); + + // now wait + chSysLock(); + msg_t msg = chThdSuspendTimeoutS(&btThreadRef, BLUETOOTH_COMMAND_TIMEOUT); + chSysUnlock(); + + if (msg == MSG_TIMEOUT) { + scheduleMsg(&btLogger, "The Bluetooth module init procedure is cancelled (timeout)!"); + return; + } else { + // call this when the thread is resumed (after the disconnect) + btProcessIsRunning = true; + runCommands(); + btProcessIsRunning = false; + } + + // release the command + btProcessIsStarted = false; + chThdExit(MSG_OK); +} + +void bluetoothStart(ts_channel_s *tsChan, bluetooth_module_e moduleType, const char *baudRate, const char *name, const char *pinCode) { + static const char *usage = "Usage: bluetooth_hc06 "; + + tsChannel = tsChan; + + // if a binary protocol uses USB, we cannot init the bluetooth module! + if (!boardConfiguration->useSerialPort) { + scheduleMsg(&btLogger, "Failed! Serial Port connection is disabled!"); + return; + } + + if (btProcessIsStarted) { + scheduleMsg(&btLogger, "The Bluetooth module init procedure is already started and waiting! To cancel it, run \"bluetooth_cancel\" command!"); + return; + } + + // todo: add support for other BT module types + if (moduleType != BLUETOOTH_HC_06) { + scheduleMsg(&btLogger, "This Bluetooth module is currently not supported!"); + return; + } + + numCommands = 0; + + // now check the arguments and add other commands: + // 1) baud rate + int baud = (baudRate != NULL) ? atoi(baudRate) : 0; + int i; + // find a known baud rate in our list + setBaudIdx = -1; + for (i = 1; baudRates[i] > 0; i++) { + if (baudRates[i] == baud) { + setBaudIdx = i; + break; + } + } + // check the baud rate index + if (setBaudIdx < 1) { + if (baud == 0) + scheduleMsg(&btLogger, "The parameter is set to zero! The baud rate won't be set!"); + else { + // unknown baud rate + scheduleMsg(&btLogger, "Wrong parameter '%s'! %s", baudRate, usage); + return; + } + } else { + // ok, add command! + + } + + // 2) check name + if (name == NULL || strlen(name) < 1 || strlen(name) > 20) { + scheduleMsg(&btLogger, "Wrong parameter! Up to 20 characters expected! %s", usage); + return; + } + + // 3) check pin code + int numDigits = 0; + // check the pincode + if (pinCode != NULL && strlen(pinCode) == 4) { + for (i = 0; i < 4; i++) { + if (pinCode[i] >= '0' && pinCode[i] <= '9') // digit + numDigits++; + } + } + if (numDigits != 4) { + scheduleMsg(&btLogger, "Wrong parameter! 4 digits expected! %s", usage); + return; + } + + // ok, add commands! + commands[numCommands++] = "AT"; // this command is added to test a connection + chsnprintf(cmdBaud, sizeof(cmdBaud), "AT+BAUD%c", '0' + setBaudIdx); + commands[numCommands++] = cmdBaud; + chsnprintf(cmdName, sizeof(cmdName), "AT+NAME%s", name); + commands[numCommands++] = cmdName; + chsnprintf(cmdPin, sizeof(cmdPin), "AT+PIN%s", pinCode); + commands[numCommands++] = cmdPin; + + // create a thread to execute these commands later + btThread = chThdCreateStatic(btThreadStack, sizeof(btThreadStack), NORMALPRIO, (tfunc_t)btThreadEntryPoint, NULL); + + btProcessIsStarted = true; +} + +void bluetoothSoftwareDisconnectNotify() { + if (btProcessIsStarted) { + // start communication with the module + chThdResume(&btThreadRef, MSG_OK); + // wait the thread to finish + chThdWait(btThread); + } +} + +void bluetoothCancel() { + if (!btProcessIsStarted) { + scheduleMsg(&btLogger, "The Bluetooth module init procedure was not started! Nothing to cancel!"); + return; + } + + if (btProcessIsRunning) + return; + + // terminate thread + chThdTerminate(btThread); + + btProcessIsStarted = false; + scheduleMsg(&btLogger, "The Bluetooth module init procedure is cancelled!"); +} + +#endif /* EFI_BLUETOOTH_SETUP */ diff --git a/firmware/console/binary/bluetooth.h b/firmware/console/binary/bluetooth.h new file mode 100644 index 0000000000..87e0b69b08 --- /dev/null +++ b/firmware/console/binary/bluetooth.h @@ -0,0 +1,45 @@ +/** + * @file tunerstudio.h + * + * @date Aug 26, 2013 + * @author Andrey Belomutskiy, (c) 2012-2017 + */ + +#ifndef BLUETOOTH_H_ +#define BLUETOOTH_H_ + +#include "main.h" +#include "tunerstudio_io.h" + + +// The Bluetooth setup procedure will wait 10 seconds for the user to disconnect the UART cable. +// This is required because the BT setup procedure reads a response from the module during the communication. +// Thus any bytes sent from the Console Software may interfere with the procedure. +#define BLUETOOTH_COMMAND_TIMEOUT MS2ST(10000) + +// Supported Bluetooth module types +typedef enum { + BLUETOOTH_HC_06, +} bluetooth_module_e; + +/** + * Start Bluetooth module initialization using UART connection: + * - wait for PC communication disconnect; + * - reconfigure the UART; + * - send AT-commands to the module; + * - restore connection to PC. + */ +void bluetoothStart(ts_channel_s *tsChannel, bluetooth_module_e moduleType, const char *baudRate, const char *name, const char *pinCode); + +/** + * Cancel Bluetooth procedure + */ +void bluetoothCancel(void); + +/** + * Called by runBinaryProtocolLoop() if a connection disconnect is detected. + * Bluetooth init code needs to make sure that there's no interference of the BT module and USB-UART (connected to PC) + */ +void bluetoothSoftwareDisconnectNotify(); + +#endif /* BLUETOOTH_H_ */ diff --git a/firmware/console/binary/bluetooth_readme.txt b/firmware/console/binary/bluetooth_readme.txt new file mode 100644 index 0000000000..9c0831b352 --- /dev/null +++ b/firmware/console/binary/bluetooth_readme.txt @@ -0,0 +1,38 @@ +Bluetooth module setup procedure. User Manual. + +To activate your Bluetooth module, you'll need: +1) Connect your PC to the rusEFI board using UART cable. +2) Run "rusEFI Console" software. +3) Turn on the board power and wait for the console connection. +4) Type the following command: + "bluetooth_hc06 " + Where: + - is the baud rate of the Bluetooth connection. Allowed values are: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200. + Please set this to the baud rate currently used by your UART console. + - is the name of your Bluetooth connection. It will be visible in the device list on your PC. + - is 4-digit PIN-code needed to authorize the Bluetooth connection to your PC. + Example: "bluetooth_hc06 38400 rusefi 1234" +5) After entering the command the following text will appear: + *** Bluetooth module setup procedure *** + !Warning! Please make sure you're not currently using the BT module for communication (not paired)! + TO START THE PROCEDURE: PLEASE DISCONNECT YOUR PC COM-PORT FROM THE BOARD NOW! + After that please don't turn off the board power and wait for ~15 seconds to complete. Then reconnect to the board! +6) If you ignore this message and do nothing, the Bluetooth secup procedure will be cancelled in 10 seconds. + You can also use "bluetooth_cancel" command to cancel it. +7) If you disconnect the UART cable or close the software, then the procedure will begin. +8) It takes up to 15 seconds to complete. The Bluetooth LED may blink several times during the procedure - it's normal. +9) After that, you may restore the UART connection to your PC or start using Bluetooth module. + + +*** Developers Section *** + +How it works, in two words: +- adds 2 new commands: "bluetooth_hc06(baud, name, pincode)" and "bluetooth_cancel"; +- adds stopTsPort() to tunerstudio_io - needed to change the baud rate on fly; +- added bluetoothSoftwareDisconnectNotify() handler to runBinaryProtocolLoop() - to detect UART disconnects; +- added a thread with btThreadEntryPoint(): + - It will wait up to 10 seconds for the user to disconnect the UART cable. + This is required because the BT setup procedure reads a response from the module during the communication - using the same UART. + Thus any bytes sent from the Console Software may interfere with the procedure. +- added bluetoothStart() which processes user input and creates a command list; +- added runCommands() where all the Bluetooth magic happens! From 28eab796d895fa6c3afa5640a563f3c01b7baada Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 4 Jun 2017 18:23:48 +0300 Subject: [PATCH 10/36] Bluetooth fix win32 simulator compile error --- simulator/simulator/efifeatures.h | 1 + 1 file changed, 1 insertion(+) diff --git a/simulator/simulator/efifeatures.h b/simulator/simulator/efifeatures.h index 9ad90ff434..1f502d4fc9 100644 --- a/simulator/simulator/efifeatures.h +++ b/simulator/simulator/efifeatures.h @@ -85,6 +85,7 @@ #define EFI_HISTOGRAMS FALSE #define EFI_TUNER_STUDIO TRUE +#define EFI_BLUETOOTH_SETUP FALSE /** * This is the size of the MemoryStream used by chvprintf From b7c0e62e68a3021e38bfda24aa2acbe8b8fe58dc Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 11:26:12 -0400 Subject: [PATCH 11/36] fixing build --- simulator/simulator/efifeatures.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/simulator/simulator/efifeatures.h b/simulator/simulator/efifeatures.h index 9ad90ff434..22b9cb4520 100644 --- a/simulator/simulator/efifeatures.h +++ b/simulator/simulator/efifeatures.h @@ -14,6 +14,8 @@ #define EFI_PRINTF_FUEL_DETAILS TRUE +#define EFI_BLUETOOTH_SETUP FALSE + #define EFI_GPIO_HARDWARE FALSE #define EFI_CLOCK_LOCKS FALSE From 1e77f1b1f27f06a9c45538db9cb36ee9bc2609f9 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 11:26:37 -0400 Subject: [PATCH 12/36] #437 --- firmware/console/eficonsole.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/firmware/console/eficonsole.cpp b/firmware/console/eficonsole.cpp index 17922b9324..decfc9f883 100644 --- a/firmware/console/eficonsole.cpp +++ b/firmware/console/eficonsole.cpp @@ -56,9 +56,6 @@ static void sayHello(void) { #ifdef CH_FREQUENCY scheduleMsg(&logger, "CH_FREQUENCY=%d", CH_FREQUENCY); #endif -#ifdef SERIAL_SPEED - scheduleMsg(&logger, "SERIAL_SPEED=%d", SERIAL_SPEED); -#endif #ifdef CORTEX_MAX_KERNEL_PRIORITY scheduleMsg(&logger, "CORTEX_MAX_KERNEL_PRIORITY=%d", CORTEX_MAX_KERNEL_PRIORITY); From c150329d62033a18b5198eb31e5298703c167596 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 11:31:20 -0400 Subject: [PATCH 13/36] #437 --- firmware/console/console_io.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/firmware/console/console_io.cpp b/firmware/console/console_io.cpp index 62958600c2..467e7e33c1 100644 --- a/firmware/console/console_io.cpp +++ b/firmware/console/console_io.cpp @@ -138,7 +138,7 @@ bool isCommandLineConsoleOverTTL(void) { } #if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR ) || defined(__DOXYGEN__) -static SerialConfig serialConfig = { SERIAL_SPEED, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 }; +static SerialConfig serialConfig = { 0, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 }; #endif bool consoleInBinaryMode = false; @@ -256,9 +256,10 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p) if (isCommandLineConsoleOverTTL()) { /* - * Activates the serial using the driver default configuration (that's 38400) + * Activates the serial * it is important to set 'NONE' as flow control! in terminal application on the PC */ + serialConfig.speed = engineConfiguration->uartConsoleSerialSpeed; sdStart(EFI_CONSOLE_UART_DEVICE, &serialConfig); // cannot use pin repository here because pin repository prints to console From c5f9828bc282363d2033354aeae483e5e40683b4 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 12:21:31 -0400 Subject: [PATCH 14/36] fixed #437 --- firmware/config/stm32f4ems/efifeatures.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/firmware/config/stm32f4ems/efifeatures.h b/firmware/config/stm32f4ems/efifeatures.h index 29512c5bbb..e8c1e8300b 100644 --- a/firmware/config/stm32f4ems/efifeatures.h +++ b/firmware/config/stm32f4ems/efifeatures.h @@ -45,12 +45,6 @@ */ #define EFI_WAVE_ANALYZER TRUE -//#define SERIAL_SPEED (8 * 115200) -//#define SERIAL_SPEED (2 * 115200) -//todo: make this configurable via Tuner Studio -//todo: see uartConsoleSerialSpeed -#define SERIAL_SPEED 115200 - /** * TunerStudio support. */ From 9623b3938b793aeec7b009809a3fce73499c09f1 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 4 Jun 2017 12:59:24 -0400 Subject: [PATCH 15/36] good enough solution for now #435 --- firmware/controllers/math/pid.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/firmware/controllers/math/pid.cpp b/firmware/controllers/math/pid.cpp index e28585fea8..bcf553e52d 100644 --- a/firmware/controllers/math/pid.cpp +++ b/firmware/controllers/math/pid.cpp @@ -53,8 +53,9 @@ float Pid::getValue(float target, float input, float dTime) { if (iTerm > pid->maxValue) iTerm = pid->maxValue; - if (iTerm < pid->minValue) - iTerm = pid->minValue; + // this is kind of a hack. a proper fix would be having separate additional settings 'maxIValue' and 'minIValye' + if (iTerm < -pid->maxValue) + iTerm = -pid->maxValue; float result = pTerm + iTerm + dTerm + pid->offset; if (result > pid->maxValue) { From 2f9623555c898a1a6014129e512b67ade577f2ba Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 4 Jun 2017 13:07:22 -0400 Subject: [PATCH 16/36] ETB --- firmware/integration/rusefi_config.txt | 4 +- firmware/tunerstudio/rusefi.ini | 65 +++++++++++++------------- firmware/tunerstudio/rusefi.input | 27 +++++------ 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 9c54a62bc0..7b25b6750f 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -107,8 +107,8 @@ struct pid_s float dFactor;;"value", 1, 0, -1000, 1000, 5 int16_t offset;Linear addition to PID logic;"value", 1, 0, 0, 1000, 0 int16_t period;PID dTime;"ms", 1, 0, 0, 3000, 0 - int16_t minValue;;"v", 1, 0, 0, 3000.0, 3 - int16_t maxValue;;"v", 1, 0, 0, 3000.0, 3 + int16_t minValue;;"", 1, 0, 0, 3000.0, 3 + int16_t maxValue;;"", 1, 0, 0, 3000.0, 3 end_struct struct cranking_parameters_s diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index 99ef785d24..a68ada366c 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -45,7 +45,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Mon May 29 22:21:18 EDT 2017 +; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jun 04 13:06:50 EDT 2017 pageSize = 16376 page = 1 @@ -514,22 +514,22 @@ page = 1 alternatorControl_dFactor = scalar, F32, 1836, "value", 1, 0, -1000, 1000, 5 alternatorControl_offset = scalar, S16, 1840, "value", 1, 0, 0, 1000, 0 alternatorControl_period = scalar, S16, 1842, "ms", 1, 0, 0, 3000, 0 - alternatorControl_minValue = scalar, S16, 1844, "v", 1, 0, 0, 3000.0, 3 - alternatorControl_maxValue = scalar, S16, 1846, "v", 1, 0, 0, 3000.0, 3 + alternatorControl_minValue = scalar, S16, 1844, "", 1, 0, 0, 3000.0, 3 + alternatorControl_maxValue = scalar, S16, 1846, "", 1, 0, 0, 3000.0, 3 etb_pFactor = scalar, F32, 1848, "value", 1, 0, -1000, 1000, 5 etb_iFactor = scalar, F32, 1852, "value", 1, 0, -1000, 1000, 5 etb_dFactor = scalar, F32, 1856, "value", 1, 0, -1000, 1000, 5 etb_offset = scalar, S16, 1860, "value", 1, 0, 0, 1000, 0 etb_period = scalar, S16, 1862, "ms", 1, 0, 0, 3000, 0 - etb_minValue = scalar, S16, 1864, "v", 1, 0, 0, 3000.0, 3 - etb_maxValue = scalar, S16, 1866, "v", 1, 0, 0, 3000.0, 3 + etb_minValue = scalar, S16, 1864, "", 1, 0, 0, 3000.0, 3 + etb_maxValue = scalar, S16, 1866, "", 1, 0, 0, 3000.0, 3 warmupAfrPid_pFactor = scalar, F32, 1868, "value", 1, 0, -1000, 1000, 5 warmupAfrPid_iFactor = scalar, F32, 1872, "value", 1, 0, -1000, 1000, 5 warmupAfrPid_dFactor = scalar, F32, 1876, "value", 1, 0, -1000, 1000, 5 warmupAfrPid_offset = scalar, S16, 1880, "value", 1, 0, 0, 1000, 0 warmupAfrPid_period = scalar, S16, 1882, "ms", 1, 0, 0, 3000, 0 - warmupAfrPid_minValue = scalar, S16, 1884, "v", 1, 0, 0, 3000.0, 3 - warmupAfrPid_maxValue = scalar, S16, 1886, "v", 1, 0, 0, 3000.0, 3 + warmupAfrPid_minValue = scalar, S16, 1884, "", 1, 0, 0, 3000.0, 3 + warmupAfrPid_maxValue = scalar, S16, 1886, "", 1, 0, 0, 3000.0, 3 mapErrorDetectionTooLow = scalar, F32, 1888, "kPa", 1, 0, -100.0, 100.0, 2 mapErrorDetectionTooHigh = scalar, F32, 1892, "kPa", 1, 0, -100.0, 800.0, 2 step1RpmWindow = scalar, S32, 1896, "rpm", 1, 0, 0, 3000.0, 2 @@ -538,8 +538,8 @@ page = 1 idleRpmPid_dFactor = scalar, F32, 1908, "value", 1, 0, -1000, 1000, 5 idleRpmPid_offset = scalar, S16, 1912, "value", 1, 0, 0, 1000, 0 idleRpmPid_period = scalar, S16, 1914, "ms", 1, 0, 0, 3000, 0 - idleRpmPid_minValue = scalar, S16, 1916, "v", 1, 0, 0, 3000.0, 3 - idleRpmPid_maxValue = scalar, S16, 1918, "v", 1, 0, 0, 3000.0, 3 + idleRpmPid_minValue = scalar, S16, 1916, "", 1, 0, 0, 3000.0, 3 + idleRpmPid_maxValue = scalar, S16, 1918, "", 1, 0, 0, 3000.0, 3 addedToWallCoef = scalar, F32, 1920, "%", 1, 0, 0.0, 300.0, 2 communicationPin = bits, U32, 1924, [0:6], "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PA8", "PA9", "PA10", "PA11", "PA12", "PA13", "PA14", "PA15", "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", "PB8", "PB9", "PB10", "PB11", "PB12", "PB13", "PB14", "PB15", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15", "PD0", "PD1", "PD2", "PD3", "PD4", "PD5", "PD6", "PD7", "PD8", "PD9", "PD10", "PD11", "PD12", "PD13", "PD14", "PD15", "PE0", "PE1", "PE2", "PE3", "PE4", "PE5", "PE6", "PE7", "PE8", "PE9", "PE10", "PE11", "PE12", "PE13", "PE14", "PE15", "NONE", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" runningPin = bits, U32, 1928, [0:6], "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PA8", "PA9", "PA10", "PA11", "PA12", "PA13", "PA14", "PA15", "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", "PB8", "PB9", "PB10", "PB11", "PB12", "PB13", "PB14", "PB15", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15", "PD0", "PD1", "PD2", "PD3", "PD4", "PD5", "PD6", "PD7", "PD8", "PD9", "PD10", "PD11", "PD12", "PD13", "PD14", "PD15", "PE0", "PE1", "PE2", "PE3", "PE4", "PE5", "PE6", "PE7", "PE8", "PE9", "PE10", "PE11", "PE12", "PE13", "PE14", "PE15", "NONE", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" @@ -650,8 +650,8 @@ page = 1 fuelClosedLoopPid_dFactor = scalar, F32, 2748, "value", 1, 0, -1000, 1000, 5 fuelClosedLoopPid_offset = scalar, S16, 2752, "value", 1, 0, 0, 1000, 0 fuelClosedLoopPid_period = scalar, S16, 2754, "ms", 1, 0, 0, 3000, 0 - fuelClosedLoopPid_minValue = scalar, S16, 2756, "v", 1, 0, 0, 3000.0, 3 - fuelClosedLoopPid_maxValue = scalar, S16, 2758, "v", 1, 0, 0, 3000.0, 3 + fuelClosedLoopPid_minValue = scalar, S16, 2756, "", 1, 0, 0, 3000.0, 3 + fuelClosedLoopPid_maxValue = scalar, S16, 2758, "", 1, 0, 0, 3000.0, 3 fuelClosedLoopAfrHighThreshold = scalar, F32, 2760, "ratio", 1, 0, 0, 100, 1 stepperEnablePinMode = bits, U32, 2764, [0:5], "default", "INVALID", "INVALID", "INVALID", "opendrain", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "mode12", "mode13", "mode14", "mode15", "mode16", "mode17", "mode18", "mode19", "mode20", "mode21", "mode22", "mode23", "mode24", "mode25", "mode26", "mode27", "mode28", "mode29", "mode30", "mode31", "PULLUP", "mode33", "mode34", "mode35" cj125ua = bits, U32, 2768, [0:4] "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PB0", "PB1", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "Disabled", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" @@ -683,29 +683,29 @@ page = 1 auxPid1_dFactor = scalar, F32, 2872, "value", 1, 0, -1000, 1000, 5 auxPid1_offset = scalar, S16, 2876, "value", 1, 0, 0, 1000, 0 auxPid1_period = scalar, S16, 2878, "ms", 1, 0, 0, 3000, 0 - auxPid1_minValue = scalar, S16, 2880, "v", 1, 0, 0, 3000.0, 3 - auxPid1_maxValue = scalar, S16, 2882, "v", 1, 0, 0, 3000.0, 3 + auxPid1_minValue = scalar, S16, 2880, "", 1, 0, 0, 3000.0, 3 + auxPid1_maxValue = scalar, S16, 2882, "", 1, 0, 0, 3000.0, 3 auxPid2_pFactor = scalar, F32, 2884, "value", 1, 0, -1000, 1000, 5 auxPid2_iFactor = scalar, F32, 2888, "value", 1, 0, -1000, 1000, 5 auxPid2_dFactor = scalar, F32, 2892, "value", 1, 0, -1000, 1000, 5 auxPid2_offset = scalar, S16, 2896, "value", 1, 0, 0, 1000, 0 auxPid2_period = scalar, S16, 2898, "ms", 1, 0, 0, 3000, 0 - auxPid2_minValue = scalar, S16, 2900, "v", 1, 0, 0, 3000.0, 3 - auxPid2_maxValue = scalar, S16, 2902, "v", 1, 0, 0, 3000.0, 3 + auxPid2_minValue = scalar, S16, 2900, "", 1, 0, 0, 3000.0, 3 + auxPid2_maxValue = scalar, S16, 2902, "", 1, 0, 0, 3000.0, 3 auxPid3_pFactor = scalar, F32, 2904, "value", 1, 0, -1000, 1000, 5 auxPid3_iFactor = scalar, F32, 2908, "value", 1, 0, -1000, 1000, 5 auxPid3_dFactor = scalar, F32, 2912, "value", 1, 0, -1000, 1000, 5 auxPid3_offset = scalar, S16, 2916, "value", 1, 0, 0, 1000, 0 auxPid3_period = scalar, S16, 2918, "ms", 1, 0, 0, 3000, 0 - auxPid3_minValue = scalar, S16, 2920, "v", 1, 0, 0, 3000.0, 3 - auxPid3_maxValue = scalar, S16, 2922, "v", 1, 0, 0, 3000.0, 3 + auxPid3_minValue = scalar, S16, 2920, "", 1, 0, 0, 3000.0, 3 + auxPid3_maxValue = scalar, S16, 2922, "", 1, 0, 0, 3000.0, 3 auxPid4_pFactor = scalar, F32, 2924, "value", 1, 0, -1000, 1000, 5 auxPid4_iFactor = scalar, F32, 2928, "value", 1, 0, -1000, 1000, 5 auxPid4_dFactor = scalar, F32, 2932, "value", 1, 0, -1000, 1000, 5 auxPid4_offset = scalar, S16, 2936, "value", 1, 0, 0, 1000, 0 auxPid4_period = scalar, S16, 2938, "ms", 1, 0, 0, 3000, 0 - auxPid4_minValue = scalar, S16, 2940, "v", 1, 0, 0, 3000.0, 3 - auxPid4_maxValue = scalar, S16, 2942, "v", 1, 0, 0, 3000.0, 3 + auxPid4_minValue = scalar, S16, 2940, "", 1, 0, 0, 3000.0, 3 + auxPid4_maxValue = scalar, S16, 2942, "", 1, 0, 0, 3000.0, 3 ;skipping unusedEnd offset 2944 le_formulas1 = array, U08, 3048, [200],"char", 1, 0, 0.0, 3.0, 2 le_formulas2 = array, U08, 3248, [200],"char", 1, 0, 0.0, 3.0, 2 @@ -1242,7 +1242,7 @@ fileVersion = { 20161225 } massAirFlowValueGa = massAirFlowValue,"Air Flow", "kg/hr", 0, 50, -999, -999, 999, 999, 1, 1 veValueGauge = veValue, "fuel: VE", "", 0, 120, 10, 10, 100, 100, 1, 1 baroCorrectionGauge = baroCorrection,"BaroCorr", "%", 0, 120, 10, 10, 100, 100, 1, 1 - pedalPositionGauge = pedalPosition,"Pedal Position", "%", 0, 120, 10, 10, 100, 100, 1, 1 + pedalPositionGauge = pedalPosition,"Throttle Pedal Position", "%", 0, 120, 10, 10, 100, 100, 1, 1 knockCountGauge = knockCount,"Knock count", "count", 0, 120, 10, 10, 100, 100, 1, 1 knockLevelGauge = knockLevel,"Knock level", "volts", 0, 7, 10, 10, 100, 100, 1, 2 @@ -1775,7 +1775,7 @@ cmd_call_from_pit = "w\x00\x20\x34\x56" field = "AFR ADC input", afr_hwChannel field = "fuelLevelSensor", fuelLevelSensor field = "Baro ADC input", baroSensor_hwChannel - field = "pedal Position Channel", pedalPositionChannel + field = "Throttle pedal Position Channel", pedalPositionChannel field = "Primary input channel", triggerInputPins1 field = "Secondary channel", triggerInputPins2 field = "Cam Sync/VVT input", camInput @@ -2392,17 +2392,18 @@ cmd_call_from_pit = "w\x00\x20\x34\x56" field = "verbose", isVerboseETB field = "Throttle Pedal Up", throttlePedalUpVoltage field = "Throttle Pedal Wide Open", throttlePedalWOTVoltage - field = "PWM Frequency", etbFreq - field = "Dir #1", etbDirectionPin1 - field = "Dir #2", etbDirectionPin2 - field = "Control #1", etbControlPin1 - field = "Control #2", etbControlPin2 - field = "pFactor", etb_pFactor - field = "iFactor", etb_iFactor - field = "dFactor", etb_dFactor - field = "offset", etb_offset - field = "pid min", etb_minValue - field = "pid max", etb_maxValue + field = "PWM Frequency", etbFreq, {pedalPositionChannel != 16} + field = "Dir #1", etbDirectionPin1, {pedalPositionChannel != 16} + field = "Dir #2", etbDirectionPin2, {pedalPositionChannel != 16} + field = "Control #1", etbControlPin1, {pedalPositionChannel != 16} + field = "Control #2", etbControlPin2, {pedalPositionChannel != 16} + field = "pFactor", etb_pFactor, {pedalPositionChannel != 16} + field = "iFactor", etb_iFactor, {pedalPositionChannel != 16} + field = "dFactor", etb_dFactor, {pedalPositionChannel != 16} + field = "offset", etb_offset, {pedalPositionChannel != 16} + field = "control period", etb_period, {pedalPositionChannel != 16} + field = "pid min", etb_minValue, {pedalPositionChannel != 16} + field = "pid max", etb_maxValue, {pedalPositionChannel != 16} dialog = testSpark, "Spark" commandButton = "Spark #1", cmd_test_spk1 diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 601dad2598..3aa1431771 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -478,7 +478,7 @@ fileVersion = { 20161225 } massAirFlowValueGa = massAirFlowValue,"Air Flow", "kg/hr", 0, 50, -999, -999, 999, 999, 1, 1 veValueGauge = veValue, "fuel: VE", "", 0, 120, 10, 10, 100, 100, 1, 1 baroCorrectionGauge = baroCorrection,"BaroCorr", "%", 0, 120, 10, 10, 100, 100, 1, 1 - pedalPositionGauge = pedalPosition,"Pedal Position", "%", 0, 120, 10, 10, 100, 100, 1, 1 + pedalPositionGauge = pedalPosition,"Throttle Pedal Position", "%", 0, 120, 10, 10, 100, 100, 1, 1 knockCountGauge = knockCount,"Knock count", "count", 0, 120, 10, 10, 100, 100, 1, 1 knockLevelGauge = knockLevel,"Knock level", "volts", 0, 7, 10, 10, 100, 100, 1, 2 @@ -1011,7 +1011,7 @@ cmd_call_from_pit = "w\x00\x20\x34\x56" field = "AFR ADC input", afr_hwChannel field = "fuelLevelSensor", fuelLevelSensor field = "Baro ADC input", baroSensor_hwChannel - field = "pedal Position Channel", pedalPositionChannel + field = "Throttle pedal Position Channel", pedalPositionChannel field = "Primary input channel", triggerInputPins1 field = "Secondary channel", triggerInputPins2 field = "Cam Sync/VVT input", camInput @@ -1628,17 +1628,18 @@ cmd_call_from_pit = "w\x00\x20\x34\x56" field = "verbose", isVerboseETB field = "Throttle Pedal Up", throttlePedalUpVoltage field = "Throttle Pedal Wide Open", throttlePedalWOTVoltage - field = "PWM Frequency", etbFreq - field = "Dir #1", etbDirectionPin1 - field = "Dir #2", etbDirectionPin2 - field = "Control #1", etbControlPin1 - field = "Control #2", etbControlPin2 - field = "pFactor", etb_pFactor - field = "iFactor", etb_iFactor - field = "dFactor", etb_dFactor - field = "offset", etb_offset - field = "pid min", etb_minValue - field = "pid max", etb_maxValue + field = "PWM Frequency", etbFreq, {pedalPositionChannel != 16} + field = "Dir #1", etbDirectionPin1, {pedalPositionChannel != 16} + field = "Dir #2", etbDirectionPin2, {pedalPositionChannel != 16} + field = "Control #1", etbControlPin1, {pedalPositionChannel != 16} + field = "Control #2", etbControlPin2, {pedalPositionChannel != 16} + field = "pFactor", etb_pFactor, {pedalPositionChannel != 16} + field = "iFactor", etb_iFactor, {pedalPositionChannel != 16} + field = "dFactor", etb_dFactor, {pedalPositionChannel != 16} + field = "offset", etb_offset, {pedalPositionChannel != 16} + field = "control period", etb_period, {pedalPositionChannel != 16} + field = "pid min", etb_minValue, {pedalPositionChannel != 16} + field = "pid max", etb_maxValue, {pedalPositionChannel != 16} dialog = testSpark, "Spark" commandButton = "Spark #1", cmd_test_spk1 From 3b6ce7565c7c161f384fef0b137d6b474a086cc0 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 4 Jun 2017 13:21:07 -0400 Subject: [PATCH 17/36] change of PID period to reset PID --- firmware/controllers/math/pid.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/firmware/controllers/math/pid.cpp b/firmware/controllers/math/pid.cpp index bcf553e52d..d62b68f551 100644 --- a/firmware/controllers/math/pid.cpp +++ b/firmware/controllers/math/pid.cpp @@ -27,8 +27,11 @@ void Pid::init(pid_s *pid) { } bool Pid::isSame(pid_s *pid) { - return this->pid->dFactor == pid->dFactor && this->pid->iFactor == pid->iFactor && - this->pid->offset == pid->offset && this->pid->pFactor == pid->pFactor; + return this->pid->pFactor == pid->pFactor + && this->pid->iFactor == pid->iFactor + && this->pid->dFactor == pid->dFactor + && this->pid->offset == pid->offset + && this->pid->period == pid->period; } float Pid::getValue(float target, float input) { From 82b3cc5eac3362d409d188923854b803eb2de294 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 15:00:19 -0400 Subject: [PATCH 18/36] #412 --- firmware/console/binary/tunerstudio_configuration.h | 1 + firmware/console/status_loop.cpp | 1 + firmware/controllers/core/fsio_core.h | 1 + firmware/controllers/core/fsio_impl.cpp | 3 +++ 4 files changed, 6 insertions(+) diff --git a/firmware/console/binary/tunerstudio_configuration.h b/firmware/console/binary/tunerstudio_configuration.h index 569e04c574..8f2ed09265 100644 --- a/firmware/console/binary/tunerstudio_configuration.h +++ b/firmware/console/binary/tunerstudio_configuration.h @@ -82,6 +82,7 @@ typedef struct { unsigned int isTriggerError : 1; // bit 5 unsigned int hasFatalError : 1; // bit 6 unsigned int isWarnNow : 1; // bit 7 + unsigned int isCltBroken : 1; // bit 8 int tsConfigVersion; // 84 egt_values_s egtValues; // 88 float unusedOffset104; // 104 diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index a5f41dc5fd..eb4dc6e5b4 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -734,6 +734,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tsOutputChannels->firmwareVersion = getRusEfiVersion(); tsOutputChannels->isWarnNow = isWarningNow(now, true); + tsOutputChannels->isCltBroken = engine->isCltBroken; if (engineConfiguration->debugMode == DBG_TPS_ACCEL) { tsOutputChannels->debugIntField1 = engine->tpsAccelEnrichment.cb.getSize(); diff --git a/firmware/controllers/core/fsio_core.h b/firmware/controllers/core/fsio_core.h index ba4630184c..2fbfa24c4c 100644 --- a/firmware/controllers/core/fsio_core.h +++ b/firmware/controllers/core/fsio_core.h @@ -52,6 +52,7 @@ typedef enum { LE_METHOD_FSIO_ANALOG_INPUT = 116, LE_METHOD_INTAKE_VVT = 117, LE_METHOD_EXHAUST_VVT = 118, + LE_METHOD_IS_COOLANT_BROKEN = 119, Force_4b_le_action = ENUM_32_BITS, diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index e5b717e313..108668b3c1 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -33,6 +33,7 @@ static LENameOrdinalPair leMap(LE_METHOD_MAP, "map"); static LENameOrdinalPair leVBatt(LE_METHOD_VBATT, "vbatt"); static LENameOrdinalPair leFan(LE_METHOD_FAN, "fan"); static LENameOrdinalPair leCoolant(LE_METHOD_COOLANT, "coolant"); +static LENameOrdinalPair leIsCoolantBroken(LE_METHOD_IS_COOLANT_BROKEN, "is_clt_broken"); static LENameOrdinalPair leAcToggle(LE_METHOD_AC_TOGGLE, "ac_on_switch"); static LENameOrdinalPair leFanOnSetting(LE_METHOD_FAN_ON_SETTING, "fan_on_setting"); static LENameOrdinalPair leFanOffSetting(LE_METHOD_FAN_OFF_SETTING, "fan_off_setting"); @@ -83,6 +84,8 @@ float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action) { return getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE); case LE_METHOD_COOLANT: return getCoolantTemperature(PASS_ENGINE_PARAMETER_SIGNATURE); + case LE_METHOD_IS_COOLANT_BROKEN: + return engine->isCltBroken; case LE_METHOD_INTAKE_AIR: return getIntakeAirTemperature(PASS_ENGINE_PARAMETER_SIGNATURE); case LE_METHOD_RPM: From d66bd27f96ad23e946afc60c96681177a71a4e86 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 15:25:37 -0400 Subject: [PATCH 19/36] refactoring --- firmware/controllers/core/fsio_core.cpp | 25 ++++++++++--------------- firmware/controllers/core/fsio_core.h | 6 +++--- firmware/controllers/core/fsio_impl.cpp | 25 ++++++++++++------------- firmware/controllers/core/fsio_impl.h | 2 +- unit_tests/test_logic_expression.cpp | 18 +++++++++++++----- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/firmware/controllers/core/fsio_core.cpp b/firmware/controllers/core/fsio_core.cpp index a56cbffe97..830076d681 100644 --- a/firmware/controllers/core/fsio_core.cpp +++ b/firmware/controllers/core/fsio_core.cpp @@ -28,6 +28,7 @@ extern fsio8_Map3D_u8t fsioTable4; static fsio8_Map3D_u8t * fsio8t_tables[] = {NULL, NULL, &fsioTable2, &fsioTable3, &fsioTable4}; +EXTERN_ENGINE; LENameOrdinalPair * LE_FIRST = NULL; @@ -75,12 +76,6 @@ void LEElement::clear() { iValue = 0; } - -//void LEElement::init(le_action_e action, int iValue) { -// this->action = action; -// this->iValue = iValue; -//} - void LEElement::init(le_action_e action) { this->action = action; } @@ -142,7 +137,7 @@ void LECalculator::push(le_action_e action, float value) { /** * @return true in case of error, false otherwise */ -bool LECalculator::processElement(Engine *engine, LEElement *element) { +bool LECalculator::processElement(LEElement *element DECLARE_ENGINE_PARAMETER_SUFFIX) { #if EFI_PROD_CODE || defined(__DOXYGEN__) efiAssert(getRemainingStack(chThdGetSelfX()) > 64, "FSIO logic", false); #endif @@ -258,7 +253,7 @@ bool LECalculator::processElement(Engine *engine, LEElement *element) { float humanIndex = pop(LE_METHOD_FSIO_SETTING); int index = (int) humanIndex - 1; if (index >= 0 && index < LE_COMMAND_COUNT) { - push(element->action, engine->engineConfiguration->bc.fsio_setting[index]); + push(element->action, boardConfiguration->fsio_setting[index]); } else { push(element->action, NAN); } @@ -285,7 +280,7 @@ bool LECalculator::processElement(Engine *engine, LEElement *element) { } break; case LE_METHOD_FSIO_ANALOG_INPUT: - push(element->action, getVoltage("fsio", engine->engineConfiguration->fsioAdc[0])); + push(element->action, getVoltage("fsio", engineConfiguration->fsioAdc[0])); break; case LE_METHOD_KNOCK: push(element->action, engine->knockCount); @@ -294,21 +289,21 @@ bool LECalculator::processElement(Engine *engine, LEElement *element) { warning(CUSTOM_UNKNOWN_FSIO, "FSIO undefined action"); return true; default: - push(element->action, getLEValue(engine, &stack, element->action)); + push(element->action, getEngineValue(element->action PASS_ENGINE_PARAMETER_SUFFIX)); } return false; } -float LECalculator::getValue2(float selfValue, LEElement *fistElementInList, Engine *engine) { +float LECalculator::getValue2(float selfValue, LEElement *fistElementInList DECLARE_ENGINE_PARAMETER_SUFFIX) { reset(fistElementInList); - return getValue(selfValue, engine); + return getValue(selfValue PASS_ENGINE_PARAMETER_SUFFIX); } bool LECalculator::isEmpty() { return first == NULL; } -float LECalculator::getValue(float selfValue, Engine *engine) { +float LECalculator::getValue(float selfValue DECLARE_ENGINE_PARAMETER_SUFFIX) { if (isEmpty()) { warning(CUSTOM_NO_FSIO, "no FSIO code"); return NAN; @@ -324,7 +319,7 @@ float LECalculator::getValue(float selfValue, Engine *engine) { if (element->action == LE_METHOD_SELF) { push(element->action, selfValue); } else { - bool isError = processElement(engine, element); + bool isError = processElement(element PASS_ENGINE_PARAMETER_SUFFIX); if (isError) { // error already reported return NAN; @@ -432,7 +427,7 @@ LEElement *LEElementPool::parseExpression(const char * line) { /** * Cannot recognize token */ - warning((obd_code_e) 0, "unrecognized [%s]", parsingBuffer); + warning(CUSTOM_ERR_6536, "unrecognized [%s]", parsingBuffer); return NULL; } n->init(action); diff --git a/firmware/controllers/core/fsio_core.h b/firmware/controllers/core/fsio_core.h index 2fbfa24c4c..6ac2650887 100644 --- a/firmware/controllers/core/fsio_core.h +++ b/firmware/controllers/core/fsio_core.h @@ -96,8 +96,8 @@ typedef FLStack calc_stack_t; class LECalculator { public: LECalculator(); - float getValue(float selfValue, Engine *engine); - float getValue2(float selfValue, LEElement *fistElementInList, Engine *engine); + float getValue(float selfValue DECLARE_ENGINE_PARAMETER_SUFFIX); + float getValue2(float selfValue, LEElement *fistElementInList DECLARE_ENGINE_PARAMETER_SUFFIX); void add(LEElement *element); bool isEmpty(); void reset(); @@ -107,7 +107,7 @@ public: int currentCalculationLogPosition; private: void push(le_action_e action, float value); - bool processElement(Engine *engine, LEElement *element); + bool processElement(LEElement *element DECLARE_ENGINE_PARAMETER_SUFFIX); float pop(le_action_e action); LEElement *first; calc_stack_t stack; diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index 108668b3c1..6e79f9e31e 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -74,8 +74,7 @@ EXTERN_ENGINE #if EFI_PROD_CODE || EFI_SIMULATOR static Logging *logger; -float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action) { - engine_configuration_s *engineConfiguration = engine->engineConfiguration; +float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) { efiAssert(engine!=NULL, "getLEValue", NAN); switch (action) { case LE_METHOD_FAN: @@ -264,7 +263,7 @@ static void handleFsio(Engine *engine, int index) { warning(CUSTOM_NO_FSIO, "no FSIO for #%d %s", index + 1, hwPortname(boardConfiguration->fsioPins[index])); fvalue = NAN; } else { - fvalue = calc.getValue2(engine->fsioLastValue[index], fsioLogics[index], engine); + fvalue = calc.getValue2(engine->fsioLastValue[index], fsioLogics[index] PASS_ENGINE_PARAMETER_SUFFIX); } engine->fsioLastValue[index] = fvalue; @@ -301,11 +300,11 @@ static const char * action2String(le_action_e action) { return buffer; } -static void setPinState(const char * msg, OutputPin *pin, LEElement *element, Engine *engine) { +static void setPinState(const char * msg, OutputPin *pin, LEElement *element) { if (element == NULL) { warning(CUSTOM_OBD_11, "invalid expression for %s", msg); } else { - int value = (int)calc.getValue2(pin->getLogicValue(), element, engine); + int value = (int)calc.getValue2(pin->getLogicValue(), element PASS_ENGINE_PARAMETER_SUFFIX); if (pin->isInitialized() && value != pin->getLogicValue()) { if (isRunningBenchTest()) { return; // let's not mess with bench testing @@ -342,7 +341,7 @@ void runFsio(void) { #if EFI_FUEL_PUMP || defined(__DOXYGEN__) if (boardConfiguration->fuelPumpPin != GPIO_UNASSIGNED) { - setPinState("pump", &enginePins.fuelPumpRelay, fuelPumpLogic, engine); + setPinState("pump", &enginePins.fuelPumpRelay, fuelPumpLogic); } #endif /* EFI_FUEL_PUMP */ @@ -355,7 +354,7 @@ void runFsio(void) { enginePins.o2heater.setValue(engine->rpmCalculator.isRunning()); if (boardConfiguration->acRelayPin != GPIO_UNASSIGNED) { - setPinState("A/C", &enginePins.acRelay, acRelayLogic, engine); + setPinState("A/C", &enginePins.acRelay, acRelayLogic); } // if (boardConfiguration->alternatorControlPin != GPIO_UNASSIGNED) { @@ -363,7 +362,7 @@ void runFsio(void) { // } if (boardConfiguration->fanPin != GPIO_UNASSIGNED) { - setPinState("fan", &enginePins.fanRelay, radiatorFanLogic, engine); + setPinState("fan", &enginePins.fanRelay, radiatorFanLogic); } } @@ -468,7 +467,7 @@ static void setFsioExpression(const char *indexStr, const char *quotedLine, Engi #endif } -static void rpnEval(char *line, Engine *engine) { +static void rpnEval(char *line) { #if EFI_PROD_CODE || EFI_SIMULATOR line = unquote(line); scheduleMsg(logger, "Parsing [%s]", line); @@ -477,7 +476,7 @@ static void rpnEval(char *line, Engine *engine) { if (e == NULL) { scheduleMsg(logger, "parsing failed"); } else { - float result = evalCalc.getValue2(0, e, engine); + float result = evalCalc.getValue2(0, e PASS_ENGINE_PARAMETER_SUFFIX); scheduleMsg(logger, "Evaluate result: %f", result); } #endif @@ -530,11 +529,11 @@ void initFsioImpl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { #endif /* EFI_PROD_CODE */ #if EFI_PROD_CODE || EFI_SIMULATOR - addConsoleActionSSP("set_rpn_expression", (VoidCharPtrCharPtrVoidPtr) setFsioExpression, engine); + addConsoleActionSS("set_rpn_expression", (VoidCharPtrCharPtr) setFsioExpression); addConsoleActionFF("set_fsio_setting", setFsioSetting); addConsoleAction("fsioinfo", showFsioInfo); - addConsoleActionSP("rpn_eval", (VoidCharPtrVoidPtr) rpnEval, engine); -#endif + addConsoleActionS("rpn_eval", (VoidCharPtr) rpnEval); +#endif /* EFI_PROD_CODE || EFI_SIMULATOR */ fsioTable1.init(config->fsioTable1, config->fsioTable1LoadBins, config->fsioTable1RpmBins); diff --git a/firmware/controllers/core/fsio_impl.h b/firmware/controllers/core/fsio_impl.h index 742f6c42f1..90fbb7a918 100644 --- a/firmware/controllers/core/fsio_impl.h +++ b/firmware/controllers/core/fsio_impl.h @@ -18,7 +18,7 @@ typedef Map3D fsio8_Map3D_f32t; typedef Map3D fsio8_Map3D_u8t; -float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action); +float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX); void setFsio(int index, brain_pin_e pin, const char * exp DECLARE_ENGINE_PARAMETER_SUFFIX); void setFsioExt(int index, brain_pin_e pin, const char * exp, int freq DECLARE_ENGINE_PARAMETER_SUFFIX); diff --git a/unit_tests/test_logic_expression.cpp b/unit_tests/test_logic_expression.cpp index e555d10efc..b2398403a9 100644 --- a/unit_tests/test_logic_expression.cpp +++ b/unit_tests/test_logic_expression.cpp @@ -11,6 +11,7 @@ #include "test_logic_expression.h" #include "fsio_impl.h" #include "cli_registry.h" +#include "engine_test_helper.h" #define TEST_POOL_SIZE 256 @@ -19,7 +20,7 @@ static float mockFan; static float mockRpm; static float mockTimeSinceBoot; -float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action) { +float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) { switch(action) { case LE_METHOD_FAN: return mockFan; @@ -91,7 +92,11 @@ static void testExpression2(float selfValue, const char *line, float expected) { print("Parsing [%s]", line); assertTrueM("Not NULL expected", element != NULL); LECalculator c; - assertEqualsM(line, expected, c.getValue2(selfValue, element, NULL)); + + EngineTestHelper eth(FORD_INLINE_6_1995); + EXPAND_EngineTestHelper; + + assertEqualsM(line, expected, c.getValue2(selfValue, element PASS_ENGINE_PARAMETER_SUFFIX)); } static void testExpression(const char *line, float expected) { @@ -103,13 +108,16 @@ void testLogicExpressions(void) { testParsing(); + EngineTestHelper eth(FORD_INLINE_6_1995); + EXPAND_EngineTestHelper; + LECalculator c; LEElement value1; value1.init(LE_NUMERIC_VALUE, 123.0); c.add(&value1); - assertEqualsM("123", 123.0, c.getValue(0, NULL)); + assertEqualsM("123", 123.0, c.getValue(0 PASS_ENGINE_PARAMETER_SUFFIX)); LEElement value2; value2.init(LE_NUMERIC_VALUE, 321.0); @@ -118,7 +126,7 @@ void testLogicExpressions(void) { LEElement value3; value3.init(LE_OPERATOR_AND); c.add(&value3); - assertEqualsM("123 and 321", 1.0, c.getValue(0, NULL)); + assertEqualsM("123 and 321", 1.0, c.getValue(0 PASS_ENGINE_PARAMETER_SUFFIX)); /** * fuel_pump = (time_since_boot < 4 seconds) OR (rpm > 0) @@ -183,7 +191,7 @@ void testLogicExpressions(void) { LEElement * element = pool.parseExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR"); assertTrueM("Not NULL expected", element != NULL); LECalculator c; - assertEqualsM("that expression", 1, c.getValue2(0, element, NULL)); + assertEqualsM("that expression", 1, c.getValue2(0, element PASS_ENGINE_PARAMETER_SUFFIX)); assertEquals(12, c.currentCalculationLogPosition); assertEquals(102, c.calcLogAction[0]); From 384b459ca0f509892d3e9a21ea134d10b1d341b7 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 15:50:33 -0400 Subject: [PATCH 20/36] refactoring --- firmware/controllers/injector_central.cpp | 12 ++++++------ firmware/controllers/injector_central.h | 2 -- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/firmware/controllers/injector_central.cpp b/firmware/controllers/injector_central.cpp index 1ab40cc700..d6f1cb0774 100644 --- a/firmware/controllers/injector_central.cpp +++ b/firmware/controllers/injector_central.cpp @@ -45,7 +45,7 @@ bool isRunningBenchTest(void) { return isRunningBench; } -void assertCylinderId(int cylinderId, const char *msg) { +static void assertCylinderId(int cylinderId, const char *msg) { int isValid = cylinderId >= 1 && cylinderId <= engineConfiguration->specs.cylindersCount; if (!isValid) { // we are here only in case of a fatal issue - at this point it is fine to make some blocking i-o @@ -58,12 +58,12 @@ void assertCylinderId(int cylinderId, const char *msg) { /** * @param cylinderId - from 1 to NUMBER_OF_CYLINDERS */ -int isInjectorEnabled(int cylinderId) { +static int isInjectorEnabled(int cylinderId) { assertCylinderId(cylinderId, "isInjectorEnabled"); return is_injector_enabled[cylinderId - 1]; } -static void printStatus(void) { +static void printInjectorsStatus(void) { for (int id = 1; id <= engineConfiguration->specs.cylindersCount; id++) { scheduleMsg(logger, "injector_%d_%d", isInjectorEnabled(id)); } @@ -72,7 +72,7 @@ static void printStatus(void) { static void setInjectorEnabled(int id, int value) { efiAssertVoid(id >= 0 && id < engineConfiguration->specs.cylindersCount, "injector id"); is_injector_enabled[id] = value; - printStatus(); + printInjectorsStatus(); } static void runBench(brain_pin_e brainPin, OutputPin *output, float delayMs, float onTimeMs, float offTimeMs, @@ -304,14 +304,14 @@ void initInjectorCentral(Logging *sharedLogger) { logger = sharedLogger; chThdCreateStatic(benchThreadStack, sizeof(benchThreadStack), NORMALPRIO, (tfunc_t) benchThread, NULL); - for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { + for (int i = 0; i < INJECTION_PIN_COUNT; i++) { is_injector_enabled[i] = true; } startInjectionPins(); startIgnitionPins(); - printStatus(); + printInjectorsStatus(); addConsoleActionII("injector", setInjectorEnabled); addConsoleAction("fuelpumpbench", fuelPumpBench); diff --git a/firmware/controllers/injector_central.h b/firmware/controllers/injector_central.h index 91182857c0..359c422b44 100644 --- a/firmware/controllers/injector_central.h +++ b/firmware/controllers/injector_central.h @@ -19,8 +19,6 @@ void fuelPumpBench(void); void milBench(void); void initInjectorCentral(Logging *sharedLogger); bool isRunningBenchTest(void); -int isInjectorEnabled(int cylinderId); -void assertCylinderId(int cylinderId, const char *msg); void stopInjectionPins(void); void startInjectionPins(void); From a22f52c5cadddc184876ee668f7057dc2cdd866d Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 15:57:57 -0400 Subject: [PATCH 21/36] todo --- firmware/hw_layer/hardware.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 7f46721897..8ba6574e89 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -200,6 +200,7 @@ static void calcFastAdcIndexes(void) { } static void adcConfigListener(Engine *engine) { + // todo: something is not right here - looks like should be a callback for each configuration change? calcFastAdcIndexes(); } From f65af61e82b1dec030dc8aad10389fac478bf810 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 16:18:29 -0400 Subject: [PATCH 22/36] a bit of OOP --- firmware/controllers/injector_central.cpp | 23 ++++------ firmware/controllers/injector_central.h | 1 - firmware/controllers/system/efiGpio.h | 2 + firmware/hw_layer/hardware.cpp | 54 +++++++++++------------ 4 files changed, 37 insertions(+), 43 deletions(-) diff --git a/firmware/controllers/injector_central.cpp b/firmware/controllers/injector_central.cpp index d6f1cb0774..0b63f0d970 100644 --- a/firmware/controllers/injector_central.cpp +++ b/firmware/controllers/injector_central.cpp @@ -222,33 +222,28 @@ static msg_t benchThread(int param) { #endif } -static void unregister(brain_pin_e currentPin, OutputPin *output) { - if (currentPin == GPIO_UNASSIGNED) - return; - scheduleMsg(logger, "unregistering %s", hwPortname(currentPin)); - unmarkPin(currentPin); - output->unregister(); -} -void unregisterOutput(brain_pin_e oldPin, brain_pin_e newPin, OutputPin *output) { - if (oldPin != newPin) { - unregister(oldPin, output); +void OutputPin::unregisterOutput(brain_pin_e oldPin, brain_pin_e newPin) { + if (oldPin != GPIO_UNASSIGNED && oldPin != newPin) { + scheduleMsg(logger, "unregistering %s", hwPortname(oldPin)); + unmarkPin(oldPin); + unregister(); } } void stopIgnitionPins(void) { for (int i = 0; i < IGNITION_PIN_COUNT; i++) { NamedOutputPin *output = &enginePins.coils[i]; - unregisterOutput(activeConfiguration.bc.ignitionPins[i], - engineConfiguration->bc.ignitionPins[i], output); + output->unregisterOutput(activeConfiguration.bc.ignitionPins[i], + engineConfiguration->bc.ignitionPins[i]); } } void stopInjectionPins(void) { for (int i = 0; i < INJECTION_PIN_COUNT; i++) { NamedOutputPin *output = &enginePins.injectors[i]; - unregisterOutput(activeConfiguration.bc.injectionPins[i], - engineConfiguration->bc.injectionPins[i], output); + output->unregisterOutput(activeConfiguration.bc.injectionPins[i], + engineConfiguration->bc.injectionPins[i]); } } diff --git a/firmware/controllers/injector_central.h b/firmware/controllers/injector_central.h index 359c422b44..a280469e8a 100644 --- a/firmware/controllers/injector_central.h +++ b/firmware/controllers/injector_central.h @@ -22,7 +22,6 @@ bool isRunningBenchTest(void); void stopInjectionPins(void); void startInjectionPins(void); -void unregisterOutput(brain_pin_e oldPin, brain_pin_e newPin, OutputPin *output); void stopIgnitionPins(void); void startIgnitionPins(void); diff --git a/firmware/controllers/system/efiGpio.h b/firmware/controllers/system/efiGpio.h index e2ff3899c3..d5a42e4680 100644 --- a/firmware/controllers/system/efiGpio.h +++ b/firmware/controllers/system/efiGpio.h @@ -35,6 +35,8 @@ public: bool isPinAssigned(); void initPin(const char *msg, brain_pin_e brainPin); void initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e *outputMode); + void unregisterOutput(brain_pin_e oldPin, brain_pin_e newPin); + #if EFI_GPIO_HARDWARE || defined(__DOXYGEN__) ioportid_t port; diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 8ba6574e89..947ae52e73 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -263,36 +263,34 @@ void applyNewHardwareSettings(void) { unregisterPin(engineConfiguration->bc.clutchUpPin, activeConfiguration.bc.clutchUpPin); - unregisterOutput(activeConfiguration.bc.fuelPumpPin, engineConfiguration->bc.fuelPumpPin, - &enginePins.fuelPumpRelay); - unregisterOutput(activeConfiguration.bc.fanPin, engineConfiguration->bc.fanPin, &enginePins.fanRelay); - unregisterOutput(activeConfiguration.bc.hip9011CsPin, - engineConfiguration->bc.hip9011CsPin, &enginePins.hipCs); - unregisterOutput(activeConfiguration.bc.triggerErrorPin, - engineConfiguration->bc.triggerErrorPin, &enginePins.triggerDecoderErrorPin); - unregisterOutput(activeConfiguration.bc.sdCardCsPin, engineConfiguration->bc.sdCardCsPin, - &enginePins.sdCsPin); - unregisterOutput(activeConfiguration.bc.etbDirectionPin1, - engineConfiguration->bc.etbDirectionPin1, &enginePins.etbOutput1); - unregisterOutput(activeConfiguration.bc.etbDirectionPin2, - engineConfiguration->bc.etbDirectionPin2, &enginePins.etbOutput2); - unregisterOutput(activeConfiguration.bc.malfunctionIndicatorPin, - engineConfiguration->bc.malfunctionIndicatorPin, &enginePins.checkEnginePin); - unregisterOutput(activeConfiguration.dizzySparkOutputPin, - engineConfiguration->dizzySparkOutputPin, &enginePins.dizzyOutput); - unregisterOutput(activeConfiguration.bc.tachOutputPin, - engineConfiguration->bc.tachOutputPin, &enginePins.tachOut); - unregisterOutput(activeConfiguration.bc.idle.solenoidPin, - engineConfiguration->bc.idle.solenoidPin, &enginePins.idleSolenoidPin); + enginePins.fuelPumpRelay.unregisterOutput(activeConfiguration.bc.fuelPumpPin, engineConfiguration->bc.fuelPumpPin); + enginePins.fanRelay.unregisterOutput(activeConfiguration.bc.fanPin, engineConfiguration->bc.fanPin); + enginePins.hipCs.unregisterOutput(activeConfiguration.bc.hip9011CsPin, engineConfiguration->bc.hip9011CsPin); + enginePins.triggerDecoderErrorPin.unregisterOutput(activeConfiguration.bc.triggerErrorPin, + engineConfiguration->bc.triggerErrorPin); + enginePins.sdCsPin.unregisterOutput(activeConfiguration.bc.sdCardCsPin, engineConfiguration->bc.sdCardCsPin); + enginePins.etbOutput1.unregisterOutput(activeConfiguration.bc.etbDirectionPin1, + engineConfiguration->bc.etbDirectionPin1); + enginePins.etbOutput2.unregisterOutput(activeConfiguration.bc.etbDirectionPin2, + engineConfiguration->bc.etbDirectionPin2); + enginePins.checkEnginePin.unregisterOutput(activeConfiguration.bc.malfunctionIndicatorPin, + engineConfiguration->bc.malfunctionIndicatorPin); + enginePins.dizzyOutput.unregisterOutput(activeConfiguration.dizzySparkOutputPin, + engineConfiguration->dizzySparkOutputPin); + enginePins.tachOut.unregisterOutput(activeConfiguration.bc.tachOutputPin, + engineConfiguration->bc.tachOutputPin); + enginePins.idleSolenoidPin.unregisterOutput(activeConfiguration.bc.idle.solenoidPin, + engineConfiguration->bc.idle.solenoidPin); - for (int i = 0;i < LE_COMMAND_COUNT;i++) - unregisterOutput(activeConfiguration.bc.fsioPins[i], - engineConfiguration->bc.fsioPins[i], &enginePins.fsioOutputs[i]); + for (int i = 0;i < LE_COMMAND_COUNT;i++) { + enginePins.fsioOutputs[i].unregisterOutput(activeConfiguration.bc.fsioPins[i], + engineConfiguration->bc.fsioPins[i]); + } - unregisterOutput(activeConfiguration.bc.alternatorControlPin, - engineConfiguration->bc.alternatorControlPin, &enginePins.alternatorPin); - unregisterOutput(activeConfiguration.bc.mainRelayPin, - engineConfiguration->bc.mainRelayPin, &enginePins.mainRelay); + enginePins.alternatorPin.unregisterOutput(activeConfiguration.bc.alternatorControlPin, + engineConfiguration->bc.alternatorControlPin); + enginePins.mainRelay.unregisterOutput(activeConfiguration.bc.mainRelayPin, + engineConfiguration->bc.mainRelayPin); startInjectionPins(); startIgnitionPins(); From b83e378534a23498cc1b1f855e412c84dc7fa264 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 16:18:51 -0400 Subject: [PATCH 23/36] a bit of OOP --- firmware/controllers/injector_central.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/firmware/controllers/injector_central.cpp b/firmware/controllers/injector_central.cpp index 0b63f0d970..bacbcaa33e 100644 --- a/firmware/controllers/injector_central.cpp +++ b/firmware/controllers/injector_central.cpp @@ -222,7 +222,6 @@ static msg_t benchThread(int param) { #endif } - void OutputPin::unregisterOutput(brain_pin_e oldPin, brain_pin_e newPin) { if (oldPin != GPIO_UNASSIGNED && oldPin != newPin) { scheduleMsg(logger, "unregistering %s", hwPortname(oldPin)); From d5f338a209d711380af0310ab445e3beac6f1b5c Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 16:24:17 -0400 Subject: [PATCH 24/36] todo --- firmware/controllers/injector_central.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/firmware/controllers/injector_central.cpp b/firmware/controllers/injector_central.cpp index bacbcaa33e..ea8c294dba 100644 --- a/firmware/controllers/injector_central.cpp +++ b/firmware/controllers/injector_central.cpp @@ -39,6 +39,8 @@ EXTERN_ENGINE static Logging * logger; static bool isRunningBench = false; +// todo: move into Engine object? +// todo: looks like these flags are not currently used? dead functionality? unfinished functionality? static int is_injector_enabled[INJECTION_PIN_COUNT]; bool isRunningBenchTest(void) { From 5e6d2c5f03ccf5edfed702635e2cee9ef680022d Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 16:35:13 -0400 Subject: [PATCH 25/36] refactoring --- firmware/controllers/system/efiGpio.cpp | 14 ++++++++++++-- firmware/controllers/system/efiGpio.h | 1 + firmware/hw_layer/hardware.cpp | 6 +----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/firmware/controllers/system/efiGpio.cpp b/firmware/controllers/system/efiGpio.cpp index f5fba659d1..943c88d0cd 100644 --- a/firmware/controllers/system/efiGpio.cpp +++ b/firmware/controllers/system/efiGpio.cpp @@ -50,8 +50,7 @@ EnginePins::EnginePins() { * Sets the value of the pin. On this layer the value is assigned as is, without any conversion. */ -#if EFI_PROD_CODE \ - +#if EFI_PROD_CODE #define setPinValue(outputPin, electricalValue, logicValue) \ { \ if ((outputPin)->currentLogicValue != (logicValue)) { \ @@ -79,6 +78,17 @@ bool EnginePins::stopPins() { return result; } +void EnginePins::unregisterPins() { +#if EFI_PROD_CODE || defined(__DOXYGEN__) + fuelPumpRelay.unregisterOutput(activeConfiguration.bc.fuelPumpPin, engineConfiguration->bc.fuelPumpPin); + fanRelay.unregisterOutput(activeConfiguration.bc.fanPin, engineConfiguration->bc.fanPin); + hipCs.unregisterOutput(activeConfiguration.bc.hip9011CsPin, engineConfiguration->bc.hip9011CsPin); + triggerDecoderErrorPin.unregisterOutput(activeConfiguration.bc.triggerErrorPin, + engineConfiguration->bc.triggerErrorPin); + +#endif /* EFI_PROD_CODE */ +} + void EnginePins::reset() { for (int i = 0; i < INJECTION_PIN_COUNT;i++) { injectors[i].reset(); diff --git a/firmware/controllers/system/efiGpio.h b/firmware/controllers/system/efiGpio.h index d5a42e4680..867d078e13 100644 --- a/firmware/controllers/system/efiGpio.h +++ b/firmware/controllers/system/efiGpio.h @@ -90,6 +90,7 @@ public: EnginePins(); void reset(); bool stopPins(); + void unregisterPins(); OutputPin mainRelay; OutputPin fanRelay; OutputPin acRelay; diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 947ae52e73..ed7b1bff41 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -262,12 +262,8 @@ void applyNewHardwareSettings(void) { unregisterPin(engineConfiguration->bc.clutchUpPin, activeConfiguration.bc.clutchUpPin); + enginePins.unregisterPins(); - enginePins.fuelPumpRelay.unregisterOutput(activeConfiguration.bc.fuelPumpPin, engineConfiguration->bc.fuelPumpPin); - enginePins.fanRelay.unregisterOutput(activeConfiguration.bc.fanPin, engineConfiguration->bc.fanPin); - enginePins.hipCs.unregisterOutput(activeConfiguration.bc.hip9011CsPin, engineConfiguration->bc.hip9011CsPin); - enginePins.triggerDecoderErrorPin.unregisterOutput(activeConfiguration.bc.triggerErrorPin, - engineConfiguration->bc.triggerErrorPin); enginePins.sdCsPin.unregisterOutput(activeConfiguration.bc.sdCardCsPin, engineConfiguration->bc.sdCardCsPin); enginePins.etbOutput1.unregisterOutput(activeConfiguration.bc.etbDirectionPin1, engineConfiguration->bc.etbDirectionPin1); From 96f0624c3637a2328232a1c836775738b11d4486 Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 5 Jun 2017 01:07:02 +0300 Subject: [PATCH 26/36] Bluetooth HC-05 draft --- firmware/console/binary/bluetooth.cpp | 35 +++++++++++++++++-------- firmware/console/binary/bluetooth.h | 1 + firmware/console/binary/tunerstudio.cpp | 5 ++++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/firmware/console/binary/bluetooth.cpp b/firmware/console/binary/bluetooth.cpp index 8f83f97f7a..a160af4f70 100644 --- a/firmware/console/binary/bluetooth.cpp +++ b/firmware/console/binary/bluetooth.cpp @@ -15,7 +15,8 @@ static const char *commands[5]; static int numCommands = 0; static int setBaudIdx = -1; -static char cmdBaud[10]; +static char cmdHello[5]; +static char cmdBaud[25]; static char cmdName[30]; static char cmdPin[16]; @@ -166,12 +167,6 @@ void bluetoothStart(ts_channel_s *tsChan, bluetooth_module_e moduleType, const c return; } - // todo: add support for other BT module types - if (moduleType != BLUETOOTH_HC_06) { - scheduleMsg(&btLogger, "This Bluetooth module is currently not supported!"); - return; - } - numCommands = 0; // now check the arguments and add other commands: @@ -221,12 +216,30 @@ void bluetoothStart(ts_channel_s *tsChan, bluetooth_module_e moduleType, const c } // ok, add commands! - commands[numCommands++] = "AT"; // this command is added to test a connection - chsnprintf(cmdBaud, sizeof(cmdBaud), "AT+BAUD%c", '0' + setBaudIdx); + switch (moduleType) { + case BLUETOOTH_HC_05: + chsnprintf(cmdHello, sizeof(cmdHello), "AT\r\n"); + chsnprintf(cmdBaud, sizeof(cmdBaud), "AT+UART=%d,0,0\r\n", baud); // baud rate, 0=(1 stop bit), 0=(no parity bits) + chsnprintf(cmdName, sizeof(cmdName), "AT+NAME=%s\r\n", name); + chsnprintf(cmdPin, sizeof(cmdPin), "AT+PSWD=%s\r\n", pinCode); + // todo: add more commands? + // AT+RMAAD + // AT+ROLE=0 + break; + case BLUETOOTH_HC_06: + chsnprintf(cmdHello, sizeof(cmdHello), "AT"); + chsnprintf(cmdBaud, sizeof(cmdBaud), "AT+BAUD%c", '0' + setBaudIdx); + chsnprintf(cmdName, sizeof(cmdName), "AT+NAME%s", name); + chsnprintf(cmdPin, sizeof(cmdPin), "AT+PIN%s", pinCode); + break; + default: + // todo: add support for other BT module types + scheduleMsg(&btLogger, "This Bluetooth module is currently not supported!"); + return; + } + commands[numCommands++] = cmdHello; // this command is added to test a connection commands[numCommands++] = cmdBaud; - chsnprintf(cmdName, sizeof(cmdName), "AT+NAME%s", name); commands[numCommands++] = cmdName; - chsnprintf(cmdPin, sizeof(cmdPin), "AT+PIN%s", pinCode); commands[numCommands++] = cmdPin; // create a thread to execute these commands later diff --git a/firmware/console/binary/bluetooth.h b/firmware/console/binary/bluetooth.h index 87e0b69b08..1ee4415b87 100644 --- a/firmware/console/binary/bluetooth.h +++ b/firmware/console/binary/bluetooth.h @@ -19,6 +19,7 @@ // Supported Bluetooth module types typedef enum { + BLUETOOTH_HC_05, BLUETOOTH_HC_06, } bluetooth_module_e; diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index d0377c59a3..945704c24d 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -169,6 +169,10 @@ static void setTsSpeed(int value) { } #if EFI_BLUETOOTH_SETUP || defined(__DOXYGEN__) +// Bluetooth HC-05 module initialization start (it waits for disconnect and then communicates to the module) +static void bluetoothHC05(const char *baudRate, const char *name, const char *pinCode) { + bluetoothStart(&tsChannel, BLUETOOTH_HC_05, baudRate, name, pinCode); +} // Bluetooth HC-06 module initialization start (it waits for disconnect and then communicates to the module) static void bluetoothHC06(const char *baudRate, const char *name, const char *pinCode) { bluetoothStart(&tsChannel, BLUETOOTH_HC_06, baudRate, name, pinCode); @@ -844,6 +848,7 @@ void startTunerStudioConnectivity(void) { #if EFI_BLUETOOTH_SETUP || defined(__DOXYGEN__) // Usage: "bluetooth_hc06 " // Example: "bluetooth_hc06 38400 rusefi 1234" + addConsoleActionSSS("bluetooth_hc05", bluetoothHC05); addConsoleActionSSS("bluetooth_hc06", bluetoothHC06); addConsoleAction("bluetooth_cancel", bluetoothCancel); #endif /* EFI_BLUETOOTH_SETUP */ From cdda0758f5fec82c055555943dd81a1cb95482b0 Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 5 Jun 2017 01:10:48 +0300 Subject: [PATCH 27/36] Bluetooth HC-05 draft --- firmware/svnversion.h | 4 ++-- simulator/simulator/efifeatures.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/firmware/svnversion.h b/firmware/svnversion.h index 5404c5ece6..a5e4a9b2a9 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,5 +1,5 @@ // This file was generated by Version2Header -// Fri Jun 02 23:03:47 EDT 2017 +// Mon Jun 05 01:08:50 EEST 2017 #ifndef VCS_VERSION -#define VCS_VERSION "14281" +#define VCS_VERSION "14309" #endif diff --git a/simulator/simulator/efifeatures.h b/simulator/simulator/efifeatures.h index 1f502d4fc9..9ad90ff434 100644 --- a/simulator/simulator/efifeatures.h +++ b/simulator/simulator/efifeatures.h @@ -85,7 +85,6 @@ #define EFI_HISTOGRAMS FALSE #define EFI_TUNER_STUDIO TRUE -#define EFI_BLUETOOTH_SETUP FALSE /** * This is the size of the MemoryStream used by chvprintf From b47c4814a39d41991d6158473b7e3b6745888eca Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 5 Jun 2017 01:12:09 +0300 Subject: [PATCH 28/36] Bluetooth HC-05 draft --- firmware/svnversion.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/svnversion.h b/firmware/svnversion.h index a5e4a9b2a9..5404c5ece6 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,5 +1,5 @@ // This file was generated by Version2Header -// Mon Jun 05 01:08:50 EEST 2017 +// Fri Jun 02 23:03:47 EDT 2017 #ifndef VCS_VERSION -#define VCS_VERSION "14309" +#define VCS_VERSION "14281" #endif From c08140d1126c0a547ebc0747e7f714d735f486e7 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 18:29:57 -0400 Subject: [PATCH 29/36] refactoring --- firmware/controllers/system/efiGpio.cpp | 24 ++++++++++++++++++++++++ firmware/hw_layer/hardware.cpp | 23 ----------------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/firmware/controllers/system/efiGpio.cpp b/firmware/controllers/system/efiGpio.cpp index 943c88d0cd..ea465260e0 100644 --- a/firmware/controllers/system/efiGpio.cpp +++ b/firmware/controllers/system/efiGpio.cpp @@ -86,6 +86,30 @@ void EnginePins::unregisterPins() { triggerDecoderErrorPin.unregisterOutput(activeConfiguration.bc.triggerErrorPin, engineConfiguration->bc.triggerErrorPin); + sdCsPin.unregisterOutput(activeConfiguration.bc.sdCardCsPin, engineConfiguration->bc.sdCardCsPin); + etbOutput1.unregisterOutput(activeConfiguration.bc.etbDirectionPin1, + engineConfiguration->bc.etbDirectionPin1); + etbOutput2.unregisterOutput(activeConfiguration.bc.etbDirectionPin2, + engineConfiguration->bc.etbDirectionPin2); + checkEnginePin.unregisterOutput(activeConfiguration.bc.malfunctionIndicatorPin, + engineConfiguration->bc.malfunctionIndicatorPin); + dizzyOutput.unregisterOutput(activeConfiguration.dizzySparkOutputPin, + engineConfiguration->dizzySparkOutputPin); + tachOut.unregisterOutput(activeConfiguration.bc.tachOutputPin, + engineConfiguration->bc.tachOutputPin); + idleSolenoidPin.unregisterOutput(activeConfiguration.bc.idle.solenoidPin, + engineConfiguration->bc.idle.solenoidPin); + + for (int i = 0;i < LE_COMMAND_COUNT;i++) { + fsioOutputs[i].unregisterOutput(activeConfiguration.bc.fsioPins[i], + engineConfiguration->bc.fsioPins[i]); + } + + alternatorPin.unregisterOutput(activeConfiguration.bc.alternatorControlPin, + engineConfiguration->bc.alternatorControlPin); + mainRelay.unregisterOutput(activeConfiguration.bc.mainRelayPin, + engineConfiguration->bc.mainRelayPin); + #endif /* EFI_PROD_CODE */ } diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index ed7b1bff41..cff6ae5ce9 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -264,29 +264,6 @@ void applyNewHardwareSettings(void) { enginePins.unregisterPins(); - enginePins.sdCsPin.unregisterOutput(activeConfiguration.bc.sdCardCsPin, engineConfiguration->bc.sdCardCsPin); - enginePins.etbOutput1.unregisterOutput(activeConfiguration.bc.etbDirectionPin1, - engineConfiguration->bc.etbDirectionPin1); - enginePins.etbOutput2.unregisterOutput(activeConfiguration.bc.etbDirectionPin2, - engineConfiguration->bc.etbDirectionPin2); - enginePins.checkEnginePin.unregisterOutput(activeConfiguration.bc.malfunctionIndicatorPin, - engineConfiguration->bc.malfunctionIndicatorPin); - enginePins.dizzyOutput.unregisterOutput(activeConfiguration.dizzySparkOutputPin, - engineConfiguration->dizzySparkOutputPin); - enginePins.tachOut.unregisterOutput(activeConfiguration.bc.tachOutputPin, - engineConfiguration->bc.tachOutputPin); - enginePins.idleSolenoidPin.unregisterOutput(activeConfiguration.bc.idle.solenoidPin, - engineConfiguration->bc.idle.solenoidPin); - - for (int i = 0;i < LE_COMMAND_COUNT;i++) { - enginePins.fsioOutputs[i].unregisterOutput(activeConfiguration.bc.fsioPins[i], - engineConfiguration->bc.fsioPins[i]); - } - - enginePins.alternatorPin.unregisterOutput(activeConfiguration.bc.alternatorControlPin, - engineConfiguration->bc.alternatorControlPin); - enginePins.mainRelay.unregisterOutput(activeConfiguration.bc.mainRelayPin, - engineConfiguration->bc.mainRelayPin); startInjectionPins(); startIgnitionPins(); From 89c25af9d222d1489e9a846714a9d36a0794c1e2 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 18:43:08 -0400 Subject: [PATCH 30/36] refactoring --- firmware/controllers/injector_central.cpp | 12 ++++++------ firmware/controllers/injector_central.h | 5 ----- firmware/controllers/system/efiGpio.h | 4 ++++ firmware/hw_layer/hardware.cpp | 8 ++++---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/firmware/controllers/injector_central.cpp b/firmware/controllers/injector_central.cpp index ea8c294dba..7cf62ca662 100644 --- a/firmware/controllers/injector_central.cpp +++ b/firmware/controllers/injector_central.cpp @@ -232,7 +232,7 @@ void OutputPin::unregisterOutput(brain_pin_e oldPin, brain_pin_e newPin) { } } -void stopIgnitionPins(void) { +void EnginePins::stopIgnitionPins(void) { for (int i = 0; i < IGNITION_PIN_COUNT; i++) { NamedOutputPin *output = &enginePins.coils[i]; output->unregisterOutput(activeConfiguration.bc.ignitionPins[i], @@ -240,7 +240,7 @@ void stopIgnitionPins(void) { } } -void stopInjectionPins(void) { +void EnginePins::stopInjectionPins(void) { for (int i = 0; i < INJECTION_PIN_COUNT; i++) { NamedOutputPin *output = &enginePins.injectors[i]; output->unregisterOutput(activeConfiguration.bc.injectionPins[i], @@ -248,7 +248,7 @@ void stopInjectionPins(void) { } } -void startIgnitionPins(void) { +void EnginePins::startIgnitionPins(void) { for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { NamedOutputPin *output = &enginePins.coils[i]; // todo: we need to check if mode has changed @@ -265,7 +265,7 @@ void startIgnitionPins(void) { } } -void startInjectionPins(void) { +void EnginePins::startInjectionPins(void) { // todo: should we move this code closer to the injection logic? for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { NamedOutputPin *output = &enginePins.injectors[i]; @@ -304,8 +304,8 @@ void initInjectorCentral(Logging *sharedLogger) { is_injector_enabled[i] = true; } - startInjectionPins(); - startIgnitionPins(); + enginePins.startInjectionPins(); + enginePins.startIgnitionPins(); printInjectorsStatus(); addConsoleActionII("injector", setInjectorEnabled); diff --git a/firmware/controllers/injector_central.h b/firmware/controllers/injector_central.h index a280469e8a..06663ce228 100644 --- a/firmware/controllers/injector_central.h +++ b/firmware/controllers/injector_central.h @@ -20,11 +20,6 @@ void milBench(void); void initInjectorCentral(Logging *sharedLogger); bool isRunningBenchTest(void); -void stopInjectionPins(void); -void startInjectionPins(void); - -void stopIgnitionPins(void); -void startIgnitionPins(void); void runIoTest(int subsystem, int index); #endif /* INJECTOR_CENTRAL_H_ */ diff --git a/firmware/controllers/system/efiGpio.h b/firmware/controllers/system/efiGpio.h index 867d078e13..bbed4a3227 100644 --- a/firmware/controllers/system/efiGpio.h +++ b/firmware/controllers/system/efiGpio.h @@ -91,6 +91,10 @@ public: void reset(); bool stopPins(); void unregisterPins(); + void startInjectionPins(); + void startIgnitionPins(); + void stopInjectionPins(); + void stopIgnitionPins(); OutputPin mainRelay; OutputPin fanRelay; OutputPin acRelay; diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index cff6ae5ce9..1a9ad26451 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -232,8 +232,8 @@ void applyNewHardwareSettings(void) { // all 'stop' methods need to go before we begin starting pins - stopInjectionPins(); - stopIgnitionPins(); + enginePins.stopInjectionPins(); + enginePins.stopIgnitionPins(); stopCanPins(); bool etbRestartNeeded = isETBRestartNeeded(); if (etbRestartNeeded) { @@ -265,8 +265,8 @@ void applyNewHardwareSettings(void) { enginePins.unregisterPins(); - startInjectionPins(); - startIgnitionPins(); + enginePins.startInjectionPins(); + enginePins.startIgnitionPins(); startCanPins(); if (etbRestartNeeded) { startETBPins(); From beee5452a55aefc15591cf0579abdc2f56dd4e54 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 18:53:43 -0400 Subject: [PATCH 31/36] refactoring --- firmware/controllers/injector_central.cpp | 46 ------------------- firmware/controllers/system/efiGpio.cpp | 54 +++++++++++++++++++++++ 2 files changed, 54 insertions(+), 46 deletions(-) diff --git a/firmware/controllers/injector_central.cpp b/firmware/controllers/injector_central.cpp index 7cf62ca662..193fec45e1 100644 --- a/firmware/controllers/injector_central.cpp +++ b/firmware/controllers/injector_central.cpp @@ -232,52 +232,6 @@ void OutputPin::unregisterOutput(brain_pin_e oldPin, brain_pin_e newPin) { } } -void EnginePins::stopIgnitionPins(void) { - for (int i = 0; i < IGNITION_PIN_COUNT; i++) { - NamedOutputPin *output = &enginePins.coils[i]; - output->unregisterOutput(activeConfiguration.bc.ignitionPins[i], - engineConfiguration->bc.ignitionPins[i]); - } -} - -void EnginePins::stopInjectionPins(void) { - for (int i = 0; i < INJECTION_PIN_COUNT; i++) { - NamedOutputPin *output = &enginePins.injectors[i]; - output->unregisterOutput(activeConfiguration.bc.injectionPins[i], - engineConfiguration->bc.injectionPins[i]); - } -} - -void EnginePins::startIgnitionPins(void) { - for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { - NamedOutputPin *output = &enginePins.coils[i]; - // todo: we need to check if mode has changed - if (boardConfiguration->ignitionPins[i] != activeConfiguration.bc.ignitionPins[i]) { - output->initPin(output->name, boardConfiguration->ignitionPins[i], - &boardConfiguration->ignitionPinMode); - } - } - // todo: we need to check if mode has changed - if (engineConfiguration->dizzySparkOutputPin != activeConfiguration.dizzySparkOutputPin) { - enginePins.dizzyOutput.initPin("dizzy tach", engineConfiguration->dizzySparkOutputPin, - &engineConfiguration->dizzySparkOutputPinMode); - - } -} - -void EnginePins::startInjectionPins(void) { - // todo: should we move this code closer to the injection logic? - for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { - NamedOutputPin *output = &enginePins.injectors[i]; - // todo: we need to check if mode has changed - if (engineConfiguration->bc.injectionPins[i] != activeConfiguration.bc.injectionPins[i]) { - - output->initPin(output->name, boardConfiguration->injectionPins[i], - &boardConfiguration->injectionPinMode); - } - } -} - void runIoTest(int subsystem, int index) { scheduleMsg(logger, "IO test subsystem=%d index=%d", subsystem, index); diff --git a/firmware/controllers/system/efiGpio.cpp b/firmware/controllers/system/efiGpio.cpp index ea465260e0..e81f8e6f34 100644 --- a/firmware/controllers/system/efiGpio.cpp +++ b/firmware/controllers/system/efiGpio.cpp @@ -122,6 +122,60 @@ void EnginePins::reset() { } } +void EnginePins::stopIgnitionPins(void) { +#if EFI_PROD_CODE || defined(__DOXYGEN__) + for (int i = 0; i < IGNITION_PIN_COUNT; i++) { + NamedOutputPin *output = &enginePins.coils[i]; + output->unregisterOutput(activeConfiguration.bc.ignitionPins[i], + engineConfiguration->bc.ignitionPins[i]); + } +#endif /* EFI_PROD_CODE */ +} + +void EnginePins::stopInjectionPins(void) { +#if EFI_PROD_CODE || defined(__DOXYGEN__) + for (int i = 0; i < INJECTION_PIN_COUNT; i++) { + NamedOutputPin *output = &enginePins.injectors[i]; + output->unregisterOutput(activeConfiguration.bc.injectionPins[i], + engineConfiguration->bc.injectionPins[i]); + } +#endif /* EFI_PROD_CODE */ +} + +void EnginePins::startIgnitionPins(void) { +#if EFI_PROD_CODE || defined(__DOXYGEN__) + for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { + NamedOutputPin *output = &enginePins.coils[i]; + // todo: we need to check if mode has changed + if (boardConfiguration->ignitionPins[i] != activeConfiguration.bc.ignitionPins[i]) { + output->initPin(output->name, boardConfiguration->ignitionPins[i], + &boardConfiguration->ignitionPinMode); + } + } + // todo: we need to check if mode has changed + if (engineConfiguration->dizzySparkOutputPin != activeConfiguration.dizzySparkOutputPin) { + enginePins.dizzyOutput.initPin("dizzy tach", engineConfiguration->dizzySparkOutputPin, + &engineConfiguration->dizzySparkOutputPinMode); + + } +#endif /* EFI_PROD_CODE */ +} + +void EnginePins::startInjectionPins(void) { +#if EFI_PROD_CODE || defined(__DOXYGEN__) + // todo: should we move this code closer to the injection logic? + for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { + NamedOutputPin *output = &enginePins.injectors[i]; + // todo: we need to check if mode has changed + if (engineConfiguration->bc.injectionPins[i] != activeConfiguration.bc.injectionPins[i]) { + + output->initPin(output->name, boardConfiguration->injectionPins[i], + &boardConfiguration->injectionPinMode); + } + } +#endif /* EFI_PROD_CODE */ +} + NamedOutputPin::NamedOutputPin() : OutputPin() { name = NULL; } From 1c966abc9dff9cb7a8ce8ee2ac13ea3c36107169 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 19:15:06 -0400 Subject: [PATCH 32/36] date --- firmware/rusefi.cpp | 2 +- firmware/svnversion.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 55e3aa70da..61be1c58ca 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -251,5 +251,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20170602; + return 20170604; } diff --git a/firmware/svnversion.h b/firmware/svnversion.h index 5404c5ece6..2397ca1b8b 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,5 +1,5 @@ // This file was generated by Version2Header -// Fri Jun 02 23:03:47 EDT 2017 +// Sun Jun 04 19:14:56 EDT 2017 #ifndef VCS_VERSION -#define VCS_VERSION "14281" +#define VCS_VERSION "14317" #endif From 92927cbb79e66c64f957cc7c773029c3631525d0 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 19:33:54 -0400 Subject: [PATCH 33/36] #4 --- firmware/tunerstudio/rusefi.ini | 3 ++- firmware/tunerstudio/rusefi.input | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index a68ada366c..6b02fddce9 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -45,7 +45,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jun 04 13:06:50 EDT 2017 +; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jun 04 19:18:22 EDT 2017 pageSize = 16376 page = 1 @@ -1985,6 +1985,7 @@ cmd_call_from_pit = "w\x00\x20\x34\x56" field = "idle I", idleRpmPid_iFactor, { idleMode == 0} field = "idle D", idleRpmPid_dFactor, { idleMode == 0} field = "idle offset", idleRpmPid_offset, { idleMode == 0} + field = "period", idleRpmPid_period field = "pid min", idleRpmPid_minValue, { idleMode == 0} field = "pid max", idleRpmPid_maxValue, { idleMode == 0} field = "pid TPS deactivation", idlePidDeactivationTpsThreshold, { idleMode == 0} diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 3aa1431771..adcaaeac2b 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -1221,6 +1221,7 @@ cmd_call_from_pit = "w\x00\x20\x34\x56" field = "idle I", idleRpmPid_iFactor, { idleMode == 0} field = "idle D", idleRpmPid_dFactor, { idleMode == 0} field = "idle offset", idleRpmPid_offset, { idleMode == 0} + field = "period", idleRpmPid_period field = "pid min", idleRpmPid_minValue, { idleMode == 0} field = "pid max", idleRpmPid_maxValue, { idleMode == 0} field = "pid TPS deactivation", idlePidDeactivationTpsThreshold, { idleMode == 0} From e9d1e8a4d3dc46b9d8cbdb095abe463d3d6268ee Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 20:13:37 -0400 Subject: [PATCH 34/36] #4 --- firmware/controllers/algo/engine_configuration.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index ee699e0397..3e023aa3ea 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -693,6 +693,9 @@ void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { engineConfiguration->cranking.baseFuel = 5; + engineConfiguration->idleRpmPid.pFactor = 0.05; + engineConfiguration->idleRpmPid.iFactor = 0.002; + engineConfiguration->idleRpmPid.minValue = 5; engineConfiguration->idleRpmPid.maxValue = 95; boardConfiguration->idlePidDeactivationTpsThreshold = 2; From 725e855e28c9ba2aa6dd343ab2484a89eb1baba7 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 20:56:58 -0400 Subject: [PATCH 35/36] #4 --- firmware/tunerstudio/rusefi.ini | 8 ++++---- firmware/tunerstudio/rusefi.input | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index 6b02fddce9..429ef387f1 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -45,7 +45,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jun 04 19:18:22 EDT 2017 +; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jun 04 20:56:41 EDT 2017 pageSize = 16376 page = 1 @@ -952,7 +952,7 @@ fileVersion = { 20161225 } wallFuelAmount = scalar, F32, 160, "ms", 1, 0 iatCorrection = scalar, F32, 164, "%", 1, 0 wallFuelCorrection = scalar, F32, 168, "ms", 1, 0 - curIdlePosition = scalar, F32, 172, "percent", 1, 0 + idleAirValvePosition = scalar, F32, 172, "percent", 1, 0 currentTargetAfr = scalar, F32, 176, "ratio", 1, 0 chargeAirMass = scalar, F32, 180, "g", 1, 0 cltCorrection = scalar, F32, 184, "%", 1, 0 @@ -1267,7 +1267,7 @@ fileVersion = { 20161225 } wallFuelAmountGauge = wallFuelAmount, "fuel: wall amount", "ms", 0, 100, 0, 0, 100, 100, 0, 0 wallFuelCorrectionGauge = wallFuelCorrection, "fuel: wall correction extra", "ms", 0, 100, 0, 0, 100, 100, 0, 0 - curIdlePositionGauge = curIdlePosition, "idle position", "%", 0, 100, 0, 0, 100, 100, 0, 0 + idleAirValvePositionGauge = idleAirValvePosition, "idle position", "%", 0, 100, 0, 0, 100, 100, 0, 0 debugFloatField1Gauge = debugFloatField1, "debug f1", "%", 0, 100, 0, 0, 100, 100, 4, 4 debugFloatField2Gauge = debugFloatField2, "debug f2", "%", 0, 100, 0, 0, 100, 100, 4, 4 @@ -1356,7 +1356,7 @@ fileVersion = { 20161225 } entry = massAirFlowValue,"airMass", float, "%.3f" entry = pedalPosition, "pedal", float, "%.3f" entry = triggerErrorsCounter, "trg err",int, "%d" - entry = curIdlePosition, "Idle Air Valve", float, "%.3f" + entry = idleAirValvePosition, "Idle Air Valve", float, "%.3f" entry = fuelRunning, "fuel: running", float, "%.3f" diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index adcaaeac2b..390000556c 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -188,7 +188,7 @@ fileVersion = { 20161225 } wallFuelAmount = scalar, F32, 160, "ms", 1, 0 iatCorrection = scalar, F32, 164, "%", 1, 0 wallFuelCorrection = scalar, F32, 168, "ms", 1, 0 - curIdlePosition = scalar, F32, 172, "percent", 1, 0 + idleAirValvePosition = scalar, F32, 172, "percent", 1, 0 currentTargetAfr = scalar, F32, 176, "ratio", 1, 0 chargeAirMass = scalar, F32, 180, "g", 1, 0 cltCorrection = scalar, F32, 184, "%", 1, 0 @@ -503,7 +503,7 @@ fileVersion = { 20161225 } wallFuelAmountGauge = wallFuelAmount, "fuel: wall amount", "ms", 0, 100, 0, 0, 100, 100, 0, 0 wallFuelCorrectionGauge = wallFuelCorrection, "fuel: wall correction extra", "ms", 0, 100, 0, 0, 100, 100, 0, 0 - curIdlePositionGauge = curIdlePosition, "idle position", "%", 0, 100, 0, 0, 100, 100, 0, 0 + idleAirValvePositionGauge = idleAirValvePosition, "idle position", "%", 0, 100, 0, 0, 100, 100, 0, 0 debugFloatField1Gauge = debugFloatField1, "debug f1", "%", 0, 100, 0, 0, 100, 100, 4, 4 debugFloatField2Gauge = debugFloatField2, "debug f2", "%", 0, 100, 0, 0, 100, 100, 4, 4 @@ -592,7 +592,7 @@ fileVersion = { 20161225 } entry = massAirFlowValue,"airMass", float, "%.3f" entry = pedalPosition, "pedal", float, "%.3f" entry = triggerErrorsCounter, "trg err",int, "%d" - entry = curIdlePosition, @@GAUGE_NAME_IAC@@, float, "%.3f" + entry = idleAirValvePosition, @@GAUGE_NAME_IAC@@, float, "%.3f" entry = fuelRunning, @@GAUGE_NAME_FUEL_RUNNING@@, float, "%.3f" From 98b5b990173bac6b392d464cb1fa11f90062c905 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 4 Jun 2017 21:15:44 -0400 Subject: [PATCH 36/36] #4 --- firmware/controllers/idle_thread.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/firmware/controllers/idle_thread.cpp b/firmware/controllers/idle_thread.cpp index 76265138bb..49dbb617f9 100644 --- a/firmware/controllers/idle_thread.cpp +++ b/firmware/controllers/idle_thread.cpp @@ -63,7 +63,6 @@ void idleDebug(const char *msg, percent_t value) { scheduleMsg(logger, "idle debug: %s%f", msg, value); } - static void showIdleInfo(void) { const char * idleModeStr = getIdle_mode_e(engineConfiguration->idleMode); scheduleMsg(logger, "idleMode=%s position=%f isStepper=%s", idleModeStr, @@ -150,14 +149,8 @@ static void undoIdleBlipIfNeeded() { } } -static percent_t currentIdleValve = -1; - percent_t getIdlePosition(void) { - if (engineConfiguration->idleMode == IM_AUTO) { - return currentIdleValve; - } else { - return boardConfiguration->manIdlePosition; - } + return currentIdlePosition; } static float autoIdle(float cltCorrection) {