コード例 #1
0
        /// <sumary>
        /// Returns the default address value for the pipe
        /// </sumary>
        public byte[] GetDefaultAddress(AddressSlot s)
        {
            byte[] addr = new byte[1];

            switch (s)
            {
            case AddressSlot.Zero: addr = _def_rx_addr_p0;
                break;

            case AddressSlot.One: addr = _def_rx_addr_p1;
                break;

            case AddressSlot.Two: addr = _def_rx_addr_p2;
                break;

            case AddressSlot.Three: addr = _def_rx_addr_p3;
                break;

            case AddressSlot.Four: addr = _def_rx_addr_p4;
                break;

            case AddressSlot.Five: addr = _def_rx_addr_p5;
                break;
            }
            return(addr);
        }
コード例 #2
0
ファイル: RF24.cs プロジェクト: KiwiBryn/nRF24L01-NetNF
        /// <summary>
        ///   Read 1 of 6 available module addresses
        /// </summary>
        /// <param name="slot">
        ///   The slot to read from
        /// </param>
        /// <param name="width">
        ///   The width, in bytes, of the address
        /// </param>
        /// <returns>byte[] representing the address</returns>
        public byte[] GetAddress(AddressSlot slot, byte width)
        {
            CheckIsInitialized();
            AddressWidth.IsValid(width);
            var read   = Execute(Commands.R_REGISTER, (byte)slot, new byte[width]);
            var result = new byte[read.Length - 1];

            Array.Copy(read, 1, result, 0, result.Length);
            return(result);
        }
コード例 #3
0
ファイル: RF24.cs プロジェクト: KiwiBryn/nRF24L01-NetNF
        /// <summary>
        ///   Set one of 6 available module addresses
        /// </summary>
        /// <param name="slot">
        ///   The slot to write the address to
        /// </param>
        /// <param name="address">
        ///   The address to write. Must be between 3 and 5 bytes, otherwise an ArgumentException is thrown.
        /// </param>
        public void SetAddress(AddressSlot slot, byte[] address)
        {
            CheckIsInitialized();
            AddressWidth.IsValid(address);
            Execute(Commands.W_REGISTER, (byte)slot, address);

            if (slot == AddressSlot.Zero)
            {
                _slot0Address = address;
            }
        }
コード例 #4
0
        /// <summary>
        /// Read 1 of 6 available module addresses
        /// </summary>
        public byte[] GetAddress(AddressSlot slot, int width)
        {
            CheckIsInitialized();
            AddressWidth.Check(width);
            var read   = Execute(Commands.R_REGISTER, (byte)slot, new byte[width]);
            var result = new byte[read.Length - 1];

            Array.Copy(read, 1, result, 0, result.Length);

            // Reverse the LSByte to MSByte per nRF24L01+ Datasheet
            result = ByteReverse(result);

            return(result);
        }
コード例 #5
0
        /// <summary>
        /// Set one of 6 available module addresses to its default value and disables it
        /// </summary>
        public void SetToDefaultAddress(AddressSlot s)
        {
            byte[] addr = new byte[1];

            CheckIsInitialized();


            switch (s)
            {
            case AddressSlot.Zero:
                AddressWidth.Check(_def_rx_addr_p0);
                Execute(Commands.W_REGISTER, (byte)s, _def_rx_addr_p0);
                _slot0Address = _def_rx_addr_p0;
                break;

            case AddressSlot.One:
                AddressWidth.Check(_def_rx_addr_p1);
                Execute(Commands.W_REGISTER, (byte)s, _def_rx_addr_p1);
                _slot0Address = _def_rx_addr_p1;
                break;

            case AddressSlot.Two:
                addr[0] = (byte)_def_rx_addr_p2.GetValue(0);
                Execute(Commands.W_REGISTER, (byte)s, addr);
                _slot2Address = addr;
                break;

            case AddressSlot.Three:
                addr[0] = (byte)_def_rx_addr_p3.GetValue(0);
                Execute(Commands.W_REGISTER, (byte)s, addr);
                _slot3Address = addr;
                break;

            case AddressSlot.Four:
                addr[0] = (byte)_def_rx_addr_p4.GetValue(0);
                Execute(Commands.W_REGISTER, (byte)s, addr);
                _slot4Address = addr;
                break;

            case AddressSlot.Five:
                addr[0] = (byte)_def_rx_addr_p5.GetValue(0);
                Execute(Commands.W_REGISTER, (byte)s, addr);
                _slot5Address = addr;
                break;
            }

            DisableAA(s);
            DisableRX(s);
        }
コード例 #6
0
        /// <summary>
        /// Enables a specific module address slot for reception
        /// </summary>
        public void EnableRX(AddressSlot s)
        {
            byte[] b  = new byte[2];
            byte[] bb = new byte[1];
            switch (s)
            {
            case AddressSlot.Zero:
                b    = Execute(Commands.R_REGISTER, Registers.EN_RXADDR, new byte[1]);
                b[1] = (byte)(b[1] | ((byte)(1 << Bits.ENAA_P0)));
                Array.Copy(b, 1, bb, 0, 1);
                Execute(Commands.W_REGISTER, Registers.EN_RXADDR, bb);
                break;

            case AddressSlot.One:
                b    = Execute(Commands.R_REGISTER, Registers.EN_RXADDR, new byte[1]);
                b[1] = (byte)(b[1] | ((byte)(1 << Bits.ENAA_P1)));
                Array.Copy(b, 1, bb, 0, 1);
                Execute(Commands.W_REGISTER, Registers.EN_RXADDR, bb);
                break;

            case AddressSlot.Two:
                b    = Execute(Commands.R_REGISTER, Registers.EN_RXADDR, new byte[1]);
                b[1] = (byte)(b[1] | ((byte)(1 << Bits.ENAA_P2)));
                Array.Copy(b, 1, bb, 0, 1);
                Execute(Commands.W_REGISTER, Registers.EN_RXADDR, bb);
                break;

            case AddressSlot.Three:
                b    = Execute(Commands.R_REGISTER, Registers.EN_RXADDR, new byte[1]);
                b[1] = (byte)(b[1] | ((byte)(1 << Bits.ENAA_P3)));
                Array.Copy(b, 1, bb, 0, 1);
                Execute(Commands.W_REGISTER, Registers.EN_RXADDR, bb);
                break;

            case AddressSlot.Four:
                b    = Execute(Commands.R_REGISTER, Registers.EN_RXADDR, new byte[1]);
                b[1] = (byte)(b[1] | ((byte)(1 << Bits.ENAA_P4)));
                Array.Copy(b, 1, bb, 0, 1);
                Execute(Commands.W_REGISTER, Registers.EN_RXADDR, bb);
                break;

            case AddressSlot.Five:
                b    = Execute(Commands.R_REGISTER, Registers.EN_RXADDR, new byte[1]);
                b[1] = (byte)(b[1] | ((byte)(1 << Bits.ENAA_P5)));
                Array.Copy(b, 1, bb, 0, 1);
                Execute(Commands.W_REGISTER, Registers.EN_RXADDR, bb);
                break;
            }
        }
コード例 #7
0
        /// <summary>
        /// Set one of 6 available module addresses
        /// </summary>
        public void SetAddress(AddressSlot slot, byte[] address)
        {
            CheckIsInitialized();
            AddressWidth.Check(address);

            // Address must be LSByte to MSByte per nRF24L01+ Datasheet
            address = ByteReverse(address);

            Execute(Commands.W_REGISTER, (byte)slot, address);

            if (slot == AddressSlot.Zero)
            {
                _slot0Address = address;
            }
        }
コード例 #8
0
        /// <summary>
        /// Set one of 6 available module addresses and enables it when in RX mode, sets also auto-ack if EN_AA is true
        /// </summary>
        public void SetAddress(AddressSlot s, byte[] address, bool EN_AA)
        {
            byte[] addr = new byte[1];

            CheckIsInitialized();

            if (s == AddressSlot.Zero || s == AddressSlot.One)
            {
                AddressWidth.Check(address);
                Execute(Commands.W_REGISTER, (byte)s, address);
            }
            else
            {
                addr[0] = (byte)address.GetValue(0);
                Execute(Commands.W_REGISTER, (byte)s, addr);
            }
            switch (s)
            {
            case AddressSlot.Zero: _slot0Address = address;
                break;

            case AddressSlot.One: _slot1Address = address;
                break;

            case AddressSlot.Two: _slot2Address = addr;
                break;

            case AddressSlot.Three: _slot3Address = addr;
                break;

            case AddressSlot.Four: _slot4Address = addr;
                break;

            case AddressSlot.Five: _slot5Address = addr;
                break;
            }
            if (EN_AA)
            {
                EnableAA(s);
            }
            EnableRX(s);
        }
コード例 #9
0
        /// <summary>
        /// Read 1 of 6 available module addresses
        /// </summary>
        public byte[] GetAddress(AddressSlot slot, int width)
        {
            var read   = new byte[width];
            var result = new byte[width];

            CheckIsInitialized();

            if (slot == AddressSlot.Zero || slot == AddressSlot.One)
            {
                AddressWidth.Check(width);
            }
            else
            {
                width = 1;
            }
            read   = Execute(Commands.R_REGISTER, (byte)slot, new byte[width]);
            result = new byte[read.Length - 1];
            Array.Copy(read, 1, result, 0, result.Length);
            return(result);
        }
コード例 #10
0
        /// <sumary>
        /// Returns the default address value for the pipe
        /// </sumary>
        public byte[] GetDefaultAddress(AddressSlot s)
        {
            byte[] addr = new byte[1];

            switch (s)
            {
                case AddressSlot.Zero: addr = _def_rx_addr_p0;
                    break;
                case AddressSlot.One: addr = _def_rx_addr_p1;
                    break;
                case AddressSlot.Two: addr = _def_rx_addr_p2;
                    break;
                case AddressSlot.Three: addr = _def_rx_addr_p3;
                    break;
                case AddressSlot.Four: addr = _def_rx_addr_p4;
                    break;
                case AddressSlot.Five: addr = _def_rx_addr_p5;
                    break;
            }
            return addr;
        }
コード例 #11
0
        /// <summary>
        /// Set one of 6 available module addresses and enables it when in RX mode, sets also auto-ack if EN_AA is true
        /// </summary>
        public void SetAddress(AddressSlot s, byte[] address, bool EN_AA)
        {
            byte[] addr = new byte[1];

            CheckIsInitialized();

            if (s == AddressSlot.Zero || s == AddressSlot.One)
            {
                AddressWidth.Check(address);
                Execute(Commands.W_REGISTER, (byte)s, address);
            }
            else
            {
                addr[0] = (byte)address.GetValue(0);
                Execute(Commands.W_REGISTER, (byte)s, addr);
            }
            switch (s)
            {
                case AddressSlot.Zero: _slot0Address = address;
                    break;
                case AddressSlot.One: _slot1Address = address;
                    break;
                case AddressSlot.Two: _slot2Address = addr;
                    break;
                case AddressSlot.Three: _slot3Address = addr;
                    break;
                case AddressSlot.Four: _slot4Address = addr;
                    break;
                case AddressSlot.Five: _slot5Address = addr;
                    break;
            }
            if (EN_AA)
            {
                EnableAA(s);
            }
            EnableRX(s);
        }
コード例 #12
0
 /// <summary>
 /// Enables a specific module address slot for reception
 /// </summary>
 public void EnableRX(AddressSlot s)
 {
     byte[] b = new byte[2];
     byte[] bb = new byte[1];
     switch (s)
     {
         case AddressSlot.Zero:
             b = Execute(Commands.R_REGISTER, Registers.EN_RXADDR, new byte[1]);
             b[1] = (byte)(b[1] | ((byte)(1 << Bits.ENAA_P0)));
             Array.Copy(b, 1, bb, 0, 1);
             Execute(Commands.W_REGISTER, Registers.EN_RXADDR, bb);
             break;
         case AddressSlot.One:
             b = Execute(Commands.R_REGISTER, Registers.EN_RXADDR, new byte[1]);
             b[1] = (byte)(b[1] | ((byte)(1 << Bits.ENAA_P1)));
             Array.Copy(b, 1, bb, 0, 1);
             Execute(Commands.W_REGISTER, Registers.EN_RXADDR, bb);
             break;
         case AddressSlot.Two:
             b = Execute(Commands.R_REGISTER, Registers.EN_RXADDR, new byte[1]);
             b[1] = (byte)(b[1] | ((byte)(1 << Bits.ENAA_P2)));
             Array.Copy(b, 1, bb, 0, 1);
             Execute(Commands.W_REGISTER, Registers.EN_RXADDR, bb);
             break;
         case AddressSlot.Three:
             b = Execute(Commands.R_REGISTER, Registers.EN_RXADDR, new byte[1]);
             b[1] = (byte)(b[1] | ((byte)(1 << Bits.ENAA_P3)));
             Array.Copy(b, 1, bb, 0, 1);
             Execute(Commands.W_REGISTER, Registers.EN_RXADDR, bb);
             break;
         case AddressSlot.Four:
             b = Execute(Commands.R_REGISTER, Registers.EN_RXADDR, new byte[1]);
             b[1] = (byte)(b[1] | ((byte)(1 << Bits.ENAA_P4)));
             Array.Copy(b, 1, bb, 0, 1);
             Execute(Commands.W_REGISTER, Registers.EN_RXADDR, bb);
             break;
         case AddressSlot.Five:
             b = Execute(Commands.R_REGISTER, Registers.EN_RXADDR, new byte[1]);
             b[1] = (byte)(b[1] | ((byte)(1 << Bits.ENAA_P5)));
             Array.Copy(b, 1, bb, 0, 1);
             Execute(Commands.W_REGISTER, Registers.EN_RXADDR, bb);
             break;
     }
 }
コード例 #13
0
 /// <summary>
 /// Read 1 of 6 available module addresses
 /// </summary>
 public byte[] GetAddress(AddressSlot slot, int width)
 {
     CheckIsInitialized();
     AddressWidth.Check(width);
     var read = Execute(Commands.R_REGISTER, (byte)slot, new byte[width]);
     var result = new byte[read.Length - 1];
     Array.Copy(read, 1, result, 0, result.Length);
     return result;
 }
コード例 #14
0
        /// <summary>
        /// Set one of 6 available module addresses
        /// </summary>
        public void SetAddress(AddressSlot slot, byte[] address)
        {
            CheckIsInitialized();
            AddressWidth.Check(address);

            // Address must be LSByte to MSByte per nRF24L01+ Datasheet
            address = ByteReverse(address);

            Execute(Commands.W_REGISTER, (byte)slot, address);

            if (slot == AddressSlot.Zero)
            {
                _slot0Address = address;
            }
        }
コード例 #15
0
        /// <summary>
        /// Read 1 of 6 available module addresses
        /// </summary>
        public byte[] GetAddress(AddressSlot slot, int width)
        {
            CheckIsInitialized();
            AddressWidth.Check(width);
            var read = Execute(Commands.R_REGISTER, (byte)slot, new byte[width]);
            var result = new byte[read.Length - 1];
            Array.Copy(read, 1, result, 0, result.Length);

            // Reverse the LSByte to MSByte per nRF24L01+ Datasheet
            result = ByteReverse(result);

            return result;
        }
コード例 #16
0
        /// <summary>
        /// Set one of 6 available module addresses to its default value and disables it
        /// </summary>
        public void SetToDefaultAddress(AddressSlot s)
        {
            byte[] addr = new byte[1];

            CheckIsInitialized();


            switch (s)
            {
                case AddressSlot.Zero:
                    AddressWidth.Check(_def_rx_addr_p0);
                    Execute(Commands.W_REGISTER, (byte)s, _def_rx_addr_p0);
                    _slot0Address = _def_rx_addr_p0;
                    break;
                case AddressSlot.One:
                    AddressWidth.Check(_def_rx_addr_p1);
                    Execute(Commands.W_REGISTER, (byte)s, _def_rx_addr_p1);
                    _slot0Address = _def_rx_addr_p1;
                    break;
                case AddressSlot.Two:
                    addr[0] = (byte)_def_rx_addr_p2.GetValue(0);
                    Execute(Commands.W_REGISTER, (byte)s, addr);
                    _slot2Address = addr;
                    break;
                case AddressSlot.Three:
                    addr[0] = (byte)_def_rx_addr_p3.GetValue(0);
                    Execute(Commands.W_REGISTER, (byte)s, addr);
                    _slot3Address = addr;
                    break;
                case AddressSlot.Four:
                    addr[0] = (byte)_def_rx_addr_p4.GetValue(0);
                    Execute(Commands.W_REGISTER, (byte)s, addr);
                    _slot4Address = addr;
                    break;
                case AddressSlot.Five:
                    addr[0] = (byte)_def_rx_addr_p5.GetValue(0);
                    Execute(Commands.W_REGISTER, (byte)s, addr);
                    _slot5Address = addr;
                    break;
            }

            DisableAA(s);
            DisableRX(s);
        }
コード例 #17
0
        /// <summary>
        /// Read 1 of 6 available module addresses
        /// </summary>
        public byte[] GetAddress(AddressSlot slot, int width)
        {
            var read = new byte[width];
            var result = new byte[width];
            CheckIsInitialized();

            if (slot == AddressSlot.Zero || slot == AddressSlot.One)
            {
                AddressWidth.Check(width);
            }
            else
            {
                width = 1;
            }
            read = Execute(Commands.R_REGISTER, (byte)slot, new byte[width]);
            result = new byte[read.Length - 1];
            Array.Copy(read, 1, result, 0, result.Length);
            return result;
        }
コード例 #18
0
        /// <summary>
        /// Set one of 6 available module addresses
        /// </summary>
        public void SetAddress(AddressSlot slot, byte[] address)
        {
            CheckIsInitialized();
            AddressWidth.Check(address);
            Execute(Commands.W_REGISTER, (byte)slot, address);

            if (slot == AddressSlot.Zero)
            {
                _slot0Address = address;
            }
        }