How to Add My Own Sensor(s) to AIRS?

The following picture provides an overview of the AIRS platform from the viewpoint of the various classes being used:



Within this structure, a particular sensor in AIRS is implemented by a dedicated Handler. This Handler class encapsulates all methods required to determine whether the sensor is available (Discover()) and what its current value is (Acquire()). There are also methods for sharing and visualising the sensors, both of which use platform methods to share/visualise.

Hence, if you want to add a sensor to AIRS, you will need to add another Handler to AIRS. For this:

  • create a new Java file in the com.airs.handlers package directory with the new handler implementing the Handler interface.
  • Pick the sensor symbol you want to use. You are limited to 2 characters only and you will need to see here that you choose a symbol not taken already. NOTE that you can realise a number of sensors in a single handler. 
  • Implement the various methods (see our Javadocs for the API descriptions) – an easy example to learn from is the RandomHandler, which allows for possibly understanding how the Discover() and Acquire() method need to be realised.
  • Add the new Handler implementation to the list of handler being instantiated by the HandlerManager in its createHandlers() method.

Compile AIRS according to your settings and install it (either in the emulator or on your device). The new handler should be available at the next start (assuming that your availability checks succeeded).

Each handler, however, might require some configuration through the user, similar to the configurations that are available for other handlers. For this, you will need to add a HandlerUI class implementation. For this:

  • create a new Java file in the com.airs.handlerUIs package directory with the new class implementing the HandlerUI interface.
  • create your own Android Preference XML file in the /res/xml directory (see the Android documentation for how to design preference dialogs).
  • It is best to look through the other examples of how to initiate the HandlerUI methods – in most cases, a simple copy and paste (with changes to use the right XML files) will suffice since the actual sensor-specific configuration is defined in the XML file itself.

Similar to adding the Handler instantiation, you will need to add the HandlerUI instantiation in the createHandlerUIs() method of the HandlerUIManager class. Depending on where you add the instantiation, it will determine where the UI will appear in the list of configuration dialogs.

Re-compile, re-install and your new handler should appear with your own configuration dialog.