forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbutton_maps.h
85 lines (72 loc) · 2.26 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright (c) 2021-2025 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 <cstdint>
#include <vector>
using ProductIdHash = std::uint32_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
{
uint32_t nameAtomeIndex;
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 ButtonCluster
{
uint32_t nameAtomIndex;
uint32_t clusterId;
};
struct ButtonClusterCommand
{
uint32_t clusterNameAtomIndex;
uint32_t commandNameAtomIndex;
uint32_t commandId;
};
struct ButtonMap
{
struct Item
{
uint8_t mode;
uint8_t endpoint;
uint8_t zclCommandId;
uint8_t pad0;
uint16_t clusterId;
uint16_t zclParam0;
int button;
uint32_t nameAtomIndex;
};
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