A optical beam breaker detector that appears to aPC as a USB keyboard, typing characters when the beam is broken

Dependencies:   mbed

Committer:
chris
Date:
Thu May 12 16:44:09 2011 +0000
Revision:
0:9d0f47bc66da

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:9d0f47bc66da 1 #include "USBMouse.h"
chris 0:9d0f47bc66da 2
chris 0:9d0f47bc66da 3 USBMouse::USBMouse() {
chris 0:9d0f47bc66da 4 _buttons = 0;
chris 0:9d0f47bc66da 5 }
chris 0:9d0f47bc66da 6
chris 0:9d0f47bc66da 7 void USBMouse::move(int x, int y) {
chris 0:9d0f47bc66da 8 while(x > 127) {
chris 0:9d0f47bc66da 9 mouse(127, 0, _buttons, 0);
chris 0:9d0f47bc66da 10 x = x - 127;
chris 0:9d0f47bc66da 11 }
chris 0:9d0f47bc66da 12 while(x < -128) {
chris 0:9d0f47bc66da 13 mouse(-128, 0, _buttons, 0);
chris 0:9d0f47bc66da 14 x = x + 128;
chris 0:9d0f47bc66da 15 }
chris 0:9d0f47bc66da 16 while(y > 127) {
chris 0:9d0f47bc66da 17 mouse(0, 127, _buttons, 0);
chris 0:9d0f47bc66da 18 y = y - 127;
chris 0:9d0f47bc66da 19 }
chris 0:9d0f47bc66da 20 while(y < -128) {
chris 0:9d0f47bc66da 21 mouse(0, -128, _buttons, 0);
chris 0:9d0f47bc66da 22 y = y + 128;
chris 0:9d0f47bc66da 23 }
chris 0:9d0f47bc66da 24 mouse(x, y, _buttons, 0);
chris 0:9d0f47bc66da 25 }
chris 0:9d0f47bc66da 26
chris 0:9d0f47bc66da 27 void USBMouse::scroll(int z) {
chris 0:9d0f47bc66da 28 while(z > 127) {
chris 0:9d0f47bc66da 29 mouse(0, 0, _buttons, 127);
chris 0:9d0f47bc66da 30 z = z - 127;
chris 0:9d0f47bc66da 31 }
chris 0:9d0f47bc66da 32 while(z < -128) {
chris 0:9d0f47bc66da 33 mouse(0, 0, _buttons, -128);
chris 0:9d0f47bc66da 34 z = z + 128;
chris 0:9d0f47bc66da 35 }
chris 0:9d0f47bc66da 36 mouse(0, 0, _buttons, z);
chris 0:9d0f47bc66da 37 }
chris 0:9d0f47bc66da 38
chris 0:9d0f47bc66da 39 void USBMouse::buttons(int left, int middle, int right) {
chris 0:9d0f47bc66da 40 int _buttons = 0;
chris 0:9d0f47bc66da 41 if(left) {
chris 0:9d0f47bc66da 42 _buttons |= MOUSE_L;
chris 0:9d0f47bc66da 43 }
chris 0:9d0f47bc66da 44 if(middle) {
chris 0:9d0f47bc66da 45 _buttons |= MOUSE_M;
chris 0:9d0f47bc66da 46 }
chris 0:9d0f47bc66da 47 if(right) {
chris 0:9d0f47bc66da 48 _buttons |= MOUSE_R;
chris 0:9d0f47bc66da 49 }
chris 0:9d0f47bc66da 50 mouse(0,0, _buttons, 0);
chris 0:9d0f47bc66da 51 }