Close

App SDK Development Pt. 2

A project log for Polymorphic Hardware

Applying polymorphism to hardware enables users to do more with their devices while avoiding IoT pitfalls.

trey-germanTrey German 05/09/2016 at 21:020 Comments

Over the past few weeks, I've brushed up on my HTML and Javascript and have begun to write a javascript library in order to make getting started with the Polymorphic Dot that much easier. I started this process mostly by experimenting around with Cordova as well as reading tutorials and articles on javascript software architecture.

After going back and forth between brainstorming and testing, I came up with the following overall app software architecture:

Just like any other piece of software, the SDK will be made up of a stack of other pieces of software:

  1. Cordova, the ble-central plug-in, as well as any additional Cordova plug-ins run directly on the host OS (Android/iOS) and expose Javascript APIs to higher layers.
  2. PML Manager is a Javascript library that manages connection to Bluetooth devices. Once a connection is established and a hardware match found, the manager loads the appropriate device library(pmlDotMove.js for instance) and exposes a user friendly API for accessing the hardware.
  3. App is the user application to be built with Cordova. This app will make calls to the PML Manager to interact with Polymorphic Hardware devices as well as any Cordova or plug-in APIs it may need.

Since I'm actually writing the PML Manager and its associated device libraries, let's focus on that. As stated earlier, the goal is to make this hardware as easy to use as possible. Of course, nowadays this means making the software as easy to use as possible. Let's walk through a typical connection scenario:

1) Application initiates BLE device scan:

pmlManager.startScan(app.onDiscoverDevice);

    When devices are found, a callback function (app.onDiscoverDevice in this case) is called and passed a device object so the app can populate a "devices found" list for the user.

    2) User selects device(s) to connect to. App stops scanning and passes device(s) to the connect API:

    pmlManager.stopScan();
    pmlManager.connect(app.selectedDevices, app.onDeviceConnect);

    Note: pmlManager supports simultaneous connections to 8 devices.

    As each device is connected to, pmlManager looks at its advertising data to figure out what kind of Polymorphic Hardware it is. If it finds a match in its hardware definitions library, pmlManager will load a software interface object that matches the device and pass it back to the application via a callback (app.onDeviceConnect in this case).

    3) Now that the application has access to the software interface for a given device, it can configure the services and start receiving data:

    var onMoveData = function(data){
            var a = new Int16Array(data);
    	        //a[0] - Gyro X   a[1] - Gyro Y    a[2] - Gyro Z
                    //a[3] - Accel X  a[4] - Accel Y  a[5] - Accel Z
                    //a[6] - Mag X    a[7] - Mag Y    a[8] - Mag Z
    	};
    swInterface.registerMoveCallback(onMoveData);
    swInterface.enableMoveCallback();
    swInterface.setMovePeriod(0x0A);
    swInterface.enableAllMove();

    In this example I:

    1. Create a movement callback function to receive data from the Polymorphic Hardware.
    2. Register the movement callback and enable it.
    3. Configure how often I want to receive movement data.
    4. Enable all movement sensors (gyro, accel, mag).

    The user application would then do something with the data received in the onMoveData function. I went ahead and put together a quick example app which shows how to connect to multiple sensors and graph the movement data from each sensor. You can find the example Cordova app here.

    First the user selects the devices to connect to (user may select more than one):

    After devices are selected the user clicks on connect and the movement data is graphed:

    As you can see, everything appears to be working well so far.

    Graphing movement data is great, but without a solid sensor fusion algorithm its of questionable use. My next hurdle is to implement an attitude/heading reference system (AHRS) using this sensor data. In about two weeks, I'll be doing my first major field test of Polymorphic Hardware and having solid AHRS data will be critical to this test. Stay tuned for details. I guarantee you're going to want to see what I strap these sensors to...Colin Furze ain't got nothing on me...

    Discussions