Untitled
unknown
plain_text
3 years ago
2.6 kB
3
Indexable
Never
"#!python3 import irsdk import time import pyautogui class State: ir_connected = False engineState = True def check_iracing(): if state.ir_connected and not (ir.is_initialized and ir.is_connected): state.ir_connected = False state.last_car_setup_tick = -1 ir.shutdown() print('irsdk disconnected') elif not state.ir_connected and ir.startup() and ir.is_initialized and ir.is_connected: state.ir_connected = True print('irsdk connected') def savefuel(ThrottleRaw): print("Engine State ", state.engineState) print("Throttle State ", ThrottleRaw) # Only toggle the ignition, if the engine is on and there is not throttle applied if state.engineState == True and ThrottleRaw <= 1: pyautogui.press("I") # press I to toggle the ignition state.engineState = False # and turn the state to false, to indicate that the engine is off print("Engine Off") def loop(): ir.freeze_var_buffer_latest() LapDistPct = int(ir['LapDistPct'] * 100) ThrottleRaw = int(ir['ThrottleRaw'] * 100) # Rough percentages of where one could lift and coast at Daytona # 13%-16% # 25%-30% # 34%-37% # 55%-67% # 95%-07% # Not very efficient, but it kind of works ¯\_(ツ)_/¯ if LapDistPct > 13 and LapDistPct < 16: print("Fuel Save Available") savefuel(ThrottleRaw) elif LapDistPct > 25 and LapDistPct < 30: print("Fuel Save Available") savefuel(ThrottleRaw) elif LapDistPct > 34 and LapDistPct < 37: print("Fuel Save Available") savefuel(ThrottleRaw) elif LapDistPct > 55 and LapDistPct < 67: print("Fuel Save Available") savefuel(ThrottleRaw) elif LapDistPct > 95 or (LapDistPct > 0 and LapDistPct < 7): print("Fuel Save Available") savefuel(ThrottleRaw) else: print("Fuel Save NOT Available") # Print out, if the engine is on or off print("Car Engine State ", state.engineState) # In case, the driver wants to get onto the throttle again, turn on the engine if state.engineState == False and ThrottleRaw > 1: print("Engine was off, turning it on again") pyautogui.press("I") # press I to toggle the ignition of the car state.engineState = True # switch the toggle to state, that the engine is on again print("Lap Distance % ", LapDistPct) print("Fuel Use per Hour ", ir['FuelUsePerHour']) if __name__ == '__main__': ir = irsdk.IRSDK() state = State() try: while True: check_iracing() if state.ir_connected: loop() time.sleep(.1) except KeyboardInterrupt: pass