diff --git a/src/GasolineGenerator.cpp b/src/GasolineGenerator.cpp index 7d506b1..e15908d 100644 --- a/src/GasolineGenerator.cpp +++ b/src/GasolineGenerator.cpp @@ -2,23 +2,24 @@ 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); @@ -47,7 +48,7 @@ void GasolineGenerator::initialize(DigitalInputCard *inputCard, DigitalOutputCar */ void GasolineGenerator::loop() { - unsigned long currentTime = (xTaskGetTickCount() * 1000) / configTICK_RATE_HZ; + unsigned long currentTime = millis(); switch (state) { @@ -82,7 +83,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. @@ -95,7 +96,7 @@ void GasolineGenerator::start() } state = GeneratorState::STARTING; - startupStartTime = (xTaskGetTickCount() * 1000) / configTICK_RATE_HZ; + startupStartTime = millis(); ignitionStartTime = 0; isEngineRunning = false; starterEngaged = false; @@ -105,12 +106,12 @@ void GasolineGenerator::start() // Step 2: Power up ignition system setIgnitionSystem(true); - ignitionStartTime = (xTaskGetTickCount() * 1000) / configTICK_RATE_HZ; + ignitionStartTime = millis(); } /** * @brief Shutdown the gasoline generator. - * + * * This function stops the generator by turning off all systems, * including the starter, ignition system, and carburetor valve. */ @@ -127,7 +128,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. */ @@ -139,7 +140,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) @@ -149,7 +150,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) @@ -160,10 +161,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 +211,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. */ diff --git a/src/GasolineGenerator.hpp b/src/GasolineGenerator.hpp index e236843..71b569d 100644 --- a/src/GasolineGenerator.hpp +++ b/src/GasolineGenerator.hpp @@ -3,7 +3,7 @@ /** * @brief Configuration structure for the Gasoline Generator. - * + * * This structure holds the configuration parameters for the gasoline generator, * including input and output cards, pin assignments, and sensor settings. * It is used to initialize the GasolineGenerator class. @@ -28,17 +28,17 @@ struct GasolineGeneratorConfig * @brief Enumeration for the generator states. * This enum defines the possible states of the gasoline generator. */ -enum class GeneratorState -{ +enum class GeneratorState { STOPPED, STARTING, RUNNING, SHUTTING_DOWN }; + /** * @brief Gasoline Generator class for managing a gasoline-powered generator. - * + * * This class handles the ignition system, starter relay, and carburetor control * For startup first it closes the carburetor valve, creating a rich air-fuel mixture, * then it powers the ignition system, wait a bit then spin the starter relay to start the engine. @@ -48,7 +48,7 @@ class GasolineGenerator { public: GasolineGenerator(); - void initialize(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, const GasolineGeneratorConfig &config); + void initialize(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, const GasolineGeneratorConfig &config); void loop(); void start(); void shutdown();