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(); } }
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); }
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; }
/// <summary> /// Initialization Constructor /// </summary> public Replace(LegoNxtBackupBeepState state) { this.Body = state; }