2020-04-26 11:06:28 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "gppwm.h"
|
|
|
|
|
2020-11-11 16:06:04 -08:00
|
|
|
#include "rusefi_types.h"
|
|
|
|
|
|
|
|
struct gppwm_channel;
|
2020-04-26 11:06:28 -07:00
|
|
|
class OutputPin;
|
2021-07-06 18:44:59 -07:00
|
|
|
struct IPwm;
|
2020-04-26 11:06:28 -07:00
|
|
|
class ValueProvider3D;
|
|
|
|
|
2023-02-06 04:53:31 -08:00
|
|
|
struct GppwmResult {
|
|
|
|
percent_t Result;
|
|
|
|
float X;
|
|
|
|
float Y;
|
|
|
|
};
|
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
class GppwmChannel {
|
2020-04-26 11:06:28 -07:00
|
|
|
public:
|
2021-07-01 06:21:18 -07:00
|
|
|
void init(bool usePwm, IPwm* pwm, OutputPin* outputPin, const ValueProvider3D* table, const gppwm_channel* config);
|
2023-02-06 04:53:31 -08:00
|
|
|
GppwmResult update();
|
|
|
|
GppwmResult getOutput() const;
|
2022-09-17 18:38:06 -07:00
|
|
|
|
|
|
|
// Returns actual output duty, with hysteresis applied
|
|
|
|
float setOutput(float result);
|
2020-04-26 11:06:28 -07:00
|
|
|
|
2020-09-03 19:52:29 -07:00
|
|
|
private:
|
2020-04-26 11:06:28 -07:00
|
|
|
// Store the current state so we can apply hysteresis
|
|
|
|
bool m_state = false;
|
|
|
|
|
|
|
|
// Configuration fields
|
|
|
|
const gppwm_channel* m_config = nullptr;
|
|
|
|
bool m_usePwm = false;
|
2021-07-01 06:21:18 -07:00
|
|
|
IPwm* m_pwm = nullptr;
|
2020-06-11 17:43:26 -07:00
|
|
|
OutputPin* m_output = nullptr;
|
2020-04-26 11:06:28 -07:00
|
|
|
const ValueProvider3D* m_table = nullptr;
|
|
|
|
};
|