Posts Tagged ‘code’

Mobile Logger – GPX extensions

Tuesday, August 10th, 2010

gpx-extRolling the extra logged sensor data into the GPX export took more effort that it should have…but I uncovered and fixed a latent bug in the export feature, so that’s a win right? Regardless, it’s was nice to use the new issue tracker at bugs.robertcarlsen.net for real(z) for the first time. I’m looking to get several other features implemented before the next released update…planning on a few weeks. Otherwise, code is available, as always, on github.

Parsing foursquare KML files

Tuesday, February 23rd, 2010

We’re using Foursquare as a data logger for one of our assignments in the Telling Stories with Sensors, Data and Humans class at ITP. As an aid to begin understanding the relationships between venues for our tracks, it’s helpful to munge the KML into CSV so it can be plotted and played with in a spreadsheet, Illustrator, R, Processing or whatever…

Below is a short python script to parse a Foursquare KML file into a simple CSV file. It outputs the check-in name, description, timestamp and location (as lat, lon). The Foursquare KML feed is available at the Feeds page on their site. (more…)

(overly simplistic) saving state in oF for iPhone

Friday, June 19th, 2009

save_stateThere was a recent comment about saving / restoring application state when using openFrameworks for iPhone which got me to thinking about how to do it. Apple’s frameworks provide a fairly thorough way to save state to the disk and restore later. There seem to be three primary ways to do this: simple plist files (usually encoded in binary on the iPhone), archived data (they like to refer to this as freeze-dried object graphs) and core data.

I believe that archiving objects require methods inherited from NSObject, which we don’t have in openFrameworks’ ofSimpleApp. Core Data seems like overkill, so I looked into using plist files.

There are likely better ways to do this, but this ad-hoc solution works wonderfully for a small app I’m working on, and only requires a bit of Objective-C code that could likely be moved up into a nice wrapper class. However, since the question was asked I’d just like to get it out there before working on a more elegant approach. (more…)

Simple things feel so good. (warning: geekery)

Wednesday, March 4th, 2009

Toggle an integer variable between 0 and 1. Useful for a flag to control program flow in C without boolean types.

toggleVar = 1>>toggleVar;

What this is doing is right shifting the integer 1 either zero or one place, depending on the current value of toggleVar.

An 8-bit (unsigned – positive values only) integer has 256 possible values. This is a byte of information whose bits can be represented in binary as 00000000. The least significant bit, the smallest values are on the right…so, 00000001 = 1, 00000010 = 2 … 11111111 = 255.

Ok, this isn’t a binary lesson…so, right shifting is simply moving all the bits to columns to the right. 2>>1 = 1 or, 00000010 >> 1 = 00000001 (which is binary for 1).

The expression at the top does exactly this: When toggleVar is zero, it becomes 1>>0 = 1 and when toggleVar is 1 the expression is 1>>1 = 0. The last bit gets shifted right into oblivion!!! (sorry for that).

Of course, with boolean data types toggleVar = !toggleVar is still shorter, by one char! :)