summaryrefslogtreecommitdiff
path: root/scripts/gugus/controls.lua
blob: fc4aa7eb45bd999b17079c46d7019e1b8ff611c0 (plain)
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

---
mLCDup    = 10
mLCDdown  = 9 
mKeyDelay = 100

--
-- rFactor
--
mRFactorLCD_keys = {
	"H", -- std
	"J", -- standings
	"K", -- pit
	"L", -- vehicle
	"Y", -- aids
	"I", -- extra
	"O"  -- race
}
mRFactorLCD_state = 0

--
-- rFactor2
--
mRFactor2LCD_keys = {
	"6", -- std
	"7", -- standings
	"8", -- pit
	"9", -- vehicle
	"]", -- aids
	"0", -- extra
	"-", -- race
	"="  -- penalities
}
mRFactor2LCD_state = 0

function custom_controlsEvent(deviceType, ctrlType, ctrlPos, value, funcIndex, targetDevice)

	-- print ( string.format("[%s] %s:%s = %s => %s (%s)", deviceType, ctrlType, ctrlPos, value, funcIndex, targetDevice) )

	if funcIndex == -1 then
		if ctrlType == 1 and ( ctrlPos == mLCDup or ctrlPos == mLCDdown ) and value == 0 then
			local Key = nil
			--if ctrlPos == mLCDup then
			--	print ( " + LCD up")
			--else
			--	print ( " + LCD down")
			--end
			local sim = GetContextInfo("simulation")
			if sim == "rFactor2.exe" or sim == "rFactor.exe" then
				if sim == "rFactor2.exe" then

					--print ( " >> rF2 :" , mRFactor2LCD_state)

					if ctrlPos == mLCDup then
						mRFactor2LCD_state = mRFactor2LCD_state + 1
					elseif ctrlPos == mLCDdown then
						mRFactor2LCD_state = mRFactor2LCD_state - 1
					end

					mRFactor2LCD_state = mRFactor2LCD_state % table.getn(mRFactor2LCD_keys) 
					--print ( " << rF2 :" , mRFactor2LCD_state)

					Key = mRFactor2LCD_keys[mRFactor2LCD_state + 1]
				elseif sim == "rFactor.exe" then

					--print ( " >> rF :" , mRFactorLCD_state)

					if ctrlPos == mLCDup then
						mRFactorLCD_state = mRFactorLCD_state + 1
					elseif ctrlPos == mLCDdown then
						mRFactorLCD_state = mRFactorLCD_state - 1
					end

					mRFactorLCD_state = mRFactorLCD_state % table.getn(mRFactorLCD_keys)
					--print ( " << rF :" , mRFactorLCD_state)

					Key = mRFactorLCD_keys[mRFactorLCD_state + 1]
				end
			end
			if Key ~= nil then
				--print ( "KeyStroke : ", Key )
				SetKeystroke(Key, mKeyDelay, "")
				return 0
			end
		end
	end

	return 2
end

print ( "gugus> + controls" )