ロボコンマガジン 2013年1月号に掲載されている 「第3回お手軽mbedではじめるロボットプロトタイピング」 で紹介しているうおーるぼっとをマウスで動かすプログラムです。

Dependencies:   FatFileSystem TB6612FNG2 mbed

Fork of BlueUSB by Peter Barrett

Revision:
1:2526b2c89256
Parent:
0:606b230e5b4a
--- a/AutoEvents.cpp	Sat Apr 10 00:30:24 2010 +0000
+++ b/AutoEvents.cpp	Fri Dec 14 03:34:00 2012 +0000
@@ -24,6 +24,7 @@
 #include "mbed.h"
 #include "USBHost.h"
 #include "Utils.h"
+#include "TB6612.h"
 
 #define AUTOEVT(_class,_subclass,_protocol) (((_class) << 16) | ((_subclass) << 8) | _protocol)
 #define AUTO_KEYBOARD AUTOEVT(CLASS_HID,1,1)
@@ -33,8 +34,12 @@
 u8 auto_keyboard[8];    // modifiers,reserved,keycode1..keycode6
 u8 auto_joystick[4];    // x,y,buttons,throttle
 
+TB6612 left(p21,p12,p11);
+TB6612 right(p22,p14,p13);
+
 void AutoEventCallback(int device, int endpoint, int status, u8* data, int len, void* userData)
 {
+    static int speed = 100;
     int evt = (int)userData;
     switch (evt)
     {
@@ -47,6 +52,31 @@
         default:
             printf("HUH ");
     }
+    
+    if( (data[0] & 0x01) != 0 )
+    {
+        left = speed;
+    }
+    else
+    {
+        left = 0;
+    }
+    if( (data[0] & 0x02) != 0 )
+    {
+        right = speed;
+    }
+    else
+    {
+        right = 0;
+    }
+    
+    speed = speed + (signed char)data[3];
+    
+    if( speed > 100 ) speed = 100;
+    if( speed < -100 ) speed = -100;
+    
+    printf("speed = %d  ",speed);
+    
     printfBytes("data",data,len);
     USBInterruptTransfer(device,endpoint,data,len,AutoEventCallback,userData);
 }