Automatic Sensor Source Code Generation

Automatic Sensor Source Code Generation

At the same time as I’ve been trying all kinds of different approaches to sensor material and attachment (including paint, glue, wire, thread, tape, and fabric), I’ve been working on customization and efficient touch sensor test code as well. In a post quite a while ago, I mentioned that after spending some time figuring out all of the ergonomically possible combinations of touches, I actually came up with many hundreds of unique possibilities—a lot more than I’d anticipated.

As you might guess, it’s not very easy to work efficiently with hundreds of unique tests in the source code, especially after I came across a couple of base 1-to-1 combinations that I’d missed before. Making one slight change to the foundation of the system results in a tremendously complicate series of changes all through the code. I have to keep track of which pins correlate to which sensors, which base combinations exist, which complex combinations exist, and which order to check each of them in.

This last consideration has been the most difficult. I spent a few hours this past Wednesday working on the touch priority, and while it wasn’t difficult to do for the base combinations, to became extremely complicated as soon as I started to get into the complex ones.

So, I created a PHP script to automate the entire sensor code generation process. I realize that a PHP script may not be a good final solution, but I chose that approach because I use the language every day and it’s very easily accessible to me. I don’t know if web-based Keyglove configuration will be possible in the future, but if not, I can at least port it to other languages.

Anyway, the basic idea of the script is to use the sensor array, the base combinations, and a fun set of “impossible combination” arrays to build everything automatically. This takes care of literally all of the code necessary to paste into the Arduino IDE. On top of that, the PHP script also builds only the combinations needed for whatever touchset you want to define. That means smaller, simpler, more efficient code.

One of the problems I’ve had is in figuring out how to have the minimum possible code while still allowing touchset customization. It is possible to have a very flexible array list or hash table using pure Arduino code, but for a limited hardware scenario like the Arduino, it’s a bad idea to use dynamic memory allocation and complex data types all over the place. It can seriously slow down the process. So, for the moment, I’m relying on hard-coded sensor control. Actually, except for the touchset portion, the hard code this script generates is perfectly acceptable in any situation. I’d like to make the touchset code more dynamic, but that can wait for now.

The most complicated part of the script of the set of of “impossible combination” arrays. It is an associative array with one keyed element for each base touch combination, and each of those elements contains a list of other base touch combinations that are impossible while the element’s key touch combination is active. For example, the “AY” combination (index tip to thumb tip) would include “Y1” as an impossible combination (thumb tip to top of palm). Obviously, you cannot touch your index fingertip and your palm both at the same time with your thumb tip—unless you are freakishly double-jointed, anyway, and even then not in a very controlled and repeatable fashion.

The rest of the script uses a recursive build function and a few convenient features of PHP to directly create all of the code, complete with the correct touch test order. It’s beautiful. And, more importantly, it will save me hours and hours of time and lots of frustration trying to figure out everything manually.

I hope to have a good test video up within a week showing some real typing with the glove. That, of course, is contingent on finishing a good Prototype B. I’ve been trying so many different things lately that I think maybe I ought to take a few hours and simply build something that fundamentally works even if I’m only 80% satisfied with it. The last 20% will come later.

Leave a Reply