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

#include <gc_generic.h>

Inheritance diagram for GenericGearController:
Inheritance graph
[legend]
Collaboration diagram for GenericGearController:
Collaboration graph
[legend]

Public Member Functions

 GenericGearController ()
 
void update ()
 
void init ()
 
GearControllerMode getMode () const
 
- Public Member Functions inherited from AutomaticGearController
 AutomaticGearController ()
 
void findDesiredGear ()
 
- Public Member Functions inherited from GearControllerBase
virtual gear_e getDesiredGear () const
 

Private Member Functions

bool isNearest (float value, int pinIndex, float *rangeStates)
 
SensorType getAnalogSensorType (int zeroBasedSensorIndex)
 

Private Attributes

Timer shiftTimer
 
SelectedGear lastRange
 

Additional Inherited Members

- Data Fields inherited from GearControllerBase
TransmissionControllerBasetransmissionController
 
- Protected Member Functions inherited from GearControllerBase
virtual gear_e setDesiredGear (gear_e)
 
void initTransmissionController ()
 
floatgetRangeStateArray (int)
 

Detailed Description

Definition at line 7 of file gc_generic.h.

Constructor & Destructor Documentation

◆ GenericGearController()

GenericGearController::GenericGearController ( )

Definition at line 9 of file gc_generic.cpp.

9 {
10}

Member Function Documentation

◆ getAnalogSensorType()

SensorType GenericGearController::getAnalogSensorType ( int  zeroBasedSensorIndex)
private

Definition at line 24 of file gc_generic.cpp.

24 {
25 return static_cast<SensorType>(zeroBasedSensorIndex + static_cast<int>(SensorType::RangeInput1));
26}
SensorType
Definition sensor_type.h:18

Referenced by update().

Here is the caller graph for this function:

◆ getMode()

GearControllerMode GenericGearController::getMode ( ) const
inlinevirtual

Reimplemented from AutomaticGearController.

Definition at line 13 of file gc_generic.h.

◆ init()

void GenericGearController::init ( )
virtual

Reimplemented from GearControllerBase.

Definition at line 12 of file gc_generic.cpp.

12 {
13#if EFI_PROD_CODE
14 for (size_t i = 0; i < efi::size(engineConfiguration->tcu_rangeInput); i++) {
17 }
18 }
19#endif /* EFI_PROD_CODE */
20
22}
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
virtual void init()
static constexpr engine_configuration_s * engineConfiguration
iomode_t getInputMode(pin_input_mode_e mode)
Definition io_pins.cpp:103
bool isBrainPinValid(brain_pin_e brainPin)
Here is the call graph for this function:

◆ isNearest()

bool GenericGearController::isNearest ( float  value,
int  pinIndex,
float rangeStates 
)
private

Definition at line 28 of file gc_generic.cpp.

28 {
29 float distance = fabs(rangeStates[pinIndex] - value);
30 for (int i = 1; i <= TCU_RANGE_COUNT; i++) {
31 float pinDistance = fabs(getRangeStateArray(i)[pinIndex] - value);
32 if (pinDistance < distance) {
33 return false;
34 }
35 }
36 return true;
37}
float * getRangeStateArray(int)

Referenced by update().

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

◆ update()

void GenericGearController::update ( )
virtual

Reimplemented from AutomaticGearController.

Definition at line 39 of file gc_generic.cpp.

39 {
41 // Loop through possible range states
42 // 1 based because 0 is SelectedGear::Invalid
43 for (int i = 1; i <= TCU_RANGE_COUNT; i++) {
44 float *rangeStates = getRangeStateArray(i);
45 // Loop through inputs
46 for (size_t p = 0; p < efi::size(engineConfiguration->tcu_rangeInput); p++) {
47 float cellState = rangeStates[p];
48 // We allow the user to configure either a digital input or an analog input for each pin,
49 // so we need to check which is valid.
51 float pinState = Sensor::getOrZero(getAnalogSensorType(p));
52 if (getRangeStateArray(i)[p] == 0 || isNearest(pinState, p, rangeStates)) {
53 // Set the gear to the one we're checking, and continue to the next pin
54 gear = static_cast<SelectedGear>(i);
55 } else {
56 // This possibility doesn't match, set to invalid
58 break;
59 }
62 // If the pin doesn't matter, or if it matches the cellState
63 if (cellState == 2 || (pinState && cellState == 1) || (!pinState && cellState == 0)) {
64 // Set the gear to the one we're checking, and continue to the next pin
65 gear = static_cast<SelectedGear>(i);
66 } else {
67 // This possibility doesn't match, set to invalid
69 break;
70 }
71 }
72 }
73 // If we didn't find it, try the next range
74 if (gear == SelectedGear::Invalid) {
75 continue;
76 // We found a match
77 } else {
78 break;
79 }
80 }
81 if (gear != SelectedGear::Invalid) {
82 switch (gear) {
85 break;
88 break;
91 break;
94 break;
98 break;
100 // Only allow manual shift once per 500 ms,
101 // and if the selected range was Manual prior to this update
102 if (!shiftTimer.hasElapsedMs(500) || lastRange != SelectedGear::Manual) {
103 break;
104 }
105 shiftTimer.reset();
106 switch (getDesiredGear()) {
107 case GEAR_1 :
109 break;
110 case GEAR_2 :
112 break;
113 case GEAR_3 :
115 break;
116 default:
117 break;
118 }
119 break;
121 // Only allow manual shift once per 500 ms,
122 // and if the selected range was Manual prior to this update
123 if (!shiftTimer.hasElapsedMs(500) || lastRange != SelectedGear::Manual) {
124 break;
125 }
126 shiftTimer.reset();
127 switch (getDesiredGear()) {
128 case GEAR_2 :
130 break;
131 case GEAR_3 :
133 break;
134 case GEAR_4 :
136 break;
137 default:
138 break;
139 }
140 break;
142 // If the gear selector is in drive, let AutomaticGearController,
143 // which this class inherits from, decide what gear the transmission should be in.
145 return;
146 default:
147 break;
148 }
149
150 lastRange = gear;
151 }
152
154}
bool isAdcChannelValid(adc_channel_e hwChannel)
Definition adc_inputs.h:23
virtual void update()
virtual gear_e getDesiredGear() const
virtual gear_e setDesiredGear(gear_e)
bool isNearest(float value, int pinIndex, float *rangeStates)
SelectedGear lastRange
Definition gc_generic.h:18
SensorType getAnalogSensorType(int zeroBasedSensorIndex)
static float getOrZero(SensorType type)
Definition sensor.h:83
bool efiReadPin(brain_pin_e pin)
Definition io_pins.cpp:89
@ GEAR_2
@ REVERSE
@ GEAR_1
@ GEAR_4
@ NEUTRAL
@ GEAR_3
SelectedGear
Here is the call graph for this function:

Field Documentation

◆ lastRange

SelectedGear GenericGearController::lastRange
private

Definition at line 18 of file gc_generic.h.

Referenced by update().

◆ shiftTimer

Timer GenericGearController::shiftTimer
private

Definition at line 17 of file gc_generic.h.

Referenced by update().


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