root/trunk/libffado/src/rme/fireface_settings_ctrls.cpp

Revision 1600, 3.8 kB (checked in by jwoithe, 14 years ago)

RME: put setting control type defines in a more intelligent place. Add a separate type to denote an unset type field.
RME: Export a "model" info control to report the model via dbus (to be used by ffadomixer). Handle unknown control types in set/get methods.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  * Copyright (C) 2008-2009 by Jonathan Woithe
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 2 of the License, or
13  * (at your option) version 3 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24 #include "rme/rme_avdevice.h"
25 #include "rme/fireface_settings_ctrls.h"
26
27 namespace Rme {
28
29 RmeSettingsCtrl::RmeSettingsCtrl(Device &parent, unsigned int type,
30     unsigned int info)
31 : Control::Discrete(&parent)
32 , m_parent(parent)
33 , m_type(type)
34 , m_value(0)
35 , m_info(info)
36 {
37 }
38
39 RmeSettingsCtrl::RmeSettingsCtrl(Device &parent, unsigned int type,
40     unsigned int info,
41     std::string name, std::string label, std::string descr)
42 : Control::Discrete(&parent)
43 , m_parent(parent)
44 , m_type(type)
45 , m_value(0)
46 , m_info(info)
47 {
48     setName(name);
49     setLabel(label);
50     setDescription(descr);
51 }
52
53 bool
54 RmeSettingsCtrl::setValue(int v) {
55
56 signed int i;
57 signed int err = 0;
58
59     switch (m_type) {
60         case RME_CTRL_NONE:
61             debugOutput(DEBUG_LEVEL_ERROR, "control has no type set\n");
62             err = 1;
63             break;
64         case RME_CTRL_PHANTOM_SW:
65             // Lowest 16 bits are phantom status bits (max 16 channels).
66             // High 16 bits are "write enable" bits for the correspoding
67             // channel represented in the low 16 bits.  This way changes can
68             // be made to one channel without needing to first read the
69             // existing value.
70             //
71             // At present there are at most 4 phantom-capable channels.
72             // Flag attempts to write to the bits corresponding to channels
73             // beyond this.
74             if (v & 0xfff00000) {
75                 debugOutput(DEBUG_LEVEL_WARNING, "Ignored out-of-range phantom set request: mask=0x%04x, value=0x%04x\n",
76                   (v >> 16) & 0xfff0, v && 0xfff0);
77             }
78
79             for (i=0; i<4; i++) {
80                 if (v & (0x00010000 << i)) {
81                     unsigned int on = (v & (0x00000001 << i)) != 0;
82                     err = m_parent.setPhantom(i, on);
83                     if (!err && on) {
84                         m_value |= (0x01 << i);
85                     } else {
86                         m_value &= ~(0x01 << i);
87                     }
88                 }
89             }
90             break;
91
92         // All RME_CTRL_INFO_* controls are read-only.  Warn on attempts to
93         // set these.
94         case RME_CTRL_INFO_MODEL:
95             debugOutput(DEBUG_LEVEL_ERROR, "Attempt to set readonly info control 0x%08x\n", m_type);
96             err = 1;
97             break;
98
99         default:
100             debugOutput(DEBUG_LEVEL_ERROR, "Unknown control type 0x%08x\n", m_type);
101             err = 1;
102     }
103
104     return err==0?true:false;
105 }
106
107 int
108 RmeSettingsCtrl::getValue() {
109
110     switch (m_type) {
111         case RME_CTRL_NONE:
112             debugOutput(DEBUG_LEVEL_ERROR, "control has no type set\n");
113             break;
114
115         case RME_CTRL_PHANTOM_SW:
116             return m_value;
117             break;
118
119         case RME_CTRL_INFO_MODEL:
120             return m_parent.getRmeModel();
121             break;
122
123         default:
124             debugOutput(DEBUG_LEVEL_ERROR, "Unknown control type 0x%08x\n", m_type);
125     }
126
127     return 0;
128 }
129
130 }
Note: See TracBrowser for help on using the browser.