Index: sky/examples/shell/sensor.sky |
diff --git a/sky/examples/shell/sensor.sky b/sky/examples/shell/sensor.sky |
new file mode 100644 |
index 0000000000000000000000000000000000000000..80879a54ddd6dfa0a907f4315df95f4622f74a67 |
--- /dev/null |
+++ b/sky/examples/shell/sensor.sky |
@@ -0,0 +1,38 @@ |
+<script> |
+import '/sky/framework/shell.dart' as shell; |
+import 'dart:sky'; |
+import 'package:sky/services/sensors/sensors.mojom.dart'; |
+ |
+class MyListener extends SensorListener { |
+ int count = 0; |
+ |
+ void onAccuracyChanged(int accuracy) { |
+ print("onAccuracyChanged $accuracy"); |
+ } |
+ |
+ void onSensorChanged(SensorData data) { |
+ double value = data.values[0] + data.values[1] + data.values[2]; |
+ if (value > 40.0) { |
+ document.querySelector('div').textContent = |
+ "Shake count " + (count++).toString(); |
+ } |
+ } |
+ |
+ MyListener.unbound() { |
+ stub = new SensorListenerStub.unbound() |
+ ..delegate = this; |
+ } |
+ |
+ SensorListenerStub stub; |
+} |
+ |
+void main() { |
+ var sensorService = new SensorServiceProxy.unbound(); |
+ shell.requestService(sensorService); |
+ |
+ var listener = new MyListener.unbound(); |
+ sensorService.ptr.addListener(SensorType_ACCELEROMETER, listener.stub); |
+ listener.stub.listen(); |
+} |
+</script> |
+<div>Shake me.</div> |