code style and some refactoring

This commit is contained in:
rusefi 2018-12-08 16:59:16 -05:00
parent a6d83e1cc2
commit 8c3934a7b3
6 changed files with 17 additions and 24 deletions

View File

@ -21,35 +21,35 @@ void single_wave_s::init(pin_state_t *pinStates) {
this->pinStates = pinStates; this->pinStates = pinStates;
} }
void multi_wave_s::baseConstructor() { void MultiWave::baseConstructor() {
waves = NULL; waves = NULL;
switchTimes = NULL; switchTimes = NULL;
reset(); reset();
} }
multi_wave_s::multi_wave_s() { MultiWave::MultiWave() {
baseConstructor(); baseConstructor();
} }
multi_wave_s::multi_wave_s(float *switchTimes, single_wave_s *waves) { MultiWave::MultiWave(float *switchTimes, single_wave_s *waves) {
baseConstructor(); baseConstructor();
init(switchTimes, waves); init(switchTimes, waves);
} }
void multi_wave_s::init(float *switchTimes, single_wave_s *waves) { void MultiWave::init(float *switchTimes, single_wave_s *waves) {
this->switchTimes = switchTimes; this->switchTimes = switchTimes;
this->waves = waves; this->waves = waves;
} }
void multi_wave_s::reset(void) { void MultiWave::reset(void) {
waveCount = 0; waveCount = 0;
} }
float multi_wave_s::getSwitchTime(int index) const { float MultiWave::getSwitchTime(int index) const {
return switchTimes[index]; return switchTimes[index];
} }
void checkSwitchTimes2(int size, float *switchTimes) { void MultiWave::checkSwitchTimes(int size) {
if (switchTimes[size - 1] != 1) { if (switchTimes[size - 1] != 1) {
firmwareError(CUSTOM_ERR_WAVE_1, "last switch time has to be 1 not %.2f", switchTimes[size - 1]); firmwareError(CUSTOM_ERR_WAVE_1, "last switch time has to be 1 not %.2f", switchTimes[size - 1]);
return; return;
@ -61,14 +61,14 @@ void checkSwitchTimes2(int size, float *switchTimes) {
} }
} }
int multi_wave_s::getChannelState(int channelIndex, int phaseIndex) const { int MultiWave::getChannelState(int channelIndex, int phaseIndex) const {
return waves[channelIndex].pinStates[phaseIndex]; return waves[channelIndex].pinStates[phaseIndex];
} }
/** /**
* returns the index at which given value would need to be inserted into sorted array * returns the index at which given value would need to be inserted into sorted array
*/ */
int multi_wave_s::findInsertionAngle(float angle, int size) const { int MultiWave::findInsertionAngle(float angle, int size) const {
for (int i = size - 1; i >= 0; i--) { for (int i = size - 1; i >= 0; i--) {
if (angle > switchTimes[i]) if (angle > switchTimes[i])
return i + 1; return i + 1;
@ -76,7 +76,7 @@ int multi_wave_s::findInsertionAngle(float angle, int size) const {
return 0; return 0;
} }
int multi_wave_s::findAngleMatch(float angle, int size) const { int MultiWave::findAngleMatch(float angle, int size) const {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
if (isSameF(switchTimes[i], angle)) if (isSameF(switchTimes[i], angle))
return i; return i;
@ -84,8 +84,7 @@ int multi_wave_s::findAngleMatch(float angle, int size) const {
return EFI_ERROR_CODE; return EFI_ERROR_CODE;
} }
void multi_wave_s::setSwitchTime(int index, float value) { void MultiWave::setSwitchTime(int index, float value) {
efiAssertVoid(CUSTOM_ERR_6690, switchTimes != NULL, "switchTimes"); efiAssertVoid(CUSTOM_ERR_6690, switchTimes != NULL, "switchTimes");
switchTimes[index] = value; switchTimes[index] = value;
} }

View File

@ -34,11 +34,11 @@ public:
class TriggerShape; class TriggerShape;
class multi_wave_s { class MultiWave {
public: public:
void baseConstructor(); void baseConstructor();
multi_wave_s(); MultiWave();
multi_wave_s(float *st, single_wave_s *waves); MultiWave(float *st, single_wave_s *waves);
void init(float *st, single_wave_s *waves); void init(float *st, single_wave_s *waves);
void reset(void); void reset(void);
float getSwitchTime(int phaseIndex) const; float getSwitchTime(int phaseIndex) const;
@ -62,6 +62,4 @@ public:
float *switchTimes; float *switchTimes;
}; };
void checkSwitchTimes2(int size, float *switchTimes);
#endif /* EFI_WAVE_H_ */ #endif /* EFI_WAVE_H_ */

View File

@ -199,6 +199,7 @@ void copyPwmParameters(PwmConfig *state, int phaseCount, float *switchTimes, int
state->multiWave.waves[waveIndex].pinStates[phaseIndex] = pinStates[waveIndex][phaseIndex]; state->multiWave.waves[waveIndex].pinStates[phaseIndex] = pinStates[waveIndex][phaseIndex];
} }
} }
state->multiWave.checkSwitchTimes(phaseCount);
} }
/** /**
@ -218,7 +219,6 @@ void PwmConfig::weComplexInit(const char *msg, int phaseCount, float *switchTime
return; return;
} }
efiAssertVoid(CUSTOM_ERR_6583, waveCount > 0, "waveCount should be positive"); efiAssertVoid(CUSTOM_ERR_6583, waveCount > 0, "waveCount should be positive");
checkSwitchTimes2(phaseCount, switchTimes);
this->pwmCycleCallback = pwmCycleCallback; this->pwmCycleCallback = pwmCycleCallback;
this->stateChangeCallback = stateChangeCallback; this->stateChangeCallback = stateChangeCallback;

View File

@ -59,7 +59,7 @@ public:
OutputPin *outputPins[PWM_PHASE_MAX_WAVE_PER_PWM]; OutputPin *outputPins[PWM_PHASE_MAX_WAVE_PER_PWM];
multi_wave_s multiWave; MultiWave multiWave;
efitimeus_t togglePwmState(); efitimeus_t togglePwmState();
int dbgNestingLevel; int dbgNestingLevel;

View File

@ -397,10 +397,6 @@ angle_t TriggerShape::getSwitchAngle(int index) const {
return getCycleDuration() * wave.getSwitchTime(index); return getCycleDuration() * wave.getSwitchTime(index);
} }
void multi_wave_s::checkSwitchTimes(int size) {
checkSwitchTimes2(size, switchTimes);
}
void setToothedWheelConfiguration(TriggerShape *s, int total, int skipped, void setToothedWheelConfiguration(TriggerShape *s, int total, int skipped,
operation_mode_e operationMode DECLARE_ENGINE_PARAMETER_SUFFIX) { operation_mode_e operationMode DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)

View File

@ -147,7 +147,7 @@ public:
int triggerSignals[PWM_PHASE_MAX_COUNT]; int triggerSignals[PWM_PHASE_MAX_COUNT];
#endif #endif
multi_wave_s wave; MultiWave wave;
// todo: add a runtime validation which would verify that this field was set properly // todo: add a runtime validation which would verify that this field was set properly
// tood: maybe even automate this flag calculation? // tood: maybe even automate this flag calculation?