Sub Process_Globals
Public Serial1 As Serial
Private eeprom As EEPROM
Private bc As ByteConverter
Private const SpecialMark As Int = 12345
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
'without this delay we will miss the first run as the program is reset when the logger
'is connected.
Delay(3000)
Log("AppStart")
'the special mark is stored in bytes 0, 1
'the counter is stored in bytes 2,3
'check if this is the first time
Dim counter As Int
Dim b() As Byte = eeprom.ReadBytes(0, 2)
If bc.IntsFromBytes(b)(0) = SpecialMark Then
'not first time
b = eeprom.ReadBytes(2, 2)
counter = bc.IntsFromBytes(b)(0)
Else
'write the special mark
Log("first time")
eeprom.WriteBytes(bc.IntsToBytes(Array As Int(SpecialMark)), 0)
counter = 0
End If
counter = counter + 1
Log("counter: ", counter)
'write the value to the EEPROM.
eeprom.WriteBytes(bc.IntsToBytes(Array As Int(counter)), 2)
End Sub