コード例 #1
0
        private static void loop()
        {
            // Looking over this again makes me think if it's really that smart to push as many data through the sereal port as possible :P
            // Who cares though. *shrug*
            while (true)
            {
                if (connected)
                {
                    try
                    {
                        port.Write("BLed");

                        byte[] cmd = { 0x00 };               // Cmd
                        port.Write(cmd, 0, cmd.Length);

                        LedManager.writeBuffer(port);

                        if (quit)
                        {
                            byte[] bufferAbort = { 0x01 };
                            port.Write(bufferAbort, 0, 1);
                            port.Close();
                            break;
                        }

                        while (port.BytesToWrite != 0 || port.BytesToRead != 13)
                        {
                        }

                        string ret = getSerialString();
                        if (ret == "BLed_accepted")
                        {
                            continue;
                        }
                        else
                        {
                            connected = false;
                            port.Close();
                        }
                    }
                    catch (Exception) { port.Close(); connected = false; }
                }
                else
                {
                    sdsDelegate("Scanning...");
                    if (quit)
                    {
                        break;
                    }
                    if (!getComPort())
                    {
                        Thread.Sleep(10);
                    }
                    else
                    {
                        sdsDelegate("Connected (" + port.PortName + ")");
                    }
                }
            }
        }
コード例 #2
0
ファイル: MainWindow.cs プロジェクト: RicBent/AmbiBlarg
        private void init()
        {
            LedManager.init();
            LedManager.direction = true;
            lightEnabled.Checked = Properties.Settings.Default.lightEnabled;
            LedManager.enabled   = lightEnabled.Checked;
            ArduinoCommunication.init(setDeviceStatus);

            modes = new List <DisplayMode>();
            tabControl.SelectedIndexChanged -= tabControl_SelectedIndexChanged;

            addModeTab(new StaticColorMode());
            addModeTab(new MusicMode());
            addModeTab(new ScreenCaptureMode());
        }
コード例 #3
0
ファイル: MainWindow.cs プロジェクト: RicBent/AmbiBlarg
        private void cleanUp()
        {
            Properties.Settings.Default.lastMode = getActiveModeIndex();

            foreach (DisplayMode mode in modes)
            {
                mode.deactivate();
                mode.cleanUp();
            }

            LedManager.setColor(Color.Black);

            Thread.Sleep(30);
            ArduinoCommunication.cleanUp();

            Properties.Settings.Default.ledCount     = LedManager.ledCount;
            Properties.Settings.Default.lightEnabled = LedManager.enabled;
            Properties.Settings.Default.Save();
        }
コード例 #4
0
ファイル: MainWindow.cs プロジェクト: RicBent/AmbiBlarg
        private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl.SelectedIndex > modes.Count - 1)
            {
                return;
            }

            int activeMode = getActiveModeIndex();

            if (modes[tabControl.SelectedIndex].isActive())
            {
                return;
            }

            if (activeMode >= 0)
            {
                modes[activeMode].deactivate();
            }

            LedManager.setColor(Color.Black);

            modes[tabControl.SelectedIndex].activate();
        }
コード例 #5
0
        private void tick(Object myObject, EventArgs myEventArgs)
        {
            int ret = BassWasapi.BASS_WASAPI_GetData(fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data

            if (ret < -1)
            {
                return;
            }
            int x, y;
            int b0 = 0;

            //computes the spectrum data, the code is taken from a bass_wasapi sample.
            for (x = 0; x < lines; x++)
            {
                float peak = 0;
                int   b1   = (int)Math.Pow(2, x * 10.0 / (lines - 1));
                if (b1 > 1023)
                {
                    b1 = 1023;
                }
                if (b1 <= b0)
                {
                    b1 = b0 + 1;
                }
                for (; b0 < b1; b0++)
                {
                    if (peak < fft[1 + b0])
                    {
                        peak = fft[1 + b0];
                    }
                }
                y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
                if (y > 255)
                {
                    y = 255;
                }
                if (y < 0)
                {
                    y = 0;
                }

                Color lastColor = lastColors[x];
                Color nowColor  = grd.GetColorAt(y / 255f);

                float a_smoothing = 1f - smoothing;

                byte  r         = (byte)(lastColor.R * smoothing + nowColor.R * a_smoothing);
                byte  g         = (byte)(lastColor.G * smoothing + nowColor.G * a_smoothing);
                byte  b         = (byte)(lastColor.B * smoothing + nowColor.B * a_smoothing);
                Color calcColor = Color.FromArgb(r, g, b);

                spectrumdata.Add(new Tuple <byte, Color>((byte)y, nowColor));
                lastColors[x] = calcColor;

                LedManager.setLed(x + 21, calcColor);
            }

            setValues(spectrumdata);
            spectrumdata.Clear();


            int level = BassWasapi.BASS_WASAPI_GetLevel();

            if (level == lastlevel && level != 0)
            {
                hanctr++;
            }
            lastlevel = level;

            //Required, because some programs hang the output. If the output hangs for a 75ms
            //this piece of code re initializes the output so it doesn't make a gliched sound for long.
            if (hanctr > 3)
            {
                Free();
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                BassWasapi.BASS_WASAPI_Init(devindex, 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, process, IntPtr.Zero);
                BassWasapi.BASS_WASAPI_Start();
            }
        }