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/
DigitLed.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 "DigitLed.h" |
adelino | 1:a74e42cf52b2 | 2 | |
adelino | 1:a74e42cf52b2 | 3 | DigitLed::DigitLed(Screen* mScreen,UINT16 _x,UINT16 _y,bool _ptVisible): |
adelino | 1:a74e42cf52b2 | 4 | Widget(mScreen,0,_x,_y,36,52,WHITE) |
adelino | 1:a74e42cf52b2 | 5 | { |
adelino | 1:a74e42cf52b2 | 6 | myValue=0; |
adelino | 1:a74e42cf52b2 | 7 | myColorBkg=YELLOW; |
adelino | 1:a74e42cf52b2 | 8 | myColorSeg=RED; |
adelino | 1:a74e42cf52b2 | 9 | myIncX=4; |
adelino | 1:a74e42cf52b2 | 10 | myIncY=4; |
adelino | 1:a74e42cf52b2 | 11 | |
adelino | 1:a74e42cf52b2 | 12 | isPtVisible=_ptVisible; |
adelino | 1:a74e42cf52b2 | 13 | |
adelino | 1:a74e42cf52b2 | 14 | myType=OBJ_DIGIT_LED; |
adelino | 1:a74e42cf52b2 | 15 | myState=DIGIT_LED_STATE_ON; |
adelino | 1:a74e42cf52b2 | 16 | |
adelino | 1:a74e42cf52b2 | 17 | myScreen->addWidget((Widget*) this); |
adelino | 1:a74e42cf52b2 | 18 | } |
adelino | 1:a74e42cf52b2 | 19 | //----------------------------------------- |
adelino | 1:a74e42cf52b2 | 20 | DigitLed::~DigitLed(void) |
adelino | 1:a74e42cf52b2 | 21 | { |
adelino | 1:a74e42cf52b2 | 22 | } |
adelino | 1:a74e42cf52b2 | 23 | //----------------------------------------- |
adelino | 1:a74e42cf52b2 | 24 | void DigitLed::setColorBkg(Color _colorBkg) |
adelino | 1:a74e42cf52b2 | 25 | { |
adelino | 1:a74e42cf52b2 | 26 | if(myColorBkg==_colorBkg) |
adelino | 1:a74e42cf52b2 | 27 | return; |
adelino | 1:a74e42cf52b2 | 28 | |
adelino | 1:a74e42cf52b2 | 29 | myColorBkg=_colorBkg; |
adelino | 1:a74e42cf52b2 | 30 | this->draw(); |
adelino | 1:a74e42cf52b2 | 31 | } |
adelino | 1:a74e42cf52b2 | 32 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 33 | void DigitLed::setColorSeg(Color _colorSeg) |
adelino | 1:a74e42cf52b2 | 34 | { |
adelino | 1:a74e42cf52b2 | 35 | if(myColorSeg==_colorSeg) |
adelino | 1:a74e42cf52b2 | 36 | return; |
adelino | 1:a74e42cf52b2 | 37 | |
adelino | 1:a74e42cf52b2 | 38 | myColorSeg=_colorSeg; |
adelino | 1:a74e42cf52b2 | 39 | this->draw(); |
adelino | 1:a74e42cf52b2 | 40 | } |
adelino | 1:a74e42cf52b2 | 41 | //----------------------------------------- |
adelino | 1:a74e42cf52b2 | 42 | void DigitLed::draw(void) |
adelino | 1:a74e42cf52b2 | 43 | { |
adelino | 1:a74e42cf52b2 | 44 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 45 | return; |
adelino | 1:a74e42cf52b2 | 46 | // |
adelino | 1:a74e42cf52b2 | 47 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 48 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 49 | |
adelino | 1:a74e42cf52b2 | 50 | //rec |
adelino | 1:a74e42cf52b2 | 51 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 52 | ps->draw_filled_rectangle(myX,myY,myX+myWidth,myY+myHeight,myColorBkg); |
adelino | 1:a74e42cf52b2 | 53 | } |
adelino | 1:a74e42cf52b2 | 54 | |
adelino | 1:a74e42cf52b2 | 55 | if(isPtVisible) |
adelino | 1:a74e42cf52b2 | 56 | draw_seg_pt(ps); |
adelino | 1:a74e42cf52b2 | 57 | |
adelino | 1:a74e42cf52b2 | 58 | // |
adelino | 1:a74e42cf52b2 | 59 | switch(myValue) { |
adelino | 1:a74e42cf52b2 | 60 | case 0: |
adelino | 1:a74e42cf52b2 | 61 | draw_seg_a(ps); |
adelino | 1:a74e42cf52b2 | 62 | draw_seg_b(ps); |
adelino | 1:a74e42cf52b2 | 63 | draw_seg_c(ps); |
adelino | 1:a74e42cf52b2 | 64 | draw_seg_d(ps); |
adelino | 1:a74e42cf52b2 | 65 | draw_seg_e(ps); |
adelino | 1:a74e42cf52b2 | 66 | draw_seg_f(ps); |
adelino | 1:a74e42cf52b2 | 67 | break; |
adelino | 1:a74e42cf52b2 | 68 | // |
adelino | 1:a74e42cf52b2 | 69 | case 1: |
adelino | 1:a74e42cf52b2 | 70 | draw_seg_b(ps); |
adelino | 1:a74e42cf52b2 | 71 | draw_seg_c(ps); |
adelino | 1:a74e42cf52b2 | 72 | break; |
adelino | 1:a74e42cf52b2 | 73 | // |
adelino | 1:a74e42cf52b2 | 74 | case 2: |
adelino | 1:a74e42cf52b2 | 75 | draw_seg_a(ps); |
adelino | 1:a74e42cf52b2 | 76 | draw_seg_b(ps); |
adelino | 1:a74e42cf52b2 | 77 | draw_seg_d(ps); |
adelino | 1:a74e42cf52b2 | 78 | draw_seg_e(ps); |
adelino | 1:a74e42cf52b2 | 79 | draw_seg_g(ps); |
adelino | 1:a74e42cf52b2 | 80 | break; |
adelino | 1:a74e42cf52b2 | 81 | // |
adelino | 1:a74e42cf52b2 | 82 | case 3: |
adelino | 1:a74e42cf52b2 | 83 | draw_seg_a(ps); |
adelino | 1:a74e42cf52b2 | 84 | draw_seg_b(ps); |
adelino | 1:a74e42cf52b2 | 85 | draw_seg_c(ps); |
adelino | 1:a74e42cf52b2 | 86 | draw_seg_d(ps); |
adelino | 1:a74e42cf52b2 | 87 | draw_seg_g(ps); |
adelino | 1:a74e42cf52b2 | 88 | break; |
adelino | 1:a74e42cf52b2 | 89 | // |
adelino | 1:a74e42cf52b2 | 90 | case 4: |
adelino | 1:a74e42cf52b2 | 91 | draw_seg_b(ps); |
adelino | 1:a74e42cf52b2 | 92 | draw_seg_c(ps); |
adelino | 1:a74e42cf52b2 | 93 | draw_seg_f(ps); |
adelino | 1:a74e42cf52b2 | 94 | draw_seg_g(ps); |
adelino | 1:a74e42cf52b2 | 95 | break; |
adelino | 1:a74e42cf52b2 | 96 | // |
adelino | 1:a74e42cf52b2 | 97 | case 5: |
adelino | 1:a74e42cf52b2 | 98 | draw_seg_a(ps); |
adelino | 1:a74e42cf52b2 | 99 | draw_seg_c(ps); |
adelino | 1:a74e42cf52b2 | 100 | draw_seg_d(ps); |
adelino | 1:a74e42cf52b2 | 101 | draw_seg_f(ps); |
adelino | 1:a74e42cf52b2 | 102 | draw_seg_g(ps); |
adelino | 1:a74e42cf52b2 | 103 | break; |
adelino | 1:a74e42cf52b2 | 104 | // |
adelino | 1:a74e42cf52b2 | 105 | case 6: |
adelino | 1:a74e42cf52b2 | 106 | draw_seg_a(ps); |
adelino | 1:a74e42cf52b2 | 107 | draw_seg_c(ps); |
adelino | 1:a74e42cf52b2 | 108 | draw_seg_d(ps); |
adelino | 1:a74e42cf52b2 | 109 | draw_seg_e(ps); |
adelino | 1:a74e42cf52b2 | 110 | draw_seg_f(ps); |
adelino | 1:a74e42cf52b2 | 111 | draw_seg_g(ps); |
adelino | 1:a74e42cf52b2 | 112 | break; |
adelino | 1:a74e42cf52b2 | 113 | // |
adelino | 1:a74e42cf52b2 | 114 | case 7: |
adelino | 1:a74e42cf52b2 | 115 | draw_seg_a(ps); |
adelino | 1:a74e42cf52b2 | 116 | draw_seg_b(ps); |
adelino | 1:a74e42cf52b2 | 117 | draw_seg_c(ps); |
adelino | 1:a74e42cf52b2 | 118 | break; |
adelino | 1:a74e42cf52b2 | 119 | // |
adelino | 1:a74e42cf52b2 | 120 | case 8: |
adelino | 1:a74e42cf52b2 | 121 | draw_seg_a(ps); |
adelino | 1:a74e42cf52b2 | 122 | draw_seg_b(ps); |
adelino | 1:a74e42cf52b2 | 123 | draw_seg_c(ps); |
adelino | 1:a74e42cf52b2 | 124 | draw_seg_d(ps); |
adelino | 1:a74e42cf52b2 | 125 | draw_seg_e(ps); |
adelino | 1:a74e42cf52b2 | 126 | draw_seg_f(ps); |
adelino | 1:a74e42cf52b2 | 127 | draw_seg_g(ps); |
adelino | 1:a74e42cf52b2 | 128 | break; |
adelino | 1:a74e42cf52b2 | 129 | // |
adelino | 1:a74e42cf52b2 | 130 | case 9: |
adelino | 1:a74e42cf52b2 | 131 | draw_seg_a(ps); |
adelino | 1:a74e42cf52b2 | 132 | draw_seg_b(ps); |
adelino | 1:a74e42cf52b2 | 133 | draw_seg_c(ps); |
adelino | 1:a74e42cf52b2 | 134 | draw_seg_d(ps); |
adelino | 1:a74e42cf52b2 | 135 | draw_seg_f(ps); |
adelino | 1:a74e42cf52b2 | 136 | draw_seg_g(ps); |
adelino | 1:a74e42cf52b2 | 137 | break; |
adelino | 1:a74e42cf52b2 | 138 | } |
adelino | 1:a74e42cf52b2 | 139 | ps=0; |
adelino | 1:a74e42cf52b2 | 140 | } |
adelino | 1:a74e42cf52b2 | 141 | //----------------------------------------- |
adelino | 1:a74e42cf52b2 | 142 | void DigitLed::setValue(char _value) |
adelino | 1:a74e42cf52b2 | 143 | { |
adelino | 1:a74e42cf52b2 | 144 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 145 | return; |
adelino | 1:a74e42cf52b2 | 146 | |
adelino | 1:a74e42cf52b2 | 147 | if(myValue==_value) |
adelino | 1:a74e42cf52b2 | 148 | return; |
adelino | 1:a74e42cf52b2 | 149 | |
adelino | 1:a74e42cf52b2 | 150 | |
adelino | 1:a74e42cf52b2 | 151 | if(_value >9) |
adelino | 1:a74e42cf52b2 | 152 | _value=9; |
adelino | 1:a74e42cf52b2 | 153 | |
adelino | 1:a74e42cf52b2 | 154 | myValue=_value; |
adelino | 1:a74e42cf52b2 | 155 | |
adelino | 1:a74e42cf52b2 | 156 | this->draw(); |
adelino | 1:a74e42cf52b2 | 157 | } |
adelino | 1:a74e42cf52b2 | 158 | //----------------------------------------- |
adelino | 1:a74e42cf52b2 | 159 | void DigitLed::setInvisible(bool _state) |
adelino | 1:a74e42cf52b2 | 160 | { |
adelino | 1:a74e42cf52b2 | 161 | // element devient invisible |
adelino | 1:a74e42cf52b2 | 162 | if(_state==true) { |
adelino | 1:a74e42cf52b2 | 163 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 164 | return; |
adelino | 1:a74e42cf52b2 | 165 | |
adelino | 1:a74e42cf52b2 | 166 | myIsVisible=false; |
adelino | 1:a74e42cf52b2 | 167 | |
adelino | 1:a74e42cf52b2 | 168 | Color c= myScreen->getColorBkg(); |
adelino | 1:a74e42cf52b2 | 169 | |
adelino | 1:a74e42cf52b2 | 170 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 171 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 172 | |
adelino | 1:a74e42cf52b2 | 173 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 174 | ps->draw_filled_rectangle(myX,myY,myX+myWidth,myY+myHeight,c); |
adelino | 1:a74e42cf52b2 | 175 | } |
adelino | 1:a74e42cf52b2 | 176 | ps=0; |
adelino | 1:a74e42cf52b2 | 177 | } |
adelino | 1:a74e42cf52b2 | 178 | |
adelino | 1:a74e42cf52b2 | 179 | // element devient visible |
adelino | 1:a74e42cf52b2 | 180 | else { |
adelino | 1:a74e42cf52b2 | 181 | myIsVisible=true; |
adelino | 1:a74e42cf52b2 | 182 | |
adelino | 1:a74e42cf52b2 | 183 | |
adelino | 1:a74e42cf52b2 | 184 | this->draw(); |
adelino | 1:a74e42cf52b2 | 185 | } |
adelino | 1:a74e42cf52b2 | 186 | } |
adelino | 1:a74e42cf52b2 | 187 | //----------------------------------------- |
adelino | 1:a74e42cf52b2 | 188 | void DigitLed::setPtVisible(bool _state) |
adelino | 1:a74e42cf52b2 | 189 | { |
adelino | 1:a74e42cf52b2 | 190 | if(isPtVisible==_state) |
adelino | 1:a74e42cf52b2 | 191 | return; |
adelino | 1:a74e42cf52b2 | 192 | |
adelino | 1:a74e42cf52b2 | 193 | isPtVisible=_state; |
adelino | 1:a74e42cf52b2 | 194 | } |
adelino | 1:a74e42cf52b2 | 195 | //----------------------------------------- |
adelino | 1:a74e42cf52b2 | 196 | void DigitLed::draw_seg_a(PicasoSerial* ps) |
adelino | 1:a74e42cf52b2 | 197 | { |
adelino | 1:a74e42cf52b2 | 198 | if(ps!=0) |
adelino | 1:a74e42cf52b2 | 199 | ps->draw_filled_rectangle(myX+myIncX, |
adelino | 1:a74e42cf52b2 | 200 | myY, |
adelino | 1:a74e42cf52b2 | 201 | myX+7*myIncX, |
adelino | 1:a74e42cf52b2 | 202 | myY+myIncY, |
adelino | 1:a74e42cf52b2 | 203 | myColorSeg); |
adelino | 1:a74e42cf52b2 | 204 | } |
adelino | 1:a74e42cf52b2 | 205 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 206 | void DigitLed::draw_seg_b(PicasoSerial* ps) |
adelino | 1:a74e42cf52b2 | 207 | { |
adelino | 1:a74e42cf52b2 | 208 | if(ps!=0) |
adelino | 1:a74e42cf52b2 | 209 | ps->draw_filled_rectangle(myX+6*myIncX, |
adelino | 1:a74e42cf52b2 | 210 | myY, |
adelino | 1:a74e42cf52b2 | 211 | myX+7*myIncX, |
adelino | 1:a74e42cf52b2 | 212 | myY+5*myIncY, |
adelino | 1:a74e42cf52b2 | 213 | myColorSeg); |
adelino | 1:a74e42cf52b2 | 214 | } |
adelino | 1:a74e42cf52b2 | 215 | //------------------------------------------- |
adelino | 1:a74e42cf52b2 | 216 | void DigitLed::draw_seg_c(PicasoSerial* ps) |
adelino | 1:a74e42cf52b2 | 217 | { |
adelino | 1:a74e42cf52b2 | 218 | if(ps!=0) |
adelino | 1:a74e42cf52b2 | 219 | ps->draw_filled_rectangle(myX+6*myIncX, |
adelino | 1:a74e42cf52b2 | 220 | myY+8*myIncY, |
adelino | 1:a74e42cf52b2 | 221 | myX+7*myIncX, |
adelino | 1:a74e42cf52b2 | 222 | myY+myHeight, |
adelino | 1:a74e42cf52b2 | 223 | myColorSeg); |
adelino | 1:a74e42cf52b2 | 224 | } |
adelino | 1:a74e42cf52b2 | 225 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 226 | void DigitLed::draw_seg_d(PicasoSerial* ps) |
adelino | 1:a74e42cf52b2 | 227 | { |
adelino | 1:a74e42cf52b2 | 228 | if(ps!=0) |
adelino | 1:a74e42cf52b2 | 229 | ps->draw_filled_rectangle(myX+myIncX, |
adelino | 1:a74e42cf52b2 | 230 | myY+myHeight-myIncY, |
adelino | 1:a74e42cf52b2 | 231 | myX+7*myIncX, |
adelino | 1:a74e42cf52b2 | 232 | myY+myHeight, |
adelino | 1:a74e42cf52b2 | 233 | myColorSeg); |
adelino | 1:a74e42cf52b2 | 234 | } |
adelino | 1:a74e42cf52b2 | 235 | //----------------------------------------- |
adelino | 1:a74e42cf52b2 | 236 | void DigitLed::draw_seg_e(PicasoSerial* ps) |
adelino | 1:a74e42cf52b2 | 237 | { |
adelino | 1:a74e42cf52b2 | 238 | if(ps!=0) |
adelino | 1:a74e42cf52b2 | 239 | ps->draw_filled_rectangle(myX+myIncX, |
adelino | 1:a74e42cf52b2 | 240 | myY+myHeight-5*myIncY, |
adelino | 1:a74e42cf52b2 | 241 | myX+2*myIncX, |
adelino | 1:a74e42cf52b2 | 242 | myY+myHeight, |
adelino | 1:a74e42cf52b2 | 243 | myColorSeg); |
adelino | 1:a74e42cf52b2 | 244 | } |
adelino | 1:a74e42cf52b2 | 245 | //----------------------------------------- |
adelino | 1:a74e42cf52b2 | 246 | void DigitLed::draw_seg_f(PicasoSerial* ps) |
adelino | 1:a74e42cf52b2 | 247 | { |
adelino | 1:a74e42cf52b2 | 248 | if(ps!=0) |
adelino | 1:a74e42cf52b2 | 249 | ps->draw_filled_rectangle(myX+myIncX, |
adelino | 1:a74e42cf52b2 | 250 | myY, |
adelino | 1:a74e42cf52b2 | 251 | myX+2*myIncX, |
adelino | 1:a74e42cf52b2 | 252 | myY+5*myIncY, |
adelino | 1:a74e42cf52b2 | 253 | myColorSeg); |
adelino | 1:a74e42cf52b2 | 254 | } |
adelino | 1:a74e42cf52b2 | 255 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 256 | void DigitLed::draw_seg_g(PicasoSerial* ps) |
adelino | 1:a74e42cf52b2 | 257 | { |
adelino | 1:a74e42cf52b2 | 258 | if(ps!=0) |
adelino | 1:a74e42cf52b2 | 259 | ps->draw_filled_rectangle(myX+myIncX, |
adelino | 1:a74e42cf52b2 | 260 | myY+6*myIncY, |
adelino | 1:a74e42cf52b2 | 261 | myX+7*myIncX, |
adelino | 1:a74e42cf52b2 | 262 | myY+7*myIncY, |
adelino | 1:a74e42cf52b2 | 263 | myColorSeg); |
adelino | 1:a74e42cf52b2 | 264 | } |
adelino | 1:a74e42cf52b2 | 265 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 266 | void DigitLed::draw_seg_pt(PicasoSerial* ps) |
adelino | 1:a74e42cf52b2 | 267 | { |
adelino | 1:a74e42cf52b2 | 268 | if(ps!=0) |
adelino | 1:a74e42cf52b2 | 269 | ps->draw_filled_rectangle(myX+myWidth-myIncX, |
adelino | 1:a74e42cf52b2 | 270 | myY+myHeight-myIncY, |
adelino | 1:a74e42cf52b2 | 271 | myX+myWidth, |
adelino | 1:a74e42cf52b2 | 272 | myY+myHeight, |
adelino | 1:a74e42cf52b2 | 273 | myColorSeg); |
adelino | 1:a74e42cf52b2 | 274 | } |