millis gen
This commit is contained in:
parent
863d9c1cf3
commit
73068f7b1f
2 changed files with 27 additions and 28 deletions
|
@ -2,24 +2,23 @@
|
|||
|
||||
GasolineGenerator::GasolineGenerator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the Gasoline Generator.
|
||||
*
|
||||
*
|
||||
* @note This does not start the generator, it only initializes the input and output cards,
|
||||
*
|
||||
*
|
||||
* @param inputCard The digital input card used for monitoring the generator state
|
||||
* @param outputCard The digital output card used for controlling the generator components
|
||||
* @param config The configuration settings for the generator, pins are of input and output cards specified earlier.
|
||||
*/
|
||||
void GasolineGenerator::initialize(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, const GasolineGeneratorConfig &config)
|
||||
void GasolineGenerator::initialize(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, const GasolineGeneratorConfig &config)
|
||||
{
|
||||
this->config = &config;
|
||||
this->inputCard = inputCard;
|
||||
this->outputCard = outputCard;
|
||||
|
||||
|
||||
// Initialize all outputs to safe state
|
||||
setIgnitionSystem(false);
|
||||
setStarter(false);
|
||||
|
@ -44,7 +43,7 @@ void GasolineGenerator::initialize(DigitalInputCard* inputCard, DigitalOutputCar
|
|||
*/
|
||||
void GasolineGenerator::loop()
|
||||
{
|
||||
unsigned long currentTime = millis();
|
||||
unsigned long currentTime = (xTaskGetTickCount() * 1000) / configTICK_RATE_HZ;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
|
@ -80,7 +79,7 @@ void GasolineGenerator::loop()
|
|||
|
||||
/**
|
||||
* @brief Start the gasoline generator.
|
||||
*
|
||||
*
|
||||
* This function initiates the startup sequence for the generator.
|
||||
* It will close the carburetor valve, power up the ignition system,
|
||||
* and engage the starter relay to start the engine.
|
||||
|
@ -93,7 +92,7 @@ void GasolineGenerator::start()
|
|||
}
|
||||
|
||||
state = GeneratorState::STARTING;
|
||||
startupStartTime = millis();
|
||||
startupStartTime = (xTaskGetTickCount() * 1000) / configTICK_RATE_HZ;
|
||||
ignitionStartTime = 0;
|
||||
isEngineRunning = false;
|
||||
starterEngaged = false;
|
||||
|
@ -103,12 +102,12 @@ void GasolineGenerator::start()
|
|||
|
||||
// Step 2: Power up ignition system
|
||||
setIgnitionSystem(true);
|
||||
ignitionStartTime = millis();
|
||||
ignitionStartTime = (xTaskGetTickCount() * 1000) / configTICK_RATE_HZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shutdown the gasoline generator.
|
||||
*
|
||||
*
|
||||
* This function stops the generator by turning off all systems,
|
||||
* including the starter, ignition system, and carburetor valve.
|
||||
*/
|
||||
|
@ -125,7 +124,7 @@ void GasolineGenerator::shutdown()
|
|||
|
||||
/**
|
||||
* @brief Set the carburetor valve state.
|
||||
*
|
||||
*
|
||||
* @param open If true, opens the carburetor valve; if false, closes it.
|
||||
* The actual pin state is reversed based on the configuration.
|
||||
*/
|
||||
|
@ -137,7 +136,7 @@ void GasolineGenerator::setCarburetorValve(bool open)
|
|||
|
||||
/**
|
||||
* @brief Set the ignition system state.
|
||||
*
|
||||
*
|
||||
* @param enable If true, powers the ignition system; if false, turns it off.
|
||||
*/
|
||||
void GasolineGenerator::setIgnitionSystem(bool enable)
|
||||
|
@ -147,7 +146,7 @@ void GasolineGenerator::setIgnitionSystem(bool enable)
|
|||
|
||||
/**
|
||||
* @brief Set the starter relay state.
|
||||
*
|
||||
*
|
||||
* @param enable If true, engages the starter; if false, disengages it.
|
||||
*/
|
||||
void GasolineGenerator::setStarter(bool enable)
|
||||
|
@ -158,10 +157,10 @@ void GasolineGenerator::setStarter(bool enable)
|
|||
|
||||
/**
|
||||
* @brief Handle the startup sequence of the gasoline generator.
|
||||
*
|
||||
*
|
||||
* This function manages the timing and state transitions during the startup process,
|
||||
* including engaging the starter and checking for successful engine start.
|
||||
*
|
||||
*
|
||||
* @param currentTime The current time in milliseconds since system start.
|
||||
*/
|
||||
void GasolineGenerator::handleStartupSequence(unsigned long currentTime)
|
||||
|
@ -210,7 +209,7 @@ void GasolineGenerator::handleStartupSequence(unsigned long currentTime)
|
|||
|
||||
/**
|
||||
* @brief Callback function called when the engine has successfully started.
|
||||
*
|
||||
*
|
||||
* This function is called when the engine starts successfully after engaging the starter.
|
||||
* It turns off the starter, opens the carburetor valve, and transitions to the RUNNING state.
|
||||
*/
|
||||
|
@ -229,10 +228,10 @@ void GasolineGenerator::onEngineStarted()
|
|||
|
||||
/**
|
||||
* @brief Handle input changes from the digital input card.
|
||||
*
|
||||
*
|
||||
* This function processes changes in the state of input pins, particularly for the power output sensor.
|
||||
* It checks if the engine has started or stopped based on the power output sensor state.
|
||||
*
|
||||
*
|
||||
* @param pin The pin number that changed state.
|
||||
* @param state The new state of the pin (true for HIGH, false for LOW).
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue