diff --git a/cpp/wiiuse/.cproject b/cpp/wiiuse/.cproject
index 8cc7d25..68c763a 100644
--- a/cpp/wiiuse/.cproject
+++ b/cpp/wiiuse/.cproject
@@ -6,6 +6,7 @@
+
@@ -23,24 +24,26 @@
-
+
-
+
-
+
-
+
@@ -50,10 +53,13 @@
+
+
+
@@ -820,6 +826,10 @@
+
+
+
+
@@ -835,7 +845,7 @@
-
+
@@ -847,7 +857,7 @@
-
+
+
+
diff --git a/cpp/wiiuse/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/cpp/wiiuse/.settings/org.eclipse.cdt.managedbuilder.core.prefs
index 18012c8..c7c1e64 100644
--- a/cpp/wiiuse/.settings/org.eclipse.cdt.managedbuilder.core.prefs
+++ b/cpp/wiiuse/.settings/org.eclipse.cdt.managedbuilder.core.prefs
@@ -1,4 +1,4 @@
-#Wed Jul 20 20:10:42 CEST 2011
+#Wed Jul 20 23:54:48 CEST 2011
eclipse.preferences.version=1
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.debug.1116435574/CPATH/delimiter=;
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.so.debug.1116435574/CPATH/operation=remove
diff --git a/cpp/wiiuse/Debug/copy.bat b/cpp/wiiuse/Debug/copy.bat
index 16132fa..bb541cd 100644
--- a/cpp/wiiuse/Debug/copy.bat
+++ b/cpp/wiiuse/Debug/copy.bat
@@ -1,4 +1,3 @@
copy ..\src\wiiuse.h ..\..\WiiuseJ\src\wiiuse.h
-copy ..\src\speaker.h ..\..\WiiuseJ\src\speaker.h
-copy wiiuse.dll ..\..\WiiuseJ\lib\wiiuse.dll
+copy wiiuse.lib ..\..\WiiuseJ\lib\wiiuse.lib
copy wiiuse.dll ..\..\Mimis\wiiuse.dll
\ No newline at end of file
diff --git a/cpp/wiiuse/Release/copy.bat b/cpp/wiiuse/Release/copy.bat
index 16132fa..bb541cd 100644
--- a/cpp/wiiuse/Release/copy.bat
+++ b/cpp/wiiuse/Release/copy.bat
@@ -1,4 +1,3 @@
copy ..\src\wiiuse.h ..\..\WiiuseJ\src\wiiuse.h
-copy ..\src\speaker.h ..\..\WiiuseJ\src\speaker.h
-copy wiiuse.dll ..\..\WiiuseJ\lib\wiiuse.dll
+copy wiiuse.lib ..\..\WiiuseJ\lib\wiiuse.lib
copy wiiuse.dll ..\..\Mimis\wiiuse.dll
\ No newline at end of file
diff --git a/cpp/wiiuse/src/definitions.h b/cpp/wiiuse/src/definitions.h
index 9de1158..8e23ed7 100644
--- a/cpp/wiiuse/src/definitions.h
+++ b/cpp/wiiuse/src/definitions.h
@@ -39,8 +39,6 @@
#define WIIMOTE_PI 3.14159265f
-//#define WITH_WIIUSE_DEBUG
-
/* Error output macros */
#define WIIUSE_ERROR(fmt, ...) //fprintf(stderr, "[ERROR] " fmt "\n", ##__VA_ARGS__)
@@ -57,6 +55,7 @@
int i = strlen(file) - 1; \
for (; i && (file[i] != '\\'); --i); \
fprintf(stderr, "[DEBUG] %s:%i: " fmt "\n", file+i+1, __LINE__, ##__VA_ARGS__); \
+ fflush(stderr); \
} while (0)
#else
#define WIIUSE_DEBUG(fmt, ...) fprintf(stderr, "[DEBUG] " __FILE__ ":%i: " fmt "\n", __LINE__, ##__VA_ARGS__)
diff --git a/cpp/wiiuse/src/events.c b/cpp/wiiuse/src/events.c
index 6668eda..01d8a6a 100644
--- a/cpp/wiiuse/src/events.c
+++ b/cpp/wiiuse/src/events.c
@@ -480,10 +480,11 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
#ifdef WITH_WIIUSE_DEBUG
{
int i = 0;
- printf("Read: ");
+ fprintf(stderr, "[DEBUG] Read: ");
for (; i < req->size - req->wait; ++i)
- printf("%x ", req->buf[i]);
- printf("\n");
+ fprintf(stderr, "%x ", req->buf[i]);
+ fprintf(stderr, "\n");
+ fflush(stderr);
}
#endif
diff --git a/cpp/wiiuse/src/speaker.c b/cpp/wiiuse/src/speaker.c
index 513392e..b7c1328 100644
--- a/cpp/wiiuse/src/speaker.c
+++ b/cpp/wiiuse/src/speaker.c
@@ -24,30 +24,17 @@ void wiiuse_speaker_unmute(struct wiimote_t* wm) {
wiiuse_send(wm, WM_CMD_SPEAKER_MUTE, &buf, 1);
}
-void wiiuse_speaker_config(struct wiimote_t* wm, unsigned short freq, byte vol) {
- if (freq > 0x0000) {
- cfg[2] = freq & 0x00ff;
- cfg[3] = (freq & 0xff00) >> 8;
- }
- printf("speaker 0x%02x%02x\n", cfg[2], cfg[3]);
- fflush(stdout);
- if (vol > 0x00) {
- cfg[4] = vol;
- }
- wiiuse_write_data(wm, WM_REG_SPEAKER, cfg, 9);
-}
-
-void wiiuse_speaker_data(struct wiimote_t* wm, byte* data) {
- byte buf[21];
- buf[0] = sizeof(data) << 3;
- memcpy(buf + 1, data, 20);
- wiiuse_send(wm, WM_CMD_STREAM_DATA, buf, 21);
-}
-
void wiiuse_speaker_activate(struct wiimote_t* wm) {
wiiuse_speaker_enable(wm);
+ wiiuse_speaker_mute(wm);
+ byte buf = 0x01;
+ wiiuse_write_data(wm, WM_REG_SPEAKER + 8, &buf, 1);
+ buf = 0x08;
+ wiiuse_write_data(wm, WM_REG_SPEAKER, &buf, 1);
+ wiiuse_speaker_config(wm);
+ buf = 0x01;
+ wiiuse_write_data(wm, WM_REG_SPEAKER + 7, &buf, 1);
wiiuse_speaker_unmute(wm);
- wiiuse_speaker_config(wm, 0x00, 0x00);
}
void wiiuse_speaker_deactivate(struct wiimote_t* wm) {
@@ -55,10 +42,28 @@ void wiiuse_speaker_deactivate(struct wiimote_t* wm) {
wiiuse_speaker_disable(wm);
}
-void wiiuse_speaker_frequency(struct wiimote_t* wm, unsigned short freq) {
- wiiuse_speaker_config(wm, freq, 0x00);
+void wiiuse_speaker_format(struct wiimote_t* wm, byte format) {
+ wm->speaker.format = format;
}
-void wiiuse_speaker_volume(struct wiimote_t* wm, byte vol) {
- wiiuse_speaker_config(wm, 0x0000, vol);
+void wiiuse_speaker_rate(struct wiimote_t* wm, double rate) {
+ // Check: pcm_sample_rate = 12000000 / rate_value adpcm_sample_rate = 6000000 / rate_value
+ wm->speaker.rate = 48000 / rate;
+}
+
+void wiiuse_speaker_volume(struct wiimote_t* wm, double vol) {
+ wm->speaker.vol = vol * WIIMOTE_GET_SPEAKER_MAX_VOLUME(wm);
+}
+
+void wiiuse_speaker_config(struct wiimote_t* wm) {
+ byte cfg[7] = {wm->speaker.format, 0x00, 0x00, wm->speaker.rate, wm->speaker.vol, 0x00, 0x00};
+ wiiuse_write_data(wm, WM_REG_SPEAKER, cfg, 7);
+}
+
+void wiiuse_speaker_data(struct wiimote_t* wm, byte* data) {
+ /* Todo: add data length dynamically */
+ //byte buf[21];
+ //WIIUSE_DEBUG("data length %d", sizeof(buf) / sizeof(byte));
+ //memcpy(buf, data, 21);
+ wiiuse_send(wm, WM_CMD_STREAM_DATA, data, 21);
}
diff --git a/cpp/wiiuse/src/speaker.h b/cpp/wiiuse/src/speaker.h
index 8b8267d..ee77b1a 100644
--- a/cpp/wiiuse/src/speaker.h
+++ b/cpp/wiiuse/src/speaker.h
@@ -1,6 +1,7 @@
#include "wiiuse.h"
-#define WIIMOTE_GET_RUMBLE(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE) ? 0x01 : 0x00)
+#define WIIMOTE_GET_RUMBLE(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE) ? 0x01 : 0x00)
+#define WIIMOTE_GET_SPEAKER_MAX_VOLUME(wm) (wm->speaker.format == 0x00 ? 0x40 : 0xff)
#define WM_CMD_SPEAKER_ENABLE 0x14
#define WM_CMD_STREAM_DATA 0x18
@@ -8,16 +9,4 @@
#define WM_CTRL_STATUS_BYTE1_SPEAKER_MUTE 0x04
-#define WM_REG_SPEAKER 0x04a20001
-
-static byte cfg[9] = {0x00, 0x00, 0x00, 0xdd, 0x40, 0x00, 0x00, 0x01, 0x01};
-
-WIIUSE_EXPORT extern void wiiuse_speaker_enable(struct wiimote_t* wm);
-WIIUSE_EXPORT extern void wiiuse_speaker_disable(struct wiimote_t* wm);
-WIIUSE_EXPORT extern void wiiuse_speaker_mute(struct wiimote_t* wm);
-WIIUSE_EXPORT extern void wiiuse_speaker_unmute(struct wiimote_t* wm);
-WIIUSE_EXPORT extern void wiiuse_speaker_activate(struct wiimote_t* wm);
-WIIUSE_EXPORT extern void wiiuse_speaker_deactivate(struct wiimote_t* wm);
-WIIUSE_EXPORT extern void wiiuse_speaker_volume(struct wiimote_t* wm, byte vol);
-WIIUSE_EXPORT extern void wiiuse_speaker_frequency(struct wiimote_t* wm, unsigned short freq);
-WIIUSE_EXPORT extern void wiiuse_speaker_data(struct wiimote_t* wm, byte* data);
\ No newline at end of file
+#define WM_REG_SPEAKER 0x04a20001
diff --git a/cpp/wiiuse/src/wiiuse.c b/cpp/wiiuse/src/wiiuse.c
index 4dae02f..583733c 100644
--- a/cpp/wiiuse/src/wiiuse.c
+++ b/cpp/wiiuse/src/wiiuse.c
@@ -538,10 +538,11 @@ int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte
#ifdef WITH_WIIUSE_DEBUG
{
int i = 0;
- printf("Write data is: ");
+ fprintf(stderr, "[DEBUG} Write data is: ");
for (; i < len; ++i)
- printf("%x ", data[i]);
- printf("\n");
+ fprintf(stderr, "%x ", data[i]);
+ fprintf(stderr, "\n");
+ fflush(stderr);
}
#endif
@@ -607,14 +608,15 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
#ifdef WITH_WIIUSE_DEBUG
{
int x = 2;
- printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]);
+ fprintf(stderr, "[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]);
#ifndef WIN32
for (; x < len+2; ++x)
#else
for (; x < len+1; ++x)
#endif
- printf("%.2x ", buf[x]);
- printf("\n");
+ fprintf(stderr, "%.2x ", buf[x]);
+ fprintf(stderr, "\n");
+ fflush(stderr);
}
#endif
diff --git a/cpp/wiiuse/src/wiiuse.h b/cpp/wiiuse/src/wiiuse.h
index 9dff81c..7caecfa 100644
--- a/cpp/wiiuse/src/wiiuse.h
+++ b/cpp/wiiuse/src/wiiuse.h
@@ -371,6 +371,16 @@ typedef struct ir_t {
} ir_t;
+/**
+ * @struct speaker_t
+ */
+typedef struct speaker_t {
+ byte format;
+ byte vol;
+ byte rate;
+} speaker_t;
+
+
/**
* @struct joystick_t
* @brief Joystick calibration structure.
@@ -563,6 +573,7 @@ typedef struct wiimote_t {
WCONST struct gforce_t gforce; /**< current gravity forces on each axis */
WCONST struct ir_t ir; /**< IR data */
+ WCONST struct speaker_t speaker; /**< speaker */
WCONST unsigned short btns; /**< what buttons have just been pressed */
WCONST unsigned short btns_held; /**< what buttons are being held down */
@@ -643,6 +654,18 @@ WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int le
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold);
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold);
+/* speaker.c */
+WIIUSE_EXPORT extern void wiiuse_speaker_enable(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_disable(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_mute(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_unmute(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_activate(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_deactivate(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_format(struct wiimote_t* wm, byte format);
+WIIUSE_EXPORT extern void wiiuse_speaker_volume(struct wiimote_t* wm, double vol);
+WIIUSE_EXPORT extern void wiiuse_speaker_rate(struct wiimote_t* wm, double freq);
+WIIUSE_EXPORT extern void wiiuse_speaker_config(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_data(struct wiimote_t* wm, byte* data);
#ifdef __cplusplus
}
diff --git a/cpp/wiiusej/.cproject b/cpp/wiiusej/.cproject
index e87ebf0..75d42b3 100644
--- a/cpp/wiiusej/.cproject
+++ b/cpp/wiiusej/.cproject
@@ -6,6 +6,7 @@
+
@@ -23,7 +24,7 @@
-
+
@@ -323,6 +324,7 @@
+
@@ -340,7 +342,7 @@
-
+
@@ -371,6 +373,7 @@
+
diff --git a/cpp/wiiusej/.project b/cpp/wiiusej/.project
index 90c222a..13c977a 100644
--- a/cpp/wiiusej/.project
+++ b/cpp/wiiusej/.project
@@ -27,7 +27,7 @@
org.eclipse.cdt.make.core.buildLocation
- ${workspace_loc:/WiiuseJ/Debug}
+ ${workspace_loc:/WiiuseJ/Release}
org.eclipse.cdt.make.core.contents
diff --git a/cpp/wiiusej/lib/wiiuse.dll b/cpp/wiiusej/lib/wiiuse.dll
deleted file mode 100644
index d2a4528..0000000
Binary files a/cpp/wiiusej/lib/wiiuse.dll and /dev/null differ
diff --git a/cpp/wiiusej/lib/wiiuse.lib b/cpp/wiiusej/lib/wiiuse.lib
new file mode 100644
index 0000000..40b27b9
Binary files /dev/null and b/cpp/wiiusej/lib/wiiuse.lib differ
diff --git a/cpp/wiiusej/src/speaker.h b/cpp/wiiusej/src/speaker.h
deleted file mode 100644
index 8b8267d..0000000
--- a/cpp/wiiusej/src/speaker.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "wiiuse.h"
-
-#define WIIMOTE_GET_RUMBLE(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE) ? 0x01 : 0x00)
-
-#define WM_CMD_SPEAKER_ENABLE 0x14
-#define WM_CMD_STREAM_DATA 0x18
-#define WM_CMD_SPEAKER_MUTE 0x19
-
-#define WM_CTRL_STATUS_BYTE1_SPEAKER_MUTE 0x04
-
-#define WM_REG_SPEAKER 0x04a20001
-
-static byte cfg[9] = {0x00, 0x00, 0x00, 0xdd, 0x40, 0x00, 0x00, 0x01, 0x01};
-
-WIIUSE_EXPORT extern void wiiuse_speaker_enable(struct wiimote_t* wm);
-WIIUSE_EXPORT extern void wiiuse_speaker_disable(struct wiimote_t* wm);
-WIIUSE_EXPORT extern void wiiuse_speaker_mute(struct wiimote_t* wm);
-WIIUSE_EXPORT extern void wiiuse_speaker_unmute(struct wiimote_t* wm);
-WIIUSE_EXPORT extern void wiiuse_speaker_activate(struct wiimote_t* wm);
-WIIUSE_EXPORT extern void wiiuse_speaker_deactivate(struct wiimote_t* wm);
-WIIUSE_EXPORT extern void wiiuse_speaker_volume(struct wiimote_t* wm, byte vol);
-WIIUSE_EXPORT extern void wiiuse_speaker_frequency(struct wiimote_t* wm, unsigned short freq);
-WIIUSE_EXPORT extern void wiiuse_speaker_data(struct wiimote_t* wm, byte* data);
\ No newline at end of file
diff --git a/cpp/wiiusej/src/wiiuse.h b/cpp/wiiusej/src/wiiuse.h
index 9dff81c..7caecfa 100644
--- a/cpp/wiiusej/src/wiiuse.h
+++ b/cpp/wiiusej/src/wiiuse.h
@@ -371,6 +371,16 @@ typedef struct ir_t {
} ir_t;
+/**
+ * @struct speaker_t
+ */
+typedef struct speaker_t {
+ byte format;
+ byte vol;
+ byte rate;
+} speaker_t;
+
+
/**
* @struct joystick_t
* @brief Joystick calibration structure.
@@ -563,6 +573,7 @@ typedef struct wiimote_t {
WCONST struct gforce_t gforce; /**< current gravity forces on each axis */
WCONST struct ir_t ir; /**< IR data */
+ WCONST struct speaker_t speaker; /**< speaker */
WCONST unsigned short btns; /**< what buttons have just been pressed */
WCONST unsigned short btns_held; /**< what buttons are being held down */
@@ -643,6 +654,18 @@ WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int le
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold);
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold);
+/* speaker.c */
+WIIUSE_EXPORT extern void wiiuse_speaker_enable(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_disable(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_mute(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_unmute(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_activate(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_deactivate(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_format(struct wiimote_t* wm, byte format);
+WIIUSE_EXPORT extern void wiiuse_speaker_volume(struct wiimote_t* wm, double vol);
+WIIUSE_EXPORT extern void wiiuse_speaker_rate(struct wiimote_t* wm, double freq);
+WIIUSE_EXPORT extern void wiiuse_speaker_config(struct wiimote_t* wm);
+WIIUSE_EXPORT extern void wiiuse_speaker_data(struct wiimote_t* wm, byte* data);
#ifdef __cplusplus
}
diff --git a/cpp/wiiusej/src/wiiusej_Speaker.h b/cpp/wiiusej/src/wiiusej_Speaker.h
deleted file mode 100644
index 0da6686..0000000
--- a/cpp/wiiusej/src/wiiusej_Speaker.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include
-/* Header for class wiiusej_WiiUseApi */
-
-#ifndef _Included_wiiusej_WiiUseApi
-#define _Included_wiiusej_WiiUseApi
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- * Class: wiiusej_WiiUseApi
- * Method: activateSpeaker
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSpeaker
- (JNIEnv *, jobject, jint);
-
-/*
- * Class: wiiusej_WiiUseApi
- * Method: deactivateSpeaker
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSpeaker
- (JNIEnv *, jobject, jint);
-
-/*
- * Class: wiiusej_WiiUseApi
- * Method: setSpeakerVolume
- * Signature: (IS)V
- */
-JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerVolume
- (JNIEnv *, jobject, jint, jshort);
-
-/*
- * Class: wiiusej_WiiUseApi
- * Method: setSpeakerFrequency
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerFrequency
- (JNIEnv *, jobject, jint, jint);
-
-/*
- * Class: wiiusej_WiiUseApi
- * Method: streamSpeakerData
- * Signature: (I[S)V
- */
-JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_streamSpeakerData
- (JNIEnv *, jobject, jint, jshortArray);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/cpp/wiiusej/src/wiiusej_WiiUseApi.c b/cpp/wiiusej/src/wiiusej_WiiUseApi.c
index a13e4e2..83b48e0 100644
--- a/cpp/wiiusej/src/wiiusej_WiiUseApi.c
+++ b/cpp/wiiusej/src/wiiusej_WiiUseApi.c
@@ -16,8 +16,6 @@
*/
#ifndef WIN32
#include
-#else
-
#endif
#include "wiiusej_WiiUseApi.h"
@@ -32,14 +30,14 @@
#define WIIMOTE_STATE_CONNECTED 0x0008
#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s))
#define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s))
-#define WIIUSE_GET_IR_SENSITIVITY_CORRECTED(wm, lvl) \
+#define WIIUSE_GET_IR_SENSITIVITY_CORRECTED(wm, lvl) \
do { \
if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \
else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \
else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \
else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \
else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \
- else *lvl = 0; \
+ else *lvl = 0; \
} while (0)
/********************* VARIABLES DECLARATIONS *****************************/
@@ -407,9 +405,6 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
short leds = 0;
jclass cls = (*env)->GetObjectClass(env, gath);
jmethodID mid;
- struct nunchuk_t* nc;
- struct guitar_hero_3_t* gh;
- struct classic_ctrl_t* cl;
//printf("avant poll, nbMaxwiimotes : %i \n",nbMaxWiimotes);
if (wiiuse_poll(wiimotes, nbMaxWiimotes)) {
@@ -499,7 +494,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
if (mid == 0) {
return;
}
- nc = (nunchuk_t*)&wiimotes[i]->exp.nunchuk;
+ struct nunchuk_t* nc = (nunchuk_t*)&wiimotes[i]->exp.nunchuk;
(*env)->CallVoidMethod(env, gath, mid,
/* buttons */
@@ -524,7 +519,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
if (mid == 0) {
return;
}
- gh = (guitar_hero_3_t*)&wiimotes[i]->exp.gh3;
+ struct guitar_hero_3_t* gh = (guitar_hero_3_t*)&wiimotes[i]->exp.gh3;
(*env)->CallVoidMethod(env, gath, mid,
/* buttons */
@@ -543,7 +538,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
if (mid == 0) {
return;
}
- cl = (classic_ctrl_t*)&wiimotes[i]->exp.classic;
+ struct classic_ctrl_t* cl = (classic_ctrl_t*)&wiimotes[i]->exp.classic;
(*env)->CallVoidMethod(env, gath, mid,
/* buttons */
@@ -687,65 +682,69 @@ JNIEXPORT jshortArray JNICALL Java_wiiusej_WiiUseApi_getCalibration
return jShorts;
}*/
-/* Speaker */
-#include "speaker.h"
-/*
-void test(struct wiimote_t* wm) {
- int i;
- byte data[20] = {
- 0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,
- 0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3};
- wiiuse_speaker_activate(wm);
- for (i = 0; i < 50; ++i) {
- wiiuse_speaker_data(wm, data);
- }
- wiiuse_speaker_deactivate(wm);
-}*/
+/**
+ * Speaker
+ */
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_enableSpeaker(JNIEnv *env, jobject obj, jint id) {
+ wiiuse_speaker_enable(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
+}
-JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSpeaker
-(JNIEnv *env, jobject obj, jint id) {
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_disableSpeaker(JNIEnv *env, jobject obj, jint id){
+ wiiuse_speaker_disable(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
+}
+
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_muteSpeaker(JNIEnv *env, jobject obj, jint id) {
+ wiiuse_speaker_mute(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
+}
+
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_unmuteSpeaker(JNIEnv *env, jobject obj, jint id) {
+ wiiuse_speaker_unmute(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
+}
+
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSpeaker(JNIEnv *env, jobject obj, jint id) {
wiiuse_speaker_activate(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
}
-JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSpeaker
-(JNIEnv *env, jobject obj, jint id) {
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSpeaker(JNIEnv *env, jobject obj, jint id) {
wiiuse_speaker_deactivate(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
}
-/*
-void testen(struct wiimote_t* wm, unsigned short freq) {
- if (freq > 0x0000) {
- cfg[2] = freq & 0x00ff;
- cfg[3] = (freq & 0xff00) >> 8;
- }
- printf("unaangepast %d\n", freq);
- printf("speaker 0x%02x%02x\n", cfg[2], cfg[3]);
- fflush(stdout);
- wiiuse_write_data(wm, WM_REG_SPEAKER, cfg, 9);
-}*/
-
-JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerFrequency
-(JNIEnv *env, jobject obj, jint id, jint freq) {
- wiiuse_speaker_frequency(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), (unsigned short) freq);
- //short a = ((short) freq) & 0xffff;
- //printf("jni %d %d\n", freq, a);
- //fflush(stdout);
- //testen(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), (unsigned short) freq);
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerFormat(JNIEnv *env, jobject obj, jint id, jbyte format) {
+ struct wiimote_t* wm = wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id);
+ wiiuse_speaker_config(wm);
+ wiiuse_speaker_format(wm, format);
}
-JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerVolume
-(JNIEnv *env, jobject obj, jint id, jshort vol) {
- wiiuse_speaker_frequency(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), vol);
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerRate(JNIEnv *env, jobject obj, jint id, jint rate) {
+ struct wiimote_t* wm = wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id);
+ wiiuse_speaker_rate(wm, rate);
+ wiiuse_speaker_config(wm);
}
-JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_streamSpeakerData
-(JNIEnv *env, jobject obj, jint id, jshortArray sArray) {
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerVolume(JNIEnv *env, jobject obj, jint id, jdouble vol) {
+ struct wiimote_t* wm = wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id);
+ wiiuse_speaker_volume(wm, vol);
+ wiiuse_speaker_config(wm);
+}
+
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerConfig(JNIEnv *env, jobject obj, jint id, jbyte format, jint rate, jdouble vol) {
+ struct wiimote_t* wm = wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id);
+ wiiuse_speaker_format(wm, format);
+ wiiuse_speaker_rate(wm, rate);
+ wiiuse_speaker_volume(wm, vol);
+ wiiuse_speaker_config(wm);
+}
+
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_streamSpeakerData(JNIEnv *env, jobject obj, jint id, jbyteArray jbArray) {
+ jbyte *jbData = (*env)->GetByteArrayElements(env, jbArray, JNI_FALSE);
+ /* Todo: Check for data loss by using signed vs unsigned bytes */
+ /*int length = (int) (*env)->GetArrayLength(env, jbArray);
+ byte data[length];
int i = 0;
- jshort *jShorts = (*env)->GetShortArrayElements(env, sArray, JNI_FALSE);
- byte data[sizeof(jShorts)];
- for (i = 0; i < sizeof(jShorts); ++i) {
- data[i] = (byte) jShorts[i];
- }
- wiiuse_speaker_data(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), data);
- (*env)->ReleaseShortArrayElements(env, sArray, jShorts, JNI_FALSE);
+ for (i = 0; i < length; ++i) {
+ data[i] = (byte) jbData[i];
+ }*/
+ wiiuse_speaker_data(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), (byte*) jbData);
+ (*env)->ReleaseByteArrayElements(env, jbArray, jbData, JNI_FALSE);
+
}
diff --git a/cpp/wiiusej/src/wiiusej_WiiUseApi.h b/cpp/wiiusej/src/wiiusej_WiiUseApi.h
index 29dde3f..e003a5a 100644
--- a/cpp/wiiusej/src/wiiusej_WiiUseApi.h
+++ b/cpp/wiiusej/src/wiiusej_WiiUseApi.h
@@ -273,12 +273,92 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
/*
* Class: wiiusej_WiiUseApi
- * Method: getCalibration
- * Signature: (I)[S
+ * Method: enableSpeaker
+ * Signature: (I)V
*/
-JNIEXPORT jshortArray JNICALL Java_wiiusej_WiiUseApi_getCalibration
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_enableSpeaker
(JNIEnv *, jobject, jint);
+/*
+ * Class: wiiusej_WiiUseApi
+ * Method: disableSpeaker
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_disableSpeaker
+ (JNIEnv *, jobject, jint);
+
+/*
+ * Class: wiiusej_WiiUseApi
+ * Method: muteSpeaker
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_muteSpeaker
+ (JNIEnv *, jobject, jint);
+
+/*
+ * Class: wiiusej_WiiUseApi
+ * Method: unmuteSpeaker
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_unmuteSpeaker
+ (JNIEnv *, jobject, jint);
+
+/*
+ * Class: wiiusej_WiiUseApi
+ * Method: activateSpeaker
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSpeaker
+ (JNIEnv *, jobject, jint);
+
+/*
+ * Class: wiiusej_WiiUseApi
+ * Method: deactivateSpeaker
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSpeaker
+ (JNIEnv *, jobject, jint);
+
+/*
+ * Class: wiiusej_WiiUseApi
+ * Method: setSpeakerFormat
+ * Signature: (IB)V
+ */
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerFormat
+ (JNIEnv *, jobject, jint, jbyte);
+
+/*
+ * Class: wiiusej_WiiUseApi
+ * Method: setSpeakerRate
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerRate
+ (JNIEnv *, jobject, jint, jint);
+
+/*
+ * Class: wiiusej_WiiUseApi
+ * Method: setSpeakerVolume
+ * Signature: (ID)V
+ */
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerVolume
+ (JNIEnv *, jobject, jint, jdouble);
+
+/*
+ * Class: wiiusej_WiiUseApi
+ * Method: setSpeakerConfig
+ * Signature: (IBID)V
+ */
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerConfig
+ (JNIEnv *, jobject, jint, jbyte, jint, jdouble);
+
+/*
+ * Class: wiiusej_WiiUseApi
+ * Method: streamSpeakerData
+ * Signature: (I[B)V
+ */
+JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_streamSpeakerData
+ (JNIEnv *, jobject, jint, jbyteArray);
+
#ifdef __cplusplus
}
#endif