Example #1
0
        protected override void Start()
        {
            //configure default state
            if (_state == null)
            {
                _state            = new LegoNxtBackupBeepState();
                _state.Motor1Port = 1;
                _state.Motor2Port = 3;

                _state.PauseDuration = 800;
                _state.PlayDuration  = 800;
                _state.Frequency     = 1500;

                SaveState(_state);
            }

            // Listen on the main port for requests and call the appropriate handler.
            ActivateDsspOperationHandlers();

            // Publish the service to the local Node Directory
            DirectoryInsert();

            // display HTTP service Uri
            LogInfo(LogGroups.Console, "Service uri: ");

            // Subscribe to NXT for sound sensor notifications
            if (ValidState(_state))
            {
                SubscribeToNXT();
            }
        }
Example #2
0
 private static bool ValidState(LegoNxtBackupBeepState state)
 {
     if (state != null &&
         state.Motor1Port >= 1 && state.Motor1Port <= 3 &&
         state.Motor2Port >= 1 && state.Motor2Port <= 3 &&
         state.Frequency >= 200 && state.Frequency <= 14000 &&
         state.PauseDuration > 0 &&
         state.PlayDuration > 0)
     {
         return(true);
     }
     return(false);
 }
Example #3
0
        public virtual IEnumerator <ITask> ReplaceHandler(Replace replace)
        {
            if (_subscribed)
            {
                throw new Exception("Already subscribed");
            }
            else if (ValidState(replace.Body))
            {
                _state = replace.Body;
                SaveState(_state);
                replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
                SubscribeToNXT();
            }
            else
            {
                throw new Exception("Invalid State");
            }

            yield break;
        }
Example #4
0
 /// <summary>
 /// Initialization Constructor
 /// </summary>
 public Replace(LegoNxtBackupBeepState state)
 {
     this.Body = state;
 }