DebounceButton A/C switch (#1782)
* change acSwitch name, add mode * fix * remove some adc stuff * remove some adc stuff * semicolon stupid * left behind * add readpinstate * wrong var name * add functions back * fix name * bool, not void, plus fix name * move * not sure what I broke * try setMockValue * namespace * whoops missed one * switch values because adc was set up for pullup * try 5 * comment for now * comment for now * uncomment tests, add function to mock, add mock to efiReadPin * fixes * for F's sake * if * add defy * pass params * use ASSERT_TRUE/FALSE * advance time * remove ifdef from readPin * try moving if * move to separate func * move extern * move include * try engine_test_helper * am confuse * move func to else * include hal * add efi prod check * remove include * try extern * move include * semicolon stupid * move extern again * include * move mockPinStates * size * add if * add comment * clean on instantiation
This commit is contained in:
parent
04877b8b95
commit
337106cd24
|
@ -112,8 +112,8 @@ void setBoardConfigurationOverrides(void) {
|
|||
engineConfiguration->hipOutputChannel = EFI_ADC_NONE;
|
||||
engineConfiguration->fuelLevelSensor = EFI_ADC_NONE;
|
||||
engineConfiguration->oilPressure.hwChannel = EFI_ADC_NONE;
|
||||
engineConfiguration->acSwitchAdc = EFI_ADC_NONE;
|
||||
|
||||
engineConfiguration->acSwitch = GPIO_UNASSIGNED;
|
||||
engineConfiguration->triggerInputPins[0] = GPIOB_0;
|
||||
engineConfiguration->triggerInputPins[1] = GPIO_UNASSIGNED;
|
||||
engineConfiguration->triggerInputPins[2] = GPIO_UNASSIGNED;
|
||||
|
|
|
@ -334,7 +334,7 @@ void setMiataNA6_MAP_Frankenso(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
|||
engineConfiguration->throttlePedalUpPin = GPIOA_7;
|
||||
|
||||
// green wire from 1Q/W17 to bottom of W46
|
||||
engineConfiguration->acSwitchAdc = EFI_ADC_6; // PA6
|
||||
engineConfiguration->acSwitch = GPIOA_6;
|
||||
|
||||
#if ! EFI_UNIT_TEST
|
||||
// W57 PE3 A/C compressor relay out
|
||||
|
@ -430,7 +430,7 @@ void setMiataNA6_MAP_MRE(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
|||
|
||||
|
||||
// EFI_ADC_3: "22 - AN temp 4"
|
||||
engineConfiguration->acSwitchAdc = EFI_ADC_3;
|
||||
engineConfiguration->acSwitch = GPIOA_6;
|
||||
|
||||
engineConfiguration->warningLedPin = GPIOD_13;
|
||||
engineConfiguration->triggerErrorPin = GPIOE_1;
|
||||
|
|
|
@ -108,10 +108,6 @@ TransmissionState::TransmissionState() {
|
|||
|
||||
EngineState::EngineState() {
|
||||
timeSinceLastTChargeK = getTimeNowNt();
|
||||
|
||||
#if ! EFI_PROD_CODE
|
||||
memset(mockPinStates, 0, sizeof(mockPinStates));
|
||||
#endif /* EFI_PROD_CODE */
|
||||
}
|
||||
|
||||
void EngineState::updateSlowSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
|
|
|
@ -335,7 +335,6 @@ void prepareVoidConfiguration(engine_configuration_s *engineConfiguration) {
|
|||
*/
|
||||
engineConfiguration->tps2_1AdcChannel = EFI_ADC_NONE;
|
||||
engineConfiguration->auxFastSensor1_adcChannel = EFI_ADC_NONE;
|
||||
engineConfiguration->acSwitchAdc = EFI_ADC_NONE;
|
||||
engineConfiguration->externalKnockSenseAdc = EFI_ADC_NONE;
|
||||
engineConfiguration->fuelLevelSensor = EFI_ADC_NONE;
|
||||
engineConfiguration->hipOutputChannel = EFI_ADC_NONE;
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
#include "pid.h"
|
||||
#include "engine_state_generated.h"
|
||||
|
||||
#define BRAIN_PIN_COUNT (1 << sizeof(brain_pin_e))
|
||||
|
||||
class EngineState : public engine_state2_s {
|
||||
public:
|
||||
EngineState();
|
||||
|
@ -22,10 +20,6 @@ public:
|
|||
void updateSlowSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void updateTChargeK(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
#if ! EFI_PROD_CODE
|
||||
bool mockPinStates[BRAIN_PIN_COUNT];
|
||||
#endif
|
||||
|
||||
FuelConsumptionState fuelConsumption;
|
||||
|
||||
efitick_t crankingTime = 0;
|
||||
|
|
|
@ -351,7 +351,6 @@ static void printAnalogInfo(void) {
|
|||
printAnalogChannelInfo("CJ UR", engineConfiguration->cj125ur);
|
||||
printAnalogChannelInfo("CJ UA", engineConfiguration->cj125ua);
|
||||
|
||||
printAnalogChannelInfo("A/C sw", engineConfiguration->acSwitchAdc);
|
||||
printAnalogChannelInfo("HIP9011", engineConfiguration->hipOutputChannel);
|
||||
|
||||
for (int i = 0; i < FSIO_ANALOG_INPUT_COUNT ; i++) {
|
||||
|
|
|
@ -31,6 +31,7 @@ void setMockAfrVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
|
|||
void setMockMafVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void setMockIatVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void setMockCltVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void setMockState(brain_pin_e pin, bool state DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
void printCurrentState(Logging *logging, int seconds, const char *engineTypeName, const char *firmwareBuildId);
|
||||
|
||||
|
|
|
@ -15,6 +15,10 @@ EXTERN_ENGINE;
|
|||
extern LoggingWithStorage sharedLogger;
|
||||
extern ButtonDebounce startStopButtonDebounce;
|
||||
|
||||
#if ! EFI_PROD_CODE
|
||||
extern bool mockPinStates[(1 << sizeof(brain_pin_e))];
|
||||
#endif
|
||||
|
||||
#if ENABLE_PERF_TRACE
|
||||
static uint8_t nextThreadId = 0;
|
||||
void threadInitHook(void* vtp) {
|
||||
|
@ -71,6 +75,12 @@ void setMockVBattVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
setMockVoltage(engineConfiguration->vbattAdcChannel, voltage PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
|
||||
void setMockState(brain_pin_e pin, bool state DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
#if ! EFI_PROD_CODE
|
||||
mockPinStates[static_cast<int>(pin)] = state;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* EFI_ENABLE_MOCK_ADC */
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
|
|
|
@ -12,21 +12,17 @@
|
|||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
ButtonDebounce acDebounce;
|
||||
|
||||
void initSensors(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
initMapDecoder(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
acDebounce.init(15, &CONFIG(acSwitch), &CONFIG(acSwitchMode));
|
||||
}
|
||||
|
||||
bool getAcToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
return acDebounce.readPinState();
|
||||
}
|
||||
|
||||
bool hasAcToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
return engineConfiguration->acSwitchAdc != EFI_ADC_NONE;
|
||||
}
|
||||
|
||||
// todo: move this somewhere else? maybe.
|
||||
bool getAcToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
/**
|
||||
* todo: make this flexible
|
||||
*
|
||||
* for now we are looking for a pull-up. High level means input switch is floating (which is OFF position)
|
||||
* low value means input is ground - which means ON.
|
||||
*/
|
||||
return getVoltageDivided("A/C", engineConfiguration->acSwitchAdc PASS_ENGINE_PARAMETER_SUFFIX) < 2.5;
|
||||
return (CONFIG(acSwitch) != GPIO_UNASSIGNED);
|
||||
}
|
||||
|
|
|
@ -540,7 +540,6 @@ static void configureInputs(void) {
|
|||
}
|
||||
addChannel("AFR", engineConfiguration->afr.hwChannel, ADC_SLOW);
|
||||
addChannel("Oil Pressure", engineConfiguration->oilPressure.hwChannel, ADC_SLOW);
|
||||
addChannel("AC", engineConfiguration->acSwitchAdc, ADC_SLOW);
|
||||
if (engineConfiguration->high_fuel_pressure_sensor_1 != INCOMPATIBLE_CONFIG_CHANGE) {
|
||||
addChannel("HFP1", engineConfiguration->high_fuel_pressure_sensor_1, ADC_SLOW);
|
||||
}
|
||||
|
|
|
@ -86,8 +86,10 @@ bool ButtonDebounce::readPinState() {
|
|||
// but when a method is implemented to actually get the pin's state,
|
||||
// for example to implement long button presses, it will be needed.
|
||||
readValue = false;
|
||||
#ifndef EFI_UNIT_TEST
|
||||
#if EFI_PROD_CODE || EFI_UNIT_TEST
|
||||
readValue = efiReadPin(active_pin);
|
||||
#endif
|
||||
#if EFI_PROD_CODE
|
||||
// Invert
|
||||
if (getInputMode(active_mode) == PAL_MODE_INPUT_PULLUP) {
|
||||
readValue = !readValue;
|
||||
|
|
|
@ -9,10 +9,14 @@
|
|||
|
||||
#include "global.h"
|
||||
#include "io_pins.h"
|
||||
#include "efi_gpio.h"
|
||||
#include "engine.h"
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
|
||||
#include "os_access.h"
|
||||
#include "efi_gpio.h"
|
||||
#include "drivers/gpio/gpio_ext.h"
|
||||
|
||||
#include "pin_repository.h"
|
||||
|
@ -20,7 +24,6 @@
|
|||
#include "engine_configuration.h"
|
||||
#include "console_io.h"
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
#if EFI_ENGINE_CONTROL
|
||||
#include "main_trigger_callback.h"
|
||||
|
@ -114,7 +117,9 @@ void efiIcuStart(const char *msg, ICUDriver *icup, const ICUConfig *config) {
|
|||
#endif /* HAL_USE_ICU */
|
||||
|
||||
#else
|
||||
extern bool mockPinStates[(1 << sizeof(brain_pin_e))];
|
||||
|
||||
bool efiReadPin(brain_pin_e pin) {
|
||||
return false;
|
||||
return mockPinStates[static_cast<int>(pin)];
|
||||
}
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
|
|
@ -990,7 +990,7 @@ bit useFSIO13ForIdleMinValue;
|
|||
bit useFSIO6ForRevLimiter;
|
||||
|
||||
adc_channel_e hipOutputChannel;
|
||||
adc_channel_e acSwitchAdc;A/C button input handled as analogue input
|
||||
switch_input_pin_e acSwitch; A/C button input
|
||||
adc_channel_e vRefAdcChannel;
|
||||
uint8_t etbNeutralPosition;+Expected neutral position;"%", 1, 0, 0, 100, 0
|
||||
|
||||
|
@ -1386,8 +1386,10 @@ uint8_t[4] unusedsw;;"units", 1, 0, -20, 100, 0
|
|||
pin_input_mode_e tcuUpshiftButtonPinMode
|
||||
pin_input_mode_e tcuDownshiftButtonPinMode
|
||||
|
||||
pin_input_mode_e acSwitchMode
|
||||
|
||||
! just a reminder that 'int' and 'float' are 4 bytes each
|
||||
int[371] mainUnusedEnd;;"units", 1, 0, -20, 100, 0
|
||||
int[370] mainUnusedEnd;;"units", 1, 0, -20, 100, 0
|
||||
|
||||
! end of engine_configuration_s
|
||||
end_struct
|
||||
|
|
|
@ -1881,7 +1881,8 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
|
|||
field = "Clutch up inverted", clutchUpPinMode
|
||||
field = "Throttle Up switch", throttlePedalUpPin
|
||||
field = "Brake pedal switch", brakePedalPin
|
||||
field = "A/C switch", acSwitchAdc
|
||||
field = "A/C switch", acSwitch
|
||||
field = "A/C switch mode", acSwitchMode
|
||||
|
||||
dialog = triggerInputComparator, "Built-in Comparator Settings (Kinetis-only)"
|
||||
field = "Comparator Center Point Voltage", triggerCompCenterVolt
|
||||
|
@ -1920,7 +1921,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
|
|||
field = "clutchDownPin", clutchDownPin
|
||||
field = "clutchUpPin", clutchUpPin
|
||||
field = "brakePedalPin", brakePedalPin
|
||||
field = "A/C Switch", acSwitchAdc
|
||||
field = "A/C Switch", acSwitch
|
||||
field = "Aux Temperature #1", auxTempSensor1_adcChannel
|
||||
field = "Aux Temperature #2", auxTempSensor2_adcChannel
|
||||
field = "Aux Fast Analog", auxFastSensor1_adcChannel
|
||||
|
|
|
@ -24,6 +24,10 @@ extern engine_configuration_s & activeConfiguration;
|
|||
extern bool printTriggerDebug;
|
||||
extern bool printFuelDebug;
|
||||
|
||||
// This has been made global so we don't need to worry about efiReadPin having access the object
|
||||
// we store it in, every time we need to use efiReadPin.
|
||||
bool mockPinStates[BRAIN_PIN_COUNT];
|
||||
|
||||
EngineTestHelperBase::EngineTestHelperBase() {
|
||||
// todo: make this not a global variable, we need currentTimeProvider interface on engine
|
||||
timeNowUs = 0;
|
||||
|
@ -87,6 +91,8 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callb
|
|||
// Setup running in mock airmass mode
|
||||
engineConfiguration->fuelAlgorithm = LM_MOCK;
|
||||
engine->mockAirmassModel = &mockAirmass;
|
||||
|
||||
memset(mockPinStates, 0, sizeof(mockPinStates));
|
||||
}
|
||||
|
||||
EngineTestHelper::~EngineTestHelper() {
|
||||
|
@ -97,6 +103,7 @@ EngineTestHelper::~EngineTestHelper() {
|
|||
|
||||
// Cleanup
|
||||
Sensor::resetRegistry();
|
||||
memset(mockPinStates, 0, sizeof(mockPinStates));
|
||||
}
|
||||
|
||||
static CompositeEvent compositeEvents[COMPOSITE_PACKET_COUNT];
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#define BRAIN_PIN_COUNT (1 << sizeof(brain_pin_e))
|
||||
|
||||
#include "engine.h"
|
||||
#include "trigger_central.h"
|
||||
#include "rpm_calculator.h"
|
||||
|
|
|
@ -39,15 +39,17 @@ TEST(idle, fsioPidParameters) {
|
|||
applyFsioExpression(QUOTE(MAGIC_OFFSET_FOR_IDLE_MIN_VALUE), "ac_on_switch 0 cfg_acIdleExtraMin if" PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
ASSERT_EQ(1, hasAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
|
||||
setMockVoltage(engineConfiguration->acSwitchAdc, 0 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
ASSERT_EQ(1, getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
|
||||
setMockState(engineConfiguration->acSwitch, true PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
timeNowUs += MS2US(15);
|
||||
ASSERT_TRUE(getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
|
||||
|
||||
eth.engine.periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
ASSERT_EQ(40, getIdlePidOffset(PASS_ENGINE_PARAMETER_SIGNATURE));
|
||||
ASSERT_EQ(30, getIdlePidMinValue(PASS_ENGINE_PARAMETER_SIGNATURE));
|
||||
|
||||
setMockVoltage(engineConfiguration->acSwitchAdc, 5 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
ASSERT_EQ(0, getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
|
||||
setMockState(engineConfiguration->acSwitch, false PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
timeNowUs += MS2US(15);
|
||||
ASSERT_FALSE(getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE));
|
||||
|
||||
eth.engine.periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
ASSERT_EQ(50, getIdlePidOffset(PASS_ENGINE_PARAMETER_SIGNATURE));
|
||||
|
|
Loading…
Reference in New Issue