Closed dorukeker closed 9 years ago
Let me know what you think.
This is awesome. Thanks for this!
deviceMotion.isAvailable(); // returns an object for the availability of the sensor data /* { acceleration:<true or false>, accelerationIncludingGravity:<true or false>, rotationRate:<true or false> } */
Is think this should simply return true
rather than returning an object if devicemotion events are actually being fired.
deviceMotion.isAvailable(); // true or false
Then developers could drill down to specific availability of that event data with calls like e.g.:
deviceMotion.isAvailable(deviceMotion.ACCELERATION_INCLUDING_GRAVITY); // true or false
Furthermore, I think we should go one level deeper and allow developers to do the following:
deviceMotion.isAvailable(deviceMotion.ACCELERATION_INCLUDING_GRAVITY_X); // true or false
and the same for device orientation:
if (deviceOrientation.isAvailable()) { // true or false
if (deviceOrientation.isAvailable(deviceOrientation.ALPHA)) { // true or false
console.log(".alpha is not undefined and not null! :)");
} else {
console.log(".alpha is undefined or null :(");
}
}
WDYT?
Is there any chance you could you format this so we can automatically merge it at a later point?
Specifically, it would be so good if you could instead base your changes on top of the current master HEAD.
Is there any chance you could you format this so we can automatically merge it at a later point? Specifically, it would be so good if you could instead base your changes on top of the current master HEAD.
Yes I can. I will close this pull request and make a new one later (perhaps today)
deviceMotion.isAvailable();
// returns an object for the availability of the sensor data
/*
{
acceleration:<true or false>,
accelerationIncludingGravity:<true or false>,
rotationRate:<true or false>
}
*/
Is think this should simply return true rather than returning an object if devicemotion events are actually being fired.
I think the SensorCheck is already checking if the event is fired or not. So the availability check is not about if the events are fired, but it is about if the values exist in the event.
If we say deviceMotion.isAvailable()
is true
, does it mean that all values are as expected, or only some? I think it is misleading in some cases.
Actually even deviceOrientation.isAvailable()
is misleading. Because there are some cases where .beta
and .gamma
are available but .alpha
is not.
My suggestion would be to change this availability check to only lower level (like you have suggested), and let the developers implement the checks as they see fit. (E.g. check only the .alpha
value if they are only using that one, and don't care if the rest is there or not.)
A possible implementation can be like the following:
deviceOrientation.isAvailable(deviceOrientation.ALPHA); // returns true or false
deviceOrientation.isAvailable(deviceOrientation.BETA); // returns true or false
deviceOrientation.isAvailable(deviceOrientation.GAMMA); // returns true or false
deviceMotion.isAvailable(deviceMotion.ACCELERATION_X); // returns true or false
deviceMotion.isAvailable(deviceMotion.ACCELERATION_Y); // returns true or false
deviceMotion.isAvailable(deviceMotion.ACCELERATION_Z); // returns true or false
deviceMotion.isAvailable(deviceMotion.ACCELERATION_INCLUDING_GRAVITY_X); // returns true or false
deviceMotion.isAvailable(deviceMotion.ACCELERATION_INCLUDING_GRAVITY_Y); // returns true or false
deviceMotion.isAvailable(deviceMotion.ACCELERATION_INCLUDING_GRAVITY_Z); // returns true or false
deviceMotion.isAvailable(deviceMotion.ROTATION_RATE_ALPHA); // returns true or false
deviceMotion.isAvailable(deviceMotion.ROTATION_RATE_BETA); // returns true or false
deviceMotion.isAvailable(deviceMotion.ROTATION_RATE_GAMMA); // returns true or false
In addition to this, I think we can still return an object of availabilities if the function is called without any parameters. e.g. deviceMotion.isAvailable()
or deviceOrientation.isAvailable()
. I think of myself as I am developing with those: I would like to have that option.
Let me know what you think.
Great.
In addition to this, I think we can still return an object of availabilities if the function is called without any parameters. e.g. deviceMotion.isAvailable() or deviceOrientation.isAvailable(). I think of myself as I am developing with those: I would like to have that option.
I still think the top-level isAvailable
is tricky. it might be confusing to have isAvailable
with no parameters return objects while letting isAvailable
with a parameter return booleans.
What you're asking for RE: returning an object from e.g. deviceMotion.isAvailable()
can possibly already be done in a similar way by calling deviceMotion.getLastRawEventData()
instead (?).
So I'm not sure about this top-level isAvailable
idea but +1 to everything else :)
Looking forward to the new pull request.
I still think the top-level isAvailable is tricky. it might be confusing to have isAvailable with no parameters return objects while letting isAvailable with a parameter return booleans.
It is tricky indeed. I think it is a matter of taste. Not sure if there are any conventions that tell you you should or should not do it. I leave it at low-level for now.
What you're asking for RE: returning an object from e.g. deviceMotion.isAvailable() can possibly already be done in a similar way by calling deviceMotion.getLastRawEventData() instead (?).
That is true. I overlooked that function. You can actually use that one instead.
So I'm not sure about this top-level isAvailable idea but +1 to everything else :)
Looking forward to the new pull request.
Just finished coding. Tomorrow some tests and I will make the request.
Superceded by https://github.com/richtr/Full-Tilt/pull/6.
Added new functions to DeviceMotion and DeviceOrientation classes. After the promise resolves you can check on the availability of sensor data. For device orientation:
and for DeviceMotion:
You can see a sample usage in the data_display.html in the examples. Let me know what you think. Cheers!