MeshX 0.4
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
Loading...
Searching...
No Matches
meshx::MeshXPwmImpl Class Reference

Concrete PWM Implementation Class. More...

Inheritance diagram for meshx::MeshXPwmImpl:
meshx::MeshXIoInterface

Public Member Functions

 MeshXPwmImpl (uint8_t logical_pin, const char *name)
 Constructor.
virtual ~MeshXPwmImpl ()
 Destructor.
virtual uint8_t getLogicalPin () const override
 Get logical pin number.
virtual const char * getName () const override
 Get pin name.
virtual bool isFunctionSupported (IoFunction function) const override
 Check if function is supported.
virtual int execute (IoFunction function, const std::vector< uint32_t > &args) override
 Execute IO function.
virtual int setLevel (uint8_t level) override
 Set pin level (convenience method).
virtual int getLevel (uint8_t *level) override
 Get pin level (convenience method).
virtual int toggle () override
 Toggle pin level (convenience method).
int start ()
 Start PWM output.
int stop ()
 Stop PWM output.
bool isStarted () const
 Check if PWM is started.
uint32_t getFrequency () const
 Get current frequency.
uint8_t getDutyCycle () const
 Get current duty cycle.
Public Member Functions inherited from meshx::MeshXIoInterface
virtual ~MeshXIoInterface ()=default
virtual int setPwmDutyCycle (uint8_t duty_cycle)
 Set PWM duty cycle (convenience method).
virtual int setPwmFrequency (uint32_t frequency)
 Set PWM frequency (convenience method).
virtual int registerInterrupt (void(*callback)(uint8_t, void *), void *user_data, uint8_t trigger_type)
 Register interrupt (convenience method).
virtual int unregisterInterrupt ()
 Unregister interrupt (convenience method).
virtual int enableInterrupt (bool enable)
 Enable/disable interrupt (convenience method).

Private Attributes

uint8_t m_logical_pin
char m_name [32]
bool m_initialized
bool m_started
uint32_t m_frequency
uint8_t m_duty_cycle

Detailed Description

Concrete PWM Implementation Class.

Constructor & Destructor Documentation

◆ MeshXPwmImpl()

meshx::MeshXPwmImpl::MeshXPwmImpl ( uint8_t logical_pin,
const char * name )
inline

Constructor.

Parameters
logical_pinLogical pin number
namePin name
42 : m_logical_pin(logical_pin), m_initialized(false),
43 m_started(false), m_frequency(1000), m_duty_cycle(50) {
44 strncpy(m_name, name, sizeof(m_name) - 1);
45 m_name[sizeof(m_name) - 1] = '\0';
46 }
bool m_initialized
Definition meshx_pwm_impl.cpp:29
bool m_started
Definition meshx_pwm_impl.cpp:30
char m_name[32]
Definition meshx_pwm_impl.cpp:28
uint8_t m_duty_cycle
Definition meshx_pwm_impl.cpp:32
uint32_t m_frequency
Definition meshx_pwm_impl.cpp:31
uint8_t m_logical_pin
Definition meshx_pwm_impl.cpp:27

◆ ~MeshXPwmImpl()

virtual meshx::MeshXPwmImpl::~MeshXPwmImpl ( )
inlinevirtual

Destructor.

51 {
52 if (m_started) {
53 // Stop PWM if it's running
55 }
56 }
meshx_err_t meshx_pwm_stop(uint8_t logical_pin)
Stop PWM output on pin.
Definition meshx_pwm.c:373

Member Function Documentation

◆ execute()

virtual int meshx::MeshXPwmImpl::execute ( IoFunction function,
const std::vector< uint32_t > & args )
inlineoverridevirtual

Execute IO function.

Parameters
functionIO function to execute
argsFunction arguments vector
Returns
int Error code (0 = success, negative = error)

Implements meshx::MeshXIoInterface.

118 {
119 if (!m_initialized) {
120 // Initialize PWM if not already initialized
122 if (err != MESHX_SUCCESS) {
123 return static_cast<int>(IoError::NOT_INITIALIZED);
124 }
125 m_initialized = true;
126 }
127
128 switch (function) {
130 if (args.size() < 1) {
131 return static_cast<int>(IoError::PWM_INVALID_PARAM);
132 }
133 uint8_t duty_cycle = static_cast<uint8_t>(args[0]);
134 if (duty_cycle > 100) {
135 return static_cast<int>(IoError::PWM_INVALID_PARAM);
136 }
137
139 if (err == MESHX_SUCCESS) {
140 m_duty_cycle = duty_cycle;
141 return 0;
142 }
143 return static_cast<int>(IoError::PWM_NOT_SUPPORTED);
144 }
145
147 if (args.size() < 1) {
148 return static_cast<int>(IoError::PWM_INVALID_PARAM);
149 }
150 uint32_t frequency = args[0];
151 if (frequency == 0 || frequency > 1000000) { // 1MHz max
152 return static_cast<int>(IoError::PWM_INVALID_PARAM);
153 }
154
156 if (err == MESHX_SUCCESS) {
157 m_frequency = frequency;
158 return 0;
159 }
160 return static_cast<int>(IoError::PWM_NOT_SUPPORTED);
161 }
162
166 // PWM pins don't support direct level control
167 return static_cast<int>(IoError::INVALID_MODE);
168
172 // PWM pins don't support interrupts
173 return static_cast<int>(IoError::INTR_NOT_SUPPORTED);
174
176 // Custom functions not implemented in this basic version
177 return static_cast<int>(IoError::NOT_SUPPORTED);
178 }
179
180 default:
181 return static_cast<int>(IoError::INVALID_MODE);
182 }
183 }
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
**This function is called by the parent element when a state change request *is received It validates the request and returns a result to the element not the model layer **return * MESHX_SUCCESS
Definition meshx_model_level.cpp:385
meshx_err_t meshx_pwm_init(void)
Initialize PWM subsystem.
Definition meshx_pwm.c:69
meshx_err_t meshx_pwm_set_duty_cycle(uint8_t logical_pin, uint8_t duty_cycle)
Set PWM duty cycle.
Definition meshx_pwm.c:433
meshx_err_t meshx_pwm_set_frequency(uint8_t logical_pin, uint32_t frequency)
Set PWM frequency.
Definition meshx_pwm.c:515
@ NOT_INITIALIZED
Definition meshx_io_types.hpp:90
@ PWM_NOT_SUPPORTED
Definition meshx_io_types.hpp:87
@ INVALID_MODE
Definition meshx_io_types.hpp:82
@ NOT_SUPPORTED
Definition meshx_io_types.hpp:89
@ INTR_NOT_SUPPORTED
Definition meshx_io_types.hpp:85
@ PWM_INVALID_PARAM
Definition meshx_io_types.hpp:88
@ REGISTER_INTERRUPT
Definition meshx_io_interface.hpp:31
@ TOGGLE
Definition meshx_io_interface.hpp:28
@ UNREGISTER_INTERRUPT
Definition meshx_io_interface.hpp:32
@ SET_PWM_DUTY
Definition meshx_io_interface.hpp:29
@ SET_PWM_FREQUENCY
Definition meshx_io_interface.hpp:30
@ CUSTOM_FUNCTION
Definition meshx_io_interface.hpp:34
@ SET_LEVEL
Definition meshx_io_interface.hpp:26
@ GET_LEVEL
Definition meshx_io_interface.hpp:27
@ ENABLE_INTERRUPT
Definition meshx_io_interface.hpp:33

◆ getDutyCycle()

uint8_t meshx::MeshXPwmImpl::getDutyCycle ( ) const
inline

Get current duty cycle.

Returns
uint8_t Current duty cycle (0-100%)
285 {
286 return m_duty_cycle;
287 }

◆ getFrequency()

uint32_t meshx::MeshXPwmImpl::getFrequency ( ) const
inline

Get current frequency.

Returns
uint32_t Current frequency in Hz
276 {
277 return m_frequency;
278 }

◆ getLevel()

virtual int meshx::MeshXPwmImpl::getLevel ( uint8_t * level)
inlineoverridevirtual

Get pin level (convenience method).

Parameters
[out]levelPointer to store pin level
Returns
int Error code (0 = success, negative = error)

Reimplemented from meshx::MeshXIoInterface.

205 {
206 // PWM pins don't support direct level control
207 return static_cast<int>(IoError::INVALID_MODE);
208 }

◆ getLogicalPin()

virtual uint8_t meshx::MeshXPwmImpl::getLogicalPin ( ) const
inlineoverridevirtual

Get logical pin number.

Returns
uint8_t Logical pin number

Implements meshx::MeshXIoInterface.

63 {
64 return m_logical_pin;
65 }

◆ getName()

virtual const char * meshx::MeshXPwmImpl::getName ( ) const
inlineoverridevirtual

Get pin name.

Returns
const char* Pin name

Implements meshx::MeshXIoInterface.

72 {
73 return m_name;
74 }

◆ isFunctionSupported()

virtual bool meshx::MeshXPwmImpl::isFunctionSupported ( IoFunction function) const
inlineoverridevirtual

Check if function is supported.

Parameters
functionIO function to check
Returns
true if function is supported
false if function is not supported

Implements meshx::MeshXIoInterface.

83 {
84 switch (function) {
88 // PWM pins don't support direct level control
89 return false;
90
93 // PWM-specific functions
94 return true;
95
99 // PWM pins don't support interrupts
100 return false;
101
103 // Custom functions are always supported for extensibility
104 return true;
105
106 default:
107 return false;
108 }
109 }

◆ isStarted()

bool meshx::MeshXPwmImpl::isStarted ( ) const
inline

Check if PWM is started.

Returns
true if PWM is started
false if PWM is not started
267 {
268 return m_started;
269 }

◆ setLevel()

virtual int meshx::MeshXPwmImpl::setLevel ( uint8_t level)
inlineoverridevirtual

Set pin level (convenience method).

Parameters
levelPin level (0 = low, 1 = high)
Returns
int Error code (0 = success, negative = error)

Reimplemented from meshx::MeshXIoInterface.

194 {
195 // PWM pins don't support direct level control
196 return static_cast<int>(IoError::INVALID_MODE);
197 }

◆ start()

int meshx::MeshXPwmImpl::start ( )
inline

Start PWM output.

Returns
int Error code (0 = success, negative = error)
226 {
227 if (!m_initialized) {
229 if (err != MESHX_SUCCESS) {
230 return static_cast<int>(IoError::NOT_INITIALIZED);
231 }
232 m_initialized = true;
233 }
234
236 if (err == MESHX_SUCCESS) {
237 m_started = true;
238 return 0;
239 }
240 return static_cast<int>(IoError::PWM_NOT_SUPPORTED);
241 }
meshx_err_t meshx_pwm_start(uint8_t logical_pin)
Start PWM output on pin.
Definition meshx_pwm.c:295

◆ stop()

int meshx::MeshXPwmImpl::stop ( )
inline

Stop PWM output.

Returns
int Error code (0 = success, negative = error)
248 {
249 if (!m_started) {
250 return 0; // Not an error if not started
251 }
252
254 if (err == MESHX_SUCCESS) {
255 m_started = false;
256 return 0;
257 }
258 return static_cast<int>(IoError::PWM_NOT_SUPPORTED);
259 }

◆ toggle()

virtual int meshx::MeshXPwmImpl::toggle ( )
inlineoverridevirtual

Toggle pin level (convenience method).

Returns
int Error code (0 = success, negative = error)

Reimplemented from meshx::MeshXIoInterface.

215 {
216 // PWM pins don't support direct level control
217 return static_cast<int>(IoError::INVALID_MODE);
218 }

Field Documentation

◆ m_duty_cycle

uint8_t meshx::MeshXPwmImpl::m_duty_cycle
private

Current duty cycle

◆ m_frequency

uint32_t meshx::MeshXPwmImpl::m_frequency
private

Current frequency

◆ m_initialized

bool meshx::MeshXPwmImpl::m_initialized
private

Initialization flag

◆ m_logical_pin

uint8_t meshx::MeshXPwmImpl::m_logical_pin
private

Logical pin number

◆ m_name

char meshx::MeshXPwmImpl::m_name[32]
private

Pin name

◆ m_started

bool meshx::MeshXPwmImpl::m_started
private

PWM started flag


The documentation for this class was generated from the following file: