By dave | November 11, 2020

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

Manually creating an instance of LargeNumber item

RENDERING_CALLBACK_NAME_INVOKE(fnLargeNumRtCall, largeNumItemRenderFn, "Large Num", 
                               myEepromLocation, NO_CALLBACK)
EditableLargeNumberMenuItem menuLargeNum(fnLargeNumRtCall, myId, totalDigits, decPlaces, &menuFiths);

Above we create a large number item that accepts positive and negative numbers, the name of the callback method is fnLargeNumRtCall and most requests pass through to largeNumItemRenderFn. The menu item name will be “Large Num” 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.

Other pages within this category

comments powered by Disqus

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.