Dependencies:   mbed

Fork of ADXL345Test_for_motortest by jack zen

Files at this revision

API Documentation at this revision

Comitter:
Frederick_H
Date:
Fri Sep 01 10:53:50 2017 +0000
Parent:
6:88787a48e96e
Commit message:
Add zoom and shift function on Mapper

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 88787a48e96e -r 592373200317 main.cpp
--- a/main.cpp	Fri Sep 01 10:10:46 2017 +0000
+++ b/main.cpp	Fri Sep 01 10:53:50 2017 +0000
@@ -12,15 +12,22 @@
      protected: 
      double _ratio;
      double _offset;
+     double _outrange;
      public:
      RangeMapper(double x_min, double x_max, double y_min, double y_max)
       {
           _ratio = (y_max - y_min) / (x_max - x_min);
-          _offset = y_min - x_min * _ratio; 
+          _offset = y_min - x_min * _ratio;
+          _outrange = y_max - y_min; 
       };
      ~RangeMapper(){};
      double getOutput(double x_input)
         {return x_input * _ratio + _offset;};
+     void zoom(float ratio)
+        {_ratio *=  ratio;};
+     void shift(float ratio)
+        {_offset +=  _outrange * ratio ; } ;
+      
  };
 
  
@@ -80,7 +87,6 @@
      bool output = true, mapout = true;
      pc.baud(115200);
      int readings[3] = {0, 0, 0};
-     RangeMapper DAC_Mapper( 0 - 1<<13, 1<<13, 0, 1);
      DataProcess dp1, dp2, dp3;
      DataProcess dp[3] = {dp1, dp2, dp3};
  
@@ -135,6 +141,10 @@
      pc.printf("  g -> 3rd order Integration \r\n");
      pc.printf("  h -> 1st order Differentiation \r\n");
      pc.printf("  k -> 2nd order Differentiation \r\n");
+     pc.printf("  + -> Output Zoom In 2X \r\n");
+     pc.printf("  - -> Output Zoom Out 2Z \r\n");
+     pc.printf("  ^ -> shift up 1% \r\n");
+     pc.printf("  v -> shift down 1% \r\n");
      pc.printf("Press any key to start. \r\n");
      getc = pc.getc();  
      
@@ -142,6 +152,8 @@
  
      while (1) {
          int error_count=0;
+         RangeMapper DAC_Mapper1( 0 - 1<<13, 1<<13, 0, 1);
+         RangeMapper DAC_Mapper2( 0 - 1<<13, 1<<13, 0, 1);
          if (pc.readable())
             {
                 getc = pc.getc();
@@ -163,6 +175,10 @@
                         case 'g' : datamode = 6 ; pc.printf("Set to 3rd order Integration output.\r\n"); break;
                         case 'h' : datamode = 7 ; pc.printf("Set to 1st order Differentiation output.\r\n"); break;
                         case 'k' : datamode = 8 ; pc.printf("Set to 2nd order Differentiation output.\r\n"); break;
+                        case '+' : DAC_Mapper2.zoom(2) ; pc.printf("Mapout zoom in.\r\n"); break;
+                        case '-' : DAC_Mapper2.zoom(0.5) ; pc.printf("Mapout zoom out.\r\n"); break;
+                        case '^' : DAC_Mapper2.shift(0.01) ; pc.printf("Mapout zoom out.\r\n"); break;
+                        case 'v' : DAC_Mapper2.shift(-0.01) ; pc.printf("Mapout zoom out.\r\n"); break;
                         default: break;
                     }
             }
@@ -201,7 +217,9 @@
                 default: break;         
                }
              }
-            if (mapout)
+             // Set data the DAC
+             DAC_Mapper1.getOutput(readings[channel]);
+             if (mapout)
              {
                double mapdata;
                switch (datamode)
@@ -217,9 +235,14 @@
                 case 8: mapdata = dp[channel].GetO2differ(); break;     
                 default: mapdata = 0; break;         
                }
-                // Set data the DAC
-                DAC_Mapper.getOutput(mapdata);
+               pc.printf("MAPPING OUTPUT: %jd\r\n", DAC_Mapper2.getOutput(mapdata) );
+               
              }
+             else
+             {
+               DAC_Mapper2.getOutput(0);
+             }
+
              wait(1);
             }