Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accelerometer and Gyroscope support on mobile devices #50

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from

Conversation

mulshine
Copy link
Collaborator

@mulshine mulshine commented Oct 18, 2024

Accel and Gyro classes implemented for WebChucK to be used on mobile devices. Both modeled after HID,Accel
and Gyro interface with browser/JS "devicemotion" and "deviceorientation" events, respectively, and allow you to listen for and receive AccelMsg's or GyroMsg's inline with WebChucK code, providing x, y, z data in each case.

Gyro gy;
GyroMsg msg;

0 => int device;

// open gyro 
if( !gy.openGyro( device ) ) me.exit();
<<< "gyro '" + gy.name() + "' ready", "" >>>;

<<< "only on mobile" >>>;

// infinite event loop
while( true )
{
    // wait on gyro event
    gy => now;

    // get one or more messages
    while( gy.recv( msg ) )
    {
        // print gyro values
        <<< msg.getGyroX() + " " + msg.getGyroY() + " " + msg.getGyroZ() >>>;
    }
}

Big thanks to @terryzfeng for assistance in the architecture here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants