updated app-templates
[apps/agl-service-unicens.git] / ucs2-vol / src / libmostvolume.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 "libmostvolume.h"
25 #include "setup.h"
26 /*#include <iostream>*/
27
28 static bool _running = false;
29
30 extern "C" uint8_t lib_most_volume_init(Ucs_Inst_t *UNICENS_inst, lib_most_volume_service_cb_t req_service_fptr)
31 {
32     uint8_t success = 1U;
33     /*std::cerr << "lib_most_volume_init(): called" << std::endl;*/
34
35     if (!_running)
36     {
37         CSetup::GetInstance()->Configure(UNICENS_inst, req_service_fptr);
38         success = 0U;
39         _running = true;
40     }
41
42     return success;
43 }
44
45 extern "C" uint8_t lib_most_volume_exit(void)
46 {
47     uint8_t success = 1U;
48     /*std::cerr << "lib_most_volume_exit(): called" << std::endl;*/
49
50     if (_running)
51     {
52         CSetup::Release();
53         success = 0U;
54         _running = false;
55     }
56
57     return success;
58 }
59
60 extern "C" uint8_t lib_most_volume_set(enum lib_most_volume_channel_t channel, uint8_t volume)
61 {
62     uint8_t success = 1U;
63     /*std::cerr << "lib_most_volume_set(): channel=" << channel << ", volume=" << (int)volume << std::endl;*/
64
65     if (_running)
66     {
67         CSetup::GetInstance()->SetVolume(channel, volume);
68         success = 0U;
69     }
70
71     return success;
72 }
73
74 extern "C" uint8_t lib_most_volume_service(void)
75 {   
76     uint8_t success = 1U;
77     /*std::cerr << "lib_most_volume_service(): called" << std::endl;*/
78
79     if (_running)
80     {
81         CSetup::GetInstance()->Update();
82         success = 0U;
83     }
84     
85     return success;
86 }