From c8f08c83d6e061829fb5063ced3989471cd6af5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Fri, 26 Jun 2020 12:47:29 +0100 Subject: [PATCH 1/2] Fix NuGets --- .../AbstractIO.AdafruitMotorShieldV2.nfproj | 2 +- source/AbstractIO.Netduino3/AbstractIO.Netduino3.nfproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/AbstractIO.AdafruitMotorShieldV2/AbstractIO.AdafruitMotorShieldV2.nfproj b/source/AbstractIO.AdafruitMotorShieldV2/AbstractIO.AdafruitMotorShieldV2.nfproj index adaa364..d03377c 100644 --- a/source/AbstractIO.AdafruitMotorShieldV2/AbstractIO.AdafruitMotorShieldV2.nfproj +++ b/source/AbstractIO.AdafruitMotorShieldV2/AbstractIO.AdafruitMotorShieldV2.nfproj @@ -59,7 +59,7 @@ True True - + ..\packages\nanoFramework.Windows.Devices.Pwm.1.5.1\lib\Windows.Devices.Pwm.dll True True diff --git a/source/AbstractIO.Netduino3/AbstractIO.Netduino3.nfproj b/source/AbstractIO.Netduino3/AbstractIO.Netduino3.nfproj index b8a4037..504bb20 100644 --- a/source/AbstractIO.Netduino3/AbstractIO.Netduino3.nfproj +++ b/source/AbstractIO.Netduino3/AbstractIO.Netduino3.nfproj @@ -54,7 +54,7 @@ True True - + ..\packages\nanoFramework.Windows.Devices.Pwm.1.5.1\lib\Windows.Devices.Pwm.dll True True From 837959af586c6464e3c2248ba382e03aa517580c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Fri, 26 Jun 2020 12:57:03 +0100 Subject: [PATCH 2/2] Add error handling to I2C operations (WIP) - Replace calls to I2C operation to return operation result. - WIP: missing handling errors. --- .../Pca9685PwmController.cs | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/source/AbstractIO.AdafruitMotorShieldV2/Pca9685PwmController.cs b/source/AbstractIO.AdafruitMotorShieldV2/Pca9685PwmController.cs index a4fd798..08ce96e 100644 --- a/source/AbstractIO.AdafruitMotorShieldV2/Pca9685PwmController.cs +++ b/source/AbstractIO.AdafruitMotorShieldV2/Pca9685PwmController.cs @@ -182,7 +182,12 @@ private void WriteRegister(byte registerOffset, byte data) byte[] writeBuffer = { registerOffset, data }; lock (AbstractIO.GlobalLockObjects.I2cLockObject) { - _i2cDevice.Write(writeBuffer); + var operationResult = _i2cDevice.WritePartial(writeBuffer); + if(operationResult.Status != I2cTransferStatus.FullTransfer) + { + // TODO + // handle error + } } } @@ -202,7 +207,12 @@ private void WriteConsecutiveRegisters(byte startRegisterOffset, params byte[] v } lock (AbstractIO.GlobalLockObjects.I2cLockObject) { - _i2cDevice.Write(writeBuffer); + var operationResult = _i2cDevice.WritePartial(writeBuffer); + if (operationResult.Status != I2cTransferStatus.FullTransfer) + { + // TODO + // handle error + } } } @@ -272,8 +282,19 @@ private byte ReadRegister(byte registerOffset) var readBuffer = new byte[1]; lock (AbstractIO.GlobalLockObjects.I2cLockObject) { - _i2cDevice.Write(writeBuffer); - _i2cDevice.Read(readBuffer); + var operationResult = _i2cDevice.WritePartial(writeBuffer); + if (operationResult.Status != I2cTransferStatus.FullTransfer) + { + // TODO + // handle error + } + + operationResult = _i2cDevice.ReadPartial(readBuffer); + if (operationResult.Status != I2cTransferStatus.FullTransfer) + { + // TODO + // handle error + } } return readBuffer[0]; }