Last active
December 14, 2015 06:19
-
-
Save ganzuul/5041291 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sensors begin here | |
var __device_sensors_service_entry = { | |
"name": null, | |
"version": null, | |
"proto": __device_sensors, | |
"descriptor": __device_sensors_descriptor, | |
"providers": [{ | |
"descriptor": __sp_sensors_descriptor, | |
"instance": __sp_sensors_instance | |
}] | |
}; | |
function __device_sensors(_1a0) { | |
this.provider = _1a0; | |
this.interfaceName = _1a0.descriptor.interfaceName; | |
this.version = _1a0.descriptor.version; | |
this.getChannels = __device_sensors_getChannels; | |
this.startChannel = __device_sensors_setNotifier; | |
this.stopChannel = __device_sensors_cancelNotifier; | |
this.getScaleFactor = __device_sensors_getScaleFactor; | |
}; | |
function __device_sensors_descriptor(_1a1) { | |
this.interfaceName = _1a1.interfaceName; | |
this.version = _1a1.version; | |
}; | |
function __device_sensors_getChannels() { | |
return this.provider.getChannels(); | |
}; | |
function __device_sensors_setNotifier(_1a2, _1a3, _1a4) { | |
return this.provider.startChannel(_1a2, _1a3, _1a4); | |
}; | |
function __device_sensors_cancelNotifier(_1a5) { | |
return this.provider.stopChannel(_1a5); | |
}; | |
function __device_sensors_getScaleFactor(_1a6) { | |
return this.provider.getScaleFactor(_1a6); | |
}; | |
function __sp_sensors_descriptor() { | |
this.interfaceName = "sensors"; | |
if (window.__Service_Interface_Ver) { | |
this.version = __Service_Interface_Ver; | |
} else { | |
this.version = 1; | |
} | |
}; | |
function __sp_sensors_instance() { | |
this.descriptor = new __sp_sensors_descriptor(); | |
this.getChannels = __sp_sensors_getChannels; | |
this.startChannel = __sp_sensors_setNotifier; | |
this.stopChannel = __sp_sensors_cancelNotifier; | |
this.getScaleFactor = __sp_sensors_getScaleFactor; | |
try { | |
this.so = device.getServiceObject("Service.Sensor", "ISensor"); | |
} catch (e) { | |
this.so = null; | |
__device_handle_exception(e, "sensors service not available"); | |
} | |
}; | |
var __rotation_channel = { | |
ucb: null, | |
tids: null | |
}; | |
var __XYZ_channel = { | |
ucb: null, | |
tids: null | |
}; | |
var __orientation_channel = { | |
ucb: null, | |
tids: null | |
}; | |
function __rotation_cb(arg1, arg2, arg3) { | |
if (arg2 != event_cancelled) { | |
var _1aa = null; | |
if (arg3.ReturnValue) { | |
var time = arg3.ReturnValue.TimeStamp; | |
var xrot = arg3.ReturnValue.XRotation; | |
var yrot = arg3.ReturnValue.YRotation; | |
var zrot = arg3.ReturnValue.ZRotation; | |
arg3.ReturnValue.close(); | |
_1aa = {}; | |
modifyObjectBaseProp(_1aa); | |
_1aa.timeStamp = time; | |
_1aa.rotationAboutXAxis = xrot; | |
_1aa.rotationAboutYAxis = yrot; | |
_1aa.rotationAboutZAxis = zrot; | |
} | |
__rotation_channel.ucb(_1aa); | |
} | |
}; | |
function __XYZ_cb(arg1, arg2, arg3) { | |
if (arg2 != event_cancelled) { | |
var _1b2 = null; | |
if (arg3.ReturnValue) { | |
var time = arg3.ReturnValue.TimeStamp; | |
var _1b4 = arg3.ReturnValue.XAxisData; | |
var _1b5 = arg3.ReturnValue.YAxisData; | |
var _1b6 = arg3.ReturnValue.ZAxisData; | |
arg3.ReturnValue.close(); | |
_1b2 = {}; | |
modifyObjectBaseProp(_1b2); | |
_1b2.timeStamp = time; | |
_1b2.axisX = _1b4; | |
_1b2.axisY = _1b5; | |
_1b2.axisZ = _1b6; | |
} | |
__XYZ_channel.ucb(_1b2); | |
} | |
}; | |
function __orientation_cb(arg1, arg2, arg3) { | |
if (arg2 != event_cancelled) { | |
var _1ba = null; | |
if (arg3.ReturnValue) { | |
var time = arg3.ReturnValue.TimeStamp; | |
var _1bc = arg3.ReturnValue.DeviceOrientation; | |
arg3.ReturnValue.close(); | |
_1ba = {}; | |
modifyObjectBaseProp(_1ba); | |
_1ba.timeStamp = time; | |
_1ba.deviceOrientation = _1bc; | |
} | |
__orientation_channel.ucb(_1ba); | |
} | |
}; | |
function __sp_sensors_getChannels() { | |
return ["Rotation", "AccelerometerAxis", "Orientation"]; | |
}; | |
function __sp_sensors_setNotifier(_1bd, _1be, _1bf) { | |
var _1c0 = new DeviceException(0, "dummy"); | |
if (!_1bd) { | |
throw new DeviceAPIError(_1c0.MISSING_ARG_ERR, "Callback is missing"); | |
} | |
if ((typeof _1bd) != "function") { | |
throw new DeviceAPIError(_1c0.INVALID_ARG_ERR, "Callback is of invalid type"); | |
} | |
if (_1bf && ((typeof _1bf) != "function")) { | |
throw new DeviceAPIError(_1c0.INVALID_ARG_ERR, "InValid error Callback"); | |
} | |
if (!_1be) { | |
throw new DeviceAPIError(_1c0.MISSING_ARG_ERR, "Channel is missing"); | |
} | |
if ((typeof _1be) != "string") { | |
throw new DeviceAPIError(_1c0.INVALID_ARG_ERR, "Channel is of invalid type"); | |
} | |
var rval; | |
var cb; | |
var _1c3 = {}; | |
modifyObjectBaseProp(_1c3); | |
switch (_1be) { | |
case "Rotation": | |
_1c3.SearchCriterion = "Rotation"; | |
cb = __rotation_cb; | |
__rotation_channel.ucb = _1bd; | |
break; | |
case "AccelerometerAxis": | |
_1c3.SearchCriterion = "AccelerometerAxis"; | |
cb = __XYZ_cb; | |
__XYZ_channel.ucb = _1bd; | |
break; | |
case "Orientation": | |
_1c3.SearchCriterion = "Orientation"; | |
cb = __orientation_cb; | |
__orientation_channel.ucb = _1bd; | |
break; | |
default: | |
throw new DeviceAPIError(_1c0.NOT_SUPPORTED_ERR, "Unsupported input channel"); | |
} | |
try { | |
rval = this.so.ISensor.FindSensorChannel(_1c3); | |
if (_1c3) { | |
delete _1c3.SearchCriterion; | |
} | |
if (rval.ErrorCode != 0) { | |
throw new DeviceAPIError(_1c0.NOT_SUPPORTED_ERR, "StartChannel:Operation Failed"); | |
} | |
var cmap = []; | |
var _1c5 = []; | |
var _1c6 = rval["ReturnValue"]; | |
var _1c7 = _1c6.length; | |
cmap = _1c6[0]; | |
var _1c8 = {}; | |
modifyObjectBaseProp(_1c8); | |
_1c8.ListeningType = "ChannelData"; | |
_1c8.ChannelInfoMap = cmap; | |
var _1c9 = this.so.ISensor.RegisterForNotification(_1c8, cb); | |
if (_1c8) { | |
delete _1c8.ChannelInfoMap; | |
delete _1c8.ListeningType; | |
} | |
if (cmap) { | |
delete cmap.index; | |
} | |
_1c5[0] = _1c9["TransactionID"]; | |
if (_1c9.ErrorCode != 0) { | |
if (_1c9.ErrorCode == 1005) { | |
_1bf(new DeviceAPIError(_1c0.SERVICE_IN_USE_ERR, "Not Allowed Operation")); | |
return; | |
} else { | |
throw new DeviceAPIError(_1c0.NOT_SUPPORTED_ERR, "StartChannel:Operation Failed"); | |
} | |
} | |
} catch (e2) { | |
__device_handle_exception(e2, "__sp_sensors_setNotifier: RegisterForNotification: " + e2); | |
} | |
switch (_1be) { | |
case "Rotation": | |
__rotation_channel.tid = _1c5; | |
break; | |
case "AccelerometerAxis": | |
__XYZ_channel.tid = _1c5; | |
break; | |
case "Orientation": | |
__orientation_channel.tid = _1c5; | |
break; | |
} | |
return _1c5; | |
}; | |
function __sp_sensors_cancelNotifier(_1ca) { | |
var _1cb = new DeviceException(0, "dummy"); | |
if (!_1ca) { | |
throw new DeviceAPIError(_1cb.MISSING_ARG_ERR, "Channel is missing"); | |
} | |
if ((typeof _1ca) != "string") { | |
throw new DeviceAPIError(_1cb.INVALID_ARG_ERR, "Channel is of invalid type"); | |
} | |
var id; | |
switch (_1ca) { | |
case "Rotation": | |
id = __rotation_channel.tid; | |
__rotation_channel.tid = null; | |
break; | |
case "AccelerometerAxis": | |
id = __XYZ_channel.tid; | |
__XYZ_channel.tid = null; | |
break; | |
case "Orientation": | |
id = __orientation_channel.tid; | |
__orientation_channel.tid = null; | |
break; | |
default: | |
throw new DeviceAPIError(_1cb.NOT_SUPPORTED_ERR, "Unsupported input channel"); | |
} | |
if (!id) { | |
throw new DeviceAPIError(_1cb.DATA_NOT_FOUND_ERR, "Stop Channel:Operation Failed"); | |
} | |
var _1cd = {}; | |
modifyObjectBaseProp(_1cd); | |
for (var i in id) { | |
_1cd.TransactionID = id[i]; | |
try { | |
var _1cf = this.so.ISensor.Cancel(_1cd); | |
if (_1cd) { | |
delete _1cd.TransactionID; | |
} | |
if (_1cf.ErrorCode != 0) { | |
throw new DeviceAPIError(_1cb.DATA_NOT_FOUND_ERR, "Stop Channel:Operation Failed"); | |
} | |
} catch (e1) { | |
__device_handle_exception(e1, "__sp_sensors_cancelNotifier: " + e1); | |
} | |
} | |
}; | |
function __sp_sensors_getScaleFactor(_1d0) { | |
var _1d1 = new DeviceException(0, "dummy"); | |
if (!_1d0) { | |
throw new DeviceAPIError(_1d1.MISSING_ARG_ERR, "Channel is missing"); | |
} | |
if ((typeof _1d0) != "string") { | |
throw new DeviceAPIError(_1d1.INVALID_ARG_ERR, "Channel is of invalid type"); | |
} | |
if (_1d0 != "AccelerometerAxis") { | |
throw new DeviceAPIError(_1d1.NOT_SUPPORTED_ERR, "Unsupported input channel"); | |
} | |
try { | |
var _1d2 = {}; | |
_1d2.SearchCriterion = "AccelerometerAxis"; | |
var rval = this.so.ISensor.FindSensorChannel(_1d2); | |
if (_1d2) { | |
delete _1d2.SearchCriterion; | |
} | |
if (rval.ErrorCode != 0) { | |
throw new DeviceAPIError(_1d1.NOT_SUPPORTED_ERR, "getScaleFactor:Operation Failed"); | |
} | |
var cmap = []; | |
var _1d5 = rval["ReturnValue"]; | |
cmap = _1d5[0]; | |
var _1d6 = {}; | |
modifyObjectBaseProp(_1d6); | |
_1d6.ListeningType = "ChannelData"; | |
_1d6.ChannelInfoMap = cmap; | |
var _1d7 = this.so.ISensor.GetScaleFactor(_1d6); | |
if (_1d6) { | |
delete _1d6.ChannelInfoMap; | |
delete _1d6.ListeningType; | |
} | |
if (cmap) { | |
delete cmap.index; | |
} | |
if (_1d7.ErrorCode != 0) { | |
throw new DeviceAPIError(_1d1.NOT_SUPPORTED_ERR, "getScaleFactor:Operation Failed"); | |
} | |
} catch (e1) { | |
__device_handle_exception(e1, "__sp_sensors_getScaleFactor: " + e1); | |
} | |
return _1d7["ReturnValue"]; | |
}; | |
// Sensors end here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
21:40 < NoiseEee> ganzuul: as far as i can see, when something fires that __rotation_cb function, arg3 is holding the good stuff / good values and _1aa gets udpated with info from that, then sent to _rotation_channel function. i don't
see anything odd.