private void AddExamples(Source[] array) { for (int i = 0; i < array.Length; i++) { sources.Add(array[i]); } Recostract(); SoundMethods.TukTuk(); }
private async void загрузитьНеобходимыеПакетыRToolStripMenuItem_Click(object sender, EventArgs e) { const string mess = "Требуется подключение к Интернету. Будут загружены все пакеты R, необходимые программе. Загрузка может занимать несколько минут, по окончанию загрузки консоль закроется. Уже установленные пакеты могут загрузиться заново либо обновиться. Выполнить действие?"; if (MessageBox.Show(mess, "Требуется подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { SoundMethods.OK(); await Task.Run(() => Expendator.StartProcessOnly(OtherMethods.GetResource("InstallPackages.r"), true)); } }
private void сортироватьToolStripMenuItem_Click(object sender, EventArgs e) { checkedListBox1.Items.Clear(); sources.Sort(); for (int i = 0; i < sources.Count; i++) { checkedListBox1.Items.Add(sources[i].ToString(), true); } checkedListBox1.Update(); SoundMethods.SetPositions(); }
/// <summary> /// Plays a sound file on the brick at a given volume and at certain interval /// The sound file must be stored in BrickFolder.Projects and in FolderName /// </summary> /// <param name="soundFile">A playable soundfile /// </param> /// <param name="volume">Specify volume for playback, [0 - 100]</param> /// <param name="numberOfLoops">Specify number of loops [1-n], 1 will play soundfile once</param> /// <param name="timeOut">Time in milliseconds between plays [0-n]</param> /// <exception cref="ArgumentOutOfRangeException">volume, numberOfLoops or timeOut out of range</exception> public async void PlayLoop(SoundFile soundFile, int volume, int numberOfLoops, int timeOut) { if (timeOut < 0) { throw new ArgumentException("Time out must >= 0 ms", "timeOut"); } if (numberOfLoops < 1) { throw new ArgumentException("Amount must be > 0", "numberOfLoops"); } if (numberOfLoops == 1) { await SoundMethods.Play(Brick.Socket, volume, soundFile.FilePath); } else { CancellationToken token = Brick.Socket.CancellationToken; await Task.Factory.StartNew( async() => { for (int i = 0; i < numberOfLoops; i++) { await SoundMethods.Play(Brick.Socket, volume, soundFile.FilePath); while (await IsBusy()) // test if file is still playing { token.WaitHandle.WaitOne(500); } if (i + 1 < numberOfLoops) // only pause between sounds { if (token.WaitHandle.WaitOne(timeOut)) { break; } } } }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); } }
/// <summary> /// Plays a tone based on frequency for given duration and at a given volume and at certain interval /// </summary> /// <param name="volume">Specify volume for playback, [0 - 100]</param> /// <param name="frequency">Specify frequency, [250 - 10000</param> /// <param name="duration">Specify duration in milliseconds [1-n]</param> /// <param name="numberOfLoops">Specify number of loops [1-n] if 1 will play single tone.</param> /// <param name="timeOut">Time in milliseconds between tones [1-n]</param> /// <exception cref="ArgumentOutOfRangeException">volume, frequency, duration, numberOfLoops or timeOut out of range</exception> public async void ToneLoop(int volume, int frequency, int duration, int numberOfLoops, int timeOut) { if (timeOut < 1) { throw new ArgumentOutOfRangeException("Time out must > 0 ms", "timeOut"); } if (numberOfLoops < 1) { throw new ArgumentOutOfRangeException("Amount must be > 0", "numberOfLoops"); } if (numberOfLoops == 1) { await SoundMethods.Tone(Brick.Socket, volume, frequency, duration); } else { int time = timeOut + duration; CancellationToken token = Brick.Socket.CancellationToken; await Task.Factory.StartNew( async() => { for (int i = 0; i < numberOfLoops; i++) { await SoundMethods.Tone(Brick.Socket, volume, frequency, duration); if (i + 1 < numberOfLoops) { if (token.WaitHandle.WaitOne(time)) { break; } } } }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); } }
private void очиститьToolStripMenuItem_Click(object sender, EventArgs e) { checkedListBox1.Items.Clear(); sources.Clear(); SoundMethods.Clear(); }
/// <summary> /// Plays a sound file on the brick at a given volume. /// The sound file must be stored in BrickFolder.Projects and in FolderName /// </summary> /// <param name="soundFile">A playable soundfile /// </param> /// <param name="volume">Specify volume for playback, [0 - 100]</param> /// <exception cref="ArgumentOutOfRangeException">volume out of range</exception> public async void Play(SoundFile soundFile, int volume) { await SoundMethods.Play(Brick.Socket, volume, soundFile.FilePath); }
/// <summary> /// Plays a tone based on frequency for given duration and at a given volume /// </summary> /// <param name="volume">Specify volume for playback, [0 - 100]</param> /// <param name="frequency">Specify frequency, [250 - 10000]</param> /// <param name="duration">Specify duration in milliseconds [1-n]</param> /// <exception cref="ArgumentOutOfRangeException">volume, frequency or duration out of range</exception> public async void Tone(int volume, int frequency, int duration) { await SoundMethods.Tone(Brick.Socket, volume, frequency, duration); }
/// <summary> /// This function enables the program to test if sound is busy (Playing sound or tone) /// </summary> /// <returns>Output busy flag, [0 = Ready, 1 = Busy]</returns> public async Task <bool> IsBusy() { return(await SoundMethods.Test(Brick.Socket)); }
/// <summary> /// Stops current sound playback. /// </summary> /// <returns></returns> public async Task Stop() { await SoundMethods.Break(Brick.Socket); }
/// <summary> /// Repeats playing a sound file on the brick at a given volume untill Stop() is called /// </summary> /// <param name="soundFile">A playable soundfile /// </param> /// <param name="volume">Specify volume for playback, [0 - 100]</param> /// <exception cref="ArgumentOutOfRangeException">volume out of range</exception> public async void Repeat(SoundFile soundFile, int volume) { await SoundMethods.Repeat(Brick.Socket, volume, soundFile.FilePath); }
/// <summary> /// Checks if all devices are properly connected to the brick. False on any device/port error forcing brick to disconnect /// If true will beep once for OK, twice for OK and devices found (autoConnectDevices = true), Three times ERROR for device/port error(s) /// Test runs on setting PowerUpSelfTest <see cref="Configuration.PowerUpSelfTestOptions"/> /// Brick must be connected. /// </summary> /// <returns>False on Error, otherwise true</returns> private async Task <bool> PowerUpSelfTest() { //do not stop on error detected to enable logging for all errors. bool errorDetected = false; bool autoConnectDevices = Options.PowerUpSelfTest.AutoConnectDevices; bool autoDevicesConnected = false; IEnumerable <PortInfo> list = await InputMethods.PortScan(Socket); List <PortInfo> devices = new List <PortInfo>(); devices.AddRange(list); for (int layer = 0; layer < 4; layer++) { for (int portNumber = 0; portNumber < 4; portNumber++) { int index; PortInfo entry; PortStatus status; string message; #region Input Ports index = (layer * 4) + portNumber; entry = devices[index]; InputPort inputPort = IOPort.Input.Ports[index]; message = $"Brick {(ChainLayer)layer} Port {inputPort.Name}"; switch (entry.Status) { case PortStatus.OK: { status = inputPort.CheckDevice(entry.Device.Value, Options.PowerUpSelfTest.AutoConnectDevices); switch (status) { case PortStatus.Error: { Logger.LogWarning($"Invalid device {inputPort.Device.Type} {message}"); inputPort.Status = PortStatus.Error; errorDetected = true; break; } case PortStatus.Initializing: { autoDevicesConnected = true; break; } } break; } case PortStatus.Empty: { if (inputPort.Status == PortStatus.OK) { Logger.LogWarning($"Device {inputPort.Device.Type} is not connected {message}"); inputPort.Status = PortStatus.Error; //unconnected device! errorDetected = true; } break; } case PortStatus.Error: { Logger.LogWarning($"{message} Device {entry.Device}"); inputPort.Status = PortStatus.Error; // Output device connected to InputPort errorDetected = true; break; } default: { Logger.LogWarning($"{message} Device {entry.Device}"); inputPort.Status = PortStatus.Error; errorDetected = true; break; } } if (!errorDetected && inputPort.Status == PortStatus.OK) { await inputPort.InitializeDevice(); } #endregion #region Output Ports index = 16 + (layer * 4) + portNumber; entry = devices[index]; OutputPort outputPort = IOPort.Output.Ports[index]; message = $"Brick {(ChainLayer)layer} Port {outputPort.Name}"; switch (entry.Status) { case PortStatus.OK: { status = outputPort.CheckDevice(entry.Device.Value, autoConnectDevices); switch (status) { case PortStatus.Error: { Logger.LogWarning($"Invalid device {outputPort.Device.Type} {message}"); outputPort.Status = PortStatus.Error; errorDetected = true; break; } case PortStatus.Initializing: { autoDevicesConnected = true; break; } } break; } case PortStatus.Empty: { if (outputPort.Status == PortStatus.OK) { Logger.LogWarning($"Device {outputPort.Device.Type} is not connected {message}"); outputPort.Status = PortStatus.Error; //unconnected device! errorDetected = true; } break; } case PortStatus.Error: { Logger.LogWarning($"{message} Device {entry.Device}"); outputPort.Status = PortStatus.Error; // InputPort device connected to Outputport errorDetected = true; break; } default: { Logger.LogWarning($"{message} Device {entry.Device}"); outputPort.Status = PortStatus.Error; errorDetected = true; break; } } if (!errorDetected && outputPort.Status == PortStatus.OK) { await outputPort.InitializeDevice(); } #endregion } } int numberOfLoops = 1; // beep once for OK if (errorDetected) { numberOfLoops = 3; //beep three times } else if (autoDevicesConnected) { numberOfLoops = 2; //beep two times devices found, but all is still well :-) } bool beep = false; switch (numberOfLoops) { case 1: { beep = Options.PowerUpSelfTest.BeepOnOK; break; } case 2: { // all is still well so beep once if set anyhow. beep = (Options.PowerUpSelfTest.BeepOnAutoConnect) ? true : Options.PowerUpSelfTest.BeepOnOK; break; } case 3: { beep = Options.PowerUpSelfTest.BeepOnError; break; } } if (beep) { CancellationToken token = Socket.CancellationToken; await Task.Run(async() => { for (int i = 0; i < numberOfLoops; i++) { await SoundMethods.Tone(Socket, 50, 850, 150); await Task.Delay(400, token); } }, token); } if (errorDetected && Options.PowerUpSelfTest.DisconnectOnError) { await Disconnect(); } Logger.LogInformation($"PowerUpSelfTest: {((errorDetected) ? "ERROR" : "OK")}"); return(!errorDetected); }