示例#1
0
        public string GetDetailsString()
        {
            var           status  = GetStatus();
            StringBuilder details = new StringBuilder();

            details.Append($" STATUS\t = 0x{status:X2}");
            details.Append($" RX_DR={((status & (1 << RX_DR)) != 0 ? 1 : 0):X2}");
            details.Append($" TX_DS={((status & (1 << TX_DS)) != 0 ? 1 : 0):X2}");
            details.Append($" MAX_RT={((status & (1 << MAX_RT)) != 0 ? 1 : 0):X2}");
            details.Append($" RX_P_NO={((status >> RX_P_NO) & 7):X2}");
            details.AppendLine($" TX_FULL={((status & (1 << TX_FULL)) != 0 ? 1 : 0):X2}");

            details.AppendLine(GetSettingString(" RX_ADDR_P0-1", RX_ADDR_P0, 5, 2));
            details.AppendLine(GetSettingString(" RX_ADDR_P2-5", RX_ADDR_P2, 1, 4));
            details.AppendLine(GetSettingString(" TX_ADDR", TX_ADDR, 5, 1));

            details.AppendLine(GetSettingString(" RX_PW_P0-6", RX_PW_P0, 1, 6));
            details.AppendLine(GetSettingString(" EN_AA", EN_AA));
            details.AppendLine(GetSettingString(" EN_RXADDR", EN_RXADDR));
            details.AppendLine(GetSettingString(" RF_CH", RF_CH));
            details.AppendLine(GetSettingString(" RF_SETUP", RF_SETUP));
            details.AppendLine(GetSettingString(" DYNPD/FEATURE", DYNPD, 1, 2));

            details.AppendLine(Nrf24L01Config.Read(this).ToString());

            details.AppendLine($" DataRate\t = {GetDataRate()}");
            var model = "NRF24L01" + (isPlusModel ? "+" : "");

            details.AppendLine($" Model\t\t = {model}");
            details.AppendLine($" CRC Length\t = {GetCRCLength()} bits");
            details.AppendLine($" PA Power\t = {GetPALevel()}");
            return(details.ToString());
        }
示例#2
0
        /// <summary>
        /// Set Working Mode
        /// </summary>
        /// <param name="mode">Working Mode</param>
        public void SetWorkingMode(ChipWorkMode mode)
        {
            var cfg = Nrf24L01Config.Read(this);

            if (cfg.ChipMode != mode)
            {
                cfg.ChipMode = mode;
                cfg.Persist(this);
            }
        }
示例#3
0
        /// <summary>
        /// Mask maximum retries event
        /// </summary>
        /// <param name="value"></param>
        public void MaskMaxRetries(bool value)
        {
            var cfg = Nrf24L01Config.Read(this);

            if (cfg.MaskMaximumRetries != value)
            {
                cfg.MaskMaximumRetries = value;
                cfg.Persist(this);
            }
        }
示例#4
0
        /// <summary>
        /// Mask data sent event
        /// </summary>
        /// <param name="value"></param>
        public void MaskDataSent(bool value)
        {
            var cfg = Nrf24L01Config.Read(this);

            if (cfg.MaskDataSent != value)
            {
                cfg.MaskDataSent = value;
                cfg.Persist(this);
            }
        }
示例#5
0
        /// <summary>
        /// Set CRC Length
        /// </summary>
        /// <param name="length"></param>
        public void SetCRCLength(CRCLength length)
        {
            var cfg = Nrf24L01Config.Read(this);

            if (cfg.CRCLength != length)
            {
                cfg.CRCLength = length;
                cfg.Persist(this);
            }
        }
示例#6
0
        /// <summary>
        /// Set Power Mode
        /// </summary>
        /// <param name="mode">Power Mode</param>
        public void SetPowerMode(PowerMode mode)
        {
            var cfg = Nrf24L01Config.Read(this);

            if (cfg.Power != mode)
            {
                cfg.Power = mode;
                cfg.Persist(this);
                if (mode == PowerMode.PowerUp)
                {
                    MicrosecondTimer.Wait(1600); // according to docs, need to wait only for 1500
                }
            }
        }
示例#7
0
        /// <summary>
        /// Read configuration of the given radio module
        /// </summary>
        /// <param name="radioModule"></param>
        /// <returns></returns>
        public static Nrf24L01Config Read(NRF24L01 radioModule)
        {
            var            cfg    = radioModule.ReadRegister(CONFIG_REGISTER);
            Nrf24L01Config result = new Nrf24L01Config()
            {
                RawValue           = cfg,
                MaskDataReady      = cfg.BitIsTrue(7),
                MaskDataSent       = cfg.BitIsTrue(6),
                MaskMaximumRetries = cfg.BitIsTrue(5),
                EnableCRC          = cfg.BitIsTrue(4),
                CRCLength          = cfg.BitIsTrue(3) ? CRCLength.CRC16 : CRCLength.CRC8,
                Power    = cfg.BitIsTrue(2) ? PowerMode.PowerUp : PowerMode.PowerDown,
                ChipMode = cfg.BitIsTrue(1) ? ChipWorkMode.Receive : ChipWorkMode.Transfer
            };

            return(result);
        }
示例#8
0
 /// <summary>
 /// Returns crc length (in bits)
 /// </summary>
 /// <returns></returns>
 public CRCLength GetCRCLength()
 {
     return(Nrf24L01Config.Read(this).CRCLength);
 }