Custom instruments

Use JavaScript and JSX to define the content and appearance of the instrument. CapDrive executes dashboard scripts, draws text, graphics, curves, and maps to the dashboard, and refreshes the screen when data is updated.

How the meter works

Each custom meter has a script. main() in the script is the drawing entry and returns a screen composed of built-in View: Text displays text, Circle draws circles, LineChart displays curves, and the layout container is responsible for arranging these contents.

The script can obtain the current speed, rotation engine speed (RPM) and other readings in main(), calculate the number, color or angle to be displayed, and then return the result as the content and attributes of View. For example, after reading the speed, you can either write the value into Text or convert it into the arc angle of Circle.

CapDrive will call main() again when it needs to update the screen and draw the returned result. The instrument code only needs to describe the screen based on this input, and the attribute animation is also executed by the drawing end. Picture resources can be saved with the instrument and used by resource name in the code.

Installation and display

Instruments are imported and shared via .instrument files. Existing files can be opened from Import instrument in the custom instrument menu, or files can be opened using CapDrive. Imported instruments need to be added to the dashboard separately.

The imported instruments are saved in More (…)→ Custom instruments. Select it via More (…)→ Edit dashboard → + and click Done to view it on the dashboard.

Instruments that use vehicle parameters will also need to select their own vehicle parameters in Instrument settings → Input bindings for the existing OBD input. Keeping the input identifier unchanged allows you to reuse the instrument’s code without writing the device identifier into the script.

Writing and previewing

Select Add new instrument in More (…)→ Custom instruments to enter the editor. The editor is used to write main() and View; click on the name at the top to set the instrument name, input bindings, and other options. The gear opens Parameter configuration, which can manage six types of inputs: numerical value, text, switch, selection item, basic data and OBD data. The new instrument already has a basic speed input with the identifier speed.

You can preview text, layout, graphics and animation at any time while editing. Preview provides simulated inputs for easy instrument checking while parked. When a code error occurs, it can be located from the line number in the log. After saving, add the instrument to the dashboard to use the actual readings.

“Your first speed instrument” provides complete code and description; the API reference lists the available View, properties, types, and runtime interfaces.

Make your first speed instrument

Use driving data

$data provides the current reading and recent samples to the script. Basic fields such as speed and distance can be directly used for numerical display; parameters such as vehicle engine speed (RPM) and coolant temperature are provided through the configured OBD device. The script can also generate curves using historical sampling.

Each time main() is executed, the required fields are read, the values ​​are processed, and View is generated. Readings may be temporarily unavailable, so the display code should provide appropriate content for missing measurements. Instrument data documents centrally describe field structure, OBD references, historical sampling, and null value handling.

Instrument data

Continue reading