// vendor id, , . private int vid = 0x1294; // vid' var devs = HidDevices.Enumerate(vid).ToList(); // , num_devices. .config var dev = devs[device_num]; if(dev != null) { // var data = new byte[5]; // obj data[0] = (byte)(int)obj; // Report, .. HID_SET_REPORT var report = dev.CreateReport(); // Report report.Data = data; // dev.WriteReport(report); }
// - 0, 8000 - var dev = new WaveIn(WaveCallbackInfo.FunctionCallback()); dev.DeviceNumber = 0; // - dev.DataAvailable += dev_DataAvailable; dev.WaveFormat = new WaveFormat(8000, 1); dev.StartRecording(); void dev_DataAvailable(object sender, WaveInEventArgs e) { // var max = getValueMax(e.Buffer, e.BytesRecorded); // if(max > _trigger) { if(ChangeLevelVolumeMax != null) { // , ChangeLevelVolumeMax(this, e); } } } private float getValueMax(byte[] buffer, int lenght) { // List<float> l_sample32 = new List<float>(); // , for (int index = 0; index < lenght; index += 2) { float sample32 = (float)(short)((buffer[index + 1] << 8) | buffer[index + 0]) / 32768f; l_sample32.Add(sample32); } // var max = l_sample32.Max(); return max; }
protected override void OnStart(string[] args) { //USB Notifier device = new cApi(cSettings.Usb); //Audio audio = new cAudio(cSettings.Audio, cSettings.Rate, cSettings.Chanel, cSettings.Trigger); audio.ChangeLevelVolumeMax += audio_ChangeLevelVolumeMax; base.OnStart(args); } void audio_ChangeLevelVolumeMax(object sender, NAudio.Wave.WaveInEventArgs e) { // device.setNextColor(); } protected override void OnStop() { device.Off(); device.Dispose(); audio.Dispose(); base.OnStop(); }
Source: https://habr.com/ru/post/232729/
All Articles