Exemple #1
0
        private async void draw_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            capture.IsEnabled = false;
            draw.IsEnabled    = false;
            if (_bestSolutionSoFar.Length == 0)
            {
                capture.IsEnabled = true;
                return;
            }

            // Reset the plotted bit on segments in case someone draws the same image again.
            foreach (var line in _tspSegments)
            {
                line.wasPlotted = false;
            }

            _timer.Start();

            await Task.Run(async() =>
            {
                var start = DateTime.Now;
                _pen.raise();
                await Task.Delay(kPenMoveTimeout);

                _bot.move((int)(_tspSegments[0].start.X + plottingOffsetX), (int)(_tspSegments[0].start.Y + plottingOffsetY));

                _bot.enable();
                while (_bot.run())
                {
                    ;
                }
                _bot.disable();

                TSPSegment.LineType currentType = _tspSegments[0].type;
                if (currentType == TSPSegment.LineType.Draw)
                {
                    _pen.lower();
                    await Task.Delay(kPenMoveTimeout);
                }

                foreach (var line in _tspSegments)
                {
                    if (line.type != currentType)
                    {
                        if (line.type == TSPSegment.LineType.Draw)
                        {
                            _pen.lower();
                            await Task.Delay(kPenMoveTimeout);
                        }
                        else
                        {
                            _pen.raise();
                            await Task.Delay(kPenMoveTimeout);
                        }

                        currentType = line.type;
                    }

                    _bot.move((int)(line.end.X + plottingOffsetX), (int)(line.end.Y + plottingOffsetY));
                    line.wasPlotted = true;

                    _bot.enable();
                    while (_bot.run())
                    {
                        ;
                    }
                    _bot.disable();
                }

                Debug.WriteLine("Render took: " + (DateTime.Now - start).TotalSeconds.ToString() + " seconds");

                _bot.home();
                _bot.enable();
                while (_bot.run())
                {
                    ;
                }
                _bot.disable();

                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    draw.IsEnabled    = true;
                    capture.IsEnabled = true;
                    _timer.Stop();
                });
            });
        }
Exemple #2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {

            base.OnNavigatedTo(e);

            draw.IsEnabled = false;

            _timer = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromMilliseconds(renderTimeout);
            _timer.Tick += _timer_Tick;

            await Task.Run(async () =>
            {
                _bot = new HBot(
                    HBotPin_AStep, HBotPin_ADir, HBotPin_AEn,
                    HBotPin_BStep, HBotPin_BDir, HBotPin_BEn,
                    HBotPin_XHome, HBotPin_YHome);
                _bot.setInfo(HBotBed_Width, HBotBed_Height, HBotBed_StepsPerMM);

                _pen = new PenActuator(HBotPin_PenServo);

                _pen.raise();
                await Task.Delay(kPenMoveTimeout);

                _bot.enable();
                _bot.home();
                while (_bot.run())
                    ;

                _bot.disable();
            });

            _mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
            await _mediaCaptureMgr.InitializeAsync(new MediaCaptureInitializationSettings { StreamingCaptureMode = StreamingCaptureMode.Video });

            VideoEncodingProperties smallestMedia = null;

            var cameraProperties = _mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Select(x => x as VideoEncodingProperties).ToList();
            if (cameraProperties.Count >= 1)
            {
                foreach (var mediaEncodingProperty in cameraProperties)
                {
                    if (smallestMedia == null ||
                        (smallestMedia.Width > mediaEncodingProperty.Width ||
                        smallestMedia.Height > mediaEncodingProperty.Height))
                    {
                        smallestMedia = mediaEncodingProperty;
                    }
                }
            }

            cameraWidth = smallestMedia.Width;
            cameraHeight = smallestMedia.Height;
            await _mediaCaptureMgr.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, smallestMedia);

            CapturePreview.Width = cameraWidth;
            CapturePreview.Height = cameraHeight;

            CapturePreview.Source = _mediaCaptureMgr;
            await _mediaCaptureMgr.StartPreviewAsync();

        }
Exemple #3
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            draw.IsEnabled = false;

            _timer          = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromMilliseconds(renderTimeout);
            _timer.Tick    += _timer_Tick;

            await Task.Run(async() =>
            {
                _bot = new HBot(
                    HBotPin_AStep, HBotPin_ADir, HBotPin_AEn,
                    HBotPin_BStep, HBotPin_BDir, HBotPin_BEn,
                    HBotPin_XHome, HBotPin_YHome);
                _bot.setInfo(HBotBed_Width, HBotBed_Height, HBotBed_StepsPerMM);

                _pen = new PenActuator(HBotPin_PenServo);

                _pen.raise();
                await Task.Delay(kPenMoveTimeout);

                _bot.enable();
                _bot.home();
                while (_bot.run())
                {
                    ;
                }

                _bot.disable();
            });

            _mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
            await _mediaCaptureMgr.InitializeAsync(new MediaCaptureInitializationSettings { StreamingCaptureMode = StreamingCaptureMode.Video });

            VideoEncodingProperties smallestMedia = null;

            var cameraProperties = _mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Select(x => x as VideoEncodingProperties).ToList();

            if (cameraProperties.Count >= 1)
            {
                foreach (var mediaEncodingProperty in cameraProperties)
                {
                    if (smallestMedia == null ||
                        (smallestMedia.Width > mediaEncodingProperty.Width ||
                         smallestMedia.Height > mediaEncodingProperty.Height))
                    {
                        smallestMedia = mediaEncodingProperty;
                    }
                }
            }

            cameraWidth  = smallestMedia.Width;
            cameraHeight = smallestMedia.Height;
            await _mediaCaptureMgr.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, smallestMedia);

            CapturePreview.Width  = cameraWidth;
            CapturePreview.Height = cameraHeight;

            CapturePreview.Source = _mediaCaptureMgr;
            await _mediaCaptureMgr.StartPreviewAsync();
        }