SDG+USBHost(Mouse) Sample
Dependencies: Sound_Generator USBHost_custom
Fork of SDG_Mouse_Sample by
Information
Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.
What is this?
This program is a demonstration that sounds the sound by mouse operation by using USBHost(Mouse) and Sound Generator.
Settings
Close JP3 of GR-PEACH.
Operation
| operation | effect |
|---|---|
| Right click | Sounds |
| Left click | Reset to base tone (C) |
| Moves the mouse to the right | Lower the sound |
| Moves the mouse to the left | Higher the sound |
| Center cursor | Adjust the sensitivity. Reset the reference value in the click. |
Others
The default setting of serial communication (baud rate etc.) in mbed is shown the following link.
Please refer to the link and change the settings of your PC terminal software.
The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
概要
このプログラムは、USBHost(Mouse) + Sound Generatorで、マウス操作による擬似笛デモです。
設定
GR-PEACHのJP3をショートする必要があります。
操作方法
| 操作 | 内容 |
|---|---|
| 右クリック | 音出力開始 |
| 左クリック | 基準音(ド)にリセット |
| マウス右移動 | 高音になります |
| マウス左移動 | 低音になります |
| センターカーソル | 音高低の変化量調整(クリックで基準値にリセット) |
Others
mbedのシリアル通信(ボーレート等)のデフォルト設定は以下のリンクに示しています。
リンクを参考に、お使いのPCターミナルソフトの設定を変更して下さい。
mbedでのボーレートのデフォルト値は9600で、このサンプルではボーレート9600を使います。
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
Revision 5:e48791a1ef18, committed 2013-03-13
- Comitter:
- samux
- Date:
- Wed Mar 13 10:23:01 2013 +0000
- Parent:
- 4:b320d68e98e7
- Child:
- 6:1571e517a91b
- Commit message:
- add button, x, y, z event callbacks
Changed in this revision
--- a/USBHostHID/USBHostKeyboard.cpp Tue Mar 12 17:23:37 2013 +0000
+++ b/USBHostHID/USBHostKeyboard.cpp Wed Mar 13 10:23:01 2013 +0000
@@ -103,13 +103,11 @@
bool USBHostKeyboard::connect() {
- U8 i;
-
if (dev_connected) {
return true;
}
- for (i = 0; i < MAX_DEVICE_CONNECTED; i++) {
+ for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
if ((dev = host->getDevice(i)) != NULL) {
if (host->enumerate(dev, this))
@@ -149,11 +147,11 @@
if (key && onKey) {
(*onKey)(key);
}
- if (onKeyCode) {
+ if ((report[index + 2] || modifier) && onKeyCode) {
(*onKeyCode)(report[index + 2], modifier);
}
}
- if (dev != NULL)
+ if (dev && int_in)
host->interruptRead(dev, int_in, report, len_listen, false);
}
--- a/USBHostHID/USBHostMouse.cpp Tue Mar 12 17:23:37 2013 +0000
+++ b/USBHostHID/USBHostMouse.cpp Wed Mar 13 10:23:01 2013 +0000
@@ -29,10 +29,19 @@
dev = NULL;
int_in = NULL;
onUpdate = NULL;
+ onButtonUpdate = NULL;
+ onXUpdate = NULL;
+ onYUpdate = NULL;
+ onZUpdate = NULL;
report_id = 0;
dev_connected = false;
mouse_device_found = false;
mouse_intf = -1;
+
+ buttons = 0;
+ x = 0;
+ y = 0;
+ z = 0;
}
bool USBHostMouse::connected() {
@@ -40,14 +49,12 @@
}
bool USBHostMouse::connect() {
-
- U8 i;
-
+
if (dev_connected) {
return true;
}
- for (i = 0; i < MAX_DEVICE_CONNECTED; i++) {
+ for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
if ((dev = host->getDevice(i)) != NULL) {
if(host->enumerate(dev, this))
@@ -78,10 +85,34 @@
void USBHostMouse::rxHandler() {
int len_listen = int_in->getSize();
int len = int_in->getLengthTransferred();
+
if (onUpdate) {
(*onUpdate)(report[0] & 0x07, report[1], report[2], report[3]);
}
- if (dev != NULL)
+
+ if (onButtonUpdate && (buttons != (report[0] & 0x07))) {
+ (*onButtonUpdate)(report[0] & 0x07);
+ }
+
+ if (onXUpdate && (x != report[1])) {
+ (*onXUpdate)(report[1]);
+ }
+
+ if (onYUpdate && (y != report[2])) {
+ (*onYUpdate)(report[2]);
+ }
+
+ if (onZUpdate && (z != report[3])) {
+ (*onZUpdate)(report[3]);
+ }
+
+ // update mouse state
+ buttons = report[0] & 0x07;
+ x = report[1];
+ y = report[2];
+ z = report[3];
+
+ if (dev)
host->interruptRead(dev, int_in, report, len_listen, false);
}
--- a/USBHostHID/USBHostMouse.h Tue Mar 12 17:23:37 2013 +0000
+++ b/USBHostHID/USBHostMouse.h Wed Mar 13 10:23:01 2013 +0000
@@ -55,11 +55,55 @@
*
* @param ptr function pointer
*/
- inline void attach(void (*ptr)(uint8_t buttons, int8_t x, int8_t y, int8_t z)) {
+ inline void attachEvent(void (*ptr)(uint8_t buttons, int8_t x, int8_t y, int8_t z)) {
if (ptr != NULL) {
onUpdate = ptr;
}
}
+
+ /**
+ * Attach a callback called when the button state changes
+ *
+ * @param ptr function pointer
+ */
+ inline void attachButtonEvent(void (*ptr)(uint8_t buttons)) {
+ if (ptr != NULL) {
+ onButtonUpdate = ptr;
+ }
+ }
+
+ /**
+ * Attach a callback called when the X axis value changes
+ *
+ * @param ptr function pointer
+ */
+ inline void attachXEvent(void (*ptr)(int8_t x)) {
+ if (ptr != NULL) {
+ onXUpdate = ptr;
+ }
+ }
+
+ /**
+ * Attach a callback called when the Y axis value changes
+ *
+ * @param ptr function pointer
+ */
+ inline void attachYEvent(void (*ptr)(int8_t y)) {
+ if (ptr != NULL) {
+ onYUpdate = ptr;
+ }
+ }
+
+ /**
+ * Attach a callback called when the Z axis value changes (scrolling)
+ *
+ * @param ptr function pointer
+ */
+ inline void attachZEvent(void (*ptr)(int8_t z)) {
+ if (ptr != NULL) {
+ onZUpdate = ptr;
+ }
+ }
protected:
//From IUSBEnumerator
@@ -77,8 +121,17 @@
bool mouse_device_found;
int mouse_intf;
+ uint8_t buttons;
+ int8_t x;
+ int8_t y;
+ int8_t z;
+
void rxHandler();
void (*onUpdate)(uint8_t buttons, int8_t x, int8_t y, int8_t z);
+ void (*onButtonUpdate)(uint8_t buttons);
+ void (*onXUpdate)(int8_t x);
+ void (*onYUpdate)(int8_t y);
+ void (*onZUpdate)(int8_t z);
int report_id;
void init();
};
--- a/USBHostMSD/USBHostMSD.cpp Tue Mar 12 17:23:37 2013 +0000
+++ b/USBHostMSD/USBHostMSD.cpp Wed Mar 13 10:23:01 2013 +0000
@@ -60,13 +60,12 @@
bool USBHostMSD::connect()
{
- U8 i;
if (dev_connected) {
return true;
}
- for (i = 0; i < MAX_DEVICE_CONNECTED; i++) {
+ for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
if ((dev = host->getDevice(i)) != NULL) {
USB_DBG("Trying to connect MSD device\r\n");
--- a/USBHostSerial/USBHostSerial.cpp Tue Mar 12 17:23:37 2013 +0000
+++ b/USBHostSerial/USBHostSerial.cpp Wed Mar 13 10:23:01 2013 +0000
@@ -52,7 +52,7 @@
if (dev_connected) {
return true;
}
- for (int i = 0; i < MAX_DEVICE_CONNECTED; i++) {
+ for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
if ((dev = host->getDevice(i)) != NULL) {
USB_DBG("Trying to connect serial device\r\n");
