2 Replies
      Latest reply on May 2, 2020 11:50 AM by Claude31
      frincklebery Level 1 Level 1 (0 points)



        I am working on a personal project and have gotten the following (pertinent) variables from my Apple watch:





        What I want to implement is the following:


        If totalAcceleration > acceleration_THRESHOLD:

            Wait 3 seconds


            total_Xrotation = 0


            For the next 5 seconds:

                total_Xrotation += Xrotation


            If total_Xrotation > rotation_THRESHOLD:

               Activate watch vibration



        I am mainly unsure how to implement the timing rules.


        I come from a mainly non OOP background (Python mainly), so any assistance is much appreciated!

        • Re: Implementing Sequence
          PBK Level 7 Level 7 (3,765 points)

          Regarding timing, in objective C:

          theManager = [[CMMotionManager alloc] init];
          [theManager startAccelerometerUpdates];
          [theManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryZVertical toQueue:[NSOperationQueue mainQueue] withHandler:^(CMDeviceMotion *motion,NSError*error){
          //   code here that records motions 10 tiems per second and does something after recording 30 or 50 values 
          • Re: Implementing Sequence
            Claude31 Level 8 Level 8 (9,135 points)

            Take care not to block the main thread for 3 + 5 seconds.

            Dispatch to new threads for collecting data after a delay

            Such as:


                        DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + 3.0, execute: {
                            // Compute new value for rotation

            And of course do all UI in main thread.