I had a recent discussion about changing the number of decimal points to display on a readout (from readouts.dsn) based on its value and thought it might be of general interest.
Of course, formatting of strings can be done in code or simulation and then sent out for display. But what if your code is just sending a value and you want the readout to automatically adjust?
The readouts have animations that let you easily set the number of decimal digits to display. You then have to "tickle" the value to have the new setting apply. The tricky part about this problem is that we want to change whenever we receive a new value -- and we'll be "tickling" that same value. That is, we want to ignore the values
we send.
Anyway, here is some Control code that can be used to listen to the float value and then change the number of decimal points displayed:
Code:
WHEN 1_readout_float ==
// Turn on caching so we only update once
SET altiaCacheOutput = 1
IF 1_readout_routing == 0
// This float change isn't from our "tickle," so process it
IF 1_readout_float >= 10 AND 1_readout_decimal_pts != 0
// No decimals for values over 10
SET 1_readout_decimal_pts = 0
SET 1_readout_float = 1_readout_float
SET 1_readout_routing = 1
ENDIF
ELSEIF 1_readout_float < 10 AND 1_readout_decimal_pts != 1
// 1 decimal for values under 10
SET 1_readout_decimal_pts = 1
SET 1_readout_float = 1_readout_float
SET 1_readout_routing = 1
ENDIF
ENDIF
ELSE
SET 1_readout_routing = 0
ENDIF
SET altiaCacheOutput = 0
END
In order for this control code to work as expected, be sure to set the "Number Sytle" property in the readout's properties dialog to "Decimal." This allows the "1_readout_decimal_pts" animation to drive the number of decimal places for the readout.