-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the second part of the orchestrator.
- Loading branch information
Showing
11 changed files
with
288 additions
and
251 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
Solution/LightPi.OrchestratorFirmware/Devices/IOutputDevice.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace LightPi.OrchestratorFirmware.Devices | ||
{ | ||
internal interface IOutputDevice | ||
{ | ||
void Initialize(); | ||
void WriteState(byte[] buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using Windows.Devices.I2c; | ||
|
||
namespace LightPi.OrchestratorFirmware.Devices | ||
{ | ||
internal sealed class MAX7311 : IOutputDevice | ||
{ | ||
private const int OutputRegister1 = 2; | ||
private const int ConfigurationRegister1 = 6; | ||
|
||
private readonly byte[] _stateBuffer = { OutputRegister1, 255, 255 }; | ||
|
||
private readonly string _i2CBusId; | ||
private readonly int _deviceAddress; | ||
private readonly int _stateOffset; | ||
|
||
private I2cDevice _i2CDevice; | ||
|
||
public MAX7311(string i2CBusId, int deviceAddress, int stateOffset, byte[] initialState) | ||
{ | ||
if (i2CBusId == null) throw new ArgumentNullException(nameof(i2CBusId)); | ||
if (initialState == null) throw new ArgumentNullException(nameof(initialState)); | ||
|
||
_stateBuffer[1] = initialState[0]; | ||
_stateBuffer[2] = initialState[1]; | ||
|
||
_i2CBusId = i2CBusId; | ||
_deviceAddress = deviceAddress; | ||
_stateOffset = stateOffset; | ||
} | ||
|
||
public void Initialize() | ||
{ | ||
var settings = new I2cConnectionSettings(_deviceAddress) | ||
{ | ||
BusSpeed = I2cBusSpeed.FastMode, | ||
SharingMode = I2cSharingMode.Exclusive | ||
}; | ||
|
||
_i2CDevice = I2cDevice.FromIdAsync(_i2CBusId, settings).AsTask().Result; | ||
|
||
// Write the initial state to the output register. Then set the configuration to "output". | ||
_i2CDevice.Write(_stateBuffer); | ||
|
||
byte[] setConfigurationToOutput = { ConfigurationRegister1, 0, 0 }; | ||
_i2CDevice.Write(setConfigurationToOutput); | ||
|
||
Debug.WriteLine($"Initialized MAX7311 with address {_deviceAddress}"); | ||
} | ||
|
||
public void WriteState(byte[] buffer) | ||
{ | ||
if (buffer == null) throw new ArgumentNullException(nameof(buffer)); | ||
|
||
_stateBuffer[1] = buffer[_stateOffset]; | ||
_stateBuffer[2] = buffer[_stateOffset + 1]; | ||
|
||
_i2CDevice.Write(_stateBuffer); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using Windows.Devices.I2c; | ||
|
||
namespace LightPi.OrchestratorFirmware.Devices | ||
{ | ||
internal sealed class PCF8574 : IOutputDevice | ||
{ | ||
private readonly byte[] _stateBuffer = { 0 }; | ||
|
||
private readonly string _i2CBusId; | ||
private readonly int _deviceAddress; | ||
private readonly int _stateOffset; | ||
|
||
private I2cDevice _i2CDevice; | ||
|
||
public PCF8574(string i2CBusId, int deviceAddress, int stateOffset, byte initialState) | ||
{ | ||
if (i2CBusId == null) throw new ArgumentNullException(nameof(i2CBusId)); | ||
|
||
_stateBuffer[0] = initialState; | ||
|
||
_i2CBusId = i2CBusId; | ||
_deviceAddress = deviceAddress; | ||
_stateOffset = stateOffset; | ||
} | ||
|
||
public void Initialize() | ||
{ | ||
var settings = new I2cConnectionSettings(_deviceAddress) | ||
{ | ||
BusSpeed = I2cBusSpeed.FastMode, | ||
SharingMode = I2cSharingMode.Exclusive | ||
}; | ||
|
||
_i2CDevice = I2cDevice.FromIdAsync(_i2CBusId, settings).AsTask().Result; | ||
_i2CDevice.Write(_stateBuffer); | ||
|
||
Debug.WriteLine($"Initialized PCF8574 with address {_deviceAddress}"); | ||
} | ||
|
||
public void WriteState(byte[] buffer) | ||
{ | ||
if (buffer == null) throw new ArgumentNullException(nameof(buffer)); | ||
|
||
_stateBuffer[0] = buffer[_stateOffset]; | ||
|
||
_i2CDevice.Write(_stateBuffer); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace LightPi.OrchestratorFirmware | ||
{ | ||
internal enum MoveBitMode | ||
{ | ||
Invert, | ||
Default, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.