LightHub 4.6.0
Open-source smart home controller firmware
Loading...
Searching...
No Matches
out_pwm Class Reference

Hardware PWM output driver (config channel type CH_PWM = 3). More...

#include <out_pwm.h>

Inheritance diagram for out_pwm:

Public Member Functions

int Setup () override
 Configure pin directions and (on Mega2560) the 4000 Hz PWM timers.
int Stop () override
 Release the pins back to INPUT and mark the driver uninitialized.
int getChanType () override
 Channel type derived from the number of configured pins (RGB/RGBW/RGBWW) or the raw item type.
int PixelCtrl (itemCmd cmd, char *subItem=NULL, bool show=true, bool authorized=false) override
 Apply the command to the PWM pins (single percent or R/G/B/(W) values).
Public Member Functions inherited from colorChannel
 colorChannel ()
 Default constructor.
void link (Item *_item)
 Attach to an item; retrieve and store the base address and the number of channel addresses.
int Ctrl (itemCmd cmd, char *subItem=NULL, bool toExecute=true, bool authorized=false) override
 Dispatch /set, /HSV and /cmd ON/OFF commands to PixelCtrl.
short getChannelAddr (short n=0)
 Get the pin address of the n-th channel (n=0 - base address).
Public Member Functions inherited from abstractOut
 abstractOut ()
virtual int isActive ()
virtual bool isAllowed (itemCmd cmd)
virtual itemCmd getDefaultOnVal ()
virtual int Status () override
virtual void setStatus (uint8_t status) override
Item * getItem ()
Public Member Functions inherited from abstractCh
 abstractCh ()
virtual ~abstractCh ()
virtual int Poll (short cause)

Additional Inherited Members

Protected Member Functions inherited from abstractOut
int pubAction (bool state)
Protected Member Functions inherited from abstractCh
int publishTopic (const char *topic, long value, const char *subtopic=NULL)
int publishTopic (const char *topic, float value, const char *subtopic=NULL)
int publishTopic (const char *topic, const char *value, const char *subtopic=NULL, const char *suffix=NULL)
Protected Attributes inherited from colorChannel
short iaddr
short numArgs
Protected Attributes inherited from abstractOut
Item * item
 Item currently linked to this driver.

Detailed Description

Hardware PWM output driver (config channel type CH_PWM = 3).

Drives one or more pins with analogWrite() PWM. The number of configured pins defines the color channel type:

  • 1 pin - single PWM (percent) output;
  • 3 pins - CH_RGB (3), R/G/B;
  • 4 pins - CH_RGBW (1), R/G/B + white;
  • 5 pins - CH_RGBWW (17), R/G/B + warm/white.

JSON config (item argument array):

[3, [pin0, pin1, pin2, (pin3, (pin4))]]

On Mega2560 the hardware PWM of timers 3 and 4 is reconfigured to a 4000 Hz frequency (prescaler = 2) so the white channels stay in sync with the RGB ones. On ESP32 the driver is a stub (no PWM yet).

Accepts the standard colorChannel control suffixes: /set (percent or color value), /HSV, /cmd ON/OFF.

Member Function Documentation

◆ getChanType()

int out_pwm::getChanType ( )
overridevirtual

Channel type derived from the number of configured pins (RGB/RGBW/RGBWW) or the raw item type.

Reimplemented from abstractOut.

◆ PixelCtrl()

int out_pwm::PixelCtrl ( itemCmd cmd,
char * subItem = NULL,
bool show = true,
bool authorized = false )
overridevirtual

Apply the command to the PWM pins (single percent or R/G/B/(W) values).

Implements colorChannel.

◆ Setup()

int out_pwm::Setup ( )
overridevirtual

Configure pin directions and (on Mega2560) the 4000 Hz PWM timers.

Reimplemented from abstractOut.

◆ Stop()

int out_pwm::Stop ( )
overridevirtual

Release the pins back to INPUT and mark the driver uninitialized.

Reimplemented from abstractCh.


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