protected override void OnLeftRightDirectionChanged(RacerLeftRightDirection Direction)
        {
            if (Racer != null && Racer.IsConnected)
              {
            Racer.LeftRightDirection = Direction;
            Racer.GoAsync();
              }

              base.OnLeftRightDirectionChanged(Direction);
        }
        void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
        {
            double accelLR;
              double accelFB;

              if(IsPortrait())
              {
            accelLR = args.Reading.AccelerationX;
            accelFB = args.Reading.AccelerationY;
              }
              else
              {
            accelLR = args.Reading.AccelerationY;
            accelFB = args.Reading.AccelerationX;
              }

              double polarityLR = (Orientation == PageOrientation.None || Orientation == PageOrientation.PortraitUp || Orientation == PageOrientation.LandscapeRight) ? +1 : -1;

              double polarityFB = (Orientation == PageOrientation.None || Orientation == PageOrientation.PortraitUp || Orientation == PageOrientation.LandscapeLeft) ? +1 : -1;

              //Need to figure this out better.
              var lr = (int)Clamp((int)(accelLR * polarityLR * 10),-10,10);
              var fb = (int)Clamp((int)(accelFB * polarityFB * 10),-10,10);

              var lrval = Math.Round(Map(lr, -3, 3, -1, 1));
              var fbval = Math.Round(Map(fb, -3, 3, -1, 1));

              var lrdir = (RacerLeftRightDirection)lrval;
              var fbdir = (RacerForwardBackwardDirection)fbval;

              var speedval = (int)Math.Round(Map(Math.Abs(fb), 0, 6, 0, 15));

              //Debug.WriteLine("(x,y,z)=({0:N4},{1:N4},{2:N4})", args.Reading.AccelerationX, args.Reading.AccelerationY, args.Reading.AccelerationZ);
              //Debug.WriteLine("(lr,fb)=({0},{1})", lr, fb);
              Debug.WriteLine("(lr,fb) = ({0},{1}) - (lrval,fbvbal,speedval)=({2},{3},{4}) - (lrdir,fbdir,speedval)=({5},{6},{4})", lr, fb, lrval, fbval, speedval, lrdir, fbdir);

              if (leftRightDirection != lrdir)
              {
            OnLeftRightDirectionChanged(lrdir);
            leftRightDirection = lrdir;
              }
              if (forwardBackwardDirection != fbdir)
              {
            OnForwardBackwardDirectionChanged(fbdir);
            forwardBackwardDirection = fbdir;
              }
              if (speed != speedval)
              {
            OnSpeedChanged(speedval);
            speed = speedval;
              }
        }
 public RacerLeftRightDirectionChangedEventArgs(RacerLeftRightDirection Direction)
 {
     this.Direction = Direction;
 }
Пример #4
0
 protected virtual void OnLeftRightDirectionChanged(RacerLeftRightDirection Direction)
 {
     if (RacerLeftRightDirectionChanged != null)
     RacerLeftRightDirectionChanged(this, new RacerLeftRightDirectionChangedEventArgs(Direction));
 }