DALI Library for Arduino/AVR
Loading...
Searching...
No Matches
DaliBus.h
Go to the documentation of this file.
1/***********************************************************************
2 * This library is free software; you can redistribute it and/or *
3 * modify it under the terms of the GNU Lesser General Public *
4 * License as published by the Free Software Foundation; either *
5 * version 2.1 of the License, or (at your option) any later version. *
6 * *
7 * This library is distributed in the hope that it will be useful, *
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
10 * Lesser General Public License for more details. *
11 * *
12 * You should have received a copy of the GNU Lesser General Public *
13 * License along with this library; if not, write to the Free Software *
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
15 * MA 02110-1301 USA *
16 ***********************************************************************/
17
28#include "Arduino.h"
29
30// TimerOne library for tx timer
31#include "TimerOne.h"
32// PinChangeInterrupt library for rx interrupt
33#include "PinChangeInterrupt.h"
34
35const int DALI_BAUD = 1200;
36const unsigned long DALI_TE = 417;
37const unsigned long DALI_TE_MIN = ( 80 * DALI_TE) / 100; // 333us
38const unsigned long DALI_TE_MAX = (120 * DALI_TE) / 100; // 500us
39
40
42typedef enum daliReturnValue {
43 DALI_RX_EMPTY = -1,
44 DALI_RX_ERROR = -2,
45 DALI_SENT = -3,
46 DALI_INVALID_PARAMETER = -4,
47 DALI_BUSY = -5,
48 DALI_READY_TIMEOUT = -6,
49 DALI_SEND_TIMEOUT = -7,
50 DALI_COLLISION = -8,
52
54 public:
55 void begin(byte tx_pin, byte rx_pin, bool active_low = true);
56 daliReturnValue sendRaw(const byte * message, byte length);
57
58 int getLastResponse();
59
60 bool busIsIdle();
61 volatile byte busIdleCount;
62
63 void timerISR();
64 void pinchangeISR();
65
66 protected:
67 byte txPin, rxPin;
68 bool activeLow;
69 byte txMessage[3];
70 byte txLength;
71
72 enum busStateEnum {
73 TX_START_1ST, TX_START_2ND,
74 TX_BIT_1ST, TX_BIT_2ND,
75 TX_STOP_1ST, TX_STOP,
76 IDLE,
77 SHORT,
78 WAIT_RX, RX_START, RX_BIT, RX_STOP
79 };
80 volatile busStateEnum busState;
81 volatile byte txPos;
82 volatile byte txBusLevel;
83 volatile byte txCollision;
84
85 volatile unsigned long rxLastChange;
86 volatile byte rxMessage;
87 volatile char rxLength;
88 volatile char rxError;
89
90 bool isDeltaWithinTE(unsigned long delta);
91 bool isDeltaWithin2TE(unsigned long delta);
92 byte getBusLevel();
93 void setBusLevel(byte level);
94};
95
96extern DaliBusClass DaliBus;
daliReturnValue
Definition: DaliBus.h:42
Definition: DaliBus.h:53