-
Notifications
You must be signed in to change notification settings - Fork 0
/
clCommArduino.vb
111 lines (89 loc) · 3.79 KB
/
clCommArduino.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
Public Structure SerialSend
Public wheelPower As Integer ' -255~255 0=no force
Public Reset As Boolean
Public windPower As Byte
Public shakePower As Byte
Public shakeSpeed As Byte
Public Const PacketLen As Byte = 6
Public Function GetSerialData() As Byte()
Dim res(PacketLen - 1) As Byte
res(0) = If(Reset, 252, If(wheelPower < 0, 253, 254)) ' recordtype + wheelPowerDir
res(2) = Math.Abs(wheelPower)
res(3) = windPower
res(4) = shakePower
res(5) = shakeSpeed
res(1) = CByte(255) - (res(2) Xor res(3) Xor res(4) Xor res(5)) ' checkdigit
Return res
End Function
End Structure
Public Structure SerialSend2
Public BreakLed As Boolean
Public leftPower As SByte ' -127~127 0=no force
Public rightPower As SByte ' -127~127 0=no force
Public Const PacketLen As Byte = 4
Public Function GetSerialData() As Byte()
Dim res(PacketLen - 1) As Byte
res(0) = 254 + If(BreakLed, 1, 0) ' recordtype
res(2) = leftPower + 128
res(3) = rightPower + 128
res(1) = CByte(255) - (res(2) Xor res(3)) ' checkdigit
Return res
End Function
End Structure
Public Class SerialRead2
Public Const PacketLen As Byte = 2
'Public RealLeft As Single
'Public RealRight As Single
Public Sub SetSerialData(pSerialData As List(Of Byte))
'pSerialData(0) = recordType
'pSerialData(1) = errors / ACpower
'Const soundSpeed As Single = 0.172922 ' 331300 + 606 * tempAirCelsius / 1000000 / 2 = mm per microsecond , go and return <=> 34cm = 0,002 seconds
'RealLeft = CSng(pSerialData(11) + pSerialData(12) * 256) * soundSpeed
'RealRight = CSng(pSerialData(13) + pSerialData(14) * 256) * soundSpeed
End Sub
End Class
Public Class SerialRead
Public Const PacketLen As Byte = 8
Public pedalAccel As Integer
Public pedalBreak As Integer
Public pedalClutch As Integer
Public gear1 As Boolean
Public gear2 As Boolean
Public gear3 As Boolean
Public gear4 As Boolean
Public gear5 As Boolean
Public gear6 As Boolean
Public gearR As Boolean
Public buttons(clGame.BtCount - 1) As Boolean
Public AccelCorrected As Byte
Public BrakeCorrected As Byte
Public ClutchCorrected As Byte
Public Sub SetSerialData(pSerialData As List(Of Byte))
'pSerialData(0) = recordType
buttons(8) = (pSerialData(1) And 32) <> 0 ' bits 1 and 2 are reserved for errors
buttons(9) = (pSerialData(1) And 16) <> 0
buttons(0) = (pSerialData(2) And 1) <> 0
buttons(1) = (pSerialData(2) And 2) <> 0
buttons(2) = (pSerialData(2) And 4) <> 0
buttons(3) = (pSerialData(2) And 8) <> 0
buttons(4) = (pSerialData(2) And 16) <> 0
buttons(5) = (pSerialData(2) And 32) <> 0
buttons(6) = (pSerialData(2) And 64) <> 0
buttons(7) = (pSerialData(2) And 128) <> 0
gear1 = (pSerialData(3) And 1) <> 0
gear2 = (pSerialData(3) And 2) <> 0
gear3 = (pSerialData(3) And 4) <> 0
gear4 = (pSerialData(3) And 8) <> 0
gear5 = (pSerialData(3) And 16) <> 0
gear6 = (pSerialData(3) And 32) <> 0
gearR = (pSerialData(3) And 64) <> 0
pedalAccel = pSerialData(4)
pedalBreak = pSerialData(5)
pedalClutch = pSerialData(6)
' pSerialData(7) = Checksum !
' corrected analogic values:
AccelCorrected = ScaleValue(pedalAccel, SettingsMain.AccelMin, SettingsMain.AccelMax, 0, 255, SettingsMain.AccelGama)
BrakeCorrected = ScaleValue(pedalBreak, SettingsMain.BrakeMin, SettingsMain.BrakeMax, 0, 255, SettingsMain.BrakeGama)
ClutchCorrected = ScaleValue(pedalClutch, SettingsMain.ClutchMin, SettingsMain.ClutchMax, 0, 255, SettingsMain.ClutchGama)
End Sub
End Class