Guest User

Untitled

a guest
Apr 14th, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import Toybox.Graphics;
  2. import Toybox.WatchUi;
  3. import Toybox.Timer;
  4. import Toybox.System;
  5.  
  6. class TestTimersView extends WatchUi.View {
  7. var timer1, timer2;
  8. function initialize() {
  9. View.initialize();
  10. timer1 = new Timer.Timer();
  11. timer2 = new Timer.Timer();
  12.  
  13. timer1.start(method(:onTimer1Expiry), 50, false);
  14. timer2.start(method(:onTimer2Expiry), 5000, true);
  15. }
  16.  
  17. function onLayout(dc as Dc) as Void {
  18. setLayout(Rez.Layouts.MainLayout(dc));
  19. }
  20.  
  21. function onUpdate(dc as Dc) as Void {
  22. System.println("onUpdate: " + System.getTimer());
  23. View.onUpdate(dc);
  24. }
  25.  
  26. var i = 0;
  27. function onTimer1Expiry() as Void {
  28. System.println("timer 1: " + System.getTimer());
  29. i++;
  30. if (i % 10 == 0) {
  31. WatchUi.requestUpdate();
  32. }
  33. timer1.start(method(:onTimer1Expiry), 50, false);
  34. }
  35.  
  36. static function onTimer2Expiry() as Void {
  37. System.println("timer 2: " + System.getTimer());
  38. }
  39. }
Add Comment
Please, Sign In to add comment