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(); }
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 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); }
protected override void OnStart() { CommunicationHandlerFactory.DiscoverDevices(); }