Which way is up?

Is there a way to get the current orientation of the device?

I know that corona normally works in 4 orientations, but if you wanted to code the startup code for the current orientation, it would be nice. The alternative would be for Corona to trigger a orientation event at startup, before user code is executed, so the listener would be able to update a current orientation. 

Also, to do an app like an inclinometer, it needs to know the angle off vertical the device is being held. I can see the change delta but nowhere to ask to find out what degree is up for the device.

Thanks!
stu

[lua]

local function onOrient(event)
    if event.type == “portraitUpsideDown” then
        app.isUpsideDown = true
    else
        app.isUpsideDown = false
    end
    return true
end

Runtime:addEventListener(“orientation”, onOrient)

[/lua]

How do I get the current orientation, pointing 17 degrees or 45 degrees, or whatever angle it is currently being held at… 

Also, Last time I tried the orientation listener, I didn’t get an event at startup, so you had to change the orientation after startup to get an event and correct the problem. And the delta value it sends out is a delta of what it is now from what it was before the move. If you’re unsure of what it was before, what good does delta do? Why shouldn’t it also let us query what the angle really is.

I think there should be a system info query we should be able to do to get what it is right now, whenever we want it, and as often as we want to query it. 

Thanks Rob!

Stu

Okay, then you’re interested in the accelerometer and gyroscope data.  That’s different:

[lua]

local function onTilt(event)
    app.myRocket.x = (app.myRocket.x + event.xGravity * ((app.sensitivity * 15 )+ level))
    if app.myRocket.x < 0 then
        app.myRocket.x = 0
    elseif app.myRocket.x > (display.contentWidth - 64) then
        app.myRocket.x = display.contentWidth - 64
    end
    print(string.format(“Instant x: %0.4f y:%0.4f z: %0.4f”, event.xInstant, event.yInstant, event.zInstant))
    print(string.format(“Gravity x: %0.4f y:%0.4f z: %0.4f”, event.xGravity, event.yGravity, event.zGravity))
    return true
end
 

Runtime:addEventListener(“accelerometer”, onTilt )

[/lua]

Now in my app, I only care about side to side tilting, but this should get you started.

[lua]

local function onOrient(event)
    if event.type == “portraitUpsideDown” then
        app.isUpsideDown = true
    else
        app.isUpsideDown = false
    end
    return true
end

Runtime:addEventListener(“orientation”, onOrient)

[/lua]

How do I get the current orientation, pointing 17 degrees or 45 degrees, or whatever angle it is currently being held at… 

Also, Last time I tried the orientation listener, I didn’t get an event at startup, so you had to change the orientation after startup to get an event and correct the problem. And the delta value it sends out is a delta of what it is now from what it was before the move. If you’re unsure of what it was before, what good does delta do? Why shouldn’t it also let us query what the angle really is.

I think there should be a system info query we should be able to do to get what it is right now, whenever we want it, and as often as we want to query it. 

Thanks Rob!

Stu

Okay, then you’re interested in the accelerometer and gyroscope data.  That’s different:

[lua]

local function onTilt(event)
    app.myRocket.x = (app.myRocket.x + event.xGravity * ((app.sensitivity * 15 )+ level))
    if app.myRocket.x < 0 then
        app.myRocket.x = 0
    elseif app.myRocket.x > (display.contentWidth - 64) then
        app.myRocket.x = display.contentWidth - 64
    end
    print(string.format(“Instant x: %0.4f y:%0.4f z: %0.4f”, event.xInstant, event.yInstant, event.zInstant))
    print(string.format(“Gravity x: %0.4f y:%0.4f z: %0.4f”, event.xGravity, event.yGravity, event.zGravity))
    return true
end
 

Runtime:addEventListener(“accelerometer”, onTilt )

[/lua]

Now in my app, I only care about side to side tilting, but this should get you started.