Tomoyuki Saito / Mbed 2 deprecated galvano_driver

Dependencies:   TextLCD mbed

Revision:
1:51a340435086
Parent:
0:2ead13cba2ae
--- a/main.cpp	Thu Sep 25 01:40:14 2014 +0000
+++ b/main.cpp	Fri Apr 17 01:50:54 2015 +0000
@@ -6,36 +6,41 @@
 #include "square.h"
 #include "jibanyan.h"
 
+#include "crescent_moon_edge.h"
+#include "crescent_moon_mesh.h"
+
+
+#include "blktest.h"
+#include "blktest2.h"
+
+#include "square_160x120_raster.h"
+#include "square_160x120_vector.h"
+#include "square_160x120_vector_half.h"
+#include "square_160x120_hybrid.h"
+
+#include "square_full_vector.h"
+#include "square_L_vector.h"
+#include "square_M_vector.h"
+#include "square_S_vector.h"
+
+
 #include <stdlib.h>
 
-#define soft 0
 
 Serial pc(USBTX, USBRX); // tx, rx
 TextLCD lcd(p26, p25, p24, p23, p22, p21); // rs, e, d4-d7
 
-
-uint8_t f8=0;   //if f8 == 1 , dac8bit emu
-
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
-
-#if soft
-DigitalOut CS(p10);
-DigitalOut SCK(p13);    ///
-DigitalOut SDI(p11);
-DigitalOut LDAC(p9);
-#else
 SPI spi(p11, p12, p13); // mosi, miso, sclk
 DigitalOut CS(p10);
 DigitalOut LDAC(p9);
-#endif
 
 DigitalOut BLK(p8); // laser blanking
 
 #define CHA 0x7000 // //0x0000  //0x7000
 #define CHB 0xF000 // //0x8000  //0xF000
+#define BLK_DELAY 80 // < 100 default
+//#define BLK_DELAY 160 // < 100
+
 
 //**********************************************************************
 
@@ -54,26 +59,12 @@
     }
     //
     CS = 0;
-#if soft
-    for (cnt = 0; cnt < 16; cnt++) {
-        ///if (((dt << cnt) &0b1000000000000000) != 0)
-        if (((dt << cnt) &0x8000) != 0) {
-            SDI = 1;
-        } else {
-            SDI = 0;
-        }
 
-        SCK = 1;
-        ///wait_us(10);   ///
-        SCK = 0;
-    }
-#else
     spi.write(dt);
     //LPC_SSP0->DR = dt; // | 0x10000; //hardware dependent
     //while(1) {
     //    if( (LPC_SSP0->SR &0x13) == 3) break;
     //}
-#endif
 
     CS = 1;
 }
@@ -92,20 +83,6 @@
     mcp4922DataSet('B', 0);
 }
 
-void triangle(void)
-{
-    int i=0;
-
-    while(1) {
-        i++;
-        if (i == 256) i = 0;
-        mcp4922DataSet('A', i<<4);//wait_us(20);
-        mcp4922DataSet('B', i<<4);//wait_us(20);
-        LDAC = 0;
-        LDAC = 1;
-        wait_us(400);
-    }
-}
 
 
 void high_flat(void)
@@ -113,26 +90,14 @@
     while(1) {
         mcp4922DataSet('A', 4095);//wait_us(20);
         mcp4922DataSet('B', 4095);//wait_us(20);
+
         LDAC = 0;
         LDAC = 1;
-        wait_us(400);
+        wait_us(100);
     }
 }
 
 
-void low_flat(void)
-{
-    while(1) {
-        mcp4922DataSet('A', 0);//wait_us(20);
-        mcp4922DataSet('B', 0);//wait_us(20);
-        LDAC = 0;
-        LDAC = 1;
-        wait_us(400);
-    }
-}
-
-
-
 void triangle2(void)
 {
     int i=0;
@@ -276,7 +241,7 @@
 
 
 
-void laserscan(const int *p)
+void laserscan(const int *p, const int num)
 {
     int i = 0;
     uint16_t x,y = 0;
@@ -287,7 +252,11 @@
             x = *(p + i++);
             y = *(p + i++);    
 
-            if (x == 0 && y == 0) {
+//            if (x == 0 && y == 0) {
+//                i = 0;
+//            }
+
+            if (i == num) {
                 i = 0;
             }
 
@@ -307,57 +276,92 @@
 }  
 
 
+// add laser blanking control
+void laserscan_blk(const int *p, const int num)
+{
+    int i = 0;
+    uint16_t x,y = 0;
+    bool b = 0;
+    
+//        while(1) {
+          while(CNT < 5) {
+            
+            b = *(p + i++);
+            x = *(p + i++);
+            y = *(p + i++);    
 
+//            if (x == 0 && y == 0) {
+//                i = 0;
+//            }
+
+            if (i == num) {
+                i = 0;
+            }
+
+            x += 32767;
+            y += 32767;
+            x = 65535 - x; // X-axis invert
+
+            mcp4922DataSet('A', x>>4);//wait_us(20);
+            mcp4922DataSet('B', y>>4);//wait_us(20);
+            LDAC = 0;
+            LDAC = 1;
+
+            wait_us(BLK_DELAY);
+//            BLK = b;
+                BLK = 1;
+                
+            wait_us(200 - BLK_DELAY);        // default
+//            wait_us(400 - BLK_DELAY);        
+
+        }
+        CNT = 0;
+}  
+
+
+// serial com test
+void laserscan_com(void)
+{
+    int i = 0;
+    int buff[4] = {0,0,0,0};
+    uint16_t x,y = 0;
+    
+        while(1) {
+
+        for (i = 0; i < 4; i++) {
+            char c = pc.getc();
+            buff[i] = c;
+//            lcd.printf("%02X",buff[i]);
+
+        }
+
+//        lcd.printf("\n");
+
+        x = (buff[1] << 8) + buff[0];
+        y = (buff[3] << 8) + buff[2];
+//        lcd.printf("x=%04X,y=%04X\n",x,y);
+        
+            if (x == 0 && y == 0) {
+                i = 0;
+            }
+
+            x += 32767;
+            y += 32767;
+            x = 65535 - x; // X-axis invert
+
+            mcp4922DataSet('A', x>>4);//wait_us(20);
+            mcp4922DataSet('B', y>>4);//wait_us(20);
+
+            LDAC = 0;
+            LDAC = 1;
+
+            wait_us(100);       
+        }
+}  
 
 
 
 
-#define test8bit
-void disposc(const int *p,char b)
-{
-    int x, y, c = 0;
-
-    while(CNT < 10) {
-        x = *p++;
-        y = *p++;
-        c += 2;
-        if (x == -1 &&y == -1) {
-            p = p - c;
-            c = 0;
-            x = *p++;
-            y = *p++;
-            c += 2;
-        }
-        if (b==8) {
-            x <<= 3 ;
-            y <<= 3 ;
-        }
-
-        if (x < (128<<8)) x += (128<<8);
-        else              x -= (128<<8);
-        if (y < (128<<8)) y += (128<<8);
-        else              y -= (128<<8);
-
-#ifdef test8bit
-        if (f8 == 1) {
-            mcp4922DataSet('A', (x>>4) & 0x0FF0);
-            mcp4922DataSet('B', (y>>4) & 0x0FF0);
-        } else {
-            mcp4922DataSet('A', x>>4);
-            mcp4922DataSet('B', y>>4);
-        }
-#else
-        mcp4922DataSet('A', x>>4);
-        mcp4922DataSet('B', y>>4);
-#endif
-        LDAC = 0;
-        LDAC = 1;
-        wait_us(2);
-
-    }
-    CNT = 0;
-
-}
 
 int main(void)
 {
@@ -365,6 +369,8 @@
     spi.format(16,0);
     spi.frequency(20000000);
 
+    pc.baud(230400);
+
     mcp4922Init();
     
     timer.attach(&int_timer, 1);
@@ -383,13 +389,37 @@
         }
 */
 
-
+//    triangle2();
+//        high_flat();
 
     while(1) {
-        laserscan(jibanyan);
-        laserscan(star);
-        laserscan(square);
+
+// non blanking control
+//        laserscan(jibanyan,jibanyan_dnum);
+//        laserscan(star,star_dnum);
+//        laserscan(crescent_moon_edge,crescent_moon_edge_dnum);
+//        laserscan(crescent_moon_mesh,crescent_moon_mesh_dnum);
+
+// add blanking control
+//       laserscan_blk(blktest2,blktest2_dnum);
+//       laserscan_blk(square_20x20_raster,square_20x20_raster_dnum);
+//       laserscan_blk(square_160x120_raster,square_160x120_raster_dnum);
+//       laserscan_blk(square_160x120_vector,square_160x120_vector_dnum);
+//       laserscan_blk(square_160x120_vector_half,square_160x120_vector_half_dnum);
+//       laserscan_blk(square_160x120_hybrid,square_160x120_hybrid_dnum);
+//       laserscan_blk(square_full_vector,square_full_vector_dnum);
+       laserscan_blk(square_L_vector,square_L_vector_dnum);
+       laserscan_blk(square_M_vector,square_M_vector_dnum);
+       laserscan_blk(square_S_vector,square_S_vector_dnum);
+
+
+
+// add PC serial com
+//        laserscan_com();
     }
 
 
 }
+
+
+