ILI9341 Display Issue

Status
Not open for further replies.
Great - glad it helped! It does look good - I can only imagine what it looked like before. Hopefully you picked up a lesson or two in working with the code. The function usage and make sure you understand the elapsedMillis it is a very useful way to avoid delay() and may be useful in other places, for instance you could use it to reduce the reads from the CANbus if you are calling too often.

I like your commenting style :)
**** MASSIVE thank you to defragster from pjrc.com https://forum.pjrc.com/threads/32831-ILI9341-Display-Issue ****

Indeed as long as only the fgc changes you can do what you want with that and the bgc will keep it clean just the same.

One thing could be done to have the code be 2/3'rds cleaner (but work the same) would be to move the case specific conditional from before the call into the function, and also allowing getting rid of the intermediate 'newXXX' variables too :

Code:
[U]  newMAP = MAP / 10;
  if ( newMAP != oldMAP )[/U]
    oldMAP = tftSCprintF(oldMAP, [B]newMAP[/B], ILI9341_BLUE, ILI9341_BLACK, 235, 105);

float tftSCprintF( float oldV, float newV, uint16_t fgc, uint16_t bgc,   int xxt, int yyt ) {
  tft.setCursor(xxt, yyt);
...
  return newV;
}


could become:
Code:
  oldMAP = tftSCprintF(oldMAP, [B][U]MAP / 10[/U][/B], ILI9341_BLUE, ILI9341_BLACK, 235, 105);

float tftSCprintF( float oldV, float newV, uint16_t fgc, uint16_t bgc,   int xxt, int yyt ) {
[U]  if ( oldV == newV )   return newV;[/U]
  tft.setCursor(xxt, yyt);
  tft.setTextColor(bgc);
  tft.print(oldV);
  tft.setCursor(xxt, yyt);
  tft.setTextColor(fgc);
  tft.print(newV);
  return newV;
}
 
Great - glad it helped! It does look good - I can only imagine what it looked like before. Hopefully you picked up a lesson or two in working with the code. The function usage and make sure you understand the elapsedMillis it is a very useful way to avoid delay() and may be useful in other places, for instance you could use it to reduce the reads from the CANbus if you are calling too often.

I like your commenting style :)


Indeed as long as only the fgc changes you can do what you want with that and the bgc will keep it clean just the same.

One thing could be done to have the code be 2/3'rds cleaner (but work the same) would be to move the case specific conditional from before the call into the function, and also allowing getting rid of the intermediate 'newXXX' variables too :

Code:
[U]  newMAP = MAP / 10;
  if ( newMAP != oldMAP )[/U]
    oldMAP = tftSCprintF(oldMAP, [B]newMAP[/B], ILI9341_BLUE, ILI9341_BLACK, 235, 105);

float tftSCprintF( float oldV, float newV, uint16_t fgc, uint16_t bgc,   int xxt, int yyt ) {
  tft.setCursor(xxt, yyt);
...
  return newV;
}


could become:
Code:
  oldMAP = tftSCprintF(oldMAP, [B][U]MAP / 10[/U][/B], ILI9341_BLUE, ILI9341_BLACK, 235, 105);

float tftSCprintF( float oldV, float newV, uint16_t fgc, uint16_t bgc,   int xxt, int yyt ) {
[U]  if ( oldV == newV )   return newV;[/U]
  tft.setCursor(xxt, yyt);
  tft.setTextColor(bgc);
  tft.print(oldV);
  tft.setCursor(xxt, yyt);
  tft.setTextColor(fgc);
  tft.print(newV);
  return newV;
}

I definitely have been learning, that's for sure! OK, I'll have a look at that suggestion.
 
Raymond_B: The only reason not to lose the newXXX variables would be you could use that to calculate and specify the fgc before calling, of course on those with '/10' you could just do the compare on the unscaled number with the appropriate value.

Not a big problem - taking out the test before the call, then you'll also spend a few cycles deciding on the color - only to have the value when not changed go to the function and return without using it. A couple hundred extra instructions a second when the Teensy does a couple dozen million - nothing enough to worry over. The code will be cleaner and less redundant

So many options . . .
 
Status
Not open for further replies.
Back
Top