Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Toybox.Background;
- using Toybox.System as Sys;
- using Toybox.Sensor;
- using Toybox.ActivityRecording;
- // The Service Delegate is the main entry point for background processes
- // our onTemporalEvent() method will get run each time our periodic event
- // is triggered by the system. This indicates a set timer has expired, and
- // we should attempt to notify the user.
- (:background)
- class BackgroundServiceDelegate extends Sys.ServiceDelegate {
- function initialize() {
- ServiceDelegate.initialize();
- }
- function onTemporalEvent() {
- // Register callback for the accelerometer
- //var maxSampleRate = Sensor.getMaxSampleRate();
- var options = { :period => 1,
- :sampleRate => 20,
- :enableAccelerometer => true
- };
- Sensor.registerSensorDataListener(method(:accelCallback), options);
- }
- function accelCallback(sensorData) {
- // Reading from the accelerometr occured (after 20x calls, data are saved in the array for each X, Y, Z)
- if (sensorData.accelerometerData != null) {
- Background.exit(sensorData.accelerometerData.y);
- } else {
- Background.exit(null);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement