speedo output

This commit is contained in:
Matthew Kennedy 2023-10-15 17:59:39 -04:00 committed by rusefillc
parent d2516262bd
commit ee381b2f34
9 changed files with 59 additions and 9 deletions

View File

@ -25,6 +25,7 @@
#include "idle_hardware.h"
#include "gppwm.h"
#include "tachometer.h"
#include "speedometer.h"
#include "dynoview.h"
#include "boost_control.h"
#include "fan_control.h"
@ -545,7 +546,8 @@ void Engine::periodicFastCallback() {
engineState.periodicFastCallback();
tachSignalCallback();
tachUpdate();
speedoUpdate();
engine->engineModules.apply_all([](auto & m) { m.onFastCallback(); });
}

View File

@ -26,6 +26,7 @@ CONTROLLERS_SRC_CPP = \
$(CONTROLLERS_DIR)/actuators/gppwm/gppwm_channel.cpp \
$(CONTROLLERS_DIR)/actuators/gppwm/gppwm.cpp \
$(CONTROLLERS_DIR)/gauges/tachometer.cpp \
$(CONTROLLERS_DIR)/gauges/speedometer.cpp \
$(CONTROLLERS_DIR)/gauges/malfunction_indicator.cpp \
$(CONTROLLERS_DIR)/system/timer/signal_executor_sleep.cpp \
$(CONTROLLERS_DIR)/system/timer/single_timer_executor.cpp \

View File

@ -52,6 +52,7 @@
#include "boost_control.h"
#include "launch_control.h"
#include "tachometer.h"
#include "speedometer.h"
#include "gppwm.h"
#include "date_stamp.h"
#include "rusefi_lua.h"
@ -510,6 +511,7 @@ void commonInitEngineController() {
#endif /* EFI_ENGINE_CONTROL */
initTachometer();
initSpeedometer();
}
// Returns false if there's an obvious problem with the loaded configuration

View File

@ -0,0 +1,39 @@
#include "pch.h"
#include "speedometer.h"
static SimplePwm speedoPwm("speedo");
static bool hasSpeedoInit = false;
void speedoUpdate() {
if (!hasSpeedoInit) {
return;
}
float kph = Sensor::getOrZero(SensorType::VehicleSpeed);
float kps = kph * (1. / 3600);
float freq = kps * engineConfiguration->speedometerPulsePerKm;
if (freq < 1) {
freq = NAN;
}
speedoPwm.setFrequency(freq);
}
void initSpeedometer() {
hasSpeedoInit = false;
if (!isBrainPinValid(engineConfiguration->speedometerOutputPin)) {
return;
}
startSimplePwm(&speedoPwm,
"Speedometer",
&engine->executor,
&enginePins.speedoOut,
NAN, 0.5f);
hasSpeedoInit = true;
}

View File

@ -0,0 +1,4 @@
#pragma once
void initSpeedometer();
void speedoUpdate();

View File

@ -28,7 +28,7 @@ float getTachDuty() {
static bool tachHasInit = false;
void tachSignalCallback() {
void tachUpdate() {
// Only do anything if tach enabled
if (!tachHasInit) {
return;
@ -60,12 +60,13 @@ void tachSignalCallback() {
tachFreq = NAN;
}
tachControl.setSimplePwmDutyCycle(duty);
tachControl.setSimplePwmDutyCycle(duty);
tachControl.setFrequency(tachFreq);
}
void initTachometer() {
tachHasInit = false;
if (!isBrainPinValid(engineConfiguration->tachOutputPin)) {
return;
}

View File

@ -8,4 +8,4 @@
#pragma once
void initTachometer();
void tachSignalCallback();
void tachUpdate();

View File

@ -149,9 +149,9 @@ EnginePins::EnginePins() :
alternatorPin("Alternator control", CONFIG_PIN_OFFSETS(alternatorControl)),
checkEnginePin("checkEnginePin", CONFIG_PIN_OFFSETS(malfunctionIndicator)),
tachOut("tachOut", CONFIG_PIN_OFFSETS(tachOutput)),
triggerDecoderErrorPin("led: trigger debug", CONFIG_PIN_OFFSETS(triggerError))
triggerDecoderErrorPin("led: trigger debug", CONFIG_PIN_OFFSETS(triggerError)),
speedoOut("speedoOut", CONFIG_OFFSET(speedometerOutputPin))
{
tachOut.name = PROTOCOL_TACH_NAME;
hpfpValve.name = PROTOCOL_HPFP_NAME;
static_assert(efi::size(sparkNames) >= MAX_CYLINDER_COUNT, "Too many ignition pins");

View File

@ -54,7 +54,7 @@ private:
class RegisteredNamedOutputPin : public RegisteredOutputPin, public NamedOutputPin {
public:
RegisteredNamedOutputPin(const char *name, size_t pinOffset, size_t pinModeOffset);
RegisteredNamedOutputPin(const char* name, size_t pinOffset, size_t pinModeOffset);
};
class EnginePins {
@ -106,9 +106,10 @@ public:
*/
RegisteredOutputPin checkEnginePin;
RegisteredNamedOutputPin tachOut;
RegisteredOutputPin tachOut;
RegisteredOutputPin triggerDecoderErrorPin;
RegisteredOutputPin speedoOut;
OutputPin sdCsPin;
OutputPin accelerometerCs;