http://mbed.org/users/okini3939/notebook/daisen-edes/

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Thu Feb 23 05:05:23 2012 +0000
Parent:
0:141734449aeb
Commit message:

Changed in this revision

eDES2WD.cpp Show annotated file Show diff for this revision Revisions of this file
eDES2WD.h Show annotated file Show diff for this revision Revisions of this file
diff -r 141734449aeb -r 3c8a6bd50779 eDES2WD.cpp
--- a/eDES2WD.cpp	Thu Feb 23 01:33:12 2012 +0000
+++ b/eDES2WD.cpp	Thu Feb 23 05:05:23 2012 +0000
@@ -6,7 +6,7 @@
 void eDES2WD_reset (int id) {
   char cmd[] = {1, I2C_WCMD_RESET};
   int adrs;
-	
+    
   if (0 < id){
     adrs = SUB_ADRS + (id - 1) * 2;
   } else {
@@ -18,7 +18,7 @@
 void eDES2WD_motor (int id, int l_speed, int r_speed) {
   char cmd[] = {3, I2C_WCMD_MOTOR, 0, 0};
   int adrs;
-	
+    
   cmd[2] = l_speed;
   cmd[3] = r_speed;
   if (0 < id){
@@ -32,7 +32,7 @@
 void eDES2WD_set_led (int id, int led, int sw) {
   char cmd[] = {3, I2C_WCMD_LED, 0, 0};
   int adrs;
-	
+    
   cmd[2] = led;
   cmd[3] = sw;
   if (0 < id){
@@ -42,3 +42,46 @@
   }
   i2c.write(adrs, cmd, 4);
 }
+
+unsigned int eDES2WD_get_sensor(int id, int cn, unsigned int *dat) {
+    char cmd[] = {2, I2C_RCMD_SENSOR, 0};
+    char recv[MAX_CN];
+	unsigned int d;
+	int adrs;
+	int nmax, n;
+	
+	if (id < 1 || 9 < id) return(0);
+	adrs = SUB_ADRS + (id - 1) * 2;
+	nmax = cn < MAX_CN ? 2 : MAX_CN * 2 + 2;
+	
+	cmd[2] = cn;
+    i2c.write(adrs, cmd, 3);
+    i2c.read(adrs | 1, recv, nmax);
+	if (nmax == 2){
+		d = recv[0] | (recv[1] << 8);
+		return d;
+	} else {
+		for (n = 0; n < MAX_CN; n++){
+    		d = recv[0] | (recv[1] << 8);
+			dat[n] = d;
+		}
+//		gSUB_LED_G = recv[20];
+//		gSUB_LED_R = recv[21];
+	}
+	return 0;
+}
+
+int eDES2WD_get_lat(int id, int cno) {
+    char cmd[] = {2, I2C_RCMD_LAT, 0};
+    char recv[MAX_CN];
+	int adrs;
+	
+	if (id < 1 || 9 < id) return(false);
+	if (MAX_CN - 1 < cno) return(false);
+	adrs = SUB_ADRS + (id - 1) * 2;
+
+	cmd[2] = cno;
+    i2c.write(adrs, cmd, 3);
+    i2c.read(adrs | 1, recv, 1);
+	return recv[0];
+}
diff -r 141734449aeb -r 3c8a6bd50779 eDES2WD.h
--- a/eDES2WD.h	Thu Feb 23 01:33:12 2012 +0000
+++ b/eDES2WD.h	Thu Feb 23 05:05:23 2012 +0000
@@ -1,14 +1,44 @@
-#define SUB_ADRS	0x30
+#define SUB_ADRS    0x30
 
 #define I2C_WCMD_RESET	0x00
+#define I2C_WCMD_START	0x01
+#define I2C_WCMD_ENQ	0x09
+
+#define I2C_WCMD_IO		0x10
+#define I2C_WCMD_SENSOR	0x11
 #define I2C_WCMD_MOTOR	0x12
 #define I2C_WCMD_LED	0x13
+#define I2C_WCMD_LAT	0x14
+#define I2C_WCMD_T		0x15
+#define I2C_WCMD_V		0x16
+#define I2C_WCMD_DIR	0x17
+#define I2C_WCMD_EG002	0x18
+#define I2C_WCMD_EG003	0x19
+#define I2C_WCMD_EG009	0x1A
+#define I2C_WCMD_LDM	0x1B
 
-#define LED_GREEN	0
-#define LED_RED1	1
-#define LED_RED2	2
-#define LED_RED3	3
+#define I2C_RCMD_IO		0x80
+#define I2C_RCMD_SENSOR	0x81
+#define I2C_RCMD_MOTOR	0x82
+#define I2C_RCMD_LED	0x83
+#define I2C_RCMD_LAT	0x84
+#define I2C_RCMD_T		0x85
+#define I2C_RCMD_V		0x86
+#define I2C_RCMD_DIR	0x87
+
+#define MAX_PWM			6
+#define MAX_COL			16
+
+#define MAX_CN		10
+
+#define LED_GREEN    0
+#define LED_RED1    1
+#define LED_RED2    2
+#define LED_RED3    3
 
 void eDES2WD_reset (int id);
 void eDES2WD_motor (int id, int l_speed, int r_speed);
 void eDES2WD_set_led (int id, int led, int sw);
+
+unsigned int eDES2WD_get_sensor(int id, int cn, unsigned int *dat);
+int eDES2WD_get_lat(int id, int cno);