Usb Device Interface, protocol, and programming homework #4 Audio Control device

Dependencies:   C12832_lcd USBDevice mbed

Revision:
1:948ffad3284f
Parent:
0:69eb9d19fb91
Child:
3:6da430f4818a
--- a/bargraph.cpp	Tue Jul 30 22:35:10 2013 +0000
+++ b/bargraph.cpp	Wed Jul 31 22:20:00 2013 +0000
@@ -1,36 +1,38 @@
  #include "bargraph.h"
  bargraph::bargraph(C12832_LCD *inlcd,int maxlevelsIn,int Xin,int Yin,int widthIn,int heightIn){
-      lcd=inlcd;
-      level=0;
-      lastLevel=0;
+      this->lcd=inlcd;
+      this->level=0;
+      this->lastLevel=0;
       if(maxlevelsIn<=32 && maxlevelsIn >=4)
-         maxlevels=maxlevelsIn;
+         this->maxlevels=maxlevelsIn;
       else
-         maxlevels=32;
-      if(Xin>=0 && Xin<=127-maxlevels)
-           x=Xin;
+         this->maxlevels=32;
+      if(Xin>=0 && Xin<=127-this->maxlevels)
+           this->x=Xin;
       else
-           x=0;
-      if(Yin>=0 && Yin<=31-maxlevels)
-           y=Yin;
+           this->x=0;
+      if(Yin>=0 && Yin<=31-this->maxlevels)
+           this->y=Yin;
       else
-           y=0;
+           this->y=0;
       if(widthIn>maxlevels && widthIn<128)
-        width=widthIn-1;
+        this->width=widthIn-1;
       else
-        width=127;
+        this->width=127;
       if(heightIn>=(maxlevels-1) && heightIn<31)  
-         height=heightIn;
+         this->height=heightIn;
       else 
-         height=31;
-      leveladjust=(height+1)/maxlevels;
-      levelwidth=(width+1)/maxlevels;
+         this->height=31;
+      this->leveladjust=(this->height+1)/this->maxlevels;
+      this->levelwidth=(this->width+1)/this->maxlevels;
    }
    
    void  bargraph::setMaxLevel(int maxlevels){
-      lcd->fillrect(x, y, x+width,y+height, 0);
-      leveladjust=(height+1)/maxlevels;
-      levelwidth=(width+1)/maxlevels;
+      //TODO: need to defensive check maxlevels
+      this->lcd->fillrect(this->x, this->y, this->x+this->width,this->y+this->height, 0);
+      this->lastLevel=0;    
+      this->leveladjust=(this->height+1)/maxlevels;
+      this->levelwidth=(this->width+1)/maxlevels;
    }
    
    void bargraph::setLevel(int level){
@@ -38,15 +40,23 @@
    }
    
    void  bargraph::updateBargraph(){  
-      if(lcd!=NULL) {
-        if(level!=lastLevel) {
-          for(int i = 0 ; i<lastLevel;i++) {
-             lcd->fillrect(x+levelwidth*(i), y, x+levelwidth*(i+1)-1, y+i*leveladjust, 0);
+      if(this->lcd!=NULL) {
+        if(this->level!=this->lastLevel) {
+          for(int i = 0 ; i<this->lastLevel;i++) {
+             this->lcd->fillrect(this->x+this->levelwidth*(i), 
+                                 this->y, 
+                                 this->x+this->levelwidth*(i+1)-1,
+                                 this->y+i*this->leveladjust, 
+                                 0);
           }
           for(int i = 0 ; i<level;i++) {
-             lcd->fillrect(x+levelwidth*(i), y, x+levelwidth*(i+1)-1, y+i*leveladjust, 1);
+             this->lcd->fillrect(this->x+this->levelwidth*(i), 
+                                 this->y, 
+                                 this->x+this->levelwidth*(i+1)-1,
+                                 this->y+i*this->leveladjust, 
+                                 1);
           }
-          lastLevel=level;
+          this->lastLevel = this->level;
         }
       }
     };