From b28e8348ce52648565048920b32541605ef63a52 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 20 Jul 2021 18:29:24 -0700 Subject: [PATCH] sd card indicators (#3001) * sd bits * rusefi.input --- firmware/console/binary/tunerstudio_outputs.h | 6 ++++-- firmware/console/status_loop.cpp | 8 -------- .../hw_layer/mass_storage/mass_storage_init.cpp | 6 ++++++ firmware/hw_layer/mmc_card.cpp | 9 +++++++++ firmware/tunerstudio/rusefi.input | 16 ++++++---------- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/firmware/console/binary/tunerstudio_outputs.h b/firmware/console/binary/tunerstudio_outputs.h index beb3f5917f..e0f82b41b0 100644 --- a/firmware/console/binary/tunerstudio_outputs.h +++ b/firmware/console/binary/tunerstudio_outputs.h @@ -49,7 +49,7 @@ struct TunerStudioOutputChannels { * Yes, I do not really enjoy packing bits into integers but we simply have too many boolean flags and I cannot * water 4 bytes per traffic - I want gauges to work as fast as possible */ - unsigned int hasSdCard : 1; // bit 0, 72 + unsigned int sd_present : 1; // bit 0, 72 unsigned int isIgnitionEnabledIndicator : 1; // bit 1 unsigned int isInjectionEnabledIndicator : 1; // bit 2 unsigned int unusedb3 : 1; // bit 3 @@ -237,7 +237,9 @@ struct TunerStudioOutputChannels { int16_t tuneCrc16; // 244 - uint8_t sd_status; // 246 + // Offset 246: bits + uint8_t sd_logging_internal : 1; // bit 0 + uint8_t sd_msd : 1; // bit 1 int8_t tcuCurrentGear; // 247 diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 6387968ba3..27ea3dd308 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -480,10 +480,6 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ executorStatistics(); #endif /* EFI_PROD_CODE */ -#if EFI_SIMULATOR - tsOutputChannels->sd_status = 1 + 4; -#endif - // header tsOutputChannels->tsConfigVersion = TS_FILE_VERSION; @@ -693,10 +689,6 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tsOutputChannels->needBurn = getNeedToWriteConfiguration(); #endif /* EFI_INTERNAL_FLASH */ -#if EFI_FILE_LOGGING - tsOutputChannels->hasSdCard = isSdCardAlive(); -#endif /* EFI_FILE_LOGGING */ - tsOutputChannels->isFuelPumpOn = enginePins.fuelPumpRelay.getLogicValue(); tsOutputChannels->isFanOn = enginePins.fanRelay.getLogicValue(); tsOutputChannels->isO2HeaterOn = enginePins.o2heater.getLogicValue(); diff --git a/firmware/hw_layer/mass_storage/mass_storage_init.cpp b/firmware/hw_layer/mass_storage/mass_storage_init.cpp index 2b472dfcb4..6dcab3edb2 100644 --- a/firmware/hw_layer/mass_storage/mass_storage_init.cpp +++ b/firmware/hw_layer/mass_storage/mass_storage_init.cpp @@ -1,6 +1,7 @@ #include "mass_storage_init.h" #include "mass_storage_device.h" #include "null_device.h" +#include "tunerstudio_outputs.h" #if HAL_USE_USB_MSD @@ -66,6 +67,11 @@ static const scsi_inquiry_response_t sdCardInquiry = { void attachMsdSdCard(BaseBlockDevice* blkdev) { msd.attachLun(1, blkdev, blkbuf1, &sdCardInquiry, nullptr); + +#if EFI_TUNER_STUDIO + // SD MSD attached, enable indicator in TS + tsOutputChannels.sd_msd = true; +#endif } static BaseBlockDevice* getRamdiskDevice() { diff --git a/firmware/hw_layer/mmc_card.cpp b/firmware/hw_layer/mmc_card.cpp index aaa530d74b..741b1c0775 100644 --- a/firmware/hw_layer/mmc_card.cpp +++ b/firmware/hw_layer/mmc_card.cpp @@ -394,6 +394,11 @@ static BaseBlockDevice* initializeMmcBlockDevice() { static bool mountMmc() { auto cardBlockDevice = initializeMmcBlockDevice(); +#if EFI_TUNER_STUDIO + // If not null, card is present + tsOutputChannels.sd_present = cardBlockDevice != nullptr; +#endif + #if HAL_USE_USB_MSD // Wait for the USB stack to wake up, or a 5 second timeout, whichever occurs first msg_t usbResult = usbConnectedSemaphore.wait(TIME_MS2I(5000)); @@ -480,6 +485,10 @@ static THD_FUNCTION(MMCmonThread, arg) { return; } + #if EFI_TUNER_STUDIO + tsOutputChannels.sd_logging_internal = true; + #endif + while (true) { // if the SPI device got un-picked somehow, cancel SD card if (CONFIG(sdCardSpiDevice) == SPI_NONE) { diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 420cb6d98d..18eecb2fc2 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -177,7 +177,7 @@ enable2ndByteCanID = false ; ; Bit flags - hasSdCard = bits, U32, 0, [0:0], "true", "false"; + sd_present = bits, U32, 0, [0:0], "true", "false"; isIgnitionEnabledIndicator=bits,U32, 0, [1:1], "true", "false"; isInjectionEnabledIndicator=bits,U32,0, [2:2], "true", "false"; isCylinderCleanupActivated=bits,U32, 0, [4:4], "true", "false"; @@ -365,7 +365,8 @@ enable2ndByteCanID = false ; we use this to match logs to tunes tuneCrc16 = scalar, U16, 244, "crc16", 1, 0 - sd_status = scalar, U08, 246, "", 1.0, 0.0 + sd_logging_internal = bits, U08, 246, [0:0], "true", "false" + sd_msd = bits, U08, 246, [1:1], "true", "false" ; Transmission tcuCurrentGear = scalar, S08, 247, "gear", 1, 0 @@ -1219,14 +1220,9 @@ gaugeCategory = DynoView indicator = { knockEverIndicator }, "", "Knock recently", white, black, red, black indicator = { knockNowIndicator }, "no knock", "Knock NOW", white, black, red, black -; this bit array has special meaning for TS - that's part of TS build in file transfer -; we _probably_ should officially retire TS file transfer since we have something way cooler! - indicator = { sd_status & 1}, "No SD", "SD in", white, black, green, black - indicator = { sd_status & 4}, "SD ready", "SD ready", white, black, green, black - indicator = { sd_status & 8}, "SD Log", "SD Log", white, black, green, black - indicator = { sd_status & 16}, "SD Err", "SD Err", white, black, red, black -; todo: duplication with 'SD in'?! - indicator = { hasSdCard}, "no SD", "with SD", white, black, green, black + indicator = { sd_present }, "no SD card", "SD card OK", white, black, green, black + indicator = { sd_logging_internal }, "SD logging", "SD logging", white, black, green, black + indicator = { sd_msd }, "SD USB", "SD USB", white, black, green, black ; looks like TS would append four system indicators below: Data Logging, ???, Not Connected, Protocol Error