Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Toybox.Background;
- using Toybox.System;
- using Toybox.Communications as Comm;
- (:background)
- class GetDataListener extends Comm.ConnectionListener
- {
- function initialize()
- {
- Comm.ConnectionListener.initialize();
- }
- public function onComplete()
- {
- System.println("oncomplete");
- }
- public function onError()
- {
- System.println("onerror");
- Background.exit("error");
- }
- }
- (:background)
- class BackgroundServiceDelegate extends System.ServiceDelegate {
- var communications;
- function initialize()
- {
- $.is_background = true;
- System.println("BackgroundServiceDelegate::nitialize");
- //var communications = new MyComms();
- ServiceDelegate.initialize();
- //Comm.registerForPhoneAppMessages(method(:on_received));
- }
- function onTemporalEvent()
- {
- var time = System.getClockTime();
- System.println(Lang.format("BackgroundServiceDelegate::onTemporalEvent: $1$:$2$:$3$", [time.hour, time.min, time.sec]));
- //Background.requestApplicationWake("Your timer has expired!");
- if (System.getDeviceSettings().phoneConnected)
- {
- Comm.registerForPhoneAppMessages(method(:on_received));
- //communications.enqueue(Communications.MESSAGE_TYPE_GET_DATA);
- System.println("BackgroundServiceDelegate::onTemporalEvent - before transmit");
- Comm.transmit(MyComms.MESSAGE_TYPE_GET_DATA, null, new GetDataListener());
- System.println("BackgroundServiceDelegate::onTemporalEvent - after transmit");
- }
- else
- {
- Background.exit(0);
- }
- }
- function on_received(msg)
- {
- var time = System.getClockTime();
- System.println(Lang.format("BackgroundServiceDelegate::on_received: $1$:$2$:$3$", [time.hour, time.min, time.sec]));
- Background.exit(msg.data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment