Chapter 6. Configuration

Table of Contents

Configuration Files
Writing Code that Accepts the Configuration

To configure a device, two things are needed:

  1. Configuration files

  2. Driver code that accepts the configuration

Configuration Files

Before configuring a device, a new configuration definition must be created. We recommend that this be done using VRJConfig. For the button device, the definition file will be the following:

Example 6.1. button_device.jdef: Configuration Definition File for Simple Button Device

<?xml version="1.0" encoding="UTF-8"?>
<?org-vrjuggler-jccl-settings definition.version="3.0"?>
<definition xmlns="http://www.vrjuggler.org/jccl/xsd/3.0/definition"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.vrjuggler.org/jccl/xsd/3.0/definition http://www.vrjuggler.org/jccl/xsd/3.0/definition.xsd"
            name="button_device">                                    1
   <definition_version version="1" label="My Button Device">
      <help>Configuration for simple one-button device.</help>
      <parent>digital_device</parent>
      <category>/Devices/Digital</category>
      <property valuetype="string" variable="false" name="port">     2
         <help>Serial port to which this device is connected.</help>
         <value label="Port" defaultvalue="/dev/ttyd1"/>
      </property>
      <property valuetype="integer" variable="false" name="baud">    3
         <help>Serial port speed.</help>
         <value label="Baud" defaultvalue="38400"/>
      </property>
      <upgrade_transform/>
   </definition_version>
</definition>
1

This begins the definition for our device type. The name attribute must be named as a valid XML tag because it will be used as such in a configuration file. A free-form, human-friendly string may be specified in the label attribute of the definition_version element. This string will be presented to the user of VRJConfig, and as such, it should be a meaningful identifier.

2

This declares the “port” property that will provide the name of the serial port to which the hardware is connected. The serial port name will be interpreted as a string, and it has the default value of “/dev/ttyd1”. In the case of our simple button driver, there is no serial port, but we include this property definition to demonstrate how the whole configuration definition works.

3

This declares the “baud” property that will provide the baud setting for the serial port to which the hardware is connected. The baud value will be interpreted as an integer, and it has the default value of 38400 (kilobits per second). In the case of our simple button driver, there is no serial port, but we include this property definition to demonstrate how the whole configuration definition works.

Note

In the above configuration definition, we do not declare a “device_host” property, which is used in conjunction with the Remote Input Manager. This is not necessary because we have declared our parent type to be “digital_device”, and we inherit its property definitions. All drivers that may be used with the Remote Input Manager must have the “device_host” property, and configuration definition inheritance ensures that this will be the case. Refer to the Cluster Juggler Guide for more information about this property.

For a more complex device, a more complex configuration definition may be needed. Again, the VRJConfig configuration definition editor simplifies the creation of this definition.

Once the configuration definition is in place, a new configuration element can be created. Once again, VRJConfig makes the step easier. The following is an example configuration file that configures the one-button device we have been using thus far:

Example 6.2. button_device.jconf: Configuration File for Simple Button Device

<?xml version="1.0" encoding="UTF-8"?>
<?org-vrjuggler-jccl-settings configuration.version="3.0"?>
<configuration xmlns="http://www.vrjuggler.org/jccl/xsd/3.0/configuration"
               name="Configuration"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.vrjuggler.org/jccl/xsd/3.0/configuration http://www.vrjuggler.org/jccl/xsd/3.0/configuration.xsd">
   <elements>
      <input_manager name="Button Device Input Manager"
                     version="2">                             1
         <driver_path>${HOME}</driver_path>
         <driver>ButtonDevice_drv</driver>
      </input_manager>
      <button_device name="Button Device" version="1">        2
         <port>/dev/ttyd4</port>                              3
         <baud>9600</baud>                                    4
         <device_host />                                      5
      </button_device>
   </elements>
</configuration>
1

The input_manager element configures the Gadgeteer Input Manager. In this case, we are telling the Input Manager about a driver plug-in, found at ${HOME}/ButtonDevice_drv.so, that should be loaded at runtime.

2

Next, we have an instance of the configuration definition shown in Example 6.1, “button_device.jdef: Configuration Definition File for Simple Button Device”. As described above, <button_device> is named based on the name attribute of the definition element in our configuration definition file. The name attribute here gives this instance a unique identifier.

3

Now, we set the value for the serial port name. As noted above, our simple button device does not actually use the serial port, but this demonstrates how the property value is used in a configuration file. If no value were given here, the default value set in button_device.jdef would be used.

4

This provides a value for the serial port baud setting. Again, this will not actually be used by our simple device, but we show it here to give a complete example.

5

For our example, we will not fill in a value for device_host because we are not dealing with the Remote Input Manager. Refer to the Cluster Juggler Guide for more information about this.