root/trunk/libffado/src/dice/focusrite/saffire_pro40.cpp

Revision 2547, 20.4 kB (checked in by philippe, 10 years ago)

Saffire Pro 40: introduce detection of ADAT as SPDIF switch register; introduce accounting for routing; prepare control switch for ffado-mixer.

Line 
1 /*
2  * Copyright (C) 2009 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "saffire_pro40.h"
25
26 #include "focusrite_eap.h"
27
28 #include "libutil/ByteSwap.h"
29
30 namespace Dice {
31 namespace Focusrite {
32
33 // ADAT as SPDIF state
34 bool SaffirePro40::SaffirePro40EAP::getADATSPDIF_state() {
35     quadlet_t state_tmp;
36     bool adatspdif = false;
37
38     if (!readReg(Dice::EAP::eRT_Application, SAFFIRE_PRO40_REGISTER_APP_ADATSPDIF_SWITCH_CONTROL,
39                  &state_tmp)) {
40         debugWarning("Could not read ADAT/SPDIF switch register: assume ADAT \n");
41     }
42     else {
43         adatspdif = (state_tmp&FOCUSRITE_EAP_ADATSPDIF_SWITCH_VALUE)?true:false;
44     }
45     return adatspdif;
46 }
47
48 //
49 // Under 48kHz Saffire pro 40 has
50 //  - 8 analogic inputs (mic/line)
51 //  - 8 ADAT inputs or 2 optical SPDIF inputs
52 //  - 2 SPDIF inputs
53 //  - 20 ieee1394 inputs
54 //  - 18 mixer inputs
55 //
56 //  - 10 analogic outputs
57 //  - 8 ADAT outputs or 0 optical SPDIF outputs
58 //  - 2 SPDIF outputs
59 //  - 20 ieee1394 outputs
60 //  - 16 mixer outputs
61 //
62 void SaffirePro40::SaffirePro40EAP::setupSources_low() {
63     bool adatspdif = getADATSPDIF_state();
64
65     addSource("SPDIF/In",  0,  2, eRS_AES, 1);
66     if (!adatspdif) {
67       addSource("ADAT/In",   0,  8, eRS_ADAT, 1);
68     } else {
69       addSource("SPDIF/In",  4,  2, eRS_AES, 3);
70     }
71     addSource("Mic/Lin/Inst", 0,  2, eRS_InS1, 1);
72     addSource("Mic/Lin/In", 2,  6, eRS_InS1, 3);
73     addSource("Mixer/Out",  0, 16, eRS_Mixer, 1);
74     addSource("1394/In",   0, 12, eRS_ARX0, 1);
75     addSource("1394/In",   0,  8, eRS_ARX1, 13);
76     addSource("Mute",   0,  1, eRS_Muted);
77 }
78
79 void SaffirePro40::SaffirePro40EAP::setupDestinations_low() {
80     bool adatspdif = getADATSPDIF_state();
81
82     addDestination("SPDIF/Out",  0,  2, eRD_AES, 1);
83     if (!adatspdif) {
84       addDestination("ADAT/Out",   0,  8, eRD_ADAT, 1);
85     }
86     addDestination("Line/Out", 0,  2, eRD_InS0, 1);
87     addDestination("Line/Out", 0,  8, eRD_InS1, 3);
88     addDestination("Mixer/In",  0, 16, eRD_Mixer0, 1);
89     addDestination("Mixer/In",  0,  2, eRD_Mixer1, 17);
90     addDestination("1394/Out",   0, 10, eRD_ATX0, 1);
91     addDestination("1394/Out",   0,  8, eRD_ATX1, 11);
92     addDestination("Loop",   8,  2, eRD_ATX1, 1);
93 // Is a Mute destination useful ?
94 //    addDestination("Mute",   0,  1, eRD_Muted);
95 }
96
97 //
98 // Under 96kHz Saffire pro 40 has
99 //  - 8 analogic inputs (mic/line)
100 //  - 4 ADAT inputs
101 //  - 2 SPDIF inputs
102 //  - 16 ieee1394 inputs
103 //  - 18 mixer inputs
104 //
105 //  - 10 analogic outputs
106 //  - 4 ADAT outputs
107 //  - 2 SPDIF outputs
108 //  - 16 ieee1394 outputs
109 //  - 16 mixer outputs
110 //
111 void SaffirePro40::SaffirePro40EAP::setupSources_mid() {
112     bool adatspdif = getADATSPDIF_state();
113
114     addSource("SPDIF/In",  0,  2, eRS_AES, 1);
115     if (!adatspdif) {
116       addSource("ADAT/In",   0,  4, eRS_ADAT, 1);
117     } else {
118       addSource("SPDIF/In",  4,  2, eRS_AES, 3);
119     }
120     addSource("Mic/Lin/Inst", 0,  2, eRS_InS1, 1);
121     addSource("Mic/Lin/In", 2,  6, eRS_InS1, 3);
122     addSource("Mixer/Out",  0, 16, eRS_Mixer, 1);
123     addSource("1394/In",   0, 16, eRS_ARX0, 1);
124     addSource("Mute",   0,  1, eRS_Muted);
125 }
126
127 void SaffirePro40::SaffirePro40EAP::setupDestinations_mid() {
128     bool adatspdif = getADATSPDIF_state();
129
130     addDestination("SPDIF/Out",  0,  2, eRD_AES, 1);
131     if (!adatspdif) {
132       addDestination("ADAT/Out",   0,  4, eRD_ADAT, 1);
133     }
134     addDestination("Line/Out", 0,  2, eRD_InS0, 1);
135     addDestination("Line/Out", 0,  8, eRD_InS1, 3);
136     addDestination("Mixer/In",  0, 16, eRD_Mixer0, 1);
137     addDestination("Mixer/In",  0,  2, eRD_Mixer1, 17);
138     addDestination("1394/Out",   0, 14, eRD_ATX0, 1);
139     addDestination("Loop",   14, 2, eRD_ATX0, 1);
140 // Is a Mute destination useful ?
141 //    addDestination("Mute",   0,  1, eRD_Muted);
142 }
143
144 //
145 // 192 kHz is not supported
146 //
147 void SaffirePro40::SaffirePro40EAP::setupSources_high() {
148     printMessage("High (192 kHz) sample rate not supported by Saffire Pro 40\n");
149 }
150
151 void SaffirePro40::SaffirePro40EAP::setupDestinations_high() {
152     printMessage("High (192 kHz) sample rate not supported by Saffire Pro 40\n");
153 }
154
155 /**
156  * The default configurations for the Saffire Pro 40 router.
157  *  For coherence with hardware, destinations must follow a specific ordering
158  *  There must be 60 destinations at low samplerate
159  *  Front LEDs are connected to the first eight router entries
160  */
161 void
162 SaffirePro40::SaffirePro40EAP::setupDefaultRouterConfig_low() {
163     unsigned int i;
164     // the 1394 stream receivers except the two "loops" one
165     for (i=0; i<8; i++) {
166         addRoute(eRS_InS1, i, eRD_ATX0, i);
167     }
168     for (i=0; i<2; i++) {
169         addRoute(eRS_AES, i, eRD_ATX0, i+8);
170     }
171     for (i=0; i<8; i++) {
172         addRoute(eRS_ADAT, i, eRD_ATX1, i);
173     }
174     // The audio ports
175     // Ensure that audio port are not muted
176     for (i=0; i<2; i++) {
177         addRoute(eRS_ARX0, i, eRD_InS0, i);
178     }
179     for (i=0; i<8; i++) {
180       addRoute(eRS_ARX0, i%2, eRD_InS1, i);
181     }
182     // the SPDIF receiver
183     for (i=0; i<2; i++) {
184         addRoute(eRS_Muted, 0, eRD_AES, i);
185     }
186     // the ADAT receiver
187     for (i=0; i<8; i++) {
188         addRoute(eRS_Muted, 0, eRD_ADAT, i);
189     }
190     // the "loops" 1394 stream receivers
191     for (i=0; i<2; i++) {
192         addRoute(eRS_Muted, 0, eRD_ATX1, i+8);
193     }
194     // the Mixer inputs
195     for (i=0; i<8; i++) {
196         addRoute(eRS_InS1, i, eRD_Mixer0, i);
197     }
198     for (i=0; i<8; i++) {
199         addRoute(eRS_ADAT, i, eRD_Mixer0, i+8);
200     }
201     for (i=0; i<2; i++) {
202         addRoute(eRS_ARX0, i, eRD_Mixer1, i);
203     }
204     // The two mute destinations
205     for (i=0; i<2; i++) {
206         addRoute(eRS_Mixer, i, eRD_Muted, 0);
207     }
208 }
209
210 /**
211  *  There must be 52 destinations at mid samplerate
212  *  Front LEDs are connected to the first eight router entries
213  */
214 void
215 SaffirePro40::SaffirePro40EAP::setupDefaultRouterConfig_mid() {
216     unsigned int i;
217     // the 1394 stream receivers except the two "loops" one
218     for (i=0; i<8; i++) {
219         addRoute(eRS_InS1, i, eRD_ATX0, i);
220     }
221     for (i=0; i<2; i++) {
222         addRoute(eRS_AES, i, eRD_ATX0, i+8);
223     }
224     for (i=0; i<4; i++) {
225         addRoute(eRS_ADAT, i, eRD_ATX0, i+10);
226     }
227     // The audio ports
228     // Ensure that audio port are not muted
229     for (i=0; i<2; i++) {
230         addRoute(eRS_ARX0, i, eRD_InS0, i);
231     }
232     for (i=0; i<8; i++) {
233       addRoute(eRS_ARX0, i%2, eRD_InS1, i);
234     }
235     // the SPDIF receiver
236     for (i=0; i<2; i++) {
237         addRoute(eRS_Muted, 0, eRD_AES, i);
238     }
239     // the ADAT receiver
240     for (i=0; i<4; i++) {
241         addRoute(eRS_Muted, 0, eRD_ADAT, i);
242     }
243     // the "loops" 1394 stream receivers
244     for (i=0; i<2; i++) {
245         addRoute(eRS_Muted, 0, eRD_ATX0, i+14);
246     }
247     // the Mixer inputs
248     for (i=0; i<8; i++) {
249         addRoute(eRS_InS1, i, eRD_Mixer0, i);
250     }
251     for (i=0; i<4; i++) {
252         addRoute(eRS_ADAT, i, eRD_Mixer0, i+8);
253     }
254     for (i=0; i<4; i++) {
255         addRoute(eRS_Muted, 0, eRD_Mixer0, i+12);
256     }
257     for (i=0; i<2; i++) {
258         addRoute(eRS_ARX0, i, eRD_Mixer1, i);
259     }
260     // The two mute destinations
261     for (i=0; i<2; i++) {
262         addRoute(eRS_Mixer, i, eRD_Muted, 0);
263     }
264 }
265
266 /**
267  *  High rate not supported
268  */
269 void
270 SaffirePro40::SaffirePro40EAP::setupDefaultRouterConfig_high() {
271     printMessage("High (192 kHz) sample rate not supported by Saffire Pro 40\n");
272 }
273
274 /**
275  *  Pro 40 Monitor section
276  */
277 // Subclassed switch
278 SaffirePro40::SaffirePro40EAP::Switch::Switch(Dice::Focusrite::FocusriteEAP* eap, std::string name,
279     size_t offset, int activevalue, size_t msgset_offset, int msgset_value)
280     : FocusriteEAP::Switch(eap, name, offset, activevalue, msgset_offset, msgset_value)
281     , m_eap(eap)
282     , m_name(name)
283     , m_offset(offset)
284     , m_activevalue(activevalue)
285     , m_msgset_offset(msgset_offset)
286     , m_msgset_value(msgset_value)
287 {
288     debugOutput( DEBUG_LEVEL_VERBOSE, "Create Pro 40 Switch %s)\n", m_name.c_str());   
289 }
290
291 bool SaffirePro40::SaffirePro40EAP::Switch::select(bool n) {
292     bool is_selected = FocusriteEAP::Switch::select(n);
293     m_eap->update();
294     return is_selected;
295 }
296
297 SaffirePro40::SaffirePro40EAP::MonitorSection::MonitorSection(Dice::Focusrite::FocusriteEAP* eap,
298     std::string name) : Control::Container(eap, name)
299     , m_eap(eap)
300 {
301     // Global Mute control
302     Control::Container* grp_globalmute = new Control::Container(m_eap, "GlobalMute");
303     addElement(grp_globalmute);
304     FocusriteEAP::Switch* mute =
305         new FocusriteEAP::Switch(m_eap, "State",
306                                  SAFFIRE_PRO40_REGISTER_APP_GLOBAL_MUTE_SWITCH,
307                                  FOCUSRITE_EAP_GLOBAL_MUTE_SWITCH_VALUE,
308                                  SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
309                                  SAFFIRE_PRO40_MESSAGE_SET_GLOBAL_DIM_MUTE_SWITCH);
310     grp_globalmute->addElement(mute);
311
312     // ADAT as optical SPDIF switch control
313     Control::Container* grp_adatspdif = new Control::Container(m_eap, "AdatSpdif");
314     addElement(grp_adatspdif);
315     SaffirePro40::SaffirePro40EAP::Switch* adatspdif =
316         new SaffirePro40::SaffirePro40EAP::Switch(
317                                  m_eap, "State",
318                                  SAFFIRE_PRO40_REGISTER_APP_ADATSPDIF_SWITCH_CONTROL,
319                                  FOCUSRITE_EAP_ADATSPDIF_SWITCH_VALUE,
320                                  SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
321                                  SAFFIRE_PRO40_MESSAGE_SET_INSTLINE);
322     grp_adatspdif->addElement(adatspdif);
323
324     // Global Dim control
325     Control::Container* grp_globaldim = new Control::Container(m_eap, "GlobalDim");
326     addElement(grp_globaldim);
327     FocusriteEAP::Switch* dim =
328         new FocusriteEAP::Switch(m_eap, "State",
329                                  SAFFIRE_PRO40_REGISTER_APP_GLOBAL_DIM_SWITCH,
330                                  FOCUSRITE_EAP_GLOBAL_DIM_SWITCH_VALUE,
331                                  SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
332                                  SAFFIRE_PRO40_MESSAGE_SET_GLOBAL_DIM_MUTE_SWITCH);
333     grp_globaldim->addElement(dim);
334     FocusriteEAP::Poti* dimlevel =
335         new FocusriteEAP::Poti(m_eap, "Level",
336                                SAFFIRE_PRO40_REGISTER_APP_GLOBAL_DIM_VOLUME,
337                                SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
338                                SAFFIRE_PRO40_MESSAGE_SET_LINEOUT_MONITOR_VOLUME);
339     grp_globaldim->addElement(dimlevel);
340
341     FocusriteEAP::Switch* s;
342     // Mono/stereo switch
343     Control::Container* grp_mono = new Control::Container(m_eap, "Mono");
344     addElement(grp_mono);
345     for (unsigned int i=0; i<SAFFIRE_PRO40_APP_STEREO_LINEOUT_SIZE; ++i) {
346         std::stringstream stream;
347         stream << "Line" << i*2+1 << "Line" << i*2+2;
348         s =
349           new FocusriteEAP::Switch(m_eap, stream.str(),
350                                    SAFFIRE_PRO40_REGISTER_APP_LINEOUT_SWITCH_CONTROL,
351                                    FOCUSRITE_EAP_SWITCH_CONTROL_VALUE
352                                       <<(FOCUSRITE_EAP_SWITCH_CONTROL_MONO_SHIFT+i),
353                                    SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
354                                    SAFFIRE_PRO40_MESSAGE_SET_LINEOUT_SWITCH_CONTROL);
355         grp_mono->addElement(s);
356     }
357
358     // Independent control of each line/out
359     Control::Container* grp_perchannel = new Control::Container(m_eap, "LineOut");
360     addElement(grp_perchannel);
361     FocusriteEAP::VolumeControl* vol;
362
363     // per Line/Out monitoring
364     for (unsigned int i=0; i<SAFFIRE_PRO40_APP_STEREO_LINEOUT_SIZE; ++i) {
365         std::stringstream stream;
366
367         // Activate/Unactivate per Line/Out volume monitoring
368         stream.str(std::string());
369         stream << "UnActivate" << i*2+1;
370         s =
371           new FocusriteEAP::Switch(m_eap, stream.str(),
372                                    SAFFIRE_PRO40_REGISTER_APP_LINEOUT_MONITOR_SWITCH+i*sizeof(quadlet_t),
373                                    FOCUSRITE_EAP_SWITCH_BIT_1,
374                                    SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
375                                    SAFFIRE_PRO40_MESSAGE_SET_LINEOUT_MONITOR_VOLUME);
376         grp_perchannel->addElement(s);
377         stream.str(std::string());
378         stream << "UnActivate" << i*2+2;
379         s =
380           new FocusriteEAP::Switch(m_eap, stream.str(),
381                                    SAFFIRE_PRO40_REGISTER_APP_LINEOUT_MONITOR_SWITCH+i*sizeof(quadlet_t),
382                                    FOCUSRITE_EAP_SWITCH_BIT_2,
383                                    SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
384                                    SAFFIRE_PRO40_MESSAGE_SET_LINEOUT_MONITOR_VOLUME);
385         grp_perchannel->addElement(s);
386
387         // per Line/Out mute/unmute
388         stream.str(std::string());
389         stream << "Mute" << i*2+1;
390         s =
391           new FocusriteEAP::Switch(m_eap, stream.str(),
392                                    SAFFIRE_PRO40_REGISTER_APP_LINEOUT_MONITOR_SWITCH+i*sizeof(quadlet_t),
393                                    FOCUSRITE_EAP_SWITCH_BIT_3,
394                                    SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
395                                    SAFFIRE_PRO40_MESSAGE_SET_LINEOUT_MONITOR_VOLUME);
396         grp_perchannel->addElement(s);
397         stream.str(std::string());
398         stream << "Mute" << i*2+2;
399         s =
400           new FocusriteEAP::Switch(m_eap, stream.str(),
401                                    SAFFIRE_PRO40_REGISTER_APP_LINEOUT_MONITOR_SWITCH+i*sizeof(quadlet_t),
402                                    FOCUSRITE_EAP_SWITCH_BIT_4,
403                                    SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
404                                    SAFFIRE_PRO40_MESSAGE_SET_LINEOUT_MONITOR_VOLUME);
405         grp_perchannel->addElement(s);
406
407         // per Line/Out global mute activation/unactivation
408         stream.str(std::string());
409         stream << "GMute" << 2*i+1;
410         s =
411           new FocusriteEAP::Switch(m_eap, stream.str(),
412                                    SAFFIRE_PRO40_REGISTER_APP_LINEOUT_SWITCH_CONTROL,
413                                    FOCUSRITE_EAP_SWITCH_CONTROL_VALUE
414                                         <<(FOCUSRITE_EAP_SWITCH_CONTROL_MUTE_SHIFT+2*i),
415                                    SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
416                                    SAFFIRE_PRO40_MESSAGE_SET_LINEOUT_SWITCH_CONTROL);
417         grp_perchannel->addElement(s);
418
419         stream.str(std::string());
420         stream << "GMute" << 2*i+2;
421         s =
422           new FocusriteEAP::Switch(m_eap, stream.str(),
423                                    SAFFIRE_PRO40_REGISTER_APP_LINEOUT_SWITCH_CONTROL,
424                                    FOCUSRITE_EAP_SWITCH_CONTROL_VALUE
425                                         <<(FOCUSRITE_EAP_SWITCH_CONTROL_MUTE_SHIFT+2*i+1),
426                                    SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
427                                    SAFFIRE_PRO40_MESSAGE_SET_LINEOUT_SWITCH_CONTROL);
428         grp_perchannel->addElement(s);
429
430         // per Line/Out global dim activation/unactivation
431         stream.str(std::string());
432         stream << "GDim" << 2*i+1;
433         s =
434           new FocusriteEAP::Switch(m_eap, stream.str(),
435                                    SAFFIRE_PRO40_REGISTER_APP_LINEOUT_SWITCH_CONTROL,
436                                    FOCUSRITE_EAP_SWITCH_CONTROL_VALUE
437                                         <<(FOCUSRITE_EAP_SWITCH_CONTROL_DIM_SHIFT+2*i),
438                                    SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
439                                    SAFFIRE_PRO40_MESSAGE_SET_LINEOUT_SWITCH_CONTROL);
440         grp_perchannel->addElement(s);
441
442         stream.str(std::string());
443         stream << "GDim" << 2*i+2;
444         s =
445           new FocusriteEAP::Switch(m_eap, stream.str(),
446                                    SAFFIRE_PRO40_REGISTER_APP_LINEOUT_SWITCH_CONTROL,
447                                    FOCUSRITE_EAP_SWITCH_CONTROL_VALUE
448                                         <<(FOCUSRITE_EAP_SWITCH_CONTROL_DIM_SHIFT+2*i+1),
449                                    SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
450                                    SAFFIRE_PRO40_MESSAGE_SET_LINEOUT_SWITCH_CONTROL);
451         grp_perchannel->addElement(s);
452
453         // per Line/Out volume control
454         stream.str(std::string());
455         stream << "Volume" << i*2+1;
456         vol =
457           new FocusriteEAP::VolumeControl(m_eap, stream.str(),
458                                           SAFFIRE_PRO40_REGISTER_APP_LINEOUT_MONITOR_VOLUME
459                                               +i*sizeof(quadlet_t),
460                                           FOCUSRITE_EAP_LINEOUT_VOLUME_SET_1,
461                                           SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
462                                           SAFFIRE_PRO40_MESSAGE_SET_LINEOUT_MONITOR_VOLUME);
463         grp_perchannel->addElement(vol);
464         stream.str(std::string());
465         stream << "Volume" << i*2+2;
466         vol =
467           new FocusriteEAP::VolumeControl(m_eap, stream.str(),
468                                           SAFFIRE_PRO40_REGISTER_APP_LINEOUT_MONITOR_VOLUME
469                                               +i*sizeof(quadlet_t),
470                                           FOCUSRITE_EAP_LINEOUT_VOLUME_SET_2,
471                                           SAFFIRE_PRO40_REGISTER_APP_MESSAGE_SET,
472                                           SAFFIRE_PRO40_MESSAGE_SET_LINEOUT_MONITOR_VOLUME);
473         grp_perchannel->addElement(vol);
474     }
475 }
476
477 /**
478   Device
479 */
480 SaffirePro40::SaffirePro40( DeviceManager& d,
481                                         std::auto_ptr<ConfigRom>( configRom ))
482     : Dice::Device( d , configRom)
483 {
484     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Dice::Focusrite::SaffirePro40 (NodeID %d)\n",
485                  getConfigRom().getNodeId() );
486 }
487
488 SaffirePro40::~SaffirePro40()
489 {
490     getEAP()->storeFlashConfig();
491 }
492
493 bool SaffirePro40::discover() {
494     if (Dice::Device::discover()) {
495         FocusriteEAP* eap = dynamic_cast<FocusriteEAP*>(getEAP());
496         SaffirePro40EAP::MonitorSection* monitor = new SaffirePro40EAP::MonitorSection(eap, "Monitoring");
497         eap->addElement(monitor);
498         return true;
499     }
500     return false;
501 }
502
503 void
504 SaffirePro40::showDevice()
505 {
506     debugOutput(DEBUG_LEVEL_VERBOSE, "This is a Dice::Focusrite::SaffirePro40\n");
507     Dice::Device::showDevice();
508 }
509
510 Dice::EAP* SaffirePro40::createEAP() {
511     return new SaffirePro40EAP(*this);
512 }
513
514 /**
515  *  Nickname
516  */
517 bool SaffirePro40::setNickname(std::string name) {
518     char nickname[SAFFIRE_PRO40_APP_NICK_NAME_SIZE+1];
519
520     // The device has room for SAFFIRE_PRO40_APP_NICK_NAME_SIZE characters.
521     // Erase supplementary characters or fill-in with NULL character if necessary
522     strncpy(nickname, name.c_str(), SAFFIRE_PRO40_APP_NICK_NAME_SIZE);
523
524     // Strings from the device are always little-endian,
525     // so byteswap for big-endian machines
526     #if __BYTE_ORDER == __BIG_ENDIAN
527     byteSwapBlock((quadlet_t *)nickname, SAFFIRE_PRO40_APP_NICK_NAME_SIZE/4);
528     #endif
529
530     if (!getEAP()->writeRegBlock(Dice::EAP::eRT_Application, SAFFIRE_PRO40_REGISTER_APP_NICK_NAME,
531                                  (quadlet_t*)nickname, SAFFIRE_PRO40_APP_NICK_NAME_SIZE)) {
532         debugError("Could not write nickname string \n");
533         return false;
534     }
535     return true;
536 }
537 std::string SaffirePro40::getNickname() {
538     char nickname[SAFFIRE_PRO40_APP_NICK_NAME_SIZE+1];
539     if (!getEAP()->readRegBlock(Dice::EAP::eRT_Application, SAFFIRE_PRO40_REGISTER_APP_NICK_NAME,
540                                 (quadlet_t*)nickname, SAFFIRE_PRO40_APP_NICK_NAME_SIZE)){
541         debugError("Could not read nickname string \n");
542         return std::string("(unknown)");
543     }
544
545     // Strings from the device are always little-endian,
546     // so byteswap for big-endian machines
547     #if __BYTE_ORDER == __BIG_ENDIAN
548     byteSwapBlock((quadlet_t *)nickname, SAFFIRE_PRO40_APP_NICK_NAME_SIZE/4);
549     #endif
550
551     // The device supplies at most SAFFIRE_PRO40_APP_NICK_NAME_SIZE characters.  Ensure the string is
552     // NULL terminated.
553     nickname[SAFFIRE_PRO40_APP_NICK_NAME_SIZE] = 0;
554     return std::string(nickname);
555 }
556
557 }
558 }
559 // vim: et
Note: See TracBrowser for help on using the browser.