Register / Login  |  Desktop view  |  Jump to bottom of page

tcMenu Designer UI » AnalogMenuItem error for negative Values

Author: Lee_X
30/06/2022 19:40:07
Hi Dave if I use an AnalogMenuItem in the designer (2.3.1 on Mac) it works fine if "offset from zero" is zero but if I put a negative value it seems to overflow and start form -2^16 or so
example:

Offset=-20
Max=255

the UI says it should display a value between -20 and 235 but once I start it on ESP32S2 it will display -32748 by default instead of "-20"

Can you please check at your end? Should be a pretty straightforward bug to fix, likely due to formatting.

Thanks!


Author: Lee_X
03/07/2022 16:03:19
Hi Has anybody else observed this issue? I have tried a few things to fix it but no success so far

Thanks!

Author: davetcc
04/07/2022 07:14:16
Every now and again we find a bug with the analog support where a particular value seems to cause an overflow somewhere, although that range of values seems very small to cause this problem. Could you provide the divisor as well please?

I'll try and add the same item to see what happens.

Author: Lee_X
04/07/2022 09:02:23
Hi Dave

See screenshot attached. Works as expected for values >=0 but -1 is rendered "-32767", -2 as "-32766" and so forth. Clearly an int16 format issue?

Thanks!

[Thumb - Screenshot 2022-07-04 at 09.58.27.png]
Filename Screenshot 2022-07-04 at 09.58.27.png
Description Example
Filesize 37 Kbytes
Downloaded 383 time(s)
[Disk] Download


Author: Lee_X
04/07/2022 16:19:10
Hi Dave

This seems to fix it:
calcVal=abs(calcVal);


placed in:

WholeAndFraction AnalogMenuItem::getWholeAndFraction() const {
  WholeAndFraction wf;
  int32_t calcVal = int32_t(getCurrentValue()) + int32_t(getOffset());
  int32_t divisor = getDivisor();

  wf.negative = (calcVal < 0);

  calcVal=abs(calcVal);

  if (divisor < 2) {
    wf.whole = calcVal;
    wf.fraction = 0;
  }
  else {
    wf.whole = abs(calcVal) / int16_t(divisor);
    int fractMax = getActualDecimalDivisor();
    wf.fraction = abs((calcVal % divisor)) * (fractMax / divisor);
  }
  return wf;
}


Can you check if that doesn't create other issues somewhere else?

Author: davetcc
05/07/2022 10:45:52
Many thanks for working this out.

Ah yes, I can see why that fails now, we have probably mainly tested this case based around a BurrBrown volume control that has half increments, so falls into the decimal side of that if statement.

On the plus side, there are a lot of unit tests around this code, so I'll add another one for this case and then apply the fix. Thanks again!

Author: davetcc
05/07/2022 11:28:57
https://github.com/davetcc/tcMenuLib/issues/145 already committed, will go in the next release.




Register / Login  |  Desktop view  |  Jump to top of page