Advertisement
tomasslavicek

BackgroundServiceDelegate.mc

Nov 15th, 2017
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. using Toybox.Background;
  2. using Toybox.System as Sys;
  3. using Toybox.Sensor;
  4. using Toybox.ActivityRecording;
  5.  
  6. // The Service Delegate is the main entry point for background processes
  7. // our onTemporalEvent() method will get run each time our periodic event
  8. // is triggered by the system. This indicates a set timer has expired, and
  9. // we should attempt to notify the user.
  10. (:background)
  11. class BackgroundServiceDelegate extends Sys.ServiceDelegate {
  12.  
  13.    
  14.  
  15.     function initialize() {
  16.         ServiceDelegate.initialize();
  17.     }
  18.  
  19.     function onTemporalEvent() {      
  20.         // Register callback for the accelerometer
  21.         //var maxSampleRate = Sensor.getMaxSampleRate();
  22.         var options = { :period => 1,
  23.                         :sampleRate => 20,
  24.                         :enableAccelerometer => true
  25.         };
  26.         Sensor.registerSensorDataListener(method(:accelCallback), options);
  27.     }
  28.    
  29.     function accelCallback(sensorData) {    
  30.         // Reading from the accelerometr occured (after 20x calls, data are saved in the array for each X, Y, Z)
  31.         if (sensorData.accelerometerData != null) {
  32.             Background.exit(sensorData.accelerometerData.y);
  33.         } else {
  34.             Background.exit(null);
  35.         }
  36.     }
  37.    
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement