Esempio n. 1
0
        /// <summary>
        /// Actuator callback
        /// </summary>
        protected override void SetCallback(Myro.Services.Generic.Vector.SetRequestInfo request)
        {
            var req = request as vector.SetElementsRequestInfo;

            if (req != null)
            {
                bool play = false;
                bool loud = false;
                foreach (var i in req.Indices)
                {
                    if (i == 0 || i == 1 || i == 2)
                    {
                        play = true;
                    }
                    else if (i == 3)
                    {
                        loud = true;
                    }
                }
                if (loud)
                {
                    setLoud();
                }
                if (play)
                {
                    playTone();
                }
            }
            else
            {
                // Otherwise it was a SetAllRequestInfo
                setLoud();
                playTone();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Actuator callback
        /// </summary>
        protected override IEnumerator <ITask> SetCallback(Myro.Services.Generic.Vector.SetRequestInfo request, PortSet <vector.CallbackResponseType, Fault> responsePort)
        {
            var req = request as vector.SetElementsRequestInfo;

            if (req != null)
            {
                bool play = false;
                bool loud = false;
                foreach (var i in req.Indices)
                {
                    if (i == 0 || i == 1 || i == 2)
                    {
                        play = true;
                    }
                    else if (i == 3)
                    {
                        loud = true;
                    }
                }

                Fault error = null;
                if (loud)
                {
                    yield return(Arbiter.Choice(setLoud(),
                                                delegate(vector.CallbackResponseType s) { },
                                                delegate(Fault f) { error = f; }));
                }

                if (error == null && play)
                {
                    yield return(Arbiter.Choice(playTone(),
                                                delegate(vector.CallbackResponseType s1) { },
                                                delegate(Fault f) { error = f; }));
                }

                if (error == null)
                {
                    responsePort.Post(vector.CallbackResponseType.Instance);
                }
                else
                {
                    responsePort.Post(error);
                }
            }
            else
            {
                // Otherwise it was a SetAllRequestInfo
                Activate(Arbiter.Choice(setLoud(),
                                        delegate(vector.CallbackResponseType s)
                {
                    Activate(Arbiter.Choice(playTone(),
                                            delegate(vector.CallbackResponseType s1) { responsePort.Post(vector.CallbackResponseType.Instance); },
                                            delegate(Fault f) { responsePort.Post(f); }));
                },
                                        delegate(Fault f) { responsePort.Post(f); }));
            }
            yield break;
        }
Esempio n. 3
0
 protected override void SetCallback(Myro.Services.Generic.Vector.SetRequestInfo request)
 {
     if (request is vector.SetAllRequestInfo)
     {
         Activate(Arbiter.Choice(
                      _scribblerPort.SetAllLEDs(new brick.SetAllLedsBody()
         {
             LeftLED = _state.GetBool(0), CenterLED = _state.GetBool(1), RightLED = _state.GetBool(2)
         }),
                      delegate(DefaultUpdateResponseType success) { },
                      delegate(Fault failure) { LogError(failure); }));
     }
     else if (request is vector.SetElementsRequestInfo)
     {
         vector.SetElementsRequestInfo info = (vector.SetElementsRequestInfo)request;
         if (info.Indices.Count > 1)
         {
             Activate(Arbiter.Choice(
                          _scribblerPort.SetAllLEDs(new brick.SetAllLedsBody()
             {
                 LeftLED = _state.GetBool(0), CenterLED = _state.GetBool(1), RightLED = _state.GetBool(2)
             }),
                          delegate(DefaultUpdateResponseType success) { },
                          delegate(Fault failure) { LogError(failure); }));
         }
         else if (info.Indices.Count == 1)
         {
             Activate(Arbiter.Choice(
                          _scribblerPort.SetLED(new brick.SetLedBody()
             {
                 LED = info.Indices[0], State = _state.GetBool(info.Indices[0])
             }),
                          delegate(DefaultUpdateResponseType success) { },
                          delegate(Fault failure) { LogError(failure); }));
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Callback giving you the opportunity to take action after the state
 /// is modified by a request.  The requestInfo parameter will be
 /// either a SetElementRequestInfo class, or a SetAllRequestInfo class.
 /// Use the "is" keyword to find out which one (and thus what type the
 /// request was).  This class, once casted to the right type, contains
 /// information about the specific request.  See the Vector class
 /// description for more information.
 /// </summary>
 protected virtual void SetCallback(SetRequestInfo request)
 {
 }
Esempio n. 5
0
 protected override IEnumerator <ITask> SetCallback(vector.SetRequestInfo request, PortSet <vector.CallbackResponseType, Fault> responsePort)
 {
     if (request is vector.SetAllRequestInfo)
     {
         Activate(Arbiter.Choice(
                      _scribblerPort.SetAllLEDs(new brick.SetAllLedsBody()
         {
             LeftLED = _state.GetBool(0), CenterLED = _state.GetBool(1), RightLED = _state.GetBool(2)
         }),
                      delegate(DefaultUpdateResponseType success) { responsePort.Post(vector.CallbackResponseType.Instance); },
                      delegate(Fault failure) { responsePort.Post(failure); }));
     }
     else if (request is vector.SetElementsRequestInfo)
     {
         vector.SetElementsRequestInfo info = (vector.SetElementsRequestInfo)request;
         int setLEDScribblerIndex           = -1; // will be set to -2 for set all
         var responses  = new PortSet <DefaultUpdateResponseType, Fault>();
         int nResponses = 0;
         foreach (int i in info.Indices)
         {
             if (i >= 0)
             {
                 if (i <= 2)
                 {
                     if (setLEDScribblerIndex >= 0)
                     {
                         setLEDScribblerIndex = -2;
                     }
                     else
                     {
                         setLEDScribblerIndex = i;
                     }
                 }
                 else if (i == 3)
                 {
                     nResponses++;
                     Activate(Arbiter.Choice(_scribblerPort.SetLEDFront(_state.GetBool(3)),
                                             delegate(DefaultUpdateResponseType s) { responses.Post(DefaultUpdateResponseType.Instance); },
                                             delegate(Fault f) { responses.Post(f); }));
                 }
                 else if (i == 4)
                 {
                     nResponses++;
                     Activate(Arbiter.Choice(_scribblerPort.SetLEDBack(RSUtils.UnnormalizeDouble(_state.Get(4))),
                                             delegate(DefaultUpdateResponseType s) { responses.Post(DefaultUpdateResponseType.Instance); },
                                             delegate(Fault f) { responses.Post(f); }));
                 }
             }
         }
         if (setLEDScribblerIndex == -2)
         {
             nResponses++;
             Activate(Arbiter.Choice(
                          _scribblerPort.SetAllLEDs(new brick.SetAllLedsBody()
             {
                 LeftLED = _state.GetBool(0), CenterLED = _state.GetBool(1), RightLED = _state.GetBool(2)
             }),
                          delegate(DefaultUpdateResponseType s) { responses.Post(DefaultUpdateResponseType.Instance); },
                          delegate(Fault f) { responses.Post(f); }));
         }
         else if (setLEDScribblerIndex >= 0)
         {
             nResponses++;
             Activate(Arbiter.Choice(
                          _scribblerPort.SetLED(new brick.SetLedBody()
             {
                 LED = setLEDScribblerIndex, State = _state.GetBool(setLEDScribblerIndex)
             }),
                          delegate(DefaultUpdateResponseType s) { responses.Post(DefaultUpdateResponseType.Instance); },
                          delegate(Fault f) { responses.Post(f); }));
         }
         Activate(Arbiter.MultipleItemReceive(responses, nResponses,
                                              delegate(ICollection <DefaultUpdateResponseType> ss, ICollection <Fault> fs)
         {
             if (fs.Count == 0)
             {
                 responsePort.Post(vector.CallbackResponseType.Instance);
             }
             else
             {
                 responsePort.Post(fs.First());
                 ////f.Readon could be null
                 //var reasons = new List<ReasonText>();
                 //foreach (var f in fs)
                 //    if (f.Reason != null)
                 //        reasons.AddRange(f.Reason.AsEnumerable());
                 //responsePort.Post(new Fault() { Detail = new Detail() { Any = fs.ToArray() }, Reason = reasons.ToArray() });
             }
         }));
     }
     yield break;
 }