bus.hpp
1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
*
* Licensed under GNU General Public License 3.0 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef DALI_BUS_CONTROLLER_H_
#define DALI_BUS_CONTROLLER_H_
#include <dali/dali.hpp>
namespace dali {
namespace controller {
class Bus: public IBus::IBusClient {
public:
class Listener {
public:
virtual uint8_t getShortAddr() = 0;
virtual uint16_t getGroups() = 0;
virtual Status handleCommand(uint16_t repeat, Command cmd, uint8_t param) = 0;
virtual Status handleIgnoredCommand(Command cmd, uint8_t param) = 0;
virtual void onBusDisconnected() = 0;
};
explicit Bus(IBus* bus);
virtual ~Bus();
void setListener(Listener* listener);
void onDataReceived(uint64_t timeMs, uint16_t data) override;
void onBusStateChanged(IBus::IBusState state) override;
Status sendAck(uint8_t ack);
uint64_t getLastCommandTimeMs() {
return mLastCommandTimeMs;
}
private:
Bus(const Bus& other) = delete;
Bus& operator=(const Bus&) = delete;
Status filterAddress(uint16_t data, Command* command, uint8_t* param);
IBus* const mBus;
IBus::IBusState mState;
Listener* mListener;
Command mLastCommand;
uint16_t mCommandRepeatCount;
uint64_t mLastCommandTimeMs;
};
} // namespace controller
} // namespace dali
#endif // DALI_BUS_CONTROLLER_H_