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 22 of file gc_generic.cpp.

22 {
23 return static_cast<SensorType>(zeroBasedSensorIndex + static_cast<int>(SensorType::RangeInput1));
24}
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 for (size_t i = 0; i < efi::size(engineConfiguration->tcu_rangeInput); i++) {
16 }
17 }
18
20}
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 26 of file gc_generic.cpp.

26 {
27 float distance = fabs(rangeStates[pinIndex] - value);
28 for (int i = 1; i <= TCU_RANGE_COUNT; i++) {
29 float pinDistance = fabs(getRangeStateArray(i)[pinIndex] - value);
30 if (pinDistance < distance) {
31 return false;
32 }
33 }
34 return true;
35}
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 37 of file gc_generic.cpp.

37 {
39 // Loop through possible range states
40 // 1 based because 0 is SelectedGear::Invalid
41 for (int i = 1; i <= TCU_RANGE_COUNT; i++) {
42 float *rangeStates = getRangeStateArray(i);
43 // Loop through inputs
44 for (size_t p = 0; p < efi::size(engineConfiguration->tcu_rangeInput); p++) {
45 float cellState = rangeStates[p];
46 // We allow the user to configure either a digital input or an analog input for each pin,
47 // so we need to check which is valid.
49 float pinState = Sensor::getOrZero(getAnalogSensorType(p));
50 if (isNearest(pinState, p, rangeStates)) {
51 // Set the gear to the one we're checking, and continue to the next pin
52 gear = static_cast<SelectedGear>(i);
53 } else {
54 // This possibility doesn't match, set to invalid
56 }
58 // If we've locked out this range with 3 in a cell
59 if (cellState == 3) {
61 break;
62 }
64 // If the pin doesn't matter, or if it matches the cellState
65 if (cellState == 2 || (pinState && cellState == 1) || (!pinState && cellState == 0)) {
66 // Set the gear to the one we're checking, and continue to the next pin
67 gear = static_cast<SelectedGear>(i);
68 } else {
69 // This possibility doesn't match, set to invalid
71 }
72 }
73 }
74 // If we didn't find it, try the next range
75 if (gear == SelectedGear::Invalid) {
76 continue;
77 // We found a match
78 } else {
79 break;
80 }
81 }
82 if (gear != SelectedGear::Invalid) {
83 switch (gear) {
86 break;
89 break;
92 break;
95 break;
99 break;
101 // Only allow manual shift once per 500 ms,
102 // and if the selected range was Manual prior to this update
103 if (!shiftTimer.hasElapsedMs(500) || lastRange != SelectedGear::Manual) {
104 break;
105 }
106 shiftTimer.reset();
107 switch (getDesiredGear()) {
108 case GEAR_1 :
110 break;
111 case GEAR_2 :
113 break;
114 case GEAR_3 :
116 break;
117 default:
118 break;
119 }
120 break;
122 // Only allow manual shift once per 500 ms,
123 // and if the selected range was Manual prior to this update
124 if (!shiftTimer.hasElapsedMs(500) || lastRange != SelectedGear::Manual) {
125 break;
126 }
127 shiftTimer.reset();
128 switch (getDesiredGear()) {
129 case GEAR_2 :
131 break;
132 case GEAR_3 :
134 break;
135 case GEAR_4 :
137 break;
138 default:
139 break;
140 }
141 break;
143 // If the gear selector is in drive, let AutomaticGearController,
144 // which this class inherits from, decide what gear the transmission should be in.
146 return;
147 default:
148 break;
149 }
150
151 lastRange = gear;
152 }
153
155}
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: