Just mouse test for x,y position

Dependencies:   mbed Mouse

Files at this revision

API Documentation at this revision

Comitter:
joshwilkins2013
Date:
Tue Mar 31 22:38:22 2015 +0000
Parent:
1:afd3fc7c27a2
Commit message:

Changed in this revision

Mouse.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r afd3fc7c27a2 -r ed0782fc9b00 Mouse.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mouse.lib	Tue Mar 31 22:38:22 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/The-A-Team/code/Mouse/#eb8581df1f5e
diff -r afd3fc7c27a2 -r ed0782fc9b00 main.cpp
--- a/main.cpp	Fri Mar 06 20:45:05 2015 +0000
+++ b/main.cpp	Tue Mar 31 22:38:22 2015 +0000
@@ -1,89 +1,19 @@
 #include "mbed.h"
-
-#define sensorConfig 0x00
-#define sensorStatus 0x01
-#define Delta_Y 0x02
-#define Delta_X 0x03
+#include "Mouse.h"
 
 Serial pc(USBTX, USBRX);
 
-DigitalInOut pinC(PTD0); // clock
-DigitalInOut pinD(PTC4); // data
-
-signed long mx, my; float dx, dy;
-
-void reSync(){
-  pinC = 1; // ReSync (startup) mouse
-  wait_us(5);
-  pinC = 0;
-  wait_us(1);
-  pinC = 1; 
-  wait_us(1000);  // wait for OptiMouse serial transaction timer to time out:
-}
+MOUSE mouse;
 
-uint8_t readRegister(uint8_t address){ // Bitbang SPI read operation
-  int i = 7;
-  uint8_t r = 0;
-  pinD.output();   // Write the address of the register we want to read:
-  for (; i>=0; i--){
-    pinC = 0;
-    pinD = (address & (1 << i));
-    pinC = 1;
-  }
-  pinD.input();    // Switch data line from OUTPUT to INPUT
-  wait_us(100);   // Wait according to datasheet
-  for (i=7; i>=0; i--){     // Fetch the data!                          
-    pinC = 0;
-    pinC = 1;
-    r |= ((pinD.read()) << i);
-  }
-  wait_us(100);
-  return r;
-}
-
-void writeRegister(uint8_t address, uint8_t data){
-  int i = 7;  
-  address |= 0x80;// Set MSB high, to indicate write operation:
-  pinD.output();  // Write the address:
-  for (; i>=0; i--){
-    pinC = 0;
-    pinD = (address & (1 << i));
-    pinC = 1;
-  } 
-  for (i=7; i>=0; i--){ // Write the data:
-    pinC = 0;
-    pinD = (data & (1 << i));
-    pinC = 1;
-  }
-}
-
-void forceAwake(char value){
-  if (value>0) writeRegister(sensorConfig,0x01); 
-  else writeRegister(sensorConfig,0x00);
-}
-
-signed char getDx(void){
-  return (signed char) readRegister(Delta_X);
-}
-
-signed char getDy(void){
-  return (signed char) readRegister(Delta_Y);
-}
-
-signed char status(void){
-  return (signed char) readRegister(sensorStatus);
-}
+signed long mx, my;
+float dx, dy;
 
 int main(){
     pc.baud(9600);
-    pinC.output();
-    pinD.input();
-    reSync();
-    forceAwake(1); // LED on
-    wait_ms(100);
+    mouse.init();
     while(1){
-        mx = getDx();
-        my = getDy();
+        mx = mouse.getDx();
+        my = mouse.getDy();
         dx = mx;
         dy = my;