OLD | NEW |
(Empty) | |
| 1 <script> |
| 2 import '/sky/framework/shell.dart' as shell; |
| 3 import 'dart:sky'; |
| 4 import 'package:sky/services/sensors/sensors.mojom.dart'; |
| 5 |
| 6 class MyListener extends SensorListener { |
| 7 int count = 0; |
| 8 |
| 9 void onAccuracyChanged(int accuracy) { |
| 10 print("onAccuracyChanged $accuracy"); |
| 11 } |
| 12 |
| 13 void onSensorChanged(SensorData data) { |
| 14 double value = data.values[0] + data.values[1] + data.values[2]; |
| 15 if (value > 40.0) { |
| 16 document.querySelector('div').textContent = |
| 17 "Shake count " + (count++).toString(); |
| 18 } |
| 19 } |
| 20 |
| 21 MyListener.unbound() { |
| 22 stub = new SensorListenerStub.unbound() |
| 23 ..delegate = this; |
| 24 } |
| 25 |
| 26 SensorListenerStub stub; |
| 27 } |
| 28 |
| 29 void main() { |
| 30 var sensorService = new SensorServiceProxy.unbound(); |
| 31 shell.requestService(sensorService); |
| 32 |
| 33 var listener = new MyListener.unbound(); |
| 34 sensorService.ptr.addListener(SensorType_ACCELEROMETER, listener.stub); |
| 35 listener.stub.listen(); |
| 36 } |
| 37 </script> |
| 38 <div>Shake me.</div> |
OLD | NEW |