rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
GppwmChannel Class Reference

#include <gppwm_channel.h>

Collaboration diagram for GppwmChannel:
Collaboration graph
[legend]

Public Member Functions

void init (bool usePwm, IPwm *pwm, OutputPin *outputPin, const ValueProvider3D *table, const gppwm_channel *config)
 
GppwmResult update (size_t index)
 
GppwmResult getOutput (size_t index) const
 
float setOutput (float result)
 

Private Attributes

bool m_state = false
 
const gppwm_channelm_config = nullptr
 
bool m_usePwm = false
 
IPwmm_pwm = nullptr
 
OutputPinm_output = nullptr
 
const ValueProvider3Dm_table = nullptr
 

Detailed Description

Definition at line 18 of file gppwm_channel.h.

Member Function Documentation

◆ getOutput()

GppwmResult GppwmChannel::getOutput ( size_t  index) const

Definition at line 54 of file gppwm_channel.cpp.

54 {
55 expected<float> xAxisValue = readGppwmChannel(m_config->rpmAxis);
56 expected<float> yAxisValue = readGppwmChannel(m_config->loadAxis);
57
58 GppwmResult result { (float)m_config->dutyIfError, xAxisValue.value_or(0), yAxisValue.value_or(0) };
59 expected<float> override = boardOverrideGppwm(index);
60 if (override) {
61 result.Result = override.Value;
62 return result;
63 }
64
65 // If we couldn't get load axis value, fall back on error value
66 if (!xAxisValue || !yAxisValue) {
67 return result;
68 }
69
70 float resultVal = m_table->getValue(xAxisValue.Value, yAxisValue.Value);
71
72 if (std::isnan(result.Result)) {
73 return result;
74 }
75
76 result.Result = resultVal;
77 return result;
78}
const gppwm_channel * m_config
const ValueProvider3D * m_table
virtual float getValue(float xColumn, float yRow) const =0
expected< float > boardOverrideGppwm(size_t index)
expected< float > readGppwmChannel(gppwm_channel_e channel)

Referenced by update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

void GppwmChannel::init ( bool  usePwm,
IPwm pwm,
OutputPin outputPin,
const ValueProvider3D table,
const gppwm_channel config 
)

Definition at line 41 of file gppwm_channel.cpp.

41 {
42 m_usePwm = usePwm;
43 m_pwm = pwm;
44 m_output = outputPin;
45 m_table = table;
46 m_config = p_config;
47}
OutputPin * m_output

Referenced by initGpPwm().

Here is the caller graph for this function:

◆ setOutput()

float GppwmChannel::setOutput ( float  result)

Definition at line 9 of file gppwm_channel.cpp.

9 {
10 // Not init yet, nothing to do.
11 if (!m_config) {
12 return result;
13 }
14
15 if (m_usePwm) {
16 efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_usePwm, "m_usePwm null", 0);
17 m_pwm->setSimplePwmDutyCycle(clampF(0, result / 100.0f, 1));
18
19 return result;
20 } else {
21 efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_output, "m_output null", 0);
23 firmwareError(ObdCode::CUSTOM_ERR_6122, "You can't have off below %d greater than on above %d",
26 }
27 // Apply hysteresis with provided values
28 if (m_state && result < m_config->offBelowDuty) {
29 m_state = false;
30 } else if (!m_state && result > m_config->onAboveDuty) {
31 m_state = true;
32 }
33
35
36 // Return the actual output value with hysteresis
37 return m_state ? 100 : 0;
38 }
39}
void setValue(const char *msg, int logicValue, bool isForce=false)
Definition efi_gpio.cpp:604
void firmwareError(ObdCode code, const char *fmt,...)
@ OBD_PCM_Processor_Fault
@ CUSTOM_ERR_6122
virtual void setSimplePwmDutyCycle(float dutyCycle)=0

Referenced by update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update()

GppwmResult GppwmChannel::update ( size_t  index)

Definition at line 80 of file gppwm_channel.cpp.

80 {
81 // Without a config, nothing to do.
82 if (!m_config) {
83 return {};
84 }
85
86 auto output = getOutput(index);
87 output.Result = setOutput(output.Result);
88
89 return output;
90}
GppwmResult getOutput(size_t index) const
float setOutput(float result)

Referenced by updateGppwm().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ m_config

const gppwm_channel* GppwmChannel::m_config = nullptr
private

Definition at line 32 of file gppwm_channel.h.

Referenced by getOutput(), init(), setOutput(), and update().

◆ m_output

OutputPin* GppwmChannel::m_output = nullptr
private

Definition at line 35 of file gppwm_channel.h.

Referenced by init(), and setOutput().

◆ m_pwm

IPwm* GppwmChannel::m_pwm = nullptr
private

Definition at line 34 of file gppwm_channel.h.

Referenced by init(), and setOutput().

◆ m_state

bool GppwmChannel::m_state = false
private

Definition at line 29 of file gppwm_channel.h.

Referenced by setOutput().

◆ m_table

const ValueProvider3D* GppwmChannel::m_table = nullptr
private

Definition at line 36 of file gppwm_channel.h.

Referenced by getOutput(), and init().

◆ m_usePwm

bool GppwmChannel::m_usePwm = false
private

Definition at line 33 of file gppwm_channel.h.

Referenced by init(), and setOutput().


The documentation for this class was generated from the following files: