js & reading sensors on MS surface pro 2 tablet
Hi all,
I've never used js in Max in all these years...not sure why now that I looked over the docs! Quite useful.
Anyhoo...I have an MS surface pro 2 tablet. Lots of built in sensors and one of the ways you can access the data is via java script. I knew it was wishful thinking, but couldn't get it work in Max. I am assuming it's because the calls made in the code are outside the standard js library... at least that's my guess. Here's my js code:
inlets = 1;
outlets = 4;
// bang -- start data stream
function bang()
{
var sensor = Windows.Devices.Sensors.OrientationSensor.getDefault();
if (sensor) {
// Select a report interval that works for the app and that the sensor supports.
var minimumReportInterval = sensor.minimumReportInterval;
var reportInterval = minimumReportInterval > 20 ? minimumReportInterval : 20;
// Set the report interval to enable the sensor for polling
sensor.reportInterval = reportInterval;
var reading = sensor.getCurrentReading();
if (reading) {
var quaternion = reading.quaternion;
var x = quaternion.x;
var y = quaternion.y;
var z = quaternion.z;
var w = quaternion.w;
// output values
outlet(0, x);
outlet(1, y);
outlet(2, z);
outlet(3, w);
}
}
}
It gives an error: js: orientation-sensor-read-test.js: Javascript ReferenceError: Windows is not defined, line 11
So my question is: is there a way to extend the js library to include whatever is needed to accomplish what I want to above? There are also other potential paths (c++, c#, vb), but my non-max programming stopped at Fortran77 :)
Here's the link to the reference (first link contains the code I'm using above, second link is MS' ref page:
http://blogs.msdn.com/b/windowsappdev/archive/2012/08/09/liven-up-your-app-with-location-and-sensors.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.sensors.orientationsensor.getcurrentreading.aspx
Thanks in advance for any nudges in the right direction.
Cheers,
David
Thought I'd try again to see if there were any javascript gurus out there that might have some idea on how to make this work. Even a "won't work in Max" would be great so I can head down another path with this.
Thanks!!
David