diff --git a/src/GasolineGenerator.cpp b/src/GasolineGenerator.cpp index e15908d..7d506b1 100644 --- a/src/GasolineGenerator.cpp +++ b/src/GasolineGenerator.cpp @@ -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); @@ -48,7 +47,7 @@ void GasolineGenerator::initialize(DigitalInputCard* inputCard, DigitalOutputCar */ void GasolineGenerator::loop() { - unsigned long currentTime = millis(); + unsigned long currentTime = (xTaskGetTickCount() * 1000) / configTICK_RATE_HZ; switch (state) { @@ -83,7 +82,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. @@ -96,7 +95,7 @@ void GasolineGenerator::start() } state = GeneratorState::STARTING; - startupStartTime = millis(); + startupStartTime = (xTaskGetTickCount() * 1000) / configTICK_RATE_HZ; ignitionStartTime = 0; isEngineRunning = false; starterEngaged = false; @@ -106,12 +105,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. */ @@ -128,7 +127,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. */ @@ -140,7 +139,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) @@ -150,7 +149,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) @@ -161,10 +160,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) @@ -211,7 +210,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 71b569d..e236843 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();