Sub Process_Globals
Public SlaveAddress As Byte = 0x69
Public Tmp As Double
Public AVG As Double
Private wire As WireMaster
Private raf As RandomAccessFile
Public const Size = 64 As Int
Public const PCTL = 0x00 As Byte
Public const RST = 0x01 As Byte
Public const FPSC = 0x02 As Byte
Public const INTC = 0x03 As Byte
Public const STAT = 0x04 As Byte
Public const SCLR = 0x05 As Byte
Public const AVE = 0x07 As Byte
Public const TTHL = 0x0E As Byte
Public const TTHH = 0x0F As Byte
Public const T01L = 0x80 As Byte
Public const T01H = 0x81 As Byte
End Sub
Public Sub Start
wire.Initialize
Setup_Chipset
CallSubPlus("tmr_tick", 100, 0)
End Sub
Sub Setup_Chipset
Log("Setup_Chipset")
wire.WriteTo(SlaveAddress, Array As Byte(PCTL, 0x00))
wire.WriteTo(SlaveAddress, Array As Byte(FPSC, 0x00))
End Sub
Sub tmr_tick(tag As Byte)
wire.WriteTo(SlaveAddress, Array As Byte(TTHL))
Dim b() As Byte = wire.RequestFrom(SlaveAddress, 2)
raf.Initialize(b, True)
Dim t As UInt = raf.ReadUInt16(raf.CurrentPosition)
If t > 0x800 Then
t = 0
End If
Tmp = t * 0.0625
Log("t=", T)
Log("Tmp=", Tmp)
wire.WriteTo(SlaveAddress, Array As Byte(0x80))
Dim b() As Byte = wire.RequestFrom(SlaveAddress, 128)
If b.Length <> 128 Then
Log("Error reading from chipset !")
Return
End If
raf.Initialize(b, True)
Dim av As Float, count As Int
For i = 0 To Size - 1
Dim t As UInt = raf.ReadUInt16(raf.CurrentPosition)
If t > 0x800 Then
t = 0
End If
Tmp = t * 0.25
Log("Tmp", i, "= ", Tmp,"; data=", t)
If t > 0 And t <= 125 Then
av = av + Tmp
count = count + 1
End If
Next
AVG = av / count
Log("AVG temperature = ", AVG)
End Sub