[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.

AnalogMenuItem error for negative Values RSS feed
Forum Index » tcMenu Designer UI
Author Message
Lee_X


Joined: Apr 29, 2022
Messages: 27
Offline
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!

Lee_X


Joined: Apr 29, 2022
Messages: 27
Offline
Hi Has anybody else observed this issue? I have tried a few things to fix it but no success so far

Thanks!
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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.
Lee_X


Joined: Apr 29, 2022
Messages: 27
Offline
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 [Disk] Download
 Description Example
 Filesize 37 Kbytes
 Downloaded:  383 time(s)

Lee_X


Joined: Apr 29, 2022
Messages: 27
Offline
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?
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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!
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
https://github.com/davetcc/tcMenuLib/issues/145 already committed, will go in the next release.
 
Forum Index » tcMenu Designer UI
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.