cleanup
This commit is contained in:
81
1 software design/components/os/swtimer/com/swtimer.cpp
Normal file
81
1 software design/components/os/swtimer/com/swtimer.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* @file swtimer.cpp
|
||||
* @brief Software Timer component implementation
|
||||
* @author Mahmoud Elmohtady
|
||||
* @company Nabd solutions - ASF
|
||||
* @copyright Copyright (c) 2025
|
||||
*/
|
||||
|
||||
#include "swtimer.hpp"
|
||||
|
||||
SoftwareTimer::SoftwareTimer()
|
||||
: m_isActive(false)
|
||||
, m_interval(0)
|
||||
, m_type(TimerType::ONE_SHOT)
|
||||
{
|
||||
}
|
||||
|
||||
SoftwareTimer::~SoftwareTimer()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
bool SoftwareTimer::create(uint32_t interval_ms, TimerType type, TimerCallback callback)
|
||||
{
|
||||
if (interval_ms == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_interval = interval_ms;
|
||||
m_type = type;
|
||||
m_callback = callback;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoftwareTimer::start()
|
||||
{
|
||||
if (m_callback == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_isActive = true;
|
||||
// TODO: Implement actual timer start logic
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoftwareTimer::stop()
|
||||
{
|
||||
if (!m_isActive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_isActive = false;
|
||||
// TODO: Implement actual timer stop logic
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoftwareTimer::reset()
|
||||
{
|
||||
if (!m_isActive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
stop();
|
||||
return start();
|
||||
}
|
||||
|
||||
bool SoftwareTimer::isActive() const
|
||||
{
|
||||
return m_isActive;
|
||||
}
|
||||
|
||||
uint32_t SoftwareTimer::getInterval() const
|
||||
{
|
||||
return m_interval;
|
||||
}
|
||||
|
||||
95
1 software design/components/os/swtimer/com/swtimer.hpp
Normal file
95
1 software design/components/os/swtimer/com/swtimer.hpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @file swtimer.hpp
|
||||
* @brief Software Timer component header - Manages time-based events and scheduling
|
||||
* @author Mahmoud Elmohtady
|
||||
* @company Nabd solutions - ASF
|
||||
* @copyright Copyright (c) 2025
|
||||
*/
|
||||
|
||||
#ifndef SWTIMER_HPP
|
||||
#define SWTIMER_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
/**
|
||||
* @brief Timer type enumeration
|
||||
*/
|
||||
enum class TimerType
|
||||
{
|
||||
ONE_SHOT, ///< Timer expires once and stops
|
||||
PERIODIC ///< Timer repeats until stopped
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Timer callback function type
|
||||
*/
|
||||
using TimerCallback = std::function<void(void)>;
|
||||
|
||||
/**
|
||||
* @brief Software Timer class
|
||||
*
|
||||
* Provides functionality to create, start, stop, and manage timers
|
||||
* that can trigger callbacks after specified intervals.
|
||||
*/
|
||||
class SoftwareTimer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
SoftwareTimer();
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~SoftwareTimer();
|
||||
|
||||
/**
|
||||
* @brief Create a new timer
|
||||
* @param interval_ms Timer interval in milliseconds
|
||||
* @param type Timer type (ONE_SHOT or PERIODIC)
|
||||
* @param callback Function to call when timer expires
|
||||
* @return true if timer created successfully, false otherwise
|
||||
*/
|
||||
bool create(uint32_t interval_ms, TimerType type, TimerCallback callback);
|
||||
|
||||
/**
|
||||
* @brief Start the timer
|
||||
* @return true if started successfully, false otherwise
|
||||
*/
|
||||
bool start();
|
||||
|
||||
/**
|
||||
* @brief Stop the timer
|
||||
* @return true if stopped successfully, false otherwise
|
||||
*/
|
||||
bool stop();
|
||||
|
||||
/**
|
||||
* @brief Reset the timer
|
||||
* @return true if reset successfully, false otherwise
|
||||
*/
|
||||
bool reset();
|
||||
|
||||
/**
|
||||
* @brief Check if timer is active
|
||||
* @return true if timer is running, false otherwise
|
||||
*/
|
||||
bool isActive() const;
|
||||
|
||||
/**
|
||||
* @brief Get the timer interval
|
||||
* @return Timer interval in milliseconds
|
||||
*/
|
||||
uint32_t getInterval() const;
|
||||
|
||||
private:
|
||||
bool m_isActive; ///< Timer active state
|
||||
uint32_t m_interval; ///< Timer interval in milliseconds
|
||||
TimerType m_type; ///< Timer type
|
||||
TimerCallback m_callback; ///< Callback function
|
||||
};
|
||||
|
||||
#endif // SWTIMER_HPP
|
||||
|
||||
Reference in New Issue
Block a user