Exemplo n.º 1
0
        public bool StreamingToolChange(StreamingState newState, bool always)
        {
            bool changed = streamingState != newState;

            switch (newState)
            {
            case StreamingState.ToolChange:
                model.IsJobRunning = false;     // only enable UI if no ATC?
                btnStart.IsEnabled = true;
                btnHold.IsEnabled  = false;
                btnStop.IsEnabled  = true;
                break;

            case StreamingState.Idle:
            case StreamingState.Send:
                if (JobTimer.IsRunning)
                {
                    model.IsJobRunning = true;
                    if (job.ToolChangeLine >= 0)
                    {
                        GCode.File.Data.Rows[job.ToolChangeLine]["Sent"] = "ok";
                        job.ToolChangeLine = -1;
                    }
                    SetStreamingHandler(StreamingHandler.SendFile);
                    // SendNextLine();
                }
                else
                {
                    SetStreamingHandler(StreamingHandler.Previous);
                }
                break;

            case StreamingState.Error:
                SetStreamingHandler(StreamingHandler.Previous);
                break;

            case StreamingState.Stop:
                SetStreamingHandler(StreamingHandler.Idle);
                break;
            }

            if (streamingHandler.Handler != StreamingHandler.ToolChange)
            {
                return(streamingHandler.Call(newState, true));
            }
            else if (changed)
            {
                model.StreamingState = streamingState = newState;
                StreamingStateChanged?.Invoke(streamingState, grblState.MPG);
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool StreamingAwaitIdle(StreamingState newState, bool always)
        {
            bool changed = streamingState != newState || newState == StreamingState.Idle;

            if (changed || always)
            {
                switch (newState)
                {
                case StreamingState.Idle:
                    model.RunTime = JobTimer.RunTime;
                    JobTimer.Stop();
                    RewindFile();
                    SetStreamingHandler(StreamingHandler.Idle);
                    break;

                case StreamingState.Error:
                case StreamingState.Halted:
                    btnStart.IsEnabled = !GrblSettings.IsGrblHAL;
                    btnHold.IsEnabled  = false;
                    btnStop.IsEnabled  = true;
                    break;

                case StreamingState.Send:
                    btnStart.IsEnabled  = false;
                    btnHold.IsEnabled   = true;
                    btnStop.IsEnabled   = true;
                    btnRewind.IsEnabled = false;
                    break;

                case StreamingState.FeedHold:
                    SetStreamingHandler(StreamingHandler.FeedHold);
                    break;

                case StreamingState.Stop:
                    SetStreamingHandler(StreamingHandler.Idle);
                    break;
                }
            }

            if (streamingHandler.Handler != StreamingHandler.AwaitIdle)
            {
                return(streamingHandler.Call(newState, true));
            }
            else if (changed)
            {
                model.StreamingState = streamingState = newState;
                StreamingStateChanged?.Invoke(streamingState, grblState.MPG);
            }

            return(true);
        }
Exemplo n.º 3
0
        public bool StreamingAwaitAction(StreamingState newState, bool always)
        {
            bool changed = streamingState != newState || newState == StreamingState.Idle;

            if (changed || always)
            {
                switch (newState)
                {
                case StreamingState.Idle:
                    btnStart.IsEnabled = !GrblSettings.IsGrblHAL;
                    break;

                case StreamingState.Stop:
                    if (GrblSettings.IsGrblHAL && !model.GrblReset)
                    {
                        Comms.com.WriteByte(GrblConstants.CMD_STOP);
                    }
                    newState = StreamingState.Idle;
                    SetStreamingHandler(StreamingHandler.AwaitIdle);
                    break;

                case StreamingState.Paused:
                    btnHold.IsEnabled = false;
                    btnStop.IsEnabled = true;
                    break;

                case StreamingState.Send:
                    SetStreamingHandler(StreamingHandler.SendFile);
                    SendNextLine();
                    break;

                case StreamingState.JobFinished:
                    SetStreamingHandler(StreamingHandler.SendFile);
                    break;
                }
            }

            if (streamingHandler.Handler != StreamingHandler.AwaitAction)
            {
                return(streamingHandler.Call(newState, true));
            }
            else if (changed)
            {
                model.StreamingState = streamingState = newState;
                StreamingStateChanged?.Invoke(streamingState, grblState.MPG);
            }

            return(true);
        }
Exemplo n.º 4
0
        public bool StreamingFeedHold(StreamingState newState, bool always)
        {
            bool changed = streamingState != newState;

            if (always || changed)
            {
                switch (newState)
                {
                case StreamingState.Halted:
                case StreamingState.FeedHold:
                    btnStart.IsEnabled = true;
                    btnHold.IsEnabled  = false;
                    if ((btnStop.IsEnabled = model.IsJobRunning || model.IsSDCardJob) && !GrblInfo.IsGrblHAL)
                    {
                        btnStop.Content = (string)FindResource("JobStop");
                    }
                    streamingHandler.Count = job.CurrentRow != null;
                    break;

                case StreamingState.Send:
                case StreamingState.Error:
                case StreamingState.Idle:
                    SetStreamingHandler(StreamingHandler.Previous);
                    break;

                case StreamingState.Stop:
                    SetStreamingHandler(StreamingHandler.Idle);
                    break;
                }
            }

            if (streamingHandler.Handler != StreamingHandler.FeedHold)
            {
                return(streamingHandler.Call(newState, true));
            }
            else if (changed)
            {
                model.StreamingState = streamingState = newState;
                StreamingStateChanged?.Invoke(streamingState, grblState.MPG);
            }

            return(true);
        }
Exemplo n.º 5
0
        public bool StreamingFeedHold(StreamingState newState, bool always)
        {
            bool changed = streamingState != newState;

            if (always || changed)
            {
                switch (newState)
                {
                case StreamingState.Halted:
                case StreamingState.FeedHold:
                    btnStart.IsEnabled = true;
                    btnHold.IsEnabled  = false;
                    btnStop.IsEnabled  = model.IsJobRunning;
                    break;

                case StreamingState.Send:
                case StreamingState.Error:
                case StreamingState.Idle:
                    SetStreamingHandler(StreamingHandler.Previous);
                    break;

                case StreamingState.Stop:
                    SetStreamingHandler(StreamingHandler.Idle);
                    break;
                }
            }

            if (streamingHandler.Handler != StreamingHandler.FeedHold)
            {
                return(streamingHandler.Call(newState, true));
            }
            else if (changed)
            {
                model.StreamingState = streamingState = newState;
                StreamingStateChanged?.Invoke(streamingState, grblState.MPG);
            }

            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Update message handler
        /// </summary>
        /// <param name="eventType">Value of "event-type" in the JSON body</param>
        /// <param name="body">full JSON message body</param>
        protected void ProcessEventType(string eventType, JObject body)
        {
            StreamStatus status;

            switch (eventType)
            {
            case "SwitchScenes":
                SceneChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "ScenesChanged":
                SceneListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SourceOrderChanged":
                SourceOrderChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "SceneItemAdded":
                SceneItemAdded?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneItemRemoved":
                SceneItemRemoved?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneItemVisibilityChanged":
                SceneItemVisibilityChanged?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneCollectionChanged":
                SceneCollectionChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SceneCollectionListChanged":
                SceneCollectionListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SwitchTransition":
                TransitionChanged?.Invoke(this, (string)body["transition-name"]);
                break;

            case "TransitionDurationChanged":
                TransitionDurationChanged?.Invoke(this, (int)body["new-duration"]);
                break;

            case "TransitionListChanged":
                TransitionListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "TransitionBegin":
                TransitionBegin?.Invoke(this, EventArgs.Empty);
                break;

            case "ProfileChanged":
                ProfileChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "ProfileListChanged":
                ProfileListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "StreamStarting":
                StreamingStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "StreamStarted":
                StreamingStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "StreamStopping":
                StreamingStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "StreamStopped":
                StreamingStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "RecordingStarting":
                RecordingStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "RecordingStarted":
                RecordingStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "RecordingStopping":
                RecordingStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "RecordingStopped":
                RecordingStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "StreamStatus":
                if (StreamStatus != null)
                {
                    status = new StreamStatus(body);
                    StreamStatus(this, status);
                }
                break;

            case "PreviewSceneChanged":
                PreviewSceneChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "StudioModeSwitched":
                StudioModeSwitched?.Invoke(this, (bool)body["new-state"]);
                break;

            case "ReplayStarting":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "ReplayStarted":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "ReplayStopping":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "ReplayStopped":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "Exiting":
                OBSExit?.Invoke(this, EventArgs.Empty);
                break;

            case "Heartbeat":
                Heartbeat?.Invoke(this, new Heartbeat(body));
                break;

            case "SceneItemDeselected":
                SceneItemDeselected?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                break;

            case "SceneItemSelected":
                SceneItemSelected?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                break;

            case "SceneItemTransformChanged":
                SceneItemTransformChanged?.Invoke(this, new SceneItemTransformInfo(body));
                break;

            case "SourceAudioMixersChanged":
                SourceAudioMixersChanged?.Invoke(this, new AudioMixersChangedInfo(body));
                break;

            case "SourceAudioSyncOffsetChanged":
                SourceAudioSyncOffsetChanged?.Invoke(this, (string)body["sourceName"], (int)body["syncOffset"]);
                break;

            case "SourceCreated":
                SourceCreated?.Invoke(this, new SourceSettings(body));
                break;

            case "SourceDestroyed":
                SourceDestroyed?.Invoke(this, (string)body["sourceName"], (string)body["sourceType"], (string)body["sourceKind"]);
                break;

            case "SourceRenamed":
                SourceRenamed?.Invoke(this, (string)body["newName"], (string)body["previousName"]);
                break;

            case "SourceMuteStateChanged":
                SourceMuteStateChanged?.Invoke(this, (string)body["sourceName"], (bool)body["muted"]);
                break;

            case "SourceVolumeChanged":
                SourceVolumeChanged?.Invoke(this, (string)body["sourceName"], (float)body["volume"]);
                break;

            case "SourceFilterAdded":
                SourceFilterAdded?.Invoke(this, (string)body["sourceName"], (string)body["filterName"], (string)body["filterType"], (JObject)body["filterSettings"]);
                break;

            case "SourceFilterRemoved":
                SourceFilterRemoved?.Invoke(this, (string)body["sourceName"], (string)body["filterName"]);
                break;

            case "SourceFiltersReordered":
                List <FilterReorderItem> filters = new List <FilterReorderItem>();
                JsonConvert.PopulateObject(body["filters"].ToString(), filters);
                SourceFiltersReordered?.Invoke(this, (string)body["sourceName"], filters);
                break;
            }
        }
        /// <summary>
        /// Update message handler
        /// </summary>
        /// <param name="eventType">Value of "event-type" in the JSON body</param>
        /// <param name="body">full JSON message body</param>
        protected void ProcessEventType(string eventType, JObject body)
        {
            StreamStatus status;

            switch (eventType)
            {
            case "SwitchScenes":
                SceneChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "ScenesChanged":
                SceneListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SourceOrderChanged":
                SourceOrderChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "SceneItemAdded":
                SceneItemAdded?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneItemRemoved":
                SceneItemRemoved?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneItemVisibilityChanged":
                SceneItemVisibilityChanged?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (bool)body["item-visible"]);
                break;

            case "SceneItemLockChanged":
                SceneItemLockChanged?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (int)body["item-id"], (bool)body["item-locked"]);
                break;

            case "SceneCollectionChanged":
                SceneCollectionChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SceneCollectionListChanged":
                SceneCollectionListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SwitchTransition":
                TransitionChanged?.Invoke(this, (string)body["transition-name"]);
                break;

            case "TransitionDurationChanged":
                TransitionDurationChanged?.Invoke(this, (int)body["new-duration"]);
                break;

            case "TransitionListChanged":
                TransitionListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "TransitionBegin":
                TransitionBegin?.Invoke(this, (string)body["name"], (string)body["type"], (int)body["duration"], (string)body["from-scene"], (string)body["to-scene"]);
                break;

            case "TransitionEnd":
                TransitionEnd?.Invoke(this, (string)body["name"], (string)body["type"], (int)body["duration"], (string)body["to-scene"]);
                break;

            case "TransitionVideoEnd":
                TransitionVideoEnd?.Invoke(this, (string)body["name"], (string)body["type"], (int)body["duration"], (string)body["from-scene"], (string)body["to-scene"]);
                break;

            case "ProfileChanged":
                ProfileChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "ProfileListChanged":
                ProfileListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "StreamStarting":
                StreamingStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "StreamStarted":
                StreamingStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "StreamStopping":
                StreamingStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "StreamStopped":
                StreamingStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "RecordingStarting":
                RecordingStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "RecordingStarted":
                RecordingStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "RecordingStopping":
                RecordingStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "RecordingStopped":
                RecordingStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "RecordingPaused":
                RecordingPaused?.Invoke(this, EventArgs.Empty);
                break;

            case "RecordingResumed":
                RecordingResumed?.Invoke(this, EventArgs.Empty);
                break;

            case "StreamStatus":
                if (StreamStatus != null)
                {
                    status = new StreamStatus(body);
                    StreamStatus(this, status);
                }
                break;

            case "PreviewSceneChanged":
                PreviewSceneChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "StudioModeSwitched":
                StudioModeSwitched?.Invoke(this, (bool)body["new-state"]);
                break;

            case "ReplayStarting":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "ReplayStarted":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "ReplayStopping":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "ReplayStopped":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "Exiting":
                OBSExit?.Invoke(this, EventArgs.Empty);
                break;

            case "Heartbeat":
                Heartbeat?.Invoke(this, new Heartbeat(body));
                break;

            case "SceneItemDeselected":
                SceneItemDeselected?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                break;

            case "SceneItemSelected":
                SceneItemSelected?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                break;

            case "SceneItemTransformChanged":
                SceneItemTransformChanged?.Invoke(this, new SceneItemTransformInfo(body));
                break;

            case "SourceAudioMixersChanged":
                SourceAudioMixersChanged?.Invoke(this, new AudioMixersChangedInfo(body));
                break;

            case "SourceAudioSyncOffsetChanged":
                SourceAudioSyncOffsetChanged?.Invoke(this, (string)body["sourceName"], (int)body["syncOffset"]);
                break;

            case "SourceCreated":
                SourceCreated?.Invoke(this, new SourceSettings(body));
                break;

            case "SourceDestroyed":
                SourceDestroyed?.Invoke(this, (string)body["sourceName"], (string)body["sourceType"], (string)body["sourceKind"]);
                break;

            case "SourceRenamed":
                SourceRenamed?.Invoke(this, (string)body["newName"], (string)body["previousName"]);
                break;

            case "SourceMuteStateChanged":
                SourceMuteStateChanged?.Invoke(this, (string)body["sourceName"], (bool)body["muted"]);
                break;

            case "SourceAudioDeactivated":
                SourceAudioDeactivated?.Invoke(this, (string)body["sourceName"]);
                break;

            case "SourceAudioActivated":
                SourceAudioActivated?.Invoke(this, (string)body["sourceName"]);
                break;

            case "SourceVolumeChanged":
                SourceVolumeChanged?.Invoke(this, new SourceVolume(body));
                break;

            case "SourceFilterAdded":
                SourceFilterAdded?.Invoke(this, (string)body["sourceName"], (string)body["filterName"], (string)body["filterType"], (JObject)body["filterSettings"]);
                break;

            case "SourceFilterRemoved":
                SourceFilterRemoved?.Invoke(this, (string)body["sourceName"], (string)body["filterName"]);
                break;

            case "SourceFiltersReordered":
                if (SourceFiltersReordered != null)
                {
                    List <FilterReorderItem> filters = new List <FilterReorderItem>();
                    JsonConvert.PopulateObject(body["filters"].ToString(), filters);

                    SourceFiltersReordered?.Invoke(this, (string)body["sourceName"], filters);
                }
                break;

            case "SourceFilterVisibilityChanged":
                SourceFilterVisibilityChanged?.Invoke(this, (string)body["sourceName"], (string)body["filterName"], (bool)body["filterEnabled"]);
                break;

            case "BroadcastCustomMessage":
                BroadcastCustomMessageReceived?.Invoke(this, (string)body["realm"], (JObject)body["data"]);
                break;

            case "MediaEnded":
                MediaEnded?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaStarted":
                MediaStarted?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaPrevious":
                MediaPrevious?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaNext":
                MediaNext?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaStopped":
                MediaStopped?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaRestarted":
                MediaRestarted?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaPaused":
                MediaPaused?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaPlaying":
                MediaPlaying?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "VirtualCamStarted":
                VirtualCameraStarted?.Invoke(this, EventArgs.Empty);
                break;

            case "VirtualCamStopped":
                VirtualCameraStopped?.Invoke(this, EventArgs.Empty);
                break;

            default:
                var message = $"Unsupported Event: {eventType}\n{body}";
                Console.WriteLine(message);
                Debug.WriteLine(message);
                break;
            }
        }
Exemplo n.º 8
0
        public bool StreamingIdle(StreamingState newState, bool always)
        {
            bool changed = streamingState != newState || newState == StreamingState.Idle;

            if (changed || always)
            {
                switch (newState)
                {
                case StreamingState.Disabled:
                    IsEnabled = false;
                    break;

                case StreamingState.Idle:
                case StreamingState.NoFile:
                    IsEnabled           = !grblState.MPG;
                    btnStart.IsEnabled  = GCode.File.IsLoaded;
                    btnStop.IsEnabled   = false;
                    btnHold.IsEnabled   = !grblState.MPG;
                    btnRewind.IsEnabled = !grblState.MPG && GCode.File.IsLoaded && job.CurrLine != 0;
                    model.IsJobRunning  = JobTimer.IsRunning;
                    break;

                case StreamingState.Send:
                    if (!string.IsNullOrEmpty(model.FileName) && !grblState.MPG)
                    {
                        model.IsJobRunning = true;
                    }
                    if (JobTimer.IsRunning)
                    {
                        SetStreamingHandler(StreamingHandler.SendFile);
                    }
                    else
                    {
                        btnStop.IsEnabled = true;
                        btnHold.IsEnabled = !grblState.MPG;
                    }
                    break;

                case StreamingState.Start:     // Streaming from SD Card
                    job.IsSDFile = true;
                    JobTimer.Start();
                    break;

                case StreamingState.Error:
                case StreamingState.Halted:
                    btnStart.IsEnabled = !grblState.MPG;
                    btnHold.IsEnabled  = false;
                    btnStop.IsEnabled  = !grblState.MPG;
                    break;

                case StreamingState.FeedHold:
                    SetStreamingHandler(StreamingHandler.FeedHold);
                    break;

                case StreamingState.ToolChange:
                    SetStreamingHandler(StreamingHandler.ToolChange);
                    break;

                case StreamingState.Stop:
                    btnHold.IsEnabled   = !(grblState.MPG || grblState.State == GrblStates.Alarm);
                    btnStart.IsEnabled  = btnHold.IsEnabled && GCode.File.IsLoaded;    //!GrblSettings.IsGrblHAL;
                    btnStop.IsEnabled   = false;
                    btnRewind.IsEnabled = false;
                    job.IsSDFile        = false;
                    model.IsJobRunning  = false;
                    if (!grblState.MPG)
                    {
                        if (GrblSettings.IsGrblHAL)
                        {
                            if (!model.GrblReset)
                            {
                                Comms.com.WriteByte(GrblConstants.CMD_STOP);
                            }
                        }
                        else if (grblState.State == GrblStates.Hold)
                        {
                            Comms.com.WriteByte(GrblConstants.CMD_RESET);
                        }
                    }
                    if (JobTimer.IsRunning)
                    {
                        always = false;
                        model.StreamingState = streamingState = streamingState == StreamingState.Error ? StreamingState.Idle : newState;
                        SetStreamingHandler(StreamingHandler.AwaitIdle);
                    }
                    else if (grblState.State != GrblStates.Alarm)
                    {
                        return(streamingHandler.Call(StreamingState.Idle, true));
                    }
                    break;
                }
            }

            if (streamingHandler.Handler != StreamingHandler.Idle)
            {
                return(streamingHandler.Call(newState, always));
            }
            else if (changed)
            {
                model.StreamingState = streamingState = newState;
                StreamingStateChanged?.Invoke(streamingState, grblState.MPG);
            }

            return(true);
        }
Exemplo n.º 9
0
        public bool StreamingSendFile(StreamingState newState, bool always)
        {
            bool changed = streamingState != newState;

            if (changed || always)
            {
                switch (newState)
                {
                case StreamingState.Idle:
                    if (streamingState == StreamingState.Error)
                    {
                        btnStart.IsEnabled = !GrblSettings.IsGrblHAL;     // BAD! ?
                        btnHold.IsEnabled  = false;
                        btnStop.IsEnabled  = true;
                        SetStreamingHandler(StreamingHandler.AwaitAction);
                    }
                    else
                    {
                        changed = false;     // ignore
                    }
                    break;

                case StreamingState.Send:
                    if (!model.IsJobRunning)
                    {
                        model.IsJobRunning = true;
                    }
                    btnStart.IsEnabled  = false;
                    btnHold.IsEnabled   = true;
                    btnStop.IsEnabled   = true;
                    btnRewind.IsEnabled = false;
                    break;

                case StreamingState.Error:
                case StreamingState.Halted:
                    btnHold.IsEnabled = false;
                    break;

                case StreamingState.FeedHold:
                    SetStreamingHandler(StreamingHandler.FeedHold);
                    break;

                case StreamingState.ToolChange:
                    SetStreamingHandler(StreamingHandler.ToolChange);
                    break;

                case StreamingState.JobFinished:
                    if (grblState.State == GrblStates.Idle || grblState.State == GrblStates.Check)
                    {
                        newState = StreamingState.Idle;
                    }
                    job.Complete   = true;
                    job.ACKPending = job.CurrLine = 0;
                    SetStreamingHandler(StreamingHandler.AwaitIdle);
                    break;

                case StreamingState.Stop:
                    if (GrblSettings.IsGrblHAL)
                    {
                        SetStreamingHandler(StreamingHandler.Idle);
                    }
                    else
                    {
                        newState = StreamingState.Paused;
                        SetStreamingHandler(StreamingHandler.AwaitAction);
                    }
                    break;
                }
            }

            if (streamingHandler.Handler != StreamingHandler.SendFile)
            {
                return(streamingHandler.Call(newState, true));
            }
            else if (changed)
            {
                model.StreamingState = streamingState = newState;
                StreamingStateChanged?.Invoke(streamingState, grblState.MPG);
            }

            return(true);
        }
Exemplo n.º 10
0
        public void SetStreamingState(StreamingState newState)
        {
            switch (newState)
            {
            case StreamingState.Disabled:
                IsEnabled = false;
                break;

            case StreamingState.Idle:
            case StreamingState.NoFile:
                IsEnabled           = !grblState.MPG;
                btnStart.IsEnabled  = GCode.Loaded;
                btnStop.IsEnabled   = false;
                btnHold.IsEnabled   = !grblState.MPG;
                btnRewind.IsEnabled = !grblState.MPG && GCode.Loaded && CurrLine != 0;
                model.IsJobRunning  = false;
                break;

            case StreamingState.Send:
                btnStart.IsEnabled  = false;
                btnHold.IsEnabled   = !grblState.MPG;
                btnStop.IsEnabled   = !grblState.MPG;
                btnRewind.IsEnabled = false;
                if (GCode.Loaded && !grblState.MPG)
                {
                    model.IsJobRunning = true;
                    SendNextLine();
                }
                break;

            case StreamingState.Halted:
                btnStart.IsEnabled = !grblState.MPG;
                btnHold.IsEnabled  = false;
                btnStop.IsEnabled  = !grblState.MPG;
                break;

            case StreamingState.FeedHold:
                btnStart.IsEnabled = !grblState.MPG;
                btnHold.IsEnabled  = false;
                break;

            case StreamingState.ToolChange:
                btnStart.IsEnabled = !grblState.MPG;
                btnHold.IsEnabled  = false;
                break;

            case StreamingState.Stop:
                btnStart.IsEnabled  = false;
                btnStop.IsEnabled   = false;
                btnRewind.IsEnabled = !grblState.MPG;
                model.IsJobRunning  = false;
                if (!grblState.MPG)
                {
                    Comms.com.WriteByte((byte)GrblConstants.CMD_STOP);
                    if (JobTimer.IsRunning)
                    {
                        JobTimer.Stop();
                    }
                }
                break;
            }

            model.StreamingState = streamingState = newState;

            StreamingStateChanged?.Invoke(streamingState, grblState.MPG);
        }
Exemplo n.º 11
0
        public bool StreamingAwaitAction(StreamingState newState, bool always)
        {
            bool changed = streamingState != newState || newState == StreamingState.Idle;

            if (changed || always)
            {
                switch (newState)
                {
                case StreamingState.Idle:
                    btnStart.IsEnabled = !GrblInfo.IsGrblHAL;
                    break;

                case StreamingState.Stop:
                    if (GrblInfo.IsGrblHAL)
                    {
                        if (!model.GrblReset)
                        {
                            Comms.com.WriteByte(GrblConstants.CMD_STOP);
                            if (!model.IsParserStateLive)
                            {
                                SendCommand(GrblConstants.CMD_GETPARSERSTATE);
                            }
                        }
                    }
                    else if (grblState.State == GrblStates.Run)
                    {
                        Comms.com.WriteByte(GrblConstants.CMD_RESET);
                    }
                    newState = StreamingState.Idle;
                    SetStreamingHandler(StreamingHandler.AwaitIdle);
                    break;

                // Note: Only entered in legacy mode
                case StreamingState.Paused:
                    btnStart.IsEnabled = false;
                    btnHold.IsEnabled  = false;
                    btnStart.IsEnabled = true;
                    btnStop.IsEnabled  = true;
                    btnStop.Content    = (string)FindResource("JobStop");
                    if (job.ACKPending == 0)
                    {
                        streamingHandler.Count = false;
                    }
                    break;

                case StreamingState.Send:
                    SetStreamingHandler(StreamingHandler.SendFile);
                    SendNextLine();
                    break;

                case StreamingState.JobFinished:
                    SetStreamingHandler(StreamingHandler.SendFile);
                    break;
                }
            }

            if (streamingHandler.Handler != StreamingHandler.AwaitAction)
            {
                return(streamingHandler.Call(newState, true));
            }
            else if (changed)
            {
                model.StreamingState = streamingState = newState;
                StreamingStateChanged?.Invoke(streamingState, grblState.MPG);
            }

            return(true);
        }