New codebase, KGAPI protocol, and Bluetooth developments
Over the last few months, I have been working rebuilding the Keyglove code into something that is as plug-and-play as it can be with a few off-the-shelf components and open-source software. This has always been the goal, of course, but during the last iteration of development, things had started to get a little out-of-hand. As I hinted at the end of the previous update, part of this involved looking at what I had already created and reconsidering the approach based on new technologies that have been created and all of the knowledge I have gained over the last year since changing jobs.
Simplify and Standardize
One of the first things that I did was move all of the existing Arduino code into a backup folder and rebuild only the necessary parts piece-by-piece. This doesn't mean that I rewrote everything from scratch, but instead that I went through each existing source file and copied only the parts that I wanted to include in the official "this-is-guaranteed-to-work-and-be-supported" firmware. This doesn't mean that any functionality was lost; rather, it means that I was able to focus on finishing the parts that need to be there and stop being distracted by potential or partial support for things that aren't critical.
For example, there are a few different I2C motion sensors that I had written some code for, but since moved on to a different sensor that is cheaper and more capable. I also had some structured code for Arduino hardware variants (e.g. Arduino Uno, Arduino Pro Mini) which I have never meant to fully support myself, since it is impossible to incorporate the feature set I want with those boards. There was no reason to leave that code in the standard codebase.
As a result, there is now exactly one platform supported at the moment:
- PJRC Teensy++ 2.0 for the main microcontroller (includes touch detection, "blink" feedback)
- USB wired communication using raw HID or virtual serial port
- Optional: Invensense MPU-6050 motion sensor for hand motion detection
- Optional: Bluegiga WT12 Bluetooth module for wireless communication
This is the hardware that I used for Prototype E at OHS and Maker Faire last year, and it fits with the Keyglove Kit PCB prototypes that I created to mount on the back of the Ektelon racquetball gloves. Given the performance possible with this hardware and small size and low price for exactly this configuration (~$75 for the above list), this is my target platform, and I am focusing exclusively on making it operate perfectly. I have also made the code "smarter" in that you can choose different configurations within the Arduino IDE, and compiler will take care of the code inclusions/exclusions for you without requiring any effort on your part.
My ultimate goal is to migrate to the Atmel SAM3X8E ARM processor (which is on the Arduino Due board), but I am holding off on that until the Teensy-based build is completely finished to the point where you can buy the parts, download the source code, open the Arduino IDE, compile it, and have a working device in two minutes. And honestly, apart from the glove attachment, we're almost there. I even used the current (published) code for a handbell motion capture test last week, and it performed admirably. You can find the latest code up on the Github repository, if you're interested.
Keyglove API Protocol (KGAPI)
I have my recent Bluegiga experience to thank in large part for the knowledge to pull off the standardization of the API communication protocol that I'm now using for the Keyglove. The protocol that I had before was remarkably similar to the binary one used by Bluegiga for a couple of their modules, but mine lacked a few of the features and structural definition. I have now modified the KGAPI structure such that it is easily defined and interpreted, and very extensible. I'm working with a simple protocol definition in JSON format. This is then run through a PHP script that I wrote which dynamically generates a complete KGAPI library code in Python (C/C++ coming) with example scripts for serial and raw HID usage, as well as very thorough documentation to go along with it:
This JSON API definition is enormously beneficial, since I can make a modification to the definition in exactly one location (the .json file), then re-run the documentation/code generator and have it automatically rebuild everything in a split second. I only have to make sure the definition is correct and in line with the actual Keyglove firmware, and everything else is done by the script. It's fantastic.
I've been working with Python because it makes an easy host platform, but I'll be adding pure C library support as well as VB and C# libraries for Windows development (which will let me revisit the Autodesk Inventor integration plugin I was working on last August). Stay tuned for more KGAPI updates. The documentation itself will be published as soon as I'm satisfied with the structure and introductory content.
One more topic to discuss briefly: since I've been working at Bluegiga for just over a year now, I have an intimate knowledge of all things Bluetooth and iWRAP (the firmware they run on the Bluetooth modules). Because of this, I've been able to build in proper support for using the WT12 module, including reliable pairing and automatic reconnection to multiple devices. Here's a screenshot of some debug output showing what's going on behind the scenes:
I have been focused on wired communication as a baseline for the last few weeks, but I will be able to return to this code and fully integrate it in one development session, I expect. The above test worked reliably with an iPad, Android phone, Google Glass, and my Windows 8.1 desktop PC. The auto-connection algorithm is actually the same one I wrote a Knowledge Base article for Bluegiga on, but...I digress.