<li>Register a change listener to be called when the sensor data changes.
<p>To register a change listener, use the <span style="font-family: Courier New,Courier,monospace">setChangeListener()</span> method of the <span style="font-family: Courier New,Courier,monospace">Sensor</span> interface (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/sensor.html#Sensor">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/sensor.html#Sensor">wearable</a> applications).</p>
-<p>Whenever the sensor readout changes, the registered event handler is called and a <span style="font-family: Courier New,Courier,monospace">SensorData</span> object (in <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/sensor.html#SensorData">mobile</a> and <a href="../../../../../org.tizen.web.apireference/html/device_api/wearable/tizen/sensor.html#SensorData">wearable</a> applications) is passed to the listener.</p>
+<p>This command requires two parameters. The first one is a handle to the callback method, which will be invoked for every incoming event. The second argument determines the amount of time (in milliseconds) passing between two consecutive events. Valid values are integers in range <10, 1000> inclusively. For example, setting an <span style="font-family: Courier New,Courier,monospace">interval</span> to 100 results in approximately 10 events being send every second.</p>
<pre class="prettyprint">var proximitySensor = tizen.sensorservice.getDefaultSensor("PROXIMITY");
function onsuccessCB()
console.log("proximity distance: " + sensorData.proximityState);
}
+proximitySensor.setChangeListener(onchangedCB, 500);
+proximitySensor.start(onsuccessCB);</pre>
+The default value of <span style="font-family: Courier New,Courier,monospace">interval</span> parameter is 100. If you do not pass an <span style="font-family: Courier New,Courier,monospace">interval</span> value, a default one will be used:
+<pre class="prettyprint">var lightSensor = tizen.sensorservice.getDefaultSensor("LIGHT");
+
+function onsuccessCB()
+{
+ console.log("Light sensor service has started successfully.");
+}
+
+function onchangedCB(sensorData)
+{
+ console.log("Light sensor data: " + sensorData.lightLevel);
+}
+
+// use the default interval value (100 ms):
proximitySensor.setChangeListener(onchangedCB);
+
proximitySensor.start(onsuccessCB);</pre>
+
</li>
<li>To stop receiving notifications on sensor data changes, use the <span style="font-family: Courier New,Courier,monospace">unsetChangeListener()</span> method of the Sensor interface.
<td><a href="#Sensor">Sensor</a></td>
<td>void <a href="#Sensor::start">start</a> (<a href="tizen.html#SuccessCallback">SuccessCallback</a> successCallback, optional <a href="tizen.html#ErrorCallback">ErrorCallback</a>? errorCallback)<br>
void <a href="#Sensor::stop">stop</a> ()<br>
- void <a href="#Sensor::setChangeListener">setChangeListener</a> (<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback)<br>
+ void <a href="#Sensor::setChangeListener">setChangeListener</a> (<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback, optional long? interval)<br>
void <a href="#Sensor::unsetChangeListener">unsetChangeListener</a> ()</td>
</tr>
<tr>
void stop() raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
- void setChangeListener(<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback) raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
+ void setChangeListener(<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback, optional long? interval) raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
void unsetChangeListener() raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
};</pre>
<div class="brief">
Registers a change listener to be called when sensor data of the given type changes.
</div>
-<div class="synopsis"><pre class="signature prettyprint">void setChangeListener(<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback);
+<div class="synopsis"><pre class="signature prettyprint">void setChangeListener(<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback, optional long? interval);
</pre></div>
<p><span class="version">
Since: </span>
<span class="name">successCallback</span>:
Callback method to be invoked when the sensor data changes
</li>
+ <li class="param">
+ <span class="name">interval</span> <span class="optional">[optional]</span>:
+ The period in milliseconds at which events are invoked. Valid values are integers in range <10, 1000> inclusively. The default value is 100.
+ </li>
</ul>
</div>
<div class="exceptionlist">
</li></ul>
</div>
<div class="example">
-<span class="example"><p>Code example:</p></span><pre name="code" class="examplecode prettyprint"> var proximitySensor = tizen.sensorservice.getDefaultSensor("PROXIMITY");
+<span class="example"><p>Code example:</p></span><pre name="code" class="examplecode prettyprint">
+ var proximitySensor = tizen.sensorservice.getDefaultSensor("PROXIMITY");
function onsuccessCB() {
console.log("proximity sensor start");
console.log("proximity distance : " + sensorData.proximityState);
}
+ // order to receive proximity sensor data every 100 ms (default value):
proximitySensor.setChangeListener(onchangedCB);
+ // start the sensor service to begin receiving events:
proximitySensor.start(onsuccessCB);
+ </div><div class="example"><span class="example"><p>Code example:</p></span>
+ <pre name="code" class="examplecode prettyprint">
+ var lightSensor = tizen.sensorservice.getDefaultSensor("LIGHT");
+
+ function onSuccessCB() {
+ console.log("Light sensor service has started.");
+ }
+
+ function onChangedCB(sensorData) {
+ console.log("Current light level: " + sensorData.lightLevel);
+ }
+
+ // order to receive light sensor data every 500 ms:
+ lightSensor.setChangeListener(onChangedCB, 500);
+
+ // start the sensor service to begin receiving events:
+ lightSensor.start(onSuccessCB);
</pre>
</div>
</dd>
void stop() raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
- void setChangeListener(<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback) raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
+ void setChangeListener(<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback, optional long? interval) raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
void unsetChangeListener() raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
};
<td><a href="#Sensor">Sensor</a></td>
<td>void <a href="#Sensor::start">start</a> (<a href="tizen.html#SuccessCallback">SuccessCallback</a> successCallback, optional <a href="tizen.html#ErrorCallback">ErrorCallback</a>? errorCallback)<br>
void <a href="#Sensor::stop">stop</a> ()<br>
- void <a href="#Sensor::setChangeListener">setChangeListener</a> (<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback)<br>
+ void <a href="#Sensor::setChangeListener">setChangeListener</a> (<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback, optional long? interval)<br>
void <a href="#Sensor::unsetChangeListener">unsetChangeListener</a> ()</td>
</tr>
<tr>
void stop() raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
- void setChangeListener(<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback) raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
+ void setChangeListener(<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback, optional long? interval) raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
void unsetChangeListener() raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
};</pre>
<div class="brief">
Registers a change listener to be called when sensor data of the given type changes.
</div>
-<div class="synopsis"><pre class="signature prettyprint">void setChangeListener(<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback);
+<div class="synopsis"><pre class="signature prettyprint">void setChangeListener(<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback, optional long? interval);
</pre></div>
<p><span class="version">
Since: </span>
<li class="param">
<span class="name">successCallback</span>:
Callback method to be invoked when the sensor data changes
- </li>
+ </li>
+ <li class="param">
+<span class="name">interval</span> <span class="optional">[optional]</span>:
+The period in milliseconds at which events are invoked. Valid values are integers in range <10, 1000> inclusively. The default value is 100.
+ </li>
</ul>
</div>
<div class="exceptionlist">
</ul>
</li></ul>
</div>
-<div class="example">
-<span class="example"><p>Code example:</p></span><pre name="code" class="examplecode prettyprint"> var proximitySensor = tizen.sensorservice.getDefaultSensor("PROXIMITY");
+
+
+<div class="example"><span class="example"><p>Code example:</p></span><pre name="code" class="examplecode prettyprint">
+ var proximitySensor = tizen.sensorservice.getDefaultSensor("PROXIMITY");
function onsuccessCB() {
console.log("proximity sensor start");
console.log("proximity distance : " + sensorData.proximityState);
}
+ // order to receive proximity sensor data every 100 ms (default value):
proximitySensor.setChangeListener(onchangedCB);
+ // start the sensor service to begin receiving events:
proximitySensor.start(onsuccessCB);
+ </div>
+ <div class="example"><span class="example"><p>Code example:</p></span><pre name="code" class="examplecode prettyprint">
+ var lightSensor = tizen.sensorservice.getDefaultSensor("LIGHT");
+
+ function onSuccessCB() {
+ console.log("Light sensor service has started.");
+ }
+
+ function onChangedCB(sensorData) {
+ console.log("Current light level: " + sensorData.lightLevel);
+ }
+
+ // order to receive light sensor data every 500 ms:
+ lightSensor.setChangeListener(onChangedCB, 500);
+
+ // start the sensor service to begin receiving events:
+ lightSensor.start(onSuccessCB);
</pre>
</div>
+
</dd>
<dt class="method" id="Sensor::unsetChangeListener">
<a class="backward-compatibility-anchor" name="::Sensor::Sensor::unsetChangeListener"></a><code><b><span class="methodName">unsetChangeListener</span></b></code>
void stop() raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
- void setChangeListener(<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback) raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
+ void setChangeListener(<a href="#SensorDataSuccessCallback">SensorDataSuccessCallback</a> successCallback, optional long? interval) raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
void unsetChangeListener() raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
};