Topic: Accelerometer test code

Would you please post the source for the widget that uses the accelerometer?
I know there are examples in the wiki, but they appear to not be working for me.

Thanks in advance!

Bruce

Re: Accelerometer test code

Do you have the following line in your code?
Its kind of secluded on the wiki:

_accelerometer = ["ASnative"](5,60);

I also added my Accelerometer Graph widget to the wiki.

Re: Accelerometer test code

That does the trick... Thanks!!!

B

Re: Accelerometer test code

that accelerometer graph widget code doesn't seem to work for me:
http://wiki.chumby.com/mediawiki/index. … ter_Widget

Thanks.

Re: Accelerometer test code

You have to test it on a real chumby. The virtual chumby, or just running it on the computer, will not give off acceleration values ;-)

Re: Accelerometer test code

Oh, so I can stop shaking my desktop computer?  I got it now, but what I meant to say was that I couldn't get the .fla to download from the wiki link...it's working now though.

Re: Accelerometer test code

tongue

Yeah, you have to save it as a fla, they are all like that.

I was hoping that on the virtual chumby, they would at least randomize those ASnative values, for testing purposes sad

Re: Accelerometer test code

zachninme wrote:

I was hoping that on the virtual chumby, they would at least randomize those ASnative values, for testing purposes sad

Not sure how we could do that, since the ASnative calls drop into the player itself, and the normal desktop Flash Player does not have those calls implemented.  We can't intercept those calls within Flash. The virtual chumby is simply a Flash movie that duplicates some of the functionality of the chumby's Control Panel.

What you'd probably want to do is something like:

_accelerometer = function(a) {
     var value = ["ASnative"](5,60)(a);
     if (value==undefined) {
         value = random(4096); // deprecated, but still works :)
     }
     return value;
}

Re: Accelerometer test code

Ah, smart.

Re: Accelerometer test code

I have written a quick test harness for the accelerometer.
It works fine with the accelgraph.swf example - http://wiki.chumby.com/mediawiki/index. … ter_Widget
Just change the loadMovie line to load your compiled swf.

I am also considering writing a fancy version with buttons and x/y/z sliders for precise control.

var my_mc:MovieClip = _root.createEmptyMovieClip("my_mc",_root.getNextHighestDepth());
var my_mcl:MovieClipLoader = new MovieClipLoader();
var my_listener:Object = new Object();
my_mcl.addListener(my_listener);
my_listener.onLoadComplete =function(the_mc:MovieClip) {
    the_mc.ASnative = function(n1,n2) {
        my_accelerometer = function(n) {
            return Math.random()*50 - 50;;
        }
        return my_accelerometer;
    }
}
my_mcl.loadClip("accelgraph.swf", my_mc);

As you can see, I am just creating an ASnative function that replaces the Chumby version (which won't exist on a Virtual Chumby anyway).
A fancy implementation would have a massive switch/case statement, but for now a random number does the job.

If anyone finds this useful, let me know and I might work on an advanced version.

Re: Accelerometer test code

I tried the pendulum and that works too.
Change the loadMovie line to

my_mcl.loadClip("http://www.chumby.com/xml/movies/59D1E5A0-AC29-11DB-8062-0030485A78AA", my_mc);

You will notice that the original test code makes the pendulum go crazy, which is expected.
To make it 'still', use:

my_accelerometer = function(n) {return 2000;}

This is interesting given that 2048 is the claimed zero point.  Even 2001 or 1999 make the pendulum 'move'.