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

Dependencies:   C12832_lcd USBDevice mbed

bargraph.cpp

Committer:
jakowisp
Date:
2013-07-30
Revision:
0:69eb9d19fb91
Child:
1:948ffad3284f

File content as of revision 0:69eb9d19fb91:

 #include "bargraph.h"
 bargraph::bargraph(C12832_LCD *inlcd,int maxlevelsIn,int Xin,int Yin,int widthIn,int heightIn){
      lcd=inlcd;
      level=0;
      lastLevel=0;
      if(maxlevelsIn<=32 && maxlevelsIn >=4)
         maxlevels=maxlevelsIn;
      else
         maxlevels=32;
      if(Xin>=0 && Xin<=127-maxlevels)
           x=Xin;
      else
           x=0;
      if(Yin>=0 && Yin<=31-maxlevels)
           y=Yin;
      else
           y=0;
      if(widthIn>maxlevels && widthIn<128)
        width=widthIn-1;
      else
        width=127;
      if(heightIn>=(maxlevels-1) && heightIn<31)  
         height=heightIn;
      else 
         height=31;
      leveladjust=(height+1)/maxlevels;
      levelwidth=(width+1)/maxlevels;
   }
   
   void  bargraph::setMaxLevel(int maxlevels){
      lcd->fillrect(x, y, x+width,y+height, 0);
      leveladjust=(height+1)/maxlevels;
      levelwidth=(width+1)/maxlevels;
   }
   
   void bargraph::setLevel(int level){
      this->level=level;
   }
   
   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);
          }
          for(int i = 0 ; i<level;i++) {
             lcd->fillrect(x+levelwidth*(i), y, x+levelwidth*(i+1)-1, y+i*leveladjust, 1);
          }
          lastLevel=level;
        }
      }
    };