/// <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 } } }
/// <summary> /// Send /// </summary> /// <param name="data">Data</param> public void SendData(byte[] pipeAddress, byte[] data) { gpio.Write(CE, PinValue.Low); FlushTX(); WriteRegister(RX_ADDR_P0, pipeAddress); WriteRegister(TX_ADDR, pipeAddress); WriteRegister(RX_PW_P0, packetSize); SetPowerMode(PowerMode.PowerUp); SetWorkingMode(ChipWorkMode.Transfer); byte[] buffer = new byte[1 + data.Length]; buffer[0] = W_TX_PAYLOAD; for (int i = 0; i < data.Length; i++) { buffer[1 + i] = data[i]; } sensor.Write(buffer); gpio.Write(CE, PinValue.High); MicrosecondTimer.Wait(130); gpio.Write(CE, PinValue.Low); var retryPolicy = GetRetryPolicy(); var retries = 0; var whatHappened = WhatHappened; while (!(whatHappened.DataTransfered || whatHappened.MaxRetriesExceeded) && retries <= retryPolicy.MaxRetries) { MicrosecondTimer.Wait(retryPolicy.DelayInMicroseconds); whatHappened = WhatHappened; retries++; } ClearTransmitEventRegisters(); FlushTX(); SetWorkingMode(ChipWorkMode.Receive); gpio.Write(CE, PinValue.High); }