Ejemplo n.º 1
0
        public void Persist(NRF24L01 radioModule)
        {
            byte config = 0;

            if (MaskDataReady)
            {
                config |= (1 << 6);
            }
            if (MaskDataSent)
            {
                config |= (1 << 5);
            }
            if (MaskMaximumRetries)
            {
                config |= (1 << 4);
            }
            if (EnableCRC)
            {
                config |= (1 << 3);
            }
            if (CRCLength == CRCLength.CRC16)
            {
                config |= (1 << 2);
            }
            if (Power == PowerMode.PowerUp)
            {
                config |= (1 << 1);
            }
            if (ChipMode == ChipWorkMode.Receive)
            {
                config |= 1;
            }

            radioModule.WriteRegister(CONFIG_REGISTER, config);
        }
Ejemplo n.º 2
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);
        }