Skip to content
September 16, 2009

Using CoreWLAN on MacOS 10.5

When Apple’s OS X version 10.6 shipped, they broke compatibility will all 3rd party geolocation applications.  This wasn’t entirely unexpected as we all were using a private framework which wasn’t documented.  So, Firefox 3.5 and Gears, and probably Skyhook, are busted right now on OS X 10.6.

Apple has provided, with limited documentation, a new public framework called CoreWLAN.  It looks pretty easy to use.  To do a scan of the WIFI access points, you can simply do:

#import <Cocoa/Cocoa.h>
#import <CoreWLAN/CoreWLAN.h>

NSError *err = nil;
NSDictionary *params = nil;

NSArray* scan = [NSMutableArray arrayWithArray:[[CWInterface interface] scanForNetworksWithParameters:params error:&err]];

This is all fine and dandy.  However, Firefox uses 10.5, and so using the above code will not compile using the old SDK.  Unfortunately, Apple didn’t provide any C apis – only exposing this objective-C API.  So, what I had to do was some objective-c magic.  Check out the reference (http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html)

Basically, we needed to be able to dynamically load the CoreWLAN library, that is simple enough:

void *corewlan_library = dlopen(“/System/Library/Frameworks/CoreWLAN.framework/CoreWLAN”,  RTLD_LOCAL);

Now that this library has been loaded, we want to simulate the objective-c call “[CWInterface interface]“.

// get the class
Class CWI_class = objc_getClass(“CWInterface”);
// register the selector name
SEL interfaceSel = sel_registerName(“interface”);
// make the call
id interface = objc_msgSend(CWI_class, interfaceSel);

This mess above is the same as:

id interface = [CWInterface interface];

As you probably can see, it isn’t that hard to do this, just it is syntactically nasty.  Here is the source to the little application I was testing with:

#include <mach-o/dyld.h>
#include <dlfcn.h>
#include <unistd.h>

#include <objc/objc.h>
#include <objc/objc-runtime.h>

Class CWI_class = objc_getClass(“CWInterface”);
printf(“cwi class %x\n”, CWI_class);

SEL interfaceSel = sel_registerName(“interface”);
printf(“sel: %x\n”, interfaceSel);

SEL scanSel = sel_registerName(“scanForNetworksWithParameters:error:”);
printf(“scanSel: %x\n”, interfaceSel);

id interface = objc_msgSend(CWI_class, interfaceSel);
printf(“interface: %x\n”, interface);

id scanResult = objc_msgSend(interface, scanSel, 0, 0);
printf(“scanResult: %x\n”, scanResult);

Hope this helps.  Please let me know of an easier way, if one exists.

August 30, 2009

Orientation Update…

A few days ago, I blogged about orientation support in Firefox.  I am happy to report that linux patches landed over the weekend.  (We also have Window Mobile and Thinkpads running Windows patches in the review process.)

If you a linux laptop and have a few minutes, please download one of the Firefox Trunk nightly builds and try out orientation!

What to try?

http://people.mozilla.org/~dougt/ori.html

Let it run for a little bit, then shake your laptop (not responsible for any damage :-) ).  After you have a couple dozen responses, send me the results including what distro and laptop you are using.

Demos!

While you are testing things out, check out the demo Michael Ventnor (m.ventnor at gmail.com) put together:


http://dougt.org/random/orientationdemo/index.xhtml

Justin Dolske has a few demos too:

Jesse Ruderman also cleaned up the “ball” demo that I created making the animation smoother.

Help Wanted

There are still other platforms that I would like to support.  I specifically would like to see Windows support using their Sensor API.  If you are interested in helping, file a bug, cc me, and take a look at the other implementations.

August 23, 2009

Orientation in Firefox and beyond

One of the coolest apps I saw when the iPhone came out was the wooden balance game Labyrinth.  You basically tilt your phone to move a ball around the screen, avoiding holes, and trying to get the ball to a goal.  It made use of a feature of many modern devices — accelerometers.

Obviously clear that there should be a webapp for doing just that.  What was missing was a javascript API.

In recent Mozilla trunk builds, I have added support for an orientation event.  This new event will allow you to build applications and listen for changes in orientation.  (note, the first platform to support such an event is any MacBook Pro.  Others will follow).

Simple Call:

To use this new event, you will add an event listener as you normally would:

window.addEventListener(“MozOrientation”, orientationChange, true);

Your callback will be called, when there is a change in acceleration, passing the current orientation:

function orientationChange(o) {

}

Simple Result:

The passed object has 3 attributes – “x”, “y” and “z”.  Each value is between -1 and 1 where zero is the “balance point”.  For example, suppose you device is a MacBook Pro and it is sitting on a desk that is perfectly level, you would expect to see:

x = 0
y = 0
z = 1

x is the axis in the direction from the left side of the keyboard to the right side of the keyboard (basically the axis that is along the home row keys) is level.  If I lift up the left side of the keyboard, x will increase.  if I lift up the right side, x will decrease.

y is the axis in the direction from the front of the laptop (where the mouse is) to the back of the laptop.  If I lift up the front of the laptop (the side closest to me), y will decrease.  If I left the back towards the front, y will increase.

Got that?  Yeah, physics is pretty hard. :-(

x and y can easily be visualized.  If you have a recent trunk build for the Mac, try loading this demo page:

http://people.mozilla.org/~dougt/ball.html

z basically will tell you that the laptop is sitting right side up.  if z was -1, you would know that the laptop (probably closed) and is sitting on its screen.  Of course the value will change as you rotate the laptop / device in this direction.

Right now, there is only support for the Macbook Pro.  It is pretty easy to add support for different OSs.  We have code for Samsung Windows Mobile devices, and for the HTC Windows Mobile devices.  We still need support for linux and for Windows.  If you are interested in adding support file a bug and start looking at http://mxr.mozilla.org/mozilla-central/source/widget/public/nsIAccelerometer.idl

The API isn’t fixed and may change.  I do invite you to comment.  Keep in mind that we want a really simple and straight forward API to expose orientation events to web developers.  If your response has either “RDF” or “DCCI” in it, please reread the last sentence.  :-)

Thanks again and hope you enjoy.

August 14, 2009

Eunice Kennedy Shriver

Eunice Kennedy Shriver died this week.

Best known as the founder of the Special Olympics, she reshaped how we think about people with mental disabilities. Mrs. Shriver ensured that people with mental disabilities have a place in our society, that they are guaranteed civil rights including access to an education.

Much of this you may have heard over the last few days. Unfortunately, I didn’t see any athletes speaking out. Here is one of my favorite videos.  Enjoy!

July 20, 2009

Geolocation Address

Last week, I pushed a change that will enable tomorrow’s trunk Firefox builds (Minefield) to access user-readable position information.

For example, instead only being able to work with:

37.3882005, -122.0834553

You can see the physical address as:

650 Castro St, Mountain View, California, 94041, US

This should help aide the many people that already know their physical address in familiar terms.

To access address elements, you simply do what you have been doing.  The only modification is to test to see if there is an address associated with the position, and if so, access it:

navigator.geolocation.watchPosition(successCallback)
function successCallback(position)
{
    if (position.address)
        alert(position.address.postalCode);
}

Other fields on the address object are:

address.streetNumber
address.street
address.premises
address.city
address.region
address.county
address.countryCode
address.postalCode

Please let me know what you think.

July 14, 2009

all moved over…

all moved over to the dougt.org domain.  I hope I didn’t lose too much along the away.  I think some of the media didn’t make it through the conversation, but C’est la vie!

July 9, 2009

The start of the geolocation web.

Today, when you go to maps.google.com, you will notice something new:

200907141609

See it? That little button between the map control and the street view man, when pressed, will enable geolocation for maps.

Other sites also have started adopting geolocation. Flickr has created a maps page that has a “Find my location” button that uses geolocation to position you and then show you pictures from your area:

200907141610

What other cool sites have you seen?

Technorati Tags: , , ,

Follow

Get every new post delivered to your Inbox.