Пример #1
0
        private void ConnectDevice()
        {
            DeviceInfo = Spi.GetDeviceInfoList()[toolStripComboBox_deviceList.SelectedIndex];
            ymf825     = new CbwYmf825Bb(toolStripComboBox_deviceList.SelectedIndex);
            Driver     = new Ymf825Driver(ymf825);

            ymf825.DataWrote += (sender, args) =>
            {
                registerMap.SetData(args.Address, args.Data);
            };
            ymf825.DataBurstWrote += (sender, args) =>
            {
                if (args.Data.Count <= 0)
                {
                    return;
                }

                if (args.Address == 0x07)
                {
                    registerMap.SetData(args.Address, args.Data.Last());

                    var toneNumber = args.Data[0] - 0x80;

                    if (toneNumber < 0 || toneNumber > 16 || args.Data.Count < toneNumber * 30 + 5)
                    {
                        Console.WriteLine($"Invalid BurstWrite Data - Tone Number: {toneNumber}, Data Size: {args.Data.Count} (required {toneNumber * 30 + 5})");
                        return;
                    }

                    for (var i = 0; i < toneNumber; i++)
                    {
                        for (var j = 0; j < 30; j++)
                        {
                            toneParameterRegisterMap[i].SetData(j, args.Data[i * 30 + j + 1]);
                        }
                    }
                }
                else if (args.Address >= 0x20 || args.Address <= 0x22)
                {
                    var eq = args.Address - 0x20;

                    if (args.Data.Count < 5)
                    {
                        return;
                    }

                    for (var i = 0; i < 5; i++)
                    {
                        registerMap.SetData(0x23 + 3 * eq + i, args.Data[i]);
                    }
                }
            };

            SpiConnected = true;
            Driver.ResetHardware();
            Driver.ResetSoftware();
            Connected?.Invoke(this, new EventArgs());
        }
Пример #2
0
 private void DisconnectDevice()
 {
     Driver?.ResetHardware();
     Driver = null;
     ymf825?.Dispose();
     ymf825       = null;
     SpiConnected = false;
     Disconnected?.Invoke(this, new EventArgs());
 }