Ejecta icon indicating copy to clipboard operation
Ejecta copied to clipboard

devicemotion can't support remote controller of AppleTV

Open finscn opened this issue 10 years ago • 4 comments

is this feature in the roadmap?

finscn avatar Dec 28 '15 14:12 finscn

This is an interesting issue, because the only way to get the equivalent of device motion onto the atv requires the remote. The remote is a gamepad, and the current gamepad spec (which Dominic probably wants to stick to) doesn't support the required attributes.

It's easy to add in if you're looking to do so. In the EJBindingGamepad.m file you can add the gravity/acceleration attributes to the "microGamepad"

~ line 184 (EJBindingGamepad.m)

#if TARGET_OS_TV 
    // Provide the Remote's touch pad a axis in addition to the Up/Down/Left/Right buttons
    else if( controller.microGamepad ) {
        GCMicroGamepad *gamepad = controller.microGamepad;
        JSObjectSetPropertyAtIndex(ctx, jsAxes, 0, JSValueMakeNumber(ctx, gamepad.dpad.xAxis.value), NULL);
        JSObjectSetPropertyAtIndex(ctx, jsAxes, 1, JSValueMakeNumber(ctx, -gamepad.dpad.yAxis.value), NULL);
        JSObjectSetPropertyAtIndex(ctx, jsAxes, 4, JSValueMakeNumber(ctx, controller.motion.gravity.x), NULL);
        JSObjectSetPropertyAtIndex(ctx, jsAxes, 5, JSValueMakeNumber(ctx, controller.motion.gravity.y), NULL);
        JSObjectSetPropertyAtIndex(ctx, jsAxes, 6, JSValueMakeNumber(ctx, controller.motion.gravity.z), NULL);
        JSObjectSetPropertyAtIndex(ctx, jsAxes, 7, JSValueMakeNumber(ctx, controller.motion.userAcceleration.x), NULL);
        JSObjectSetPropertyAtIndex(ctx, jsAxes, 8, JSValueMakeNumber(ctx, controller.motion.userAcceleration.y), NULL);
        JSObjectSetPropertyAtIndex(ctx, jsAxes, 9, JSValueMakeNumber(ctx, controller.motion.userAcceleration.z), NULL);
    }
#endif
return jsAxes;

You can then access this data the same way you would access the dpad info, just at the different array indexes. Not as nice as using the device motion api, but its not the same thing.

ericjbasti avatar Dec 28 '15 15:12 ericjbasti

@phoboslab , I implement this feature in my fork ~~https://github.com/finscn/Ejecta/commit/597e1e77ff25189a23ee1db7897bb579731561fb~~

I hope it could help you.

~~In my version , the devicemotion event isn't invoked by [deviceMotionDelegate triggerDeviceMotionEvents];.~~

~~It will be invoked when user call navigator.getGamepads(), I think 60FPS to hight .~~

finscn avatar Dec 29 '15 19:12 finscn

I update my fork: ~~https://github.com/finscn/Ejecta/commit/c6f19482d6f1b395b9295b9ccbba40164afdc4d6~~

finscn avatar Dec 30 '15 17:12 finscn

Update again: https://github.com/finscn/Ejecta/commit/7bfc59cb170ba69ade12f079d9e91fef13345884

finscn avatar Jan 04 '16 19:01 finscn