收到xy自动缩放

Dependencies:   MQTT SDFileSystem WIZnet_Library mbed

Fork of wmx_laser by w mx

Files at this revision

API Documentation at this revision

Comitter:
xmwmx
Date:
Fri Aug 03 09:45:20 2018 +0000
Parent:
9:a3f9faa9ca1f
Commit message:
?????????

Changed in this revision

mainwmx.cpp Show annotated file Show diff for this revision Revisions of this file
test.txt Show annotated file Show diff for this revision Revisions of this file
diff -r a3f9faa9ca1f -r 3c154d398def mainwmx.cpp
--- a/mainwmx.cpp	Tue Jul 31 03:56:05 2018 +0000
+++ b/mainwmx.cpp	Fri Aug 03 09:45:20 2018 +0000
@@ -81,7 +81,9 @@
 int key=0;//判断变量
 int dot=0;//点计数
 int flag=0;
-//char w[4294967295];
+int numbers[100][3];
+//char buf[100];
+
 
 void rotate(int id ,int pix);
 
@@ -134,6 +136,7 @@
     now_y = 0;
     step[0] = 0;
     step[1] = 0;
+    //memset(buf,0,sizeof(buf)/sizeof(char));
     //上x下y
 
 }
@@ -200,6 +203,26 @@
 }
 */
 
+void str2numbers(char buf[])
+{
+    pc.printf("%s\r\n",buf);
+    char *p = buf;
+    int index = 0;
+    int x,y,z;
+    while(true)
+    {
+        p = strchr(p, '(');
+        if(!p) break;
+        p++;
+        sscanf(p, "%d%d%d",&x,&y,&z);
+        pc.printf("%d %d %d \r\n",x,y,z);
+        numbers[index][0] = x;
+        numbers[index][1] = y;
+        numbers[index][2] = z;
+        index++;
+    }
+}
+
 void draw()
 {
     unit_xy=unit_xy*k;
@@ -222,16 +245,34 @@
     //pc.printf("Received [%s] [%s]\r\n", actuator_name, control_value);
     if (strcmp(actuator_name, "dat") == 0) {
         //接受到的坐标数据写入存储卡
+        /*
+        if(dot<10)
+        {
+            strcpy(buf,control_value);
+            dot++;
+            pc.printf("received   %d|%d|%s\r\n",status,dot,buf);
+        }
+        else
+        {
+            fprintf(fp_drawing, "%s", buf);
+            memset(buf,0,sizeof(buf)/sizeof(char));
+            dot=0;
+            strcpy(buf,control_value);
+            dot++;
+            flag=1;
+            pc.printf("received.   %d|%d|%s\r\n",status,dot,buf);
+        }
+        */
         //fprintf(fp_drawing, "%s", control_value);
+        //str2numbers(control_value);
+        pc.printf("received   %d|%d\r\n",status,dot);
         fprintf(fp_drawing, "%s", control_value);
         dot++;
-        if(strcmp(control_value, "(0,0,1)") == 0)
-        {
-            flag=1;
-            pc.printf("received (0,0,1)  %d|%d\r\n",status,dot);
-        }
+        flag=1;
+        pc.printf("received   %d|%d\r\n",status,dot);
+        
     } 
-    else if (strcmp(actuator_name, "cmd") == 0) {
+    else if (strcmp(actuator_name, "command") == 0) {
         int the_command = atoi(control_value);
         //
         if(key!=0)
@@ -298,7 +339,7 @@
     //声明所有的执行器,每行一个,每个由名字、参数类型两部分组成,最后一行必须为空指针作为结尾
     const char* actuators[][2] = {
         "dat", "",
-        "cmd", "",
+        "command", "",
         NULL, NULL //最后一行以空指针作为结束标记
     };
     pc.printf("connecting...\r\n");
@@ -341,7 +382,6 @@
                 publish_value(client, "report", "input y:");
                 client.yield(5000);
             }
-            publish_value(client, "report", "ready.");
         }
         while(y*k>widthy&&status==2)
         {
@@ -366,6 +406,10 @@
                     pc.printf("wait data.%d\r\n",status);
                 }
             }
+            else
+            {
+                publish_value(client, "report", "ready.");
+            }
              
         }
 
@@ -376,15 +420,21 @@
             {
                 //wait(15);
                 
-                publish_value(client, "report", "all wrote.");
-                pc.printf("wrote finish  %d\r\n",status);
+                publish_value(client, "report", "received.");
+                pc.printf("received.  %d\r\n",status);
+                flag=0;
             }
             if (Getdata) 
             { //数据接收完
                 Getdata = 0;
+                /*
+                fprintf(fp_drawing, "%s", buf);
+                memset(buf,0,sizeof(buf)/sizeof(char));
+                dot=0;
+                */
                 pc.printf("End receiving...  %d\r\n",status);
                 fclose(fp_drawing);
-                publish_value(client, "report", "received.");
+                publish_value(client, "report", "starting");
                 status = 4;
             }
         } 
@@ -397,6 +447,7 @@
             draw();
             publish_value(client, "report", "done.");
             pc.printf("done.  %d \r\n",status);
+            
             status = 2;
             x=0;
             y=0;
@@ -406,7 +457,7 @@
             k=1.0;
             flag=0;
             dot=0;
-            //strcpy(w,"");
+            //memset(buf,0,sizeof(buf)/sizeof(char));
         }
         client.yield(1000);
     }
diff -r a3f9faa9ca1f -r 3c154d398def test.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test.txt	Fri Aug 03 09:45:20 2018 +0000
@@ -0,0 +1,22 @@
+int numbers[100][3];
+void str2numbers(char buf[])
+{
+    pc.printf("%s\r\n",buf);
+    char *p = buf;
+    int index = 0;
+    int a,x,y,z;
+    while(true)
+    {
+        p = strchr(p, '(');
+        if(!p) break;
+        p++;
+        sscanf(p, "%d%d%d",&x,&y,&z);
+        pc.printf("%d %d %d \r\n",x,y,z);
+        numbers[index][0] = x;
+        numbers[index][1] = y;
+        numbers[index][2] = z;
+        index++;
+}
+    
+}
+            
\ No newline at end of file