By dave | November 11, 2020

Float items are useful for displaying the result of inexact calculations and are only supported for read only purposes. The issue with floating points is that they are inexact and unsuited uses where they are ticked by a rotary encoder. An example use of a float menu item would be the average temperature of many readings.

Type information for FloatMenuItem

Creating an object from the designer

Choose to add a new menu item, and from the dialog choose Float item, once created the properties panel will look similar to:

image showing the float editor

Float Editor UI

For float items, the only additional parameter is the number of decimal places to be displayed.

Accessing float menu items from code

To get and set values on float items:

menuItem.setFloatValue(newValue, silent = false);
float f = menuItem.getFloatValue();

To check how many decimal places the value should format to:

int places = menuItem.getDecimalPlaces();

Creating a float menu item from the CLI

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

tcmenu create-item --parent 0 --type float --name FloatName [--localonly --readonly --hide]

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

  "parentId": 7,
  "type": "floatItem",
  "item": {
    "numDecimalPlaces": 0,
    "name": "FloatName",
    "variableName": "FloatName",
    "id": 9,
    "eepromAddress": 0,
    "readOnly": false,
    "localOnly": false,
    "visible": true

Creating a float menu item manually

In nearly all cases it’s better to create items using the designer. However, this is how you create an additional float item manually should it be required.

const FloatMenuInfo minfoFloatItem = { "Float Item", myId, 0xFFFF, decPlaces, NO_CALLBACK };
FloatMenuItem menuFloatItem(&minfoFloatItem, &nextMenuItem);

Above we create a float item along with it’s associated info structure. myId should be replaced with the unique ID for the item, NO_CALLBACK signifies there is no callback. decPlaces refers to how many decimal places this menu item should display.

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.