-
Notifications
You must be signed in to change notification settings - Fork 503
/
button_maps.h
71 lines (60 loc) · 2.01 KB
/
button_maps.h
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
62
63
64
65
66
67
68
69
70
71
/*
* Copyright (c) 2021 dresden elektronik ingenieurtechnik gmbh.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
*/
#ifndef BUTTON_MAPS_H
#define BUTTON_MAPS_H
#include <QString>
#include <vector>
using ProductIdHash = std::size_t;
/*! Reference to a button map for quick lookup and leightweight embedding. */
struct ButtonMapRef
{
uint32_t hash = 0; //! hash of button map name
uint32_t index = UINT32_MAX; //! index into ButtonMap vector
};
/*! Meta data about buttons, not used by the plugin but exposed via REST API. */
struct ButtonMeta
{
struct Button
{
QString name;
int button;
};
std::vector<ButtonMeta::Button> buttons;
ButtonMapRef buttonMapRef{};
};
/*! Mapping between a product and a buttom map.
*/
struct ButtonProduct
{
ButtonMapRef buttonMapRef{};
ProductIdHash productHash = 0; //! hash of modelid or manufacturer name generated by \c productHash(Resource*)
};
struct ButtonMap
{
struct Item
{
quint8 mode;
quint8 endpoint;
quint16 clusterId;
quint8 zclCommandId;
quint16 zclParam0;
int button;
QString name;
};
std::vector<ButtonMap::Item> buttons;
ButtonMapRef buttonMapRef{};
};
ButtonMapRef BM_ButtonMapRefForHash(uint32_t buttonMapNameHash, const std::vector<ButtonMap> &buttonMaps);
const ButtonMap *BM_ButtonMapForRef(ButtonMapRef ref, const std::vector<ButtonMap> &buttonMaps);
const ButtonMap *BM_ButtonMapForProduct(ProductIdHash productHash, const std::vector<ButtonMap> &buttonMaps, const std::vector<ButtonProduct> &buttonProductMap);
inline bool isValid(ButtonMapRef a) { return a.hash != 0 && a.index != UINT32_MAX; }
inline bool operator==(ButtonMapRef a, ButtonMapRef b) { return a.hash == b.hash && a.index == b.index; }
inline bool operator!=(ButtonMapRef a, ButtonMapRef b) { return !(a == b); }
#endif // BUTTON_MAPS_H