DALI Library for Arduino/AVR
|
#include <Dali.h>
Public Types | |
enum | daliCmd { CMD_OFF = 0 , CMD_UP = 1 , CMD_DOWN = 2 , CMD_STEP_UP = 3 , CMD_STEP_DOWN = 4 , CMD_RECALL_MAX = 5 , CMD_RECALL_MIN = 6 , CMD_STEP_DOWN_AND_OFF = 7 , CMD_ON_AND_STEP_UP = 8 , CMD_GO_TO_LAST = 10 , CMD_GO_TO_SCENE = 16 , CMD_RESET = 32 , CMD_ARC_TO_DTR = 33 , CMD_SAVE_VARS = 34 , CMD_SET_OPMODE = 35 , CMD_RESET_MEM = 36 , CMD_IDENTIFY = 37 , CMD_DTR_AS_MAX = 42 , CMD_DTR_AS_MIN = 43 , CMD_DTR_AS_FAIL = 44 , CMD_DTR_AS_POWER_ON = 45 , CMD_DTR_AS_FADE_TIME = 46 , CMD_DTR_AS_FADE_RATE = 47 , CMD_DTR_AS_EXT_FADE_TIME = 48 , CMD_DTR_AS_SCENE = 64 , CMD_REMOVE_FROM_SCENE = 80 , CMD_ADD_TO_GROUP = 96 , CMD_REMOVE_FROM_GROUP = 112 , CMD_DTR_AS_SHORT = 128 , CMD_QUERY_STATUS = 144 , CMD_QUERY_BALLAST = 145 , CMD_QUERY_LAMP_FAILURE = 146 , CMD_QUERY_LAMP_POWER_ON = 147 , CMD_QUERY_LIMIT_ERROR = 148 , CMD_QUERY_RESET_STATE = 149 , CMD_QUERY_MISSING_SHORT = 150 , CMD_QUERY_VERSION = 151 , CMD_QUERY_DTR = 152 , CMD_QUERY_DEVICE_TYPE = 153 , CMD_QUERY_PHYS_MIN = 154 , CMD_QUERY_POWER_FAILURE = 155 , CMD_QUERY_OPMODE = 158 , CMD_QUERY_LIGHTTYPE = 159 , CMD_QUERY_ACTUAL_LEVEL = 160 , CMD_QUERY_MAX_LEVEL = 161 , CMD_QUERY_MIN_LEVEL = 162 , CMD_QUERY_POWER_ON_LEVEL = 163 , CMD_QUERY_FAIL_LEVEL = 164 , CMD_QUERY_FADE_SPEEDS = 165 , CMD_QUERY_SPECMODE = 166 , CMD_QUERY_NEXT_DEVTYPE = 167 , CMD_QUERY_EXT_FADE_TIME = 168 , CMD_QUERY_CTRL_GEAR_FAIL = 169 , CMD_QUERY_SCENE_LEVEL = 176 , CMD_QUERY_GROUPS_0_7 = 192 , CMD_QUERY_GROUPS_8_15 = 193 , CMD_QUERY_ADDRH = 194 , CMD_QUERY_ADDRM = 195 , CMD_QUERY_ADDRL = 196 } |
enum | daliSpecialCmd { CMD_TERMINATE = 256 , CMD_SET_DTR = 257 , CMD_INITIALISE = 258 , CMD_RANDOMISE = 259 , CMD_COMPARE = 260 , CMD_WITHDRAW = 261 , CMD_SEARCHADDRH = 264 , CMD_SEARCHADDRM = 265 , CMD_SEARCHADDRL = 266 , CMD_PROGRAMSHORT = 267 , CMD_VERIFYSHORT = 268 , CMD_QUERY_SHORT = 269 , CMD_PHYS_SEL = 270 , CMD_ENABLE_DT = 272 , CMD_LOAD_DTR1 = 273 , CMD_LOAD_DTR2 = 274 , CMD_WRITE_MEM_LOC = 275 , CMD_WRITE_MEM_LOC_NOREPLY = 276 } |
enum | daliDevTypes { FLUORESCENT_LAMP , EMERGENCY_LIGHT , DISCHARGE_LAMP , HALOGEN_LAMP , INCANDESCENT_LAMP , DC_CONVERTER , LED_MODULE , SWITCH , COLOUR_CTRL , SEQUENCER , OPTICAL_CTRL } |
enum | daliAddressTypes { DALI_SHORT_ADDRESS = 0 , DALI_GROUP_ADDRESS = 1 } |
enum | commissionStateEnum { COMMISSION_OFF , COMMISSION_INIT , COMMISSION_INIT2 , COMMISSION_WRITE_DTR , COMMISSION_REMOVE_SHORT , COMMISSION_REMOVE_SHORT2 , COMMISSION_RANDOM , COMMISSION_RANDOM2 , COMMISSION_RANDOMWAIT , COMMISSION_STARTSEARCH , COMMISSION_SEARCHHIGH , COMMISSION_SEARCHMID , COMMISSION_SEARCHLOW , COMMISSION_COMPARE , COMMISSION_CHECKFOUND , COMMISSION_PROGRAMSHORT , COMMISSION_VERIFYSHORT , COMMISSION_VERIFYSHORTRESPONSE , COMMISSION_QUERYDEVICETYPE , COMMISSION_QUERYDEVICETYPERESPONSE , COMMISSION_WITHDRAW , COMMISSION_TERMINATE } |
Public Member Functions | |
void | begin (byte tx_pin, byte rx_pin, bool active_low=true) |
daliReturnValue | sendArc (byte address, byte value, byte addr_type=DALI_SHORT_ADDRESS) |
daliReturnValue | sendArcWait (byte address, byte value, byte addr_type=DALI_SHORT_ADDRESS, byte timeout=50) |
daliReturnValue | sendCmd (byte address, byte command, byte addr_type=DALI_SHORT_ADDRESS) |
int | sendCmdWait (byte address, byte command, byte addr_type=DALI_SHORT_ADDRESS, byte timeout=50) |
daliReturnValue | sendSpecialCmd (word command, byte value=0) |
int | sendSpecialCmdWait (word command, byte value=0, byte timeout=50) |
int | sendRawWait (const byte *message, byte length, byte timeout=50) |
void | commission (byte startAddress=0, bool onlyNew=false) |
void | commission_tick () |
Public Attributes | |
byte | nextShortAddress |
bool | commissionOnlyNew |
commissionStateEnum | commissionState = COMMISSION_OFF |
Protected Member Functions | |
byte * | prepareCmd (byte *message, byte address, byte command, byte type, byte selector) |
byte * | prepareSpecialCmd (byte *message, word command, byte value) |
DALI library base class.
commissioning state machine states
Type of address (short/group)
enum DaliClass::daliCmd |
DALI commands
DALI device types
DALI special commands
void DaliClass::begin | ( | byte | tx_pin, |
byte | rx_pin, | ||
bool | active_low = true |
||
) |
Start the DALI bus
tx_pin | Pin to use for transmission |
rx_pin | Pin to use for reception. Must support Pin Change Interrupt. |
active_low | set to false if bus is active low |
Initialize the hardware for DALI usage (i.e. set pin modes, timer and interrupts). By default the bus is driven active-low, meaning with the µC tx pin being low the DALI bus will be high (idle). For transmission the µC pin will be set high, which will pull the DALI voltage low. This behaviour is used by most DALI hardware interfaces. The same logic applies to the rx pin.
void DaliClass::commission | ( | byte | startAddress = 0 , |
bool | onlyNew = false |
||
) |
Initiate commissioning of all DALI ballasts
startAddress | address starting short address assignment from |
onlyNew | commission only ballasts without short address |
This method starts the DALI commissioning process. During commissioning the method commission_tick() needs to be called repeatedly until commissioning has finished. By default commissioning is done for all ballasts on the bus (onlyNew
= false). With this, at first current short addresses from all ballasts are removed. Then all found ballasts are assigned a new short address, starting from startAddress
. Commissioning has finished when commissionState
is set back to COMMISSION_OFF. The number of ballasts found can be determined from nextShortAddress. With onlyNew
= true ballasts with a short address assigned are ignored. The caller is responsible for setting an appropriate value to startAddress
.
void DaliClass::commission_tick | ( | ) |
State machine ticker for commissioning. See commission().
|
protected |
Prepares a byte array for sending DALI commands
|
protected |
Prepares a byte array for sending DALI Special Commands
daliReturnValue DaliClass::sendArc | ( | byte | address, |
byte | value, | ||
byte | addr_type = DALI_SHORT_ADDRESS |
||
) |
Send a direct arc level command
address | destination address |
value | arc level |
addr_type | address type (short/group) |
This methods sends a "direct arc power control command" to the bus It doesn't check if the bus is ready and returns immediately, stating if transmission could be initiated through its response value daliReturnValue.
daliReturnValue DaliClass::sendArcWait | ( | byte | address, |
byte | value, | ||
byte | addr_type = DALI_SHORT_ADDRESS , |
||
byte | timeout = 50 |
||
) |
Send a direct arc level command and wait for its completion
address | destination address |
value | arc level |
addr_type | address type (short/group) |
This methods sends a "direct arc power control command" to the bus It uses sendRawWait(), so it waits for the bus to become idle before and after transmission.
daliReturnValue DaliClass::sendCmd | ( | byte | address, |
byte | command, | ||
byte | addr_type = DALI_SHORT_ADDRESS |
||
) |
Send a DALI command
address | destination address |
command | DALI command |
addr_type | address type (short/group) |
int DaliClass::sendCmdWait | ( | byte | address, |
byte | command, | ||
byte | addr_type = DALI_SHORT_ADDRESS , |
||
byte | timeout = 50 |
||
) |
Send a DALI command, wait for its completion and return the response if available
address | destination address |
command | DALI command |
addr_type | address type (short/group) |
timeout | time in ms to wait for action to complete |
int DaliClass::sendRawWait | ( | const byte * | message, |
byte | length, | ||
byte | timeout = 50 |
||
) |
Send raw values to the DALI bus
message | byte array to send |
length | length of the byte array |
timeout | time in ms to wait for action to complete |
This method sends a raw byte array of length
to the bus. The array can be three bytes max. It waits for the bus to become idle before and after transmission. It returns either the received response, DALI_RX_EMPTY if no response has been received or any of daliReturnValue if an error has occurred.
daliReturnValue DaliClass::sendSpecialCmd | ( | word | command, |
byte | value = 0 |
||
) |
Send a DALI special command
command | DALI special command |
value | Value (2nd byte) |
This method sends a DALI Special Command to the bus (Special Commands are commands from 256 to 287). It doesn't check if the bus is ready and returns immediately, stating if transmission could be initiated through its response value daliReturnValue. Note that some of the special commands need to be sent twice (258 - INITIALISE, 259 - RANDOMISE), which this method doesn't do by itself.
int DaliClass::sendSpecialCmdWait | ( | word | command, |
byte | value = 0 , |
||
byte | timeout = 50 |
||
) |
Send a DALI special command, wait for its completion and return the response if available
command | DALI special command |
value | Value (2nd byte) |
timeout | time in ms to wait for action to complete |
This method sends a DALI Special Command to the bus (Special Commands are commands from 256 to 287). It uses sendRawWait(), so it waits for the bus to become idle before and after transmission. It returns either the received response, DALI_RX_EMPTY if no response has been received or any of daliReturnValue if an error has occurred. Note that some of the special commands need to be sent twice (258 - INITIALISE, 259 - RANDOMISE), which this method doesn't do by itself.
bool DaliClass::commissionOnlyNew |
When true, only ballasts without short address set are commissioned.
commissionStateEnum DaliClass::commissionState = COMMISSION_OFF |
current state of commissioning state machine
byte DaliClass::nextShortAddress |
next address to program on commissioning. When commissioning finished, reflects number of ballasts found.