예제 #1
0
        private async Task <bool> ChooseTelescope()
        {
            var dlg = new DlgChooseOat()
            {
                Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner
            };

            var result = dlg.ShowDialog();

            if (result == true)
            {
                //var chooser = new Chooser();
                //chooser.DeviceType = "Telescope";
                //var name = chooser.Choose("ASCOM.OpenAstroTracker.Telescope");
                //if (!string.IsNullOrEmpty(name))
                //{
                //	ScopeName = name;
                _commHandler = CommunicationHandlerFactory.ConnectToDevice(dlg.SelectedDevice);
                //_commHandler = new TcpCommunicationHandler(new IPAddress(new byte[] { 192, 168, 86, 61 }), 4030);
                _oatMount = new OatmealTelescopeCommandHandlers(_commHandler);
                await _oatMount.SetSiteLatitude((float)dlg.Latitude);

                await _oatMount.SetSiteLongitude((float)dlg.Longitude);

                return(true);
            }

            //	Settings.Default.Scope = name;

            //	Settings.Default.Save();
            //}

            RequeryCommands();
            return(false);
        }
        public DlgChooseOat(MountVM mountViewModel, Action <string, Action <CommandResponse> > sendCommand)
        {
            stateTimer          = new DispatcherTimer();
            stateTimer.Tick    += new EventHandler(ProcessStateMachine);
            stateTimer.Interval = TimeSpan.FromMilliseconds(100);

            _sendCommand        = sendCommand;
            _mountViewModel     = mountViewModel;
            _rollOffsetHistory  = new List <double>(5);
            _pitchOffsetHistory = new List <double>(5);
            _latitude           = Settings.Default.SiteLatitude;
            _longitude          = Settings.Default.SiteLongitude;
            _altitude           = Settings.Default.SiteAltitude;

            CurrentStep            = Steps.Idle;
            _rescanCommand         = new DelegateCommand(() => { CommunicationHandlerFactory.DiscoverDevices(); }, () => (_currentStep == Steps.Idle) || (_currentStep == Steps.WaitForBaudrate));
            _connectAndNextCommand = new DelegateCommand((o) => AdvanceStateMachine(), () => IsNextEnabled);

            this.DataContext = this;
            InitializeComponent();

            this.Result = false;

            stateTimer.Start();
        }
예제 #3
0
        public async Task OnDiscoverDevices()
        {
            WpfUtilities.RunOnUiThread(() => { AvailableDevices.Clear(); }, Application.Current.Dispatcher);

            CommunicationHandlerFactory.DiscoverDevices();
            await Task.Delay(500);

            foreach (var device in CommunicationHandlerFactory.AvailableDevices)
            {
                var handler = CommunicationHandlerFactory.AvailableHandlers.First(h => h.IsDriverForDevice(device));
                var driver  = new DeviceDriver(device, handler.SupportsSetupDialog, new DelegateCommand((p) => OnRunDeviceHandlerSetup(handler, p)));
                WpfUtilities.RunOnUiThread(() => { AvailableDevices.Add(driver); }, Application.Current.Dispatcher);
            }
        }
        public DlgChooseOat()
        {
            _latitude  = Settings.Default.SiteLatitude;
            _longitude = Settings.Default.SiteLongitude;
            _okCommand = new DelegateCommand(() =>
            {
                this.DialogResult              = true;
                Settings.Default.SiteLatitude  = Latitude;
                Settings.Default.SiteLongitude = Longitude;
                Settings.Default.Save();
                Close();
            }, () => SelectedDevice != null);
            _rescanCommand = new DelegateCommand(() => { CommunicationHandlerFactory.DiscoverDevices(); });

            this.DataContext = this;
            InitializeComponent();
        }
        public void ConnectToDevice()
        {
            var device = CommunicationHandlerFactory.ConnectToDevice(CommunicationHandlerFactory.AvailableDevices.First());

            _cmdHandler = new OatmealTelescopeCommandHandlers(device);

            _cmdHandler.MountState.PropertyChanged += MountStateOnPropertyChanged;

            Commands.Add("GoHome", new Command(async() =>
            {
                await _cmdHandler?.GoHome();
                await _cmdHandler?.RefreshMountState();
            }));

            Commands.Add("StartMoveDirection", new Command <string>(x => { _cmdHandler?.StartMoving(x); }));

            Commands.Add("StopMoveDirection", new Command <string>(x => { _cmdHandler?.StopMoving(x); }));

            Commands.Add("SetTracking", new Command <bool>(x => { _cmdHandler?.SetTracking(x); }));

            Commands.Add("SetLocation", new Command(async() =>
            {
                var location = await Geolocation.GetLocationAsync(new GeolocationRequest(GeolocationAccuracy.Default));
                await _cmdHandler?.SetLocation(location.Latitude, location.Longitude, 0, 0);
            }));

            Commands.Add("ToggleParkedState", new Command(async() =>
            {
                if (_cmdHandler != null)
                {
                    if (_cmdHandler.MountState.IsTracking)
                    {
                        await _cmdHandler?.SetTracking(false);
                    }
                    else
                    {
                        await _cmdHandler?.SetTracking(true);
                    }
                }
            }));

            _cmdHandler?.RefreshMountState();
        }
예제 #6
0
        public MountVM()
        {
            Log.WriteLine("Mount: Initialization starting...");
            CommunicationHandlerFactory.DiscoverDevices();
            Log.WriteLine("Mount: Device discovery started...");

            _startTime            = DateTime.UtcNow;
            _timerStatus          = new DispatcherTimer(TimeSpan.FromMilliseconds(500), DispatcherPriority.Normal, async(s, e) => await OnTimer(s, e), Application.Current.Dispatcher);
            _timerFineSlew        = new DispatcherTimer(TimeSpan.FromMilliseconds(200), DispatcherPriority.Normal, async(s, e) => await OnFineSlewTimer(s, e), Application.Current.Dispatcher);
            _arrowCommand         = new DelegateCommand(s => OnAdjustTarget(s.ToString()));
            _connectScopeCommand  = new DelegateCommand(() => OnConnectToTelescope());
            _slewToTargetCommand  = new DelegateCommand(async() => await OnSlewToTarget(), () => MountConnected);
            _syncToTargetCommand  = new DelegateCommand(async() => await OnSyncToTarget(), () => MountConnected);
            _syncToCurrentCommand = new DelegateCommand(() => OnSyncToCurrent(), () => MountConnected);
            _startSlewingCommand  = new DelegateCommand(async s => await OnStartSlewing(s.ToString()), () => MountConnected);
            _stopSlewingCommand   = new DelegateCommand(async() => await OnStopSlewing('a'), () => MountConnected);
            _homeCommand          = new DelegateCommand(async() => await OnHome(), () => MountConnected);
            _setHomeCommand       = new DelegateCommand(async() => await OnSetHome(), () => MountConnected);
            _parkCommand          = new DelegateCommand(async() => await OnPark(), () => MountConnected);
            _driftAlignCommand    = new DelegateCommand(async dur => await OnRunDriftAlignment(int.Parse(dur.ToString())), () => MountConnected);
            _polarAlignCommand    = new DelegateCommand(() => OnRunPolarAlignment(), () => MountConnected);

            _util      = new Util();
            _transform = new ASCOM.Astrometry.Transform.Transform();

            var poiFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "PointsOfInterest.xml");

            Log.WriteLine("Mount: Attempting to read Point of Interest from {0}...", poiFile);
            if (File.Exists(poiFile))
            {
                XDocument doc = XDocument.Load(poiFile);
                _pointsOfInterest = doc.Element("PointsOfInterest").Elements("Object").Select(e => new PointOfInterest(e)).ToList();
                _pointsOfInterest.Insert(0, new PointOfInterest("--- Select Target Object ---"));
                _selectedPointOfInterest = 0;
                Log.WriteLine("Mount: Successfully read {0} Points of Interest.", _pointsOfInterest.Count - 1);
            }

            this.Version = Assembly.GetExecutingAssembly().GetName().Version;
            Log.WriteLine("Mount: Initialization of OATControl {0} complete...", this.Version);
        }
예제 #7
0
 protected override void OnStart()
 {
     CommunicationHandlerFactory.DiscoverDevices();
 }