0c831977c31f33b54ed1179076b7ada762cae8e0
[apps/agl-service-unicens.git] / ucs2-vol / inc / device_value.h
1 /*
2  * libmostvolume example
3  *
4  * Copyright (C) 2017 Microchip Technology Germany II GmbH & Co. KG
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * You may also obtain this software under a propriety license from Microchip.
20  * Please contact Microchip for further information.
21  *
22  */
23
24 #ifndef DEVICEVALUE_H
25 #define DEVICEVALUE_H
26
27 #include "ucs_api.h"
28
29 struct SRxMessage {
30     uint32_t devInst;   /*instance if multiple devices are using the same group id*/
31     uint32_t sourceAddr;
32     uint32_t targetAddr;
33     uint32_t nFBlock;
34     uint32_t nInst;
35     uint32_t nFunc;
36     uint32_t nOpType;
37     const uint8_t *pPayload;
38     uint32_t payloadLen;
39 };
40
41 struct STxMessage {
42     uint32_t devInst;   /*instance if multiple devices are using the same group id*/
43     uint32_t targetAddr;
44     uint32_t nFBlock;
45     uint32_t nInst;
46     uint32_t nFunc;
47     uint32_t nOpType;
48     const uint8_t *pPayload;
49     uint32_t payloadLen;
50 };
51
52 enum DeviceValueType {
53     DEVICE_VAL_MASTER = 0,
54     DEVICE_VAL_LEFT = 1,
55     DEVICE_VAL_RIGHT = 2
56
57 };
58
59 class CDeviceValue {
60 public:
61     CDeviceValue(uint16_t address, DeviceValueType type, uint16_t key);
62     virtual ~CDeviceValue();
63
64     uint16_t GetKey(){return _key;}
65     DeviceValueType GetType(){return _type;}        // returns the assigned type
66     void SetValue(uint8_t value){_target_value = value;}   // sets desired value
67
68     bool RequiresUpdate();      // returns true if target is not actual value
69                                 // returns true if success, false if failed
70                                 // -> stop transmission
71     bool FireUpdateMessage(void);// fires message & updates actual value
72
73 private:
74     void HandleI2cResult(Ucs_I2c_Result_t result);
75     void ApplyMostValue(uint8_t value, DeviceValueType type, uint8_t tx_payload[]);
76
77     bool     _is_initial;       // ensure first update
78     DeviceValueType _type;      // determines the remote i2c command
79     uint16_t _key;              // lookup key
80     uint16_t _address;          // target node/group address
81     uint8_t  _target_value;     // desired value
82     uint8_t  _actual_value;     // value set and confirmed via network
83     uint8_t  _tx_payload[20];
84     uint8_t  _tx_payload_sz;
85 };
86
87 #endif  /* DEVICEPROPERTY_H */
88