-

Dependencies:   CommandHandler HygroClip2 InterruptBasedEncoder SPI_TFT_ILI9341 mbed-src-no-hal

Revision:
2:81fc8f80fdb4
Parent:
0:9ed7238d49e2
Child:
3:3ef8c2d7b1bf
--- a/GraphScale.cpp	Tue Feb 16 12:04:21 2016 +0000
+++ b/GraphScale.cpp	Wed Feb 17 07:30:14 2016 +0000
@@ -17,13 +17,27 @@
     int stepsize = height_ / ((max_-min_) / scaleSteps_);
     int stepposition = min_;
       
-    for(uint16_t i = 0; i <= height_; i += stepsize)
-    {       
-        uint16_t yPos = y2-i-1;
+    while (stepposition <= max_)
+    {
+        float yPos = scaleY(stepposition);
         tft_->line(x2, yPos, x2+5, yPos, color);
         tft_->locate(x2+10,yPos-6);
         tft_->printf("%d",stepposition);
-        
         stepposition += scaleSteps_;
     }
+}
+
+float GraphScale::scaleY(float ypos)
+{
+    static float valueRange = static_cast<float>(max_-min_);
+    static float buttomOfGraph = static_cast<float>(y_+height_);
+    
+    if (ypos < min_)
+        ypos = min_;
+    if (ypos > max_)
+        ypos = max_;
+    
+    float scaled = buttomOfGraph - (height_ * ((ypos-min_) / valueRange));
+    
+    return scaled;
 }
\ No newline at end of file