Library for 3.2'' uLcd Picaso Display4D system Picaso Serial Environment Command Set web: http://www.4dsystems.com.au/product/20/67/Processors_Graphics/PICASO/
Digit3Led.cpp@1:a74e42cf52b2, 2015-04-05 (annotated)
- Committer:
- adelino
- Date:
- Sun Apr 05 13:54:48 2015 +0000
- Revision:
- 1:a74e42cf52b2
PicasoLib version 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
adelino | 1:a74e42cf52b2 | 1 | #include "Digit3Led.h" |
adelino | 1:a74e42cf52b2 | 2 | |
adelino | 1:a74e42cf52b2 | 3 | Digit3Led::Digit3Led(Screen* mScreen,UINT16 _x,UINT16 _y,UINT8 _resolution): |
adelino | 1:a74e42cf52b2 | 4 | Widget(mScreen,0,_x,_y,108,52,YELLOW) |
adelino | 1:a74e42cf52b2 | 5 | { |
adelino | 1:a74e42cf52b2 | 6 | myColorBkg=YELLOW; |
adelino | 1:a74e42cf52b2 | 7 | myColorSeg=RED; |
adelino | 1:a74e42cf52b2 | 8 | myValue=0.0; |
adelino | 1:a74e42cf52b2 | 9 | myResolution=_resolution; |
adelino | 1:a74e42cf52b2 | 10 | |
adelino | 1:a74e42cf52b2 | 11 | myDigitLedCentaine= new DigitLed(mScreen,_x,_y,false); |
adelino | 1:a74e42cf52b2 | 12 | myDigitLedDizaine=new DigitLed(mScreen,_x+36,_y,false); |
adelino | 1:a74e42cf52b2 | 13 | myDigitLedUnite= new DigitLed(mScreen,_x+36+36,_y,false); |
adelino | 1:a74e42cf52b2 | 14 | |
adelino | 1:a74e42cf52b2 | 15 | |
adelino | 1:a74e42cf52b2 | 16 | myType= OBJ_DIGITAL_3_LED; |
adelino | 1:a74e42cf52b2 | 17 | myState=DIGIT_LED_STATE_ON; |
adelino | 1:a74e42cf52b2 | 18 | |
adelino | 1:a74e42cf52b2 | 19 | myScreen->addWidget((Widget*) this); |
adelino | 1:a74e42cf52b2 | 20 | } |
adelino | 1:a74e42cf52b2 | 21 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 22 | Digit3Led::~Digit3Led(void) |
adelino | 1:a74e42cf52b2 | 23 | { |
adelino | 1:a74e42cf52b2 | 24 | delete(myDigitLedCentaine); |
adelino | 1:a74e42cf52b2 | 25 | myDigitLedCentaine=0; |
adelino | 1:a74e42cf52b2 | 26 | delete(myDigitLedDizaine); |
adelino | 1:a74e42cf52b2 | 27 | myDigitLedDizaine=0; |
adelino | 1:a74e42cf52b2 | 28 | delete(myDigitLedUnite); |
adelino | 1:a74e42cf52b2 | 29 | myDigitLedUnite=0; |
adelino | 1:a74e42cf52b2 | 30 | } |
adelino | 1:a74e42cf52b2 | 31 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 32 | void Digit3Led::draw(void) |
adelino | 1:a74e42cf52b2 | 33 | { |
adelino | 1:a74e42cf52b2 | 34 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 35 | return; |
adelino | 1:a74e42cf52b2 | 36 | |
adelino | 1:a74e42cf52b2 | 37 | myDigitLedCentaine->draw(); |
adelino | 1:a74e42cf52b2 | 38 | myDigitLedDizaine->draw(); |
adelino | 1:a74e42cf52b2 | 39 | myDigitLedUnite->draw(); |
adelino | 1:a74e42cf52b2 | 40 | |
adelino | 1:a74e42cf52b2 | 41 | } |
adelino | 1:a74e42cf52b2 | 42 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 43 | void Digit3Led::setInvisible(bool _state) |
adelino | 1:a74e42cf52b2 | 44 | { |
adelino | 1:a74e42cf52b2 | 45 | // element devient invisible |
adelino | 1:a74e42cf52b2 | 46 | if(_state==true) { |
adelino | 1:a74e42cf52b2 | 47 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 48 | return; |
adelino | 1:a74e42cf52b2 | 49 | |
adelino | 1:a74e42cf52b2 | 50 | myIsVisible=false; |
adelino | 1:a74e42cf52b2 | 51 | |
adelino | 1:a74e42cf52b2 | 52 | Color c= myScreen->getColorBkg(); |
adelino | 1:a74e42cf52b2 | 53 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 54 | |
adelino | 1:a74e42cf52b2 | 55 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 56 | |
adelino | 1:a74e42cf52b2 | 57 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 58 | ps->draw_filled_rectangle(myX,myY,myX+myWidth,myY+myHeight,c); |
adelino | 1:a74e42cf52b2 | 59 | } |
adelino | 1:a74e42cf52b2 | 60 | ps=0; |
adelino | 1:a74e42cf52b2 | 61 | } |
adelino | 1:a74e42cf52b2 | 62 | |
adelino | 1:a74e42cf52b2 | 63 | // element devient visible |
adelino | 1:a74e42cf52b2 | 64 | else { |
adelino | 1:a74e42cf52b2 | 65 | myIsVisible=true; |
adelino | 1:a74e42cf52b2 | 66 | |
adelino | 1:a74e42cf52b2 | 67 | |
adelino | 1:a74e42cf52b2 | 68 | this->draw(); |
adelino | 1:a74e42cf52b2 | 69 | } |
adelino | 1:a74e42cf52b2 | 70 | } |
adelino | 1:a74e42cf52b2 | 71 | //----------------------------------------- |
adelino | 1:a74e42cf52b2 | 72 | void Digit3Led::setValue(float _value) |
adelino | 1:a74e42cf52b2 | 73 | { |
adelino | 1:a74e42cf52b2 | 74 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 75 | return; |
adelino | 1:a74e42cf52b2 | 76 | // |
adelino | 1:a74e42cf52b2 | 77 | if(myValue==_value) |
adelino | 1:a74e42cf52b2 | 78 | return; |
adelino | 1:a74e42cf52b2 | 79 | // |
adelino | 1:a74e42cf52b2 | 80 | myValue=_value; |
adelino | 1:a74e42cf52b2 | 81 | UINT16 temp=0; |
adelino | 1:a74e42cf52b2 | 82 | |
adelino | 1:a74e42cf52b2 | 83 | char centaine=0; |
adelino | 1:a74e42cf52b2 | 84 | char dizaine=0; |
adelino | 1:a74e42cf52b2 | 85 | char unite=0; |
adelino | 1:a74e42cf52b2 | 86 | |
adelino | 1:a74e42cf52b2 | 87 | //the Pt? |
adelino | 1:a74e42cf52b2 | 88 | switch(myResolution) { |
adelino | 1:a74e42cf52b2 | 89 | case 1: //xxx |
adelino | 1:a74e42cf52b2 | 90 | temp=(UINT16)_value; |
adelino | 1:a74e42cf52b2 | 91 | myDigitLedCentaine->setPtVisible(false); |
adelino | 1:a74e42cf52b2 | 92 | myDigitLedDizaine->setPtVisible(false); |
adelino | 1:a74e42cf52b2 | 93 | myDigitLedUnite->setPtVisible(false); |
adelino | 1:a74e42cf52b2 | 94 | break; |
adelino | 1:a74e42cf52b2 | 95 | // |
adelino | 1:a74e42cf52b2 | 96 | case 10: //xx.x |
adelino | 1:a74e42cf52b2 | 97 | temp=(UINT16)(_value*10); |
adelino | 1:a74e42cf52b2 | 98 | myDigitLedCentaine->setPtVisible(false); |
adelino | 1:a74e42cf52b2 | 99 | myDigitLedDizaine->setPtVisible(true); |
adelino | 1:a74e42cf52b2 | 100 | myDigitLedUnite->setPtVisible(false); |
adelino | 1:a74e42cf52b2 | 101 | break; |
adelino | 1:a74e42cf52b2 | 102 | // |
adelino | 1:a74e42cf52b2 | 103 | case 100: //x.xx |
adelino | 1:a74e42cf52b2 | 104 | temp=(UINT16)(_value*100); |
adelino | 1:a74e42cf52b2 | 105 | myDigitLedCentaine->setPtVisible(true); |
adelino | 1:a74e42cf52b2 | 106 | myDigitLedDizaine->setPtVisible(false); |
adelino | 1:a74e42cf52b2 | 107 | myDigitLedUnite->setPtVisible(false); |
adelino | 1:a74e42cf52b2 | 108 | break; |
adelino | 1:a74e42cf52b2 | 109 | |
adelino | 1:a74e42cf52b2 | 110 | default: |
adelino | 1:a74e42cf52b2 | 111 | break; |
adelino | 1:a74e42cf52b2 | 112 | } |
adelino | 1:a74e42cf52b2 | 113 | // |
adelino | 1:a74e42cf52b2 | 114 | if(temp <100) { |
adelino | 1:a74e42cf52b2 | 115 | centaine=0; |
adelino | 1:a74e42cf52b2 | 116 | myDigitLedCentaine->setInvisible(true); |
adelino | 1:a74e42cf52b2 | 117 | } else { |
adelino | 1:a74e42cf52b2 | 118 | myDigitLedCentaine->setInvisible(false); |
adelino | 1:a74e42cf52b2 | 119 | centaine=(char)(temp/100); |
adelino | 1:a74e42cf52b2 | 120 | temp=temp-(centaine*100); |
adelino | 1:a74e42cf52b2 | 121 | } |
adelino | 1:a74e42cf52b2 | 122 | // |
adelino | 1:a74e42cf52b2 | 123 | if(temp <10) { |
adelino | 1:a74e42cf52b2 | 124 | dizaine=0; |
adelino | 1:a74e42cf52b2 | 125 | } else { |
adelino | 1:a74e42cf52b2 | 126 | dizaine=(char)(temp/10); |
adelino | 1:a74e42cf52b2 | 127 | temp=temp-(dizaine*10); |
adelino | 1:a74e42cf52b2 | 128 | } |
adelino | 1:a74e42cf52b2 | 129 | // |
adelino | 1:a74e42cf52b2 | 130 | unite=(char)temp; |
adelino | 1:a74e42cf52b2 | 131 | |
adelino | 1:a74e42cf52b2 | 132 | myDigitLedCentaine->setValue(centaine); |
adelino | 1:a74e42cf52b2 | 133 | myDigitLedDizaine->setValue(dizaine); |
adelino | 1:a74e42cf52b2 | 134 | myDigitLedUnite->setValue(unite); |
adelino | 1:a74e42cf52b2 | 135 | |
adelino | 1:a74e42cf52b2 | 136 | this->draw(); |
adelino | 1:a74e42cf52b2 | 137 | } |
adelino | 1:a74e42cf52b2 | 138 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 139 | void Digit3Led::setColorBkg(Color _colorBkg) |
adelino | 1:a74e42cf52b2 | 140 | { |
adelino | 1:a74e42cf52b2 | 141 | if(myColorBkg==_colorBkg) |
adelino | 1:a74e42cf52b2 | 142 | return; |
adelino | 1:a74e42cf52b2 | 143 | |
adelino | 1:a74e42cf52b2 | 144 | myColorBkg=_colorBkg; |
adelino | 1:a74e42cf52b2 | 145 | myDigitLedCentaine->setColorBkg(_colorBkg); |
adelino | 1:a74e42cf52b2 | 146 | myDigitLedDizaine->setColorBkg(_colorBkg); |
adelino | 1:a74e42cf52b2 | 147 | myDigitLedUnite->setColorBkg(_colorBkg); |
adelino | 1:a74e42cf52b2 | 148 | |
adelino | 1:a74e42cf52b2 | 149 | this->draw(); |
adelino | 1:a74e42cf52b2 | 150 | } |
adelino | 1:a74e42cf52b2 | 151 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 152 | void Digit3Led::setColorSeg(Color _colorSeg) |
adelino | 1:a74e42cf52b2 | 153 | { |
adelino | 1:a74e42cf52b2 | 154 | if(myColorSeg==_colorSeg) |
adelino | 1:a74e42cf52b2 | 155 | return; |
adelino | 1:a74e42cf52b2 | 156 | |
adelino | 1:a74e42cf52b2 | 157 | myColorSeg=_colorSeg; |
adelino | 1:a74e42cf52b2 | 158 | myDigitLedCentaine->setColorSeg(_colorSeg); |
adelino | 1:a74e42cf52b2 | 159 | myDigitLedDizaine->setColorSeg(_colorSeg); |
adelino | 1:a74e42cf52b2 | 160 | myDigitLedUnite->setColorSeg(_colorSeg); |
adelino | 1:a74e42cf52b2 | 161 | |
adelino | 1:a74e42cf52b2 | 162 | this->draw(); |
adelino | 1:a74e42cf52b2 | 163 | } |