added volume properties for channel 3..6
[apps/agl-service-unicens.git] / ucs2-vol / src / setup.cpp
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 #include "setup.h"
25
26 CSetup* CSetup::_instance = NULL;
27
28 // singleton
29 CSetup* CSetup::GetInstance() {
30     if (_instance == NULL) {
31         _instance = new CSetup();
32     }
33
34     return _instance;
35 }
36
37 // singleton
38 void CSetup::Release() {
39     if (_instance != NULL) {
40         delete _instance;
41     }
42     _instance = NULL;
43 }
44
45 CSetup::CSetup()
46     :   _volume_amp_270_m(0x270U, DEVICE_VAL_MASTER, LIB_MOST_VOLUME_MASTER),
47         _volume_amp_270_l(0x270U, DEVICE_VAL_LEFT, LIB_MOST_VOLUME_CH_FRONT_LEFT),
48         _volume_amp_270_r(0x270U, DEVICE_VAL_RIGHT, LIB_MOST_VOLUME_CH_FRONT_RIGHT),
49         _volume_amp_271_m(0x271U, DEVICE_VAL_MASTER, LIB_MOST_VOLUME_MASTER),
50         _volume_amp_271_l(0x271U, DEVICE_VAL_LEFT, LIB_MOST_VOLUME_CH_REAR_LEFT),
51         _volume_amp_271_r(0x271U, DEVICE_VAL_RIGHT, LIB_MOST_VOLUME_CH_REAR_RIGHT),
52         _volume_amp_272_m(0x272U, DEVICE_VAL_MASTER, LIB_MOST_VOLUME_MASTER),
53         _volume_amp_272_l(0x272U, DEVICE_VAL_LEFT, LIB_MOST_VOLUME_CH_CENTER),
54         _volume_amp_272_r(0x272U, DEVICE_VAL_RIGHT, LIB_MOST_VOLUME_CH_SUB),
55         _value_container()
56 {
57     static CDeviceValue* value_list[9] = {  &_volume_amp_270_m,
58                                             &_volume_amp_270_l,
59                                             &_volume_amp_270_r,
60                                             &_volume_amp_271_m,
61                                             &_volume_amp_271_l,
62                                             &_volume_amp_271_r,
63                                             &_volume_amp_272_m,
64                                             &_volume_amp_272_l,
65                                             &_volume_amp_272_r};
66
67     _value_container.RegisterValues(value_list, 9U);
68 }
69
70 CSetup::~CSetup()
71 {
72
73 }
74
75 void CSetup::Configure(Ucs_Inst_t *UNICENS_inst, lib_most_volume_service_cb_t service_fptr)
76 {
77     ucs_inst = UNICENS_inst;
78     _value_container.AssignService(service_fptr, UNICENS_inst);
79 }
80
81 Ucs_Inst_t* CSetup::RetrieveUnicensInst(void)
82 {
83     return ucs_inst;
84 }
85
86 void CSetup::SetVolume(enum lib_most_volume_channel_t channel, uint8_t volume)
87 {
88     _value_container.SetValue((uint16_t)channel, volume);
89 }
90
91 void CSetup::Update()
92 {
93     _value_container.Update();
94 }