private async Task PlayAsync()
        {
            string warning   = null;
            var    deviceIds = Creation.GetDeviceIds();

            if (deviceIds == null || deviceIds.Count() == 0)
            {
                warning = Translate("NoControllerActions");
            }
            else if (deviceIds.Any(di => _deviceManager.GetDeviceById(di) == null))
            {
                warning = Translate("MissingDevices");
            }

            if (warning == null)
            {
                await NavigationService.NavigateToAsync <PlayerPageViewModel>(new NavigationParameters(("creation", Creation)));
            }
            else
            {
                await _dialogService.ShowMessageBoxAsync(
                    Translate("Warning"),
                    warning,
                    Translate("Ok"),
                    _disappearingTokenSource.Token);
            }
        }
        public ControllerActionPageViewModel(
            INavigationService navigationService,
            ITranslationService translationService,
            ICreationManager creationManager,
            IDeviceManager deviceManager,
            IDialogService dialogService,
            IPreferences preferences,
            NavigationParameters parameters)
            : base(navigationService, translationService)
        {
            _creationManager = creationManager;
            _deviceManager   = deviceManager;
            _dialogService   = dialogService;
            _preferences     = preferences;

            ControllerAction = parameters.Get <ControllerAction>("controlleraction", null);
            ControllerEvent  = parameters.Get <ControllerEvent>("controllerevent", null) ?? ControllerAction?.ControllerEvent;

            var device = _deviceManager.GetDeviceById(ControllerAction?.DeviceId);

            if (ControllerAction != null && device != null)
            {
                SelectedDevice             = device;
                Action.Channel             = ControllerAction.Channel;
                Action.IsInvert            = ControllerAction.IsInvert;
                Action.ChannelOutputType   = ControllerAction.ChannelOutputType;
                Action.MaxServoAngle       = ControllerAction.MaxServoAngle;
                Action.ButtonType          = ControllerAction.ButtonType;
                Action.AxisType            = ControllerAction.AxisType;
                Action.AxisCharacteristic  = ControllerAction.AxisCharacteristic;
                Action.MaxOutputPercent    = ControllerAction.MaxOutputPercent;
                Action.AxisDeadZonePercent = ControllerAction.AxisDeadZonePercent;
                Action.ServoBaseAngle      = ControllerAction.ServoBaseAngle;
                Action.StepperAngle        = ControllerAction.StepperAngle;
                Action.SequenceName        = ControllerAction.SequenceName;
            }
            else
            {
                var lastSelectedDeviceId = _preferences.Get <string>("LastSelectedDeviceId", null, "com.scn.BrickController2.ControllerActionPage");
                SelectedDevice             = _deviceManager.GetDeviceById(lastSelectedDeviceId) ?? _deviceManager.Devices.FirstOrDefault();
                Action.Channel             = 0;
                Action.IsInvert            = false;
                Action.ChannelOutputType   = ChannelOutputType.NormalMotor;
                Action.MaxServoAngle       = 90;
                Action.ButtonType          = ControllerButtonType.Normal;
                Action.AxisType            = ControllerAxisType.Normal;
                Action.AxisCharacteristic  = ControllerAxisCharacteristic.Linear;
                Action.MaxOutputPercent    = 100;
                Action.AxisDeadZonePercent = 0;
                Action.ServoBaseAngle      = 0;
                Action.StepperAngle        = 90;
                Action.SequenceName        = string.Empty;
            }

            SaveControllerActionCommand   = new SafeCommand(async() => await SaveControllerActionAsync(), () => SelectedDevice != null);
            DeleteControllerActionCommand = new SafeCommand(async() => await DeleteControllerActionAsync());
            OpenDeviceDetailsCommand      = new SafeCommand(async() => await OpenDeviceDetailsAsync(), () => SelectedDevice != null);
            OpenChannelSetupCommand       = new SafeCommand(async() => await OpenChannelSetupAsync(), () => SelectedDevice != null);
            OpenSequenceEditorCommand     = new SafeCommand(async() => await OpenSequenceEditorAsync());
        }
예제 #3
0
            public ControllerActionViewModel(ControllerAction controllerAction, IDeviceManager deviceManager)
            {
                ControllerAction = controllerAction;
                var device = deviceManager.GetDeviceById(controllerAction.DeviceId);

                DeviceMissing = device == null;
                DeviceName    = device != null ? device.Name : "Missing";
                ChannelName   = (device == null || device.DeviceType != DeviceType.Infrared) ? $"{controllerAction.Channel + 1}" : (controllerAction.Channel == 0 ? "Blue" : "Red");
                InvertName    = controllerAction.IsInvert ? "Inv" : string.Empty;
            }
            public ControllerActionViewModel(ControllerAction controllerAction, IDeviceManager deviceManager, ITranslationService translationService)
            {
                _translationService = translationService;

                ControllerAction = controllerAction;
                var device = deviceManager.GetDeviceById(controllerAction.DeviceId);

                DeviceMissing = device == null;
                DeviceName    = device != null ? device.Name : Translate("Missing");
                ChannelName   = (device == null || device.DeviceType != DeviceType.Infrared) ? $"{controllerAction.Channel + 1}" : (controllerAction.Channel == 0 ? Translate("Blue") : Translate("Red"));
                InvertName    = controllerAction.IsInvert ? Translate("Inv") : string.Empty;
            }
예제 #5
0
        private async Task PlayAsync()
        {
            string warning   = null;
            var    deviceIds = Creation.GetDeviceIds();

            if (deviceIds == null || deviceIds.Count() == 0)
            {
                warning = "There are no controller actions added to the creation.";
            }
            else if (deviceIds.Any(di => _deviceManager.GetDeviceById(di) == null))
            {
                warning = "There are missing devices in the creation setup.";
            }

            if (warning == null)
            {
                await NavigationService.NavigateToAsync <PlayerPageViewModel>(new NavigationParameters(("creation", Creation)));
            }
            else
            {
                await _dialogService.ShowMessageBoxAsync("Warning", warning, "Ok", _disappearingTokenSource.Token);
            }
        }
예제 #6
0
            public ControllerActionViewModel(
                ControllerAction controllerAction,
                IDeviceManager deviceManager,
                IPlayLogic playLogic,
                ITranslationService translationService)
            {
                ControllerAction = controllerAction;
                var device = deviceManager.GetDeviceById(controllerAction.DeviceId);

                ControllerActionValid = playLogic.ValidateControllerAction(controllerAction);
                DeviceName            = device != null ? device.Name : translationService.Translate("Missing");
                DeviceType            = device != null ? device.DeviceType : DeviceType.Unknown;
                Channel    = controllerAction.Channel;
                InvertName = controllerAction.IsInvert ? translationService.Translate("Inv") : string.Empty;
            }
예제 #7
0
        public ControllerActionPageViewModel(
            INavigationService navigationService,
            ITranslationService translationService,
            ICreationManager creationManager,
            IDeviceManager deviceManager,
            IDialogService dialogService,
            NavigationParameters parameters)
            : base(navigationService, translationService)
        {
            _creationManager = creationManager;
            _deviceManager   = deviceManager;
            _dialogService   = dialogService;

            ControllerAction = parameters.Get <ControllerAction>("controlleraction", null);
            ControllerEvent  = parameters.Get <ControllerEvent>("controllerevent", null) ?? ControllerAction.ControllerEvent;

            var device = _deviceManager.GetDeviceById(ControllerAction?.DeviceId);

            if (ControllerAction != null && device != null)
            {
                SelectedDevice      = device;
                Channel             = ControllerAction.Channel;
                IsInvert            = ControllerAction.IsInvert;
                ChannelOutputType   = ControllerAction.ChannelOutputType;
                MaxServoAngle       = ControllerAction.MaxServoAngle;
                ButtonType          = ControllerAction.ButtonType;
                AxisCharacteristic  = ControllerAction.AxisCharacteristic;
                MaxOutputPercent    = ControllerAction.MaxOutputPercent;
                AxisDeadZonePercent = ControllerAction.AxisDeadZonePercent;
            }
            else
            {
                SelectedDevice      = _deviceManager.Devices.FirstOrDefault();
                Channel             = 0;
                IsInvert            = false;
                ChannelOutputType   = ChannelOutputType.NormalMotor;
                MaxServoAngle       = 90;
                ButtonType          = ControllerButtonType.Normal;
                AxisCharacteristic  = ControllerAxisCharacteristic.Linear;
                MaxOutputPercent    = 100;
                AxisDeadZonePercent = 0;
            }

            SaveControllerActionCommand   = new SafeCommand(async() => await SaveControllerActionAsync(), () => SelectedDevice != null);
            DeleteControllerActionCommand = new SafeCommand(async() => await DeleteControllerActionAsync());
            OpenDeviceDetailsCommand      = new SafeCommand(async() => await OpenDeviceDetailsAsync(), () => SelectedDevice != null);
        }