BlueUSB and Waveplayer merged
Dependencies: SDFileSystem mbed-rtos mbed wave_player
Fork of z_test_BlueUSBv1 by
Diff: TestShell.cpp
- Revision:
- 1:12422708d6c8
- Parent:
- 0:606b230e5b4a
- Child:
- 3:146802bc7bb8
--- a/TestShell.cpp Sat Apr 10 00:30:24 2010 +0000 +++ b/TestShell.cpp Tue Nov 18 00:11:42 2014 +0000 @@ -25,10 +25,33 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <math.h> #include "Utils.h" #include "USBHost.h" #include "hci.h" +#include "mbed.h" +#include "rtos.h" + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + +typedef enum { //MAKE STATE VALUES +Left, +Right, +Up, +Down, +Nothing +} Wiistate; + +Wiistate wiistate = Nothing; + +float vol = 0; //VOLUME FLOAT + +Mutex key; + void printf(const BD_ADDR* addr) { @@ -131,7 +154,58 @@ int x = (d[2] & 0x60) >> 5 | d[4] << 2; int y = (d[3] & 0x20) >> 4 | d[5] << 2; int z = (d[3] & 0x40) >> 5 | d[6] << 2; - printf("WII %04X %d %d %d\n",pad,x,y,z); + //printf("WII2 %04X %d %d %d\n",pad,x,y,z); + int resolution= 24; //SENSITIVITY OF STATES + + key.lock(); //LOCK GLOBAL VAR CHANGES + + if(pad==0x0800){ //CHECK FOR BUTTON A + vol= (x-420)-(x-420)%21; + vol= vol/210; + if(vol<0) vol=0; + printf("Volume= %f\n",vol); + } + else if(pad==0x0400){ //OTHERWISE CHECK B + + if(x<416+resolution){ //LEFT + wiistate=Left; + led1=1; + led2=0; + led3=0; + led4=0; + } + else if(x>630-resolution){ //RIGHT + wiistate=Right; + led1=0; + led2=1; + led3=0; + led4=0; + } + else if(y<420+resolution){ //UP + wiistate=Up; + led1=0; + led2=0; + led3=1; + led4=0; + } + else if(z>630-resolution){ //DOWN + wiistate=Down; + led1=0; + led2=0; + led3=0; + led4=1; + } + else{ //NOTHING + wiistate=Nothing; + led1=0; + led2=0; + led3=0; + led4=0; + } + } + + key.unlock(); //UNLOCK GLOBAL VAR CHANGES + } break; default: