Mouse demo

Dependencies:   C12832_lcd EthernetInterface SensorDataParser USBDevice mbed-rtos mbed

Fork of SensorStream_BlinkyDemo by -deleted-

Files at this revision

API Documentation at this revision

Comitter:
screamer
Date:
Sun Oct 27 18:06:48 2013 +0000
Child:
1:5b0ded645617
Commit message:
Initial release

Changed in this revision

C12832_lcd.lib Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
SensorDataParser.lib Show annotated file Show diff for this revision Revisions of this file
USBDevice.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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_lcd.lib	Sun Oct 27 18:06:48 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/dreschpe/code/C12832_lcd/#c9afe58d786a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Sun Oct 27 18:06:48 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#cba86db5ab96
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SensorDataParser.lib	Sun Oct 27 18:06:48 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/screamer/code/SensorDataParser/#e9d3bb2384a9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Sun Oct 27 18:06:48 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#d495202c90f4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 27 18:06:48 2013 +0000
@@ -0,0 +1,76 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "C12832_lcd.h"
+#include "SensorDataParser.h"
+#include <math.h>
+
+static EthernetInterface eth;
+static C12832_LCD lcd;
+static Serial pc(USBTX, USBRX);
+
+DigitalOut led_left(LED1);
+DigitalOut led_up(LED2);
+DigitalOut led_down(LED3);
+DigitalOut led_right(LED4);
+
+// Configuration
+#define SERVER_PORT     5555
+#define MAX_BUF_SIZE    512
+#define SENSE_DELTA     0.1
+
+static void ethernet_init() {
+    eth.init();
+    if(eth.connect(30000) == 0)
+        pc.printf("Connect OK\n\r");
+
+    lcd.locate(0,0);
+    lcd.printf("IP:%s", eth.getIPAddress());
+
+    pc.printf("IP Address: %s\n\r", eth.getIPAddress());
+}
+
+static void main_loop() {
+    UDPSocket server;
+    Endpoint client;
+    char buffer[MAX_BUF_SIZE];
+    SENSOR_DATA pd;
+    
+    server.bind(SERVER_PORT);
+    while (true) {
+        int n = server.receiveFrom(client, buffer, sizeof(buffer) - 1);
+        if (n == sizeof(buffer) - 1)
+            continue;
+        buffer[n] = 0;
+
+        if (parse_sensor_packet(buffer, &pd) == 0) continue;
+        
+        if(fabs(pd.ax) > SENSE_DELTA) {
+            //printf("ax: %f\r\n", pd.ax);
+        }
+        if(fabs(pd.ay) > SENSE_DELTA) {
+            //printf("ay: %f\r\n", pd.ay);
+        }
+
+        if (pd.ax > 0) {
+            led_left = 0;
+            led_right = fabs(pd.ax) * 2;
+        } else {
+            led_left = fabs(pd.ax) * 2;
+            led_right = 0;
+        }
+
+        if (pd.ay > 0) {
+            led_up = 0;
+            led_down = fabs(pd.ay) * 2;
+        } else {
+            led_up = fabs(pd.ay) * 2;
+            led_down = 0;
+        }
+    }
+}
+
+int main() {
+    lcd.cls(); 
+    ethernet_init();
+    main_loop();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Sun Oct 27 18:06:48 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#ee87e782d34f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Oct 27 18:06:48 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/f37f3b9c9f0b
\ No newline at end of file