07/26/2009, 02:36 PM
|
#1 (permalink) |
|
Member
![]() Join Date: Jul 2009
Location: Lebanon, Oregon, USA
Posts: 41
Likes Received: 0
Thanks: 6
Thanked 10 Times in 5 Posts
|
Here's some code for folks who want to get started playing with raw data from the accelerometer. Very, very basic. It just lets you hold your Pre flat and tip it back and forth to roll a ball around. Figured it would be something fun to play around with for coders new to the Pre.
Just one event handler and a tiny bit of math pulls off the heavy lifting: Code:
MainAssistant.prototype.handleAcceleration = function(event) {
this.driftX += (event.accelX * this.scale);
this.driftY += (event.accelY * this.scale);
this.driftZ += (event.accelZ * this.scale);
}
Code:
MainAssistant.prototype.setup = function() {
...
new PeriodicalExecuter(function(pe) {
obj.moveDot();
}, (1/30));
...
}
Code:
MainAssistant.prototype.moveDot = function(){
// Move that dot! Note that the Z axis isn't used in this demo...
this.theDot.style.left = (parseInt(this.theDot.style.left) + this.driftX) + 'px';
this.theDot.style.top = (parseInt(this.theDot.style.top) - this.driftY) + 'px';
// And there's more code to keep the ball within the viewport, just snag the source...
}
|
07/26/2009, 04:49 PM
|
#4 (permalink) |
|
Member
![]() Join Date: Jun 2009
Location: Stamford Bridge
Posts: 122
Likes Received: 0
Thanks: 19
Thanked 29 Times in 16 Posts
|
There's an app for the iPhone/iPod Touch like this but with obstacles and a Goal at the end of a maze. It's my favorite time-waster for the format.
I hope someone further expands on this. The only suggestion I could think of would be to fix the speed. It seems to move too much with little effort. I suppose it kinda makes sense though. The ball is small so it's "lighter". A bigger ball would be "heavier" so it wouldn't move as much. Thanks again! |
07/26/2009, 09:27 PM
|
#5 (permalink) | ||
|
Member
![]() Join Date: Jul 2009
Location: Lebanon, Oregon, USA
Posts: 41
Likes Received: 0
Thanks: 6
Thanked 10 Times in 5 Posts
|
Quote:
At this point I am attempting to track down a method for bumping the polling interval up. Unfortunately it doesn't appear to be quite as simple as some of the other hardware hacks. Simply changing the value in "/sys/class/input/input5/poll_interval" (hopefully I got that typed out right...) doesn't do a damn thing. But, it does contain a value of "250" and 250ms = 4Hz, so that's certainly on the right track. Any info anyone has would be greatly appreciated! Quote:
![]() The only reason this is so spartan is to show off how the code works, not to create an end user app/game. For that purpose, I wanted to add as few bells & whistles as possible. Hence why it is in the development forum and not homebrew. And personally, I feel it is still too slow. I haven't taken the time to add the math to lock this in to "real physics" yet, however I feel it is still slower than gravity. I want to get it to the point where "dropping" a ball from the top of the screen will result in it accelerating at 9.82 m/s˛, the real acceleration due to gravity. (As in, calculating out the physical width of a pixel and going from there...) Think of it this way. With the scaling set the way it is now, if you put a marble on the screen of your Pre and rolled it around along with this ball, the marble would still roll around faster than the on screen ball... But, snag the code and change the scale variable around so you can get a feel for what is going on, it really helps to solidify understanding. |
||
07/27/2009, 01:45 AM
|
#7 (permalink) |
|
Member
![]() Join Date: Jul 2009
Location: Lebanon, Oregon, USA
Posts: 41
Likes Received: 0
Thanks: 6
Thanked 10 Times in 5 Posts
|
It doesn't really...it doesn't do anything useful at this point. It simply exists to give programmers some code to start from when using the accelerometer. If I get around to adding some other physics goodies to it, then yeah, possibly should end up over in Homebrew.
|
07/27/2009, 01:55 AM
|
#8 (permalink) | |
|
Member
![]() Join Date: Jun 2009
Location: Stamford Bridge
Posts: 122
Likes Received: 0
Thanks: 19
Thanked 29 Times in 16 Posts
|
Quote:
But good luck with that possible app! Can't wait to see what develops!
__________________
![]() "We all follow the Chelsea!!!" |
|
07/27/2009, 01:58 AM
|
#9 (permalink) |
|
Member
![]() Join Date: Jul 2009
Location: Lebanon, Oregon, USA
Posts: 41
Likes Received: 0
Thanks: 6
Thanked 10 Times in 5 Posts
|
Ah, yes, inertia. Yes, that would actually be taken care of by speeding it up. The "lag" is because it is responding slower than gravity actually would. Slow it down further and that "unnatural feel" gets magnified like you wouldn't believe.
|
07/27/2009, 09:45 AM
|
#10 (permalink) |
|
Member
![]() Join Date: Jul 2009
Posts: 40
Likes Received: 0
Thanks: 1
Thanked 5 Times in 5 Posts
|
Randall. Thank you for having such a concise example of using the accelerometer. I can't wait to play with this tonight. I've been working on a mythtv controller app, and this will add a few nifty whizbang features like jog control in recordings (turn the pre like a knob), and navigation of media lists by tilting the device 'up' and 'down'.
Not killer features, I know. But the tv has such a larger screen, when you're in front of it
|
07/27/2009, 10:11 AM
|
#11 (permalink) | |
|
Member
![]() Join Date: Jul 2009
Location: Lebanon, Oregon, USA
Posts: 41
Likes Received: 0
Thanks: 6
Thanked 10 Times in 5 Posts
|
Quote:
![]() The idea of using the Pre as a "knob" is great! |
|
08/10/2009, 03:12 PM
|
#13 (permalink) | |
|
Member
![]() Join Date: Jul 2009
Location: Plano, TX
Posts: 90
Likes Received: 0
Thanks: 32
Thanked 1 Time in 1 Post
|
Quote:
|
|
08/10/2009, 03:34 PM
|
#14 (permalink) | |
|
Developer
![]() ![]() Join Date: Jul 2009
Posts: 1,400
Likes Received: 3
Thanks: 17
Thanked 1,540 Times in 376 Posts
|
Quote:
Application:AccelService - WebOS Internals I've started work on a Labyrinth game, and setting the poll frequency to 1KHZ (poll_interval = 1ms) doesn't seem to bog down the application at all. There are brief hiccups every once in a while, but I've seen those at 4HZ as well. Labyrinth - WebOS Internals |
|
08/10/2009, 06:02 PM
|
#16 (permalink) | |
|
Member
![]() Join Date: Jul 2009
Location: Lebanon, Oregon, USA
Posts: 41
Likes Received: 0
Thanks: 6
Thanked 10 Times in 5 Posts
|
Quote:
Good to know high polling rates work (1KHz is awesome!), because that's precisely what I need for the app I have in mind... Going to have to toy with this tonight. |
|
08/10/2009, 06:16 PM
|
#18 (permalink) | |
|
Developer
![]() ![]() Join Date: Jul 2009
Posts: 1,400
Likes Received: 3
Thanks: 17
Thanked 1,540 Times in 376 Posts
|
Quote:
Yes I believe webos-internals.org is down right now for upgrades. Let me know if you have trouble or need help installing the AccelService. Or come over to #webos-internals irc channel (freenode.net) |
|
08/10/2009, 08:48 PM
|
#19 (permalink) |
|
Member
![]() Join Date: Jun 2009
Location: Portland, OR
Posts: 469
Likes Received: 22
Thanks: 186
Thanked 110 Times in 80 Posts
|
I installed this and opened it with pandora, the web browser, and my emailed opened at the same time . It ran great !! I can't wait to see more. Good job and thanks!
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|



