-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCC1101Controller.cs
73 lines (61 loc) · 2.88 KB
/
CC1101Controller.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.Device.Gpio;
using CC1101.NET.Interfaces;
using System.Device.Spi;
using CC1101.NET.Internal;
namespace CC1101.NET
{
public sealed class CC1101Controller : ICC1101Init
{
#region member fields
private ICC1101 _cc1101;
private readonly ConnectionConfiguration _configuration;
private readonly GpioController _gpioController;
private readonly SPICommunication _spiCommunication;
private readonly RxTxStateController _rxTxStateController;
private readonly IPowerstate _powerstate;
private IWakeOnRadio _wakeOnRadio;
#endregion
#region constructor
/// <summary>
/// Creates a new CC1101Controller-SPI Communication
/// </summary>
/// <param name="configuration">Optional - configure custom SPI-Pins</param>
public CC1101Controller(ConnectionConfiguration? configuration)
{
_configuration = configuration ?? new ConnectionConfiguration();
_gpioController = new GpioController(PinNumberingScheme.Logical);
var spi = SpiDevice.Create(new SpiConnectionSettings(_configuration.Bus, _configuration.CS));
_spiCommunication = new SPICommunication(spi);
_rxTxStateController = new RxTxStateController(_spiCommunication);
var powerstateController = new PowerstateController(_configuration, _gpioController, _spiCommunication);
_powerstate = new Powerstate(powerstateController);
_wakeOnRadio = new WakeOnRadio(_powerstate, _spiCommunication);
}
#endregion
#region ICC01Init implementation
/// <summary>
/// Creates the CC1101 Device - Disposable!
/// </summary>
/// <param name="transmitterAddress">The address of this device. This can be changed later</param>
/// <returns></returns>
public ICC1101 Initialize(byte transmitterAddress)
{
_cc1101 = Internal.CC1101.Create(_configuration, _wakeOnRadio, _gpioController, _powerstate, _rxTxStateController, _spiCommunication);
_cc1101.DeviceAddress = transmitterAddress;
return _cc1101;
}
/// <summary>
/// Creates the CC1101 Device - Disposable!
/// </summary>
/// <param name="transmitterAddress">The address of this device. This can be changed later</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<ICC1101> InitializeAsync(byte transmitterAddress, CancellationToken cancellationToken)
{
_cc1101 = await Internal.CC1101.CreateAsync(_configuration, _wakeOnRadio, _gpioController, _powerstate, _rxTxStateController, _spiCommunication, cancellationToken);
_cc1101.DeviceAddress = transmitterAddress;
return _cc1101;
}
#endregion
}
}