Wiki

Clone wiki

libNODE-android-public / Integration FAQ

How do I initialize the Node Framework?

    public class MyApplication extends android.app.Application
     {
         @Override
          public void onCreate() {
              super.onCreate();
              //When using non chroma or color related functions all that is required is your application     context.
              com.variable.application.NodeApplication.initialize(this);

              // When using chroma, provide your api key given out by Variable
              com.variable.application.NodeApplication.initialize(this, "my_awesome_api_key")

              //When using both chroma and chroma match, provide your api key and color library key
              com.variable.application.NodeApplication.initialize(this, "my_awesome_api_key", "my_complete_color_library_access_key"
          }
     }

How do I listen for bluetooth connection events?

It is suggested to implement the ConnectionListener, which in turn can be registered by passing reference to the DefaultNotifier and the framework will alert your listener when a connection event has been received.

How do I get the instance of the connected NODE in the API Demo?

The application must hold onto the connected instance throughout the application since it is a socket connection. Therefore, we place a member in the NodeApplication class called connectedNODE.

    public class MyApplication extends android.app.Application
     {
         private NodeDevice mConnectedNODE
         public void setActiveNode(NodeDevice node) { this.mConnectedNODE = node; }

        public NodeDevice getActiveNode(NodeDevice node) { return this.mConnectedNODE; }

        /** @returns true if the NODE is connected **/
        public boolean isConnected(){ return mConnectedNODE != null && mConnectedNODE.isConnected();  }
     }

How do I get an instance of NodeDevice? Connect to a NODE?

/* Creating an instance of a NodeDevice.
 *  device_type can be one of the following 
 *                    android.bluetooth.BluetoothDevice.DEVICE_TYPE_CLASSIC,
 *                    android.bluetooth.BluetoothDevice#DEVICE_TYPE_LE = 2,
 *                    android.bluetooth.BluetoothDevice#DEVICE_TYPE_DUAL = 3,
 **/
    NodeDevice node = NodeDevice.getFactory().create(context, "bluetooth_address", device_type)
//Connecting to a Node
NodeDevice node = NodeDevice.getManager().findFromAddress("Address_Of_Already_Discovered_Node").connect()

How do I listen for when a new module has been attached?

    SensorDetector sensorDetectorCallback = new SensorDetector(){
        @Override
        public void onSensorConnected(NodeDevice node, BaseSensor sensor){
            System.out.println("Sensor Attached=" + sensor.getModuleType());
        }

        @Override
        public void onSensorRemoved( NodeDevice node, BaseSensor sensor){
            System.out.println("Sensor Removed= " + sensor.getModuleType());
        }
    };

    //Subscribe
    DefaultNotifier.instance.addSensorDetectorListener(sensorDetectorCallback);

    //...some code...

    //Unsubscribe
    DefaultNotifier.instance.addSensorDetectorListener(sensorDetectorCallback);

How do I disable all streaming on a NodeDevice instance?

    NodeDevice node = ....
    node.disableAllStreaming();

What is the DefaultNotifier class?

The default notifier is the publisher and subscriber object for all framework callbacks. This singleton allows the application to subscribe or unsubscribe to all Node.Framework callbacks. It is the responsibility of the application to unsubscribe its own callbacks.

What callbacks are marshaled to the UI Thread?

  • All Status Listener methods
  • All Chroma Listener methods
  • All Button Listener methods
  • All Sensor Detector methods
  • All Datalogging Listener methods
  • All Connection Listener methods

How do I check the battery level of a NodeDevice?

    StatusListener l = new StatusListener(){
        //Implement all other methods
        @Override
        public void onBatteryLevelUpdate(NodeDevice node)
        {
            float volts = node.getBatteryLavel();
        }
    }

    //lets not forget to Subscribe for the battery Level notification
    DefaultNotifier.instance.addStatusListener(l);

    nodeDevice.requestBatteryLevel();

Motion

How do I stream accelerometer?

    NodeDevice node = getNODE();
    MotionSensor sensor = node.getMotionSensor();
    sensor.startSensor(); //This will start with defaults

    /*sensor.setStreamMode(
            true, //Turn On Accelerometer
            false, //Turn off Gyroscope
            false, //Turn off Magnetometer
            1, //Take reading every 10 ms
            0, //Take reading forever
            true, //Always timestamp on board
    */         

##Chroma

What is white point calibration?

Whitepoint calibration allows consistent results from Chroma. Whitepoint calibration should occur between every 20 - 40 Chroma scans.

How do I perform white point calibration?

Implementing ChromaListener will allow for the framework to use the onWhitePointCalComplete listener.

    ChromaListener l = new ChromaAdapter()
    {
        @Override
        public onWhitePointCalComplete(ChromaDevice chromaDevice, boolean result){
            System.out.println("Calibration Result=" + results);
        }
    };


    //Let's not forget to register this callback.
    DefaultNotifier.instance.AddChromaListener(l);

   //Begin White Point Calibratio
    aChromaDevice.requestWhitePointCal();

Updated