11-11-2020
Visit associated GitHub repository
Visit reference documentation page

tcMenu supports Large numbers for editing, with values up to 12 digits in total, and it can optionally handle negative values too. The underlying storage is a bit packed BCD array. This makes for efficient storage and complete accuracy in all cases. However, you can convert to and from floating-point values for convenience when accuracy is not as important.

Class types for Large Number items

Creating an object from the designer

From the add dialog choose the "Large numeric value" option. The form will look similar to:

editor value for a large number menu item
Large Number Editor UI
  • Decimal Places: the number of decimal places after the point.
  • Total Digits: the maximum allowable digits for the number item (including decimal places).
  • Allow Negative: if this is un-ticked, the editor will only allow positive values.

Working with Large number items in code

There are two ways to acquire and set the values of a large number item, either as a LargeFixedNumber object that represents the whole and fraction components as 32 bit integers along with a negative flag, or a float single precision floating-point number.

// Call this method on the menu item to get the underlying number storage
LargeFixedNumber* getLargeNumber()

// To get or set the value using float
float getAsFloat()
void setFromFloat(float value)

// To get or set the value by whole and fraction
uint32_t getWhole()
uint32_t getFraction()
bool isNegative()
void setValue(uint32_t whole, uint32_t fraction, bool negative)

Creating a large number menu item from the CLI

To create a large number menu item from the CLI here is a template command (options in square brackets are optional):

tcmenu create-item --parent 0 --type largenum --eeprom AUTO --name LgeNumName [--localonly --readonly --hide]

The structure of a large number menu item in the EMF file is:

{
  "parentId": 0,
  "type": "largeNumItem",
  "item": {
    "digitsAllowed": 0,
    "decimalPlaces": 0,
    "negativeAllowed": true,
    "name": "LgeNumName",
    "variableName": "LgeNumName",
    "id": 12,
    "eepromAddress": 6,
    "readOnly": false,
    "localOnly": false,
    "visible": true,
    "staticDataInRAM": false
  }
}

Manually creating an instance of LargeNumber item

[const PROGMEM] AnyMenuInfo minfoSettingsLargeNum = { "LargeNum", myId, myEEPROMLocation, 0, NO_CALLBACK };
EditableLargeNumberMenuItem menuSettingsLargeNum(&minfoSettingsLargeNum, LargeFixedNumber(8, 3, 100U, 500U, false),
                                                 allowNegative, nextMenuPtr, [bool isInfoProgmem=true]);

Above we create a large number item that accepts positive and negative numbers, it is based on an INFO block and this really simplifies creation, most requests pass through to largeNumItemRenderFn. The menu item name will be "LargeNum" and its menu changed callback is NO_CALLBACK, you could instead define a callback. Change myId to the desired ID and myEepromLocation to a suitable storage location or 0xFFFF.

The total number of digits and decimal places, and using the other constructor the negative flag are set here too.

These may be of interest

Want to let us know about something?

We use cookies to analyse traffic and to personalise content. We also embed Twitter and Youtube on some pages, these companies have their own privacy policies.

See the privacy policy and terms of use of this site should you need more information or wish to adjust your settings.