コード例 #1
0
        /// <summary>
        /// Handles incoming SetLED requests
        /// </summary>
        private IEnumerator <ITask> SetLEDHandler(SetLED message)
        {
            switch (message.Body.LED)
            {
            case 0:
                if (message.Body.State)
                {
                    _scribblerComm.SendCommand(new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_LEFT_ON));
                }
                else
                {
                    _scribblerComm.SendCommand(new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_LEFT_OFF));
                }
                break;

            case 1:
                if (message.Body.State)
                {
                    _scribblerComm.SendCommand(new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_CENTER_ON));
                }
                else
                {
                    _scribblerComm.SendCommand(new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_CENTER_OFF));
                }
                break;

            case 2:
                if (message.Body.State)
                {
                    _scribblerComm.SendCommand(new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_RIGHT_ON));
                }
                else
                {
                    _scribblerComm.SendCommand(new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_RIGHT_OFF));
                }
                break;

            default:
                LogError("LED number set incorrect");
                break;
            }

            //reply to sender
            message.ResponsePort.Post(DefaultUpdateResponseType.Instance);
            yield break;
        }
コード例 #2
0
        /// <summary>
        /// Handles incoming SetLED requests
        /// </summary>
        private IEnumerator <ITask> SetLEDHandler(SetLED message)
        {
            if (!_state.Connected)
            {
                LogError("Trying to set LED, but not connected");
                message.ResponsePort.Post(new Fault());
                yield break;
            }

            ScribblerCommand cmd;

            switch (message.Body.LED)
            {
            case 0:     //left LED
                _state.LEDLeft = message.Body.State;
                if (message.Body.State)
                {
                    cmd = new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_LEFT_ON);
                }
                else
                {
                    cmd = new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_LEFT_OFF);
                }
                break;

            case 1:     //center LED
                _state.LEDCenter = message.Body.State;
                if (message.Body.State)
                {
                    cmd = new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_CENTER_ON);
                }
                else
                {
                    cmd = new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_CENTER_OFF);
                }
                break;

            case 2:     //right LED
                _state.LEDRight = message.Body.State;
                if (message.Body.State)
                {
                    cmd = new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_RIGHT_ON);
                }
                else
                {
                    cmd = new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_RIGHT_OFF);
                }
                break;

            case 3:     //all LEDs
                _state.LEDLeft   = message.Body.State;
                _state.LEDCenter = message.Body.State;
                _state.LEDRight  = message.Body.State;
                if (message.Body.State)
                {
                    cmd = new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_ALL_ON);
                }
                else
                {
                    cmd = new ScribblerCommand((byte)ScribblerHelper.Commands.SET_LED_ALL_OFF);
                }
                break;

            default:
                LogError("LED number set incorrect");
                cmd = new ScribblerCommand();
                break;
            }

            SendScribblerCommand sendcmd = new SendScribblerCommand(cmd);

            _scribblerComPort.Post(sendcmd);

            yield return(Arbiter.Receive <ScribblerResponse>(false, sendcmd.ResponsePort,
                                                             delegate(ScribblerResponse response)
            {
            }
                                                             ));

            //reply to sender
            message.ResponsePort.Post(DefaultUpdateResponseType.Instance);
            yield break;
        }