Browse Source

Added optional write debug.

woollybah 5 năm trước cách đây
mục cha
commit
037ea73b50
1 tập tin đã thay đổi với 18 bổ sung0 xóa
  1. 18 0
      core.mod/gpio/i2c/i2cdevice.bmx

+ 18 - 0
core.mod/gpio/i2c/i2cdevice.bmx

@@ -24,8 +24,12 @@
 SuperStrict
 SuperStrict
 
 
 Import brl.threads
 Import brl.threads
+Import brl.stringbuilder
+Import brl.standardio
 Import "../../common.bmx"
 Import "../../common.bmx"
 
 
+Const DEBUG_WRITE:Int = False
+
 Rem
 Rem
 bbdoc: The communications channel to a device on an I2C bus.
 bbdoc: The communications channel to a device on an I2C bus.
 End Rem
 End Rem
@@ -88,6 +92,20 @@ Private
 		Local messageCount:UInt
 		Local messageCount:UInt
 		
 		
 		If writeBuffer Then
 		If writeBuffer Then
+			If DEBUG_WRITE Then
+				Local sb:TStringBuilder = New TStringBuilder()
+				sb.Format("0x%x:", settings.GetDeviceAddress()).Format("0x%x:", writeBuffer[0])
+				If writeLength = 2 Then
+					sb.Format("0x%x", writeBuffer[1])
+				Else If writelength > 2 Then
+					For Local i:Int = 0 Until writelength - 1
+						sb.Format("%02x", writeBuffer[1 + i])
+					Next
+				End If
+				
+				Print sb.ToString()
+			End If
+			
 			messages[messageCount] = New i2c_msg(Short(settings.GetDeviceAddress()), Short(EI2cMessageFlags.I2C_M_WR), Short(writeLength), writeBuffer)
 			messages[messageCount] = New i2c_msg(Short(settings.GetDeviceAddress()), Short(EI2cMessageFlags.I2C_M_WR), Short(writeLength), writeBuffer)
 			messageCount :+ 1
 			messageCount :+ 1
 		End If
 		End If