コード例 #1
0
ファイル: Radio.cs プロジェクト: martin2250/NRF24Debug
        public void SetConfiguration(RadioConfiguration conf)
        {
            byte[] c = new byte[16];

            for (int i = 0; i < 5; i++)
            {
                if (!conf.Pipes[i].Enabled)
                {
                    continue;
                }
                byte info = 1 << 7;

                if (conf.Pipes[i].AutoAcknowledge)
                {
                    info |= 1 << 6;
                }

                if (conf.Pipes[i].DynamicPayload)
                {
                    info |= 0x3F;
                }
                else
                {
                    info |= conf.Pipes[i].PayloadWidth;
                }

                c[i * 2] = info;

                c[(i * 2) + 1] = conf.Pipes[i].Address;
            }

            c[10] = conf.Channel;

            byte misc = 0;

            misc |= (byte)(((byte)conf.Rate) << 6);
            misc |= (byte)(((byte)conf.Power) << 4);
            misc |= (byte)(conf.RetransmitCount & 0xF);

            c[11] = misc;

            for (int b = 0; b < 4; b++)
            {
                c[12 + b] = conf.AddressPrefix[b];
            }

            UsbSetupPacket sup = new UsbSetupPacket(0x40, 0x01, 0, 0, 16);

            int l;

            dev.ControlTransfer(ref sup, c, 16, out l);

            if (l != 16)
            {
                throw new Exception($"{l} bytes written");
            }
        }
コード例 #2
0
        private void ButtonWriteConfig_Click(object sender, RoutedEventArgs e)
        {
            RadioConfiguration c = new RadioConfiguration();

            c.Channel          = byteViewChannel.Value;
            c.Rate             = (BitRate)comboBoxDataRate.SelectedIndex;
            c.Power            = (RFPower)comboBoxRFPower.SelectedIndex;
            c.AddressPrefix[0] = bvAP0.Value;
            c.AddressPrefix[1] = bvAP1.Value;
            c.AddressPrefix[2] = bvAP2.Value;
            c.AddressPrefix[3] = bvAP3.Value;

            for (int i = 0; i < 5; i++)
            {
                if (!(c.Pipes[i].Enabled = pipesEN[i].IsChecked.Value))
                {
                    continue;
                }
                c.Pipes[i].Address         = pipesAddr[i].Value;
                c.Pipes[i].AutoAcknowledge = pipesAA[i].IsChecked.Value;
                c.Pipes[i].DynamicPayload  = pipesPW[i].SelectedIndex == 0;
                c.Pipes[i].PayloadWidth    = (byte)pipesPW[i].SelectedIndex;
            }

            c.RetransmitCount = bvRetransmit.Value;

            try
            {
                radio.SetConfiguration(c);

                MessageBox.Show("Configuration written");
            }
            catch (Exception ex)
            {
                Disconnect();
                MessageBox.Show("Could not write Config:\n" + ex.Message);
            }
        }