Esato

Forum > Sony Ericsson / Sony > Software, Firmware and Drivers > K850i Accelerometer + Flash Lite 2.0

Author K850i Accelerometer + Flash Lite 2.0
LCARS-Expert
K850 Green
Joined: Aug 24, 2007
Posts: 194
From: Croatia
PM, WWW
Posted: 2007-12-08 14:49
Reply with quoteEdit/Delete This PostPrint this post
Every one who owns K850i noticed that wallpapers in Laster Precision and Crystal themes react depending on which side is the phone turned to.
I managed to extract those Flash files and obtain their ActionScript but, unfortunately, only partial.
It's missing how the animation gets accelometer data from the phone. If you test those animations on your computer you will notice they react on position of your cursor when it's above the animation. It interprets "that side up" for where the cursor is.
I guess will never answer what's the ActionScript for accessing the Accelometer.
If you have any ideas please post them!
zaxan
C510 Black
Joined: Jun 01, 2007
Posts: 417
From: United Kingdom
PM
Posted: 2007-12-08 15:01
Reply with quoteEdit/Delete This PostPrint this post
Could you possibley post the action script / swf / fla (depending on which of these you have) so I (and any others who are interested) can see what action script you have found so far and how this changes the view of the theme on the computer.

Cheers
LCARS-Expert
K850 Green
Joined: Aug 24, 2007
Posts: 194
From: Croatia
PM, WWW
Posted: 2007-12-08 17:13
Reply with quoteEdit/Delete This PostPrint this post
Of course!
Here is a RAR archive, it contains original flash wallpapers from theme files and directory where I converted them to FLA with Flash Decompiler.
Link
When publishing those FLA to SWF the result doesn't match the original SWF, as you will notice. That means the SWF wasn't converted back to FLA completely.
zaxan
C510 Black
Joined: Jun 01, 2007
Posts: 417
From: United Kingdom
PM
Posted: 2007-12-09 13:01
Reply with quoteEdit/Delete This PostPrint this post
Thanks for uploading those files, I've had a look at them. Some of the code in there is above my ability in action script and rather confusing although I do understand sections of the script which seem to read accelerometer data. I have found in the Precision_standby.swf.flp file there is accelerometer.as which contains the following code:


_root.onEnterFrame = function ()
{
if (classes.AccelerometerManager.mMode == "phone")
{
loadVariables("accelerometer://data", _root);
this.accX = Number(this.accX);
this.accY = Number(this.accY);
this.accZ = Number(this.accZ);
var __reg3 = undefined;


This code seems to be reading an accelerometer variable and setting X, Y and Z possitions although more of the code after this uses code I can't really understand, but the above section would be my best guess for reading the accelerometer data .



[ This Message was edited by: zaxan on 2007-12-09 12:03 ]
melk
X1 Black
Joined: Jan 08, 2002
Posts: 165
From: Romania
PM, WWW
Posted: 2007-12-09 13:51
Reply with quoteEdit/Delete This PostPrint this post
Good thing that you started this thread, I never noticed that the standby flash animation moves according to the phone's position. It's so useless, but also very cool.

Good luck cracking the code.
Once you start down the path,
forever will it dominate your destiny!!!
Duran
K850 Blue
Joined: Aug 25, 2006
Posts: > 500
From: Netherlands
PM
Posted: 2007-12-09 13:54
Reply with quoteEdit/Delete This PostPrint this post
so soon we're getting the "accelerometer-ball-game" just like nokia's?;p
gregface
G900 Brown
Joined: Mar 05, 2004
Posts: > 500
PM
Posted: 2007-12-09 14:11
Reply with quoteEdit/Delete This PostPrint this post

On 2007-12-09 13:54:05, Duran wrote:
so soon we're getting the "accelerometer-ball-game" just like nokia's?;p


The w910i already has this.
zaxan
C510 Black
Joined: Jun 01, 2007
Posts: 417
From: United Kingdom
PM
Posted: 2007-12-09 14:20
Reply with quoteEdit/Delete This PostPrint this post

On 2007-12-09 14:11:35, gregface wrote:

On 2007-12-09 13:54:05, Duran wrote:
so soon we're getting the "accelerometer-ball-game" just like nokia's?;p


The w910i already has this.



Yeah, called Marble Madness afaik (I thought the K850 had this aswell?), although I think that game would use java to read the accelerometer data rather than flash actionscript, so either way the data from the accelerometer has to be accessible by external applications / files - just I'm not totally sure how yet lol

[ This Message was edited by: zaxan on 2007-12-09 13:21 ]
LCARS-Expert
K850 Green
Joined: Aug 24, 2007
Posts: 194
From: Croatia
PM, WWW
Posted: 2007-12-09 18:14
Reply with quoteEdit/Delete This PostPrint this post
@zaxan, I was looking at that too... It seems that accelerometer returns a non-numeric value:

if (classes.AccelerometerManager.mMode == "phone")
{
loadVariables("accelerometer://data", _root);
this.accX = Number(this.accX);
this.accY = Number(this.accY);
this.accZ = Number(this.accZ);
var __reg3 = undefined;


That script would say something like "If animation is loaded on the phone load variables from accelometer accX, accY and accZ." If you set the phone to write them you'll get "NaN" in each field which would be Not a Number. That means the each "Number(this.accX)" returns NaN. Since "Number(expression)" converts the parameter expression to a number and returns a value... It gives NaN only "If expression is NaN, the return value is NaN."
This is next:

if (!isNaN(this.accX) && !isNaN(this.accY) && !isNaN(this.accZ))
{
__reg3 = Math.round(Math.atan2(this.accZ, this.accX) * 10000) / 10000 + 3.14159;
this.Alpha = isNaN(__reg3) ? this.Alpha : __reg3;
__reg3 = Math.round(Math.atan2(this.accZ, this.accY) * 10000) / 10000 + 3.14159;
this.Beta = isNaN(__reg3) ? this.Beta : __reg3;
__reg3 = Math.round(Math.atan2(this.accX, this.accY) * 10000) / 10000;
this.Gamma = isNaN(__reg3) ? this.Gamma : __reg3;
var __reg5 = 0 - Math.cos(this.Alpha);
var __reg4 = Math.cos(this.Beta);
classes.Application.mAccManager.updateComponents(__reg5, __reg4);
}

return;
}

So, the script checks "isNaN" which returns true if the variable (accX, accY and accZ) is not a number. Which in this case is true. Now it gets difficult. I don't understand this second part completely but I get that it generates a numeric value, an angle in radians to be exact.
Math.atan2(this.accZ, this.accX) "Computes and returns the angle of the point y/x in radians, when measured counterclockwise from a circle's x axis (where 0,0 represents the center of the circle). The return value is between positive pi and negative pi." Now I got "oh shit, its trigonometry" in my head.

__reg3 = Math.round(Math.atan2(this.accZ, this.accX) * 10000) / 10000 + 3.14159;

Now... If I get this correctly, the angle is multiplied by 10000 and then converted to a round number. That number is divided back by 10000 and pi is added to it. I can't get it in my head how does __reg3 number look like after that. And what is this:
this.Alpha = isNaN(__reg3) ? this.Alpha : __reg3;
LCARS-Expert
K850 Green
Joined: Aug 24, 2007
Posts: 194
From: Croatia
PM, WWW
Posted: 2007-12-09 18:36
Reply with quoteEdit/Delete This PostPrint this post
WOOHHOOOH!!! Just got numbers out of it!

http://www.trekker-reactor.isq-networks-server.com/forum/acc-data.zip

Unpack this and put it on your phone! You'll see it reacts on the side you turn it to.
zaxan
C510 Black
Joined: Jun 01, 2007
Posts: 417
From: United Kingdom
PM
Posted: 2007-12-09 18:43
Reply with quoteEdit/Delete This PostPrint this post
DUUUDE!! Great to see you've worked it out Now I'll just have to wait till I've got a k850 (or hopefully k860 if it's released anytime soon) to check it myself.

Nice one
Pakzal
Satio Black
Joined: May 28, 2007
Posts: 39
From: The Netherlands
PM
Posted: 2007-12-09 18:55
Reply with quoteEdit/Delete This PostPrint this post

On 2007-12-09 18:36:53, LCARS-Expert wrote:
WOOHHOOOH!!! Just got numbers out of it!

http://www.trekker-reactor.isq-networks-server.com/forum/acc-data.zip

Unpack this and put it on your phone! You'll see it reacts on the side you turn it to.


You can also see this, by going into the service menu
LCARS-Expert
K850 Green
Joined: Aug 24, 2007
Posts: 194
From: Croatia
PM, WWW
Posted: 2007-12-09 19:00
Reply with quoteEdit/Delete This PostPrint this post

On 2007-12-09 18:55:30, Pakzal wrote:

On 2007-12-09 18:36:53, LCARS-Expert wrote:
WOOHHOOOH!!! Just got numbers out of it!

http://www.trekker-reactor.isq-networks-server.com/forum/acc-data.zip

Unpack this and put it on your phone! You'll see it reacts on the side you turn it to.



You can also see this, by going into the service menu


Of course you can but you can't use the service menu in Flash.
Check this out:
http://www.trekker-reactor.isq-networks-server.com/forum/gravity.rar
Put it on your phone (if its K850i) and try turning and shaking it
LCARS-Expert
K850 Green
Joined: Aug 24, 2007
Posts: 194
From: Croatia
PM, WWW
Posted: 2007-12-09 19:51
Reply with quoteEdit/Delete This PostPrint this post
Everyone who don't have K850i and want to know what is this about, I made a video for you:
http://www.youtube.com/watch?v=YG0WiGQ5THc
NightBlade
Sony Xperia T
Joined: Jul 29, 2007
Posts: > 500
From: Nessebar, Bulgaria
PM
Posted: 2007-12-09 21:46
Reply with quoteEdit/Delete This PostPrint this post
Cool! I didn't know K850's accelerometre worked so smooth! Like the iPhone's!
Man, that means that someone could make cool accelerometre apps for SE phones like on the iPhone.
Far out, man!! (lol, ignore that)

[ This Message was edited by: NightBlade on 2007-12-09 20:47 ]
Access the forum with a mobile phone via esato.mobi