Exemple #1
0
        private void TimerLEDUpdate_Tick(object sender, ElapsedEventArgs e)
        {
            float[] rgb = new float[3];
            int     k   = Thread.CurrentThread.ManagedThreadId;
            double  vol = Data.CurrentValue[3] + Data.Step[3];

            if (vol < 0)
            {
                vol = 0;
            }
            if (!Data.AutoVolumeEnable)
            {
                vol *= Data.BrightnessMul;
            }
            if ((Data.Step[3] >= 0 && vol > Data.StepValueLimit[3]) || (Data.Step[3] < 0 && vol < Data.StepValueLimit[3]))
            {
                vol = Data.StepValueLimit[3];
            }
            if (vol > 10)
            {
                vol = 10;
            }
            Data.CurrentValue[3] = vol;

            double v;

            for (int i = 0; i < 3; i++)
            {
                v  = Data.CurrentValue[i];
                v += Data.Step[i];
                if (v < 0)
                {
                    v = 0;
                }
                if ((Data.Step[i] >= 0 && v > Data.StepValueLimit[i]) || (Data.Step[i] < 0 && v < Data.StepValueLimit[i]))
                {
                    v = Data.StepValueLimit[i];
                }
                if (v > 200)
                {
                    v = 200;
                }
                if (v < 0)
                {
                    v = 0;
                }
                Data.CurrentValue[i] = v;
                //v *= Data.RGBMul;
                rgb[i] = (float)v;
            }
            if (serialPort.IsOpen)
            {
                byte[] array = SendCommandList.SetColourCommand(rgb[0] * (float)vol, rgb[1] * (float)vol, rgb[2] * (float)vol);
                try
                {
                    serialPort.Write(array, 0, array.Length);
                }
                catch { errorCount++; };
            }
        }
Exemple #2
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (serialPort.IsOpen)
     {
         try
         {
             if (DeviceSettings != null)
             {
                 byte[] array = SendCommandList.SetBrightnessCommand(DeviceSettings.BacklightBrightness);
                 serialPort.Write(array, 0, (int)array.Length);
                 array = SendCommandList.SetColourCommand(DeviceSettings.BacklightRed, DeviceSettings.BacklightGreen, DeviceSettings.BacklightBlue);
                 serialPort.Write(array, 0, (int)array.Length);
                 array = SendCommandList.ChangeBacklightModeCommand(DeviceSettings.BacklightMode);
                 serialPort.Write(array, 0, (int)array.Length);
             }
         }
         catch { errorCount++; }
     }
     timer?.Dispose();
     timerLEDUpdate?.Dispose();
     timerVolumeUpdate?.Dispose();
     Recorder?.StopRecording();
     if (serialPort.IsOpen)
     {
         serialPort.Close();
     }
     Thread.Sleep(10);
     Application.Exit();
 }
Exemple #3
0
 private void Button1_Click(object sender, EventArgs e)
 {
     if (timer == null)
     {
         timer           = new System.Timers.Timer();
         timer.Interval  = Data.DataProcessingTimerInterval;
         timer.AutoReset = true;
         timer.Elapsed  += new System.Timers.ElapsedEventHandler(Timer_Tick);
     }
     if (timerLEDUpdate == null)
     {
         timerLEDUpdate           = new System.Timers.Timer();
         timerLEDUpdate.Interval  = Data.DataSendingTimerInterval;
         timerLEDUpdate.AutoReset = true;
         timerLEDUpdate.Elapsed  += new System.Timers.ElapsedEventHandler(TimerLEDUpdate_Tick);
     }
     if (timerVolumeUpdate == null)
     {
         timerVolumeUpdate           = new System.Timers.Timer();
         timerVolumeUpdate.Interval  = Data.DataVolumeProcessingTimerInterval;
         timerVolumeUpdate.AutoReset = true;
         timerVolumeUpdate.Elapsed  += new System.Timers.ElapsedEventHandler(TimerVolumeUpdate_Tick);
     }
     if (!timer.Enabled)
     {
         enumerator = new MMDeviceEnumerator();
         if (serialPort.IsOpen)
         {
             try
             {
                 ShowDeviceSettings = false;
                 byte[] array = SendCommandList.RequestAltData();
                 serialPort.Write(array, 0, (int)array.Length);
                 Thread.Sleep(200);
                 array = SendCommandList.ChangeBacklightModeCommand(0);
                 serialPort.Write(array, 0, (int)array.Length);
                 array = SendCommandList.SetBrightnessCommand(1);
                 serialPort.Write(array, 0, (int)array.Length);
             }
             catch { errorCount++; }
         }
         AudioFormat = new WaveFormat();
         SampleRate  = AudioFormat.SampleRate;
         if (Recorder != null)
         {
             Recorder.Dispose();
         }
         Recorder = new LoopbackRecorder(Data.BufferSize, true);
         Recorder.StartRecording();
         timer.Enabled              = true;
         timerLEDUpdate.Enabled     = true;
         timerVolumeUpdate.Enabled  = true;
         VisualizationOnButton.Text = "Выключить";
         bufferTrackBar.Enabled     = false;
     }
     else
     {
         if (serialPort.IsOpen)
         {
             try
             {
                 if (DeviceSettings != null)
                 {
                     byte[] array = SendCommandList.SetBrightnessCommand(DeviceSettings.BacklightBrightness);
                     serialPort.Write(array, 0, (int)array.Length);
                     array = SendCommandList.SetColourCommand(DeviceSettings.BacklightRed, DeviceSettings.BacklightGreen, DeviceSettings.BacklightBlue);
                     serialPort.Write(array, 0, (int)array.Length);
                     array = SendCommandList.ChangeBacklightModeCommand(DeviceSettings.BacklightMode);
                     serialPort.Write(array, 0, (int)array.Length);
                 }
             }
             catch { errorCount++; }
         }
         timer.Enabled             = false;
         timerLEDUpdate.Enabled    = false;
         timerVolumeUpdate.Enabled = false;
         enumerator.Dispose();
         Recorder.StopRecording();
         VisualizationOnButton.Text = "Включить";
         bufferTrackBar.Enabled     = true;
     }
 }
Exemple #4
0
        private void CommanSentB_Click(object sender, EventArgs e)
        {
            switch (commandList.SelectedIndex)
            {
            case 0:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.SetColourCommand(textboxParam1.Text, textboxParam2.Text, textboxParam3.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 1:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.SetBrightnessCommand(textboxParam1.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 2:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.ChangeBacklightModeCommand(textboxParam1.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 3:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.CustomModeSetupCommand(textboxParam1.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 4:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.CustomModeDataCommand(textboxParam1.Text, textboxParam2.Text,
                                                                         textboxParam3.Text, textboxParam4.Text, textboxParam5.Text, textboxParam6.Text,
                                                                         textboxParam7.Text, textboxParam8.Text, textboxParam9.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 5:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.CustomModeCopyCommand(textboxParam1.Text, textboxParam2.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 6:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.SaveCommand(textboxParam1.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 7:
                using (MemoryStream stream = new MemoryStream())
                {
                    using (BinaryWriter binWriter = new BinaryWriter(stream))
                    {
                        binWriter.Write((byte)0x2D);
                        binWriter.Write((byte)0x2D);
                        binWriter.Write((byte)0x62);
                        binWriter.Write((byte)0x6D);
                        binWriter.Write(Convert.ToSingle(textboxParam1.Text));
                        serialPort.Write(stream.ToArray(), 0, (int)stream.Length);
                    }
                }

                break;

            case 8:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.ResetCommand();
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 9:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.CalibrationRunCommand(textboxParam1.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 10:
                if (serialPort.IsOpen)
                {
                    byte[] array = SendCommandList.SetTXControlCommand(textboxParam1.Text);
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;

            case 11:
                if (serialPort.IsOpen)
                {
                    ShowDeviceSettings = true;
                    byte[] array = SendCommandList.RequestAltData();
                    serialPort.Write(array, 0, (int)array.Length);
                }

                break;
            }
        }