Skip to content

Commit

Permalink
minor updates to readme and tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
kutu committed Apr 21, 2020
1 parent 8f1e3bc commit fbce856
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -8,10 +8,10 @@ Python 3 implementation of iRacing SDK can:

# Install

- [Python 3.4+](https://www.python.org/downloads/)
- [PyYaml 3.11+](http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyyaml)
- add `X:\Python34\Scripts` directory to your `PATH` environment variable
- `pip3 install pyirsdk`
- [Python 3.7+](https://www.python.org/downloads/)
- [PyYaml 5.3+](http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyyaml)
- add `X:\Python37\Scripts` directory to your `PATH` environment variable
- `pip install pyirsdk`

# Usage

Expand Down
6 changes: 3 additions & 3 deletions tutorials/01 Introduction.md
Expand Up @@ -10,9 +10,9 @@ First thing you want when learning new library - shortest way to see it in actio
fullScreen=0
```

4. Go to iRacing site, and start test session with any car and with "Centripetal Circuit" (this track loads faster than others)
4. Go to iRacing website, and start test session with any car and with "Centripetal Circuit" (this track loads faster than others)

5. Start `py -3` (or `ipython3` if installed in step 2.) and type:
5. Start Python with `py` command (or `ipython` if installed in step 2.) and type:
```python
>>> import irsdk
>>> ir = irsdk.IRSDK()
Expand All @@ -22,7 +22,7 @@ First thing you want when learning new library - shortest way to see it in actio
<<< 0.0
```

Reading from yaml data, you always must check it for existence:
When reading session data, you always must check it for existence first:

```python
>>> if ir['WeekendInfo']:
Expand Down
10 changes: 6 additions & 4 deletions tutorials/02 Using irsdk script.md
@@ -1,15 +1,15 @@
When you installing `pyirsdk` you also got `irsdk.exe` script in `X:\Python33\Scripts` directory, which you can use for:
When you are installing `pyirsdk` you also get `irsdk.exe` script in `X:\Python3X\Scripts` directory, which you can use for:

- Dump current iRacing state to binary file
- Dump current iRacing memory map to binary file
`irsdk.exe --dump data.bin`

- Parse dumped binary file to txt file
`irsdk.exe --test data.bin --parse data.txt`

- Parse current iRacing state to readable txt file
- Parse current iRacing memory map to readable txt file
`irsdk.exe --parse data.txt`

Now, when you write your own scripts, for test purposes you can pass binary file to irsdk, instead of keep iRacing simulator always running
Now, when you write your own scripts, for test purposes you can pass binary file to irsdk, instead of keeping iRacing simulator running

```python
#!python3
Expand All @@ -18,3 +18,5 @@ ir = irsdk.IRSDK()
ir.startup(test_file='data.bin')
print(ir['Speed'])
```

Note: `data.bin` can also be an IBT Telemetry file, use it if you need to read session data. To read IBT Telemetry samples you have to use `irsdk.IBT` Class.
29 changes: 15 additions & 14 deletions tutorials/03 Base application.md
@@ -1,4 +1,4 @@
In this tutorial, you will learn how to create base of your own iRacing application.
In this tutorial, you will learn how to create base of your own iRacing application using pyirsdk.

Entry point is at the bottom, at `if __name__ == '__main__':` line.

Expand All @@ -18,9 +18,9 @@ class State:
def check_iracing():
if state.ir_connected and not (ir.is_initialized and ir.is_connected):
state.ir_connected = False
# don't forget to reset all your in State variables
# don't forget to reset your State variables
state.last_car_setup_tick = -1
# we are shut down ir library (clear all internal variables)
# we are shutting down ir library (clearing all internal variables)
ir.shutdown()
print('irsdk disconnected')
elif not state.ir_connected and ir.startup() and ir.is_initialized and ir.is_connected:
Expand All @@ -31,11 +31,12 @@ def check_iracing():
# and do something useful with it
def loop():
# on each tick we freeze buffer with live telemetry
# it is optional, useful if you use vars like CarIdxXXX
# in this way you will have consistent data from this vars inside one tick
# it is optional, but useful if you use vars like CarIdxXXX
# this way you will have consistent data from those vars inside one tick
# because sometimes while you retrieve one CarIdxXXX variable
# another one in next line of code can be changed
# another one in next line of code could change
# to the next iracing internal tick_count
# and you will get incosistent data
ir.freeze_var_buffer_latest()

# retrieve live telemetry data
Expand All @@ -48,19 +49,19 @@ def loop():

# retrieve CarSetup from session data
# we also check if CarSetup data has been updated
# with ir.get_session_info_update_by_key
# but first you need to request data, before check if its updated
# with ir.get_session_info_update_by_key(key)
# but first you need to request data, before checking if its updated
car_setup = ir['CarSetup']
if car_setup:
car_setup_tick = ir.get_session_info_update_by_key('CarSetup')
if car_setup_tick != state.last_car_setup_tick:
state.last_car_setup_tick = car_setup_tick
print('car setup update count:', car_setup['UpdateCount'])
# now you can go to garage, and do some changes with your setup
# and that this line will be printed, only when you change something
# and not every 1 sec
# this line will be printed, only when you change something
# and press apply button, but not every 1 sec
# note about session info data
# you should always check if data is available
# you should always check if data exists first
# before do something like ir['WeekendInfo']['TeamRacing']
# so do like this:
# if ir['WeekendInfo']:
Expand All @@ -70,11 +71,11 @@ def loop():
# you can send commands to iracing
# like switch cameras, rewind in replay mode, send chat and pit commands, etc
# check pyirsdk.py library to see what commands are available
# https://github.com/kutu/pyirsdk/blob/master/irsdk.py#L332
# https://github.com/kutu/pyirsdk/blob/master/irsdk.py#L134 (class BroadcastMsg)
# when you run this script, camera will be switched to P1
# and very first camera in list of cameras in iracing
# while script is running, change camera by yourself in iracing
# and how it changed back every 1 sec
# and notice how this code changes it back every 1 sec
ir.cam_switch_pos(0, 1)

if __name__ == '__main__':
Expand All @@ -92,7 +93,7 @@ if __name__ == '__main__':
loop()
# sleep for 1 second
# maximum you can use is 1/60
# cause iracing update data with 60 fps
# cause iracing updates data with 60 fps
time.sleep(1)
except KeyboardInterrupt:
# press ctrl+c to exit
Expand Down

0 comments on commit fbce856

Please sign in to comment.