Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wiimote/src/external/wiicpp/wiic/speaker.c @ 9780

Last change on this file since 9780 was 9780, checked in by georgr, 10 years ago

WiiCpp library successfully (?) added - won't work without libbluetooth-dev

  • Property svn:executable set to *
File size: 4.0 KB
Line 
1/*
2 *      speaker.c
3 *
4 *      Written By:
5 *              Gabriele Randelli       
6 *              Email: < randelli (--AT--) dis [--DOT--] uniroma1 [--DOT--] it >
7 *
8 *      Copyright 2010
9 *
10 *      This file is part of wiiC.
11 *
12 *      This program is free software; you can redistribute it and/or modify
13 *      it under the terms of the GNU General Public License as published by
14 *      the Free Software Foundation; either version 3 of the License, or
15 *      (at your option) any later version.
16 *
17 *      This program is distributed in the hope that it will be useful,
18 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
19 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 *      GNU General Public License for more details.
21 *
22 *      You should have received a copy of the GNU General Public License
23 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
24 *
25 *      $Header$
26 *
27 */
28
29/**
30 *      @file
31 *      @brief Handles the Wiimote speakers.
32 */
33//#pragma pack(nopack)
34#include "wiic_internal.h"
35#include "speaker.h"
36
37void wiic_set_speaker(struct wiimote_t* wm, int status) {
38               
39        if (status) {
40                // if already enabled then stop
41                if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_SPEAKER))
42                        return;
43                       
44                WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_SPEAKER);
45                WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_SPEAKER_MUTE);
46               
47                byte buf;
48                 
49                /* Initialization Protocol */
50       
51                // Enable Speaker
52                buf = 0x04;
53                wiic_send(wm, WM_CMD_SPEAKER_ENABLE, &buf, 1);
54                 
55                // Mute Speaker
56                buf = 0x04;
57                wiic_send(wm, WM_CMD_SPEAKER_MUTE, &buf, 1);
58                 
59                // Write 0x01 to register 0xa20009
60                buf = 0x01;
61                wiic_write_data(wm, 0x04a20009, &buf, 1);
62   
63                // Write 0x08 to register 0xa20001
64                buf = 0x08;
65                wiic_write_data(wm, 0x04a20001, &buf, 1);
66                                 
67                // 1st byte for configuration
68                buf = 0x00;
69                wiic_write_data(wm, 0x04a20001, &buf, 1);
70                // 2nd byte for configuration
71                buf = 0x00;
72                wiic_write_data(wm, 0x04a20002, &buf, 1);
73                // 3rd byte for configuration
74                buf = 0xD0;
75                wiic_write_data(wm, 0x04a20003, &buf, 1);
76                // 4th byte for configuration
77                buf = 0x07;
78                wiic_write_data(wm, 0x04a20004, &buf, 1);
79                // 5th byte for configuration
80                buf = 40;
81                wiic_write_data(wm, 0x04a20005, &buf, 1);
82                // 6th byte for configuration
83                buf = 0x00;
84                wiic_write_data(wm, 0x04a20006, &buf, 1);
85                // 7th byte for configuration
86                buf = 0x00;
87                wiic_write_data(wm, 0x04a20007, &buf, 1);
88                 
89                // Write 0x01 to register 0xa20008
90                buf = 0x01;
91                wiic_write_data(wm, 0x04a20008, &buf, 1);
92         
93                // Unmute Speaker
94                buf = 0x00;
95                wiic_send(wm, WM_CMD_SPEAKER_MUTE, &buf, 1);     
96
97                WIIC_DEBUG("Speaker enabled");
98        } 
99        else {
100                // if already disabled then stop
101                if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_SPEAKER)) 
102                        return;
103               
104                WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_SPEAKER);
105                WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_SPEAKER_MUTE);
106                WIIC_DEBUG("Speaker disabled");
107                byte buf = 0x00;
108                wiic_send(wm, WM_CMD_SPEAKER_ENABLE, &buf, 1);
109        }
110
111        /* set the wiimote report type */
112        wiic_set_report_type(wm);
113       
114        /* wait for the wiimote to catch up */
115        usleep(50000); 
116}
117
118
119void wiic_mute_speaker(struct wiimote_t* wm, int status) {
120
121        if (status) {
122                // if already enabled then stop
123                if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_SPEAKER_MUTE))
124                        return;
125                       
126                WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_SPEAKER_MUTE);
127                WIIC_DEBUG("Speaker unmuted");
128                byte buf = 0x00;
129                wiic_send(wm, WM_CMD_SPEAKER_MUTE, &buf, 1);
130        }       
131    else {
132                // if already disabled then stop
133                if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_SPEAKER_MUTE))
134                        return;
135                       
136                WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_SPEAKER_MUTE);
137                WIIC_DEBUG("Speaker muted");
138                byte buf = 0x04;
139                wiic_send(wm, WM_CMD_SPEAKER_MUTE, &buf, 1);
140        }
141}
142
143void wiic_sound(struct wiimote_t* wm) { 
144        /*Working buffer*/
145        unsigned char buf1[21] = {0xA0, 0xC3, 0xC3, 0xC3, 0xC3,0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3,0xC3, 0xC3, 0xC3, 0xC3}; 
146       
147        int t;
148
149        for(t = 0; t <= 50; t++) {
150            wiic_send(wm, WM_CMD_SPEAKER_DATA, buf1, 21);
151            usleep(50000);
152        }
153       
154        /* set the wiimote report type */
155        wiic_set_report_type(wm);
156       
157        /* wait for the wiimote to catch up */
158        usleep(50000);
159}
Note: See TracBrowser for help on using the repository browser.