# HG changeset patch # User Eugene Ostroukhov # Date 1276798653 25200 # Node ID 7d0a718a63463f84db4b0d80902bdc0db2d0f7cc # Parent 9bf326e3aeb94cea2d884b995cc03cc7c1f82cd8 Bug 3019 - Register orientation callback problems diff -r 9bf326e3aeb9 -r 7d0a718a6346 org.symbian.tools.wrttools/plugin.xml --- a/org.symbian.tools.wrttools/plugin.xml Wed Jun 16 17:56:07 2010 -0700 +++ b/org.symbian.tools.wrttools/plugin.xml Thu Jun 17 11:17:33 2010 -0700 @@ -919,53 +919,6 @@ - -var phoneNumber = "+6505551214"; - var text = "Sent from WRT application"; - var messaging = device.getServiceObject("Service.Messaging", "IMessaging"); - var result = messaging.IMessaging.Send({ MessageType : "SMS", To : phoneNumber, BodyText : text }); - if (result.ErrorCode != null) { - var errorCode = result.ErrorCode; - var errorMessage = result.ErrorMessage; - // TODO Cannot send SMS message - } - - - - -var sensors = device.getServiceObject("Service.Sensor", "ISensor"); - var SensorParams = { - SearchCriterion : "Orientation" - }; - var result = sensors.ISensor.FindSensorChannel(SensorParams); - - if (result.ErrorCode == 0) { - // TODO Function named "orientationCallback" will be called when device orientation changes. This function should be created. - var result2 = sensors.ISensor.RegisterForNotification({ ChannelInfoMap : result.ReturnValue[0], ListeningType : "ChannelData" }, orientationCallback); - if (result.ErrorCode == 0) { - var transactionId = result.TransactionID; - // TODO Use this transaction ID to cancel notifications when watching orientation is no longer needed - } else { - var errorCode = result.ErrorCode; - var errorMessage = result.ErrorMessage; - // TODO Handle error - } - } else { - var errorCode = result.ErrorCode; - var errorMessage = result.ErrorMessage; - // TODO Handle error - } - - - @@ -999,23 +952,41 @@ + label="Send SMS message"> -// This function can be passed as callback to locationService.ILocation.GetLocation -// or locationService.ILocation.Trace method -function orientationCallback(transactionId, code, result) { +var phoneNumber = "+6505551214"; + var text = "Sent from WRT application"; + var messaging = device.getServiceObject("Service.Messaging", "IMessaging"); + var result = messaging.IMessaging.Send({ MessageType : "SMS", To : phoneNumber, BodyText : text }); + if (result.ErrorCode != null) { + var errorCode = result.ErrorCode; + var errorMessage = result.ErrorMessage; + // TODO Cannot send SMS message + } + + + + +// This function can be passed as callback to +// sensors.ISensor.RegisterForNotification method +function sensorCallback(transactionId, code, result) { if (result.ErrorCode == 0) { - var orientation = result.ReturnValue.DeviceOrientation; - // TODO Possible values: - // "Undefined" - // "DisplayUp" - // "DisplayDown" - // "DisplayLeftUp" - // "DisplayRightUp" - // "DisplayUpwards" - // "DisplayDownwards" + // TODO Process notification + var dataType = result.ReturnValue.DataType; // One of: "AxisData", "DoubleTappingData", "OrientationData" or "RotationData" + // var xAxis = result.ReturnValue.XAxisData; // Accelerometer + // var yAxis = result.ReturnValue.YAxisData; // Accelerometer + // var zAxis = result.ReturnValue.ZAxisData; // Accelerometer + // var direction = result.ReturnValue.DeviceDirection; // Accelerometer double tapping + // var orientation = result.ReturnValue.DeviceOrientation; // Orientation + // var xRotation = result.ReturnValue.XRotation; // Rotation + // var yRotation = result.ReturnValue.YRotation; // Rotation + // var zRotation = result.ReturnValue.ZRotation; // Rotation } else { var errorCode = result.ErrorCode; var errorMessage = result.ErrorMessage; @@ -1024,6 +995,47 @@ } + + +// Call this function to add a callback that will be notified of orientation changes +function watchSensorNotifications(sensorCallback) { + var sensors = device.getServiceObject("Service.Sensor", "ISensor"); + var SensorParams = { + SearchCriterion : "Orientation" // TODO Possible values (one of): + // SearchCriterion : "All" + // SearchCriterion : "AccelerometerAxis" + // SearchCriterion : "AccelerometerDoubleTapping" + // SearchCriterion : "Rotation" + }; + var result = sensors.ISensor.FindSensorChannel(SensorParams); + + if (result.ErrorCode != 0) { + var errorCode = result.ErrorCode; + var errorMessage = result.ErrorMessage; + // TODO Handle error + return null; + } + // TODO Function named "orientationCallback" will be called when device orientation changes. This function should be created. + var result2 = sensors.ISensor.RegisterForNotification( + { ChannelInfoMap : result.ReturnValue[0], + ListeningType : "ChannelData" }, sensorCallback); + if (result.ErrorCode == 0) { + var transactionId = result.TransactionID; + // TODO Use this transaction ID to cancel notifications when watching orientation is no longer needed + return transactionId; + } else { + var errorCode = result.ErrorCode; + var errorMessage = result.ErrorMessage; + // TODO Handle error + return null; + } +} + +