Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C12832_lcd DebounceInterrupts USBHost mbed
Fork of USBHostMouse_HelloWorld by
Revision 8:1b64fa37f082, committed 2014-03-27
- Comitter:
- bhakti08
- Date:
- Thu Mar 27 18:11:50 2014 +0000
- Parent:
- 7:f740e1a3890f
- Commit message:
- Modified to add comments
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Mar 27 17:33:50 2014 +0000
+++ b/main.cpp Thu Mar 27 18:11:50 2014 +0000
@@ -1,16 +1,26 @@
+/*****************************************************************************/
+/* USB MOUSE HOST */
+/*Function: This program is used to connect the MBED USB mouse. The bubble */
+/* on the LCD moves according to the input from the USB device. */
+/* The program for the MBED USB Device can be found at following */
+/* location: */
+/* <http://mbed.org/users/bhakti08/code/USB_Project_Device/> */
+/*Author: Bhakti Kulkarni */
+/*Date: 03/27/2014 */
+/*****************************************************************************/
+
#include "mbed.h"
#include "USBHostMouse.h"
#include "C12832_lcd.h"
#include "DebouncedInterrupt.h"
#include "DebouncedIn.h"
-//#define INTERRUPT
-DebouncedIn report(p14);
-DigitalOut led(LED1);
+DigitalOut connect(LED1); //LED to indicate USB Mouse connected
C12832_LCD lcd;
Serial pc(USBTX,USBRX);
-BusOut button (LED2,LED3,LED4);
+BusOut button (LED2,LED3,LED4); //LEDs for the Button pressed on Device
+/*Global Variables to process the X abd Y values*/
int x_lcd=0,y_lcd=0;
int Xpos=0,Ypos=0;
uint8_t buttons;
@@ -18,16 +28,29 @@
int8_t y;
int8_t z;
+/*****************************************************************************/
+/*Function: OnMouseEvent() */
+/* This function is called whenever there is change in mouse data */
+/* It copies the values of x,y and buttons from the device into */
+/* variables that can be accessed by the main logic to move the */
+/* bubble on the LCD */
+/*Inputs: The x,y and button values from the Mouse. */
+/*Outputs: None. */
+/*****************************************************************************/
void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) {
- if(!report)
- lcd.cls();
- //lcd.locate(0,0);
pc.printf("Mouse values: x= %d, y= %d\r\n",x,y);
Xpos = x;
Ypos = y;
button = buttons;
}
+/*****************************************************************************/
+/*****************************************************************************/
+/*This thread is the mouse_task thread which will check for the USB Device */
+/*connectivity. If the device is not connected it will issue an error message*/
+/*Once the device is connected, this thread will attach the mouse event */
+/*thread. */
+/*****************************************************************************/
void mouse_task(void const *) {
USBHostMouse mouse;
@@ -35,8 +58,12 @@
while(1) {
// try to connect a USB mouse
- while(!mouse.connect())
+ while(!mouse.connect()){
+ lcd.cls();
+ lcd.locate(0,0);
+ lcd.printf("Connect the USB Mouse\n");
Thread::wait(500);
+ }
// when connected, attach handler called on mouse event
mouse.attachEvent(onMouseEvent);
@@ -44,20 +71,25 @@
// wait until the mouse is disconnected
while(mouse.connected()){
lcd.cls();
- led = 1;
+ connect = 1;
lcd.fillcircle(Xpos,Ypos, 2, 1);
wait(.05);
lcd.fillcircle(Xpos,Ypos, 2, 1);
Thread::wait(100);
}
- led = 0;
+ connect= 0;
}
}
-
+/*****************************************************************************/
+
+/*****************************************************************************/
+/*This is the main thread. This will do nothing but initiate the mouse task */
+/*thread and then wait forever in the loop */
+/*****************************************************************************/
int main() {
Thread mouseTask(mouse_task, NULL, osPriorityNormal, 256 * 4);
while(1) {
- //led=!led;
Thread::wait(osWaitForever);
}
-}
\ No newline at end of file
+}
+/*****************************************************************************/
