From 6b0283b20612aba4cc5aaca9f5b78919fec2c05d Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Sun, 23 Aug 2026 23:53:14 +0100 Subject: [PATCH] added these examples I'm using them for development... --- .../read_from_ibt_file.go} | 9 ++- .../read_from_mmap_file.go | 62 +++++++++++++++++++ 2 files changed, 66 insertions(+), 5 deletions(-) rename examples/{example.go => read_from_ibt_file/read_from_ibt_file.go} (88%) create mode 100644 examples/read_from_mmap_file/read_from_mmap_file.go diff --git a/examples/example.go b/examples/read_from_ibt_file/read_from_ibt_file.go similarity index 88% rename from examples/example.go rename to examples/read_from_ibt_file/read_from_ibt_file.go index caaa9b2..5694d65 100644 --- a/examples/example.go +++ b/examples/read_from_ibt_file/read_from_ibt_file.go @@ -15,12 +15,11 @@ func msToKph(v float32) int { func main() { // Instantiate our iRacing SDK instance irsdk, err := goirsdk.Init(goirsdk.Options{ - SourceType: goirsdk.IBTFile, - SourcePath: "../../../testTelemetry/gt3_mustang_bathurst.ibt", - // SourcePath: "./exported.ibt", + SourceType: goirsdk.IBTFile, + SourcePath: "../../../../testTelemetry/gt3_mustang_bathurst.ibt", IBTExportType: goirsdk.SharedMemoryFile, - // IBTExportPath: "./exported.ibt", - IBTExport: true, + IBTExportPath: "./exported.ibt", + IBTExport: true, }) if err != nil { log.Fatalf("Failed to create iRacing interface: %v", err) diff --git a/examples/read_from_mmap_file/read_from_mmap_file.go b/examples/read_from_mmap_file/read_from_mmap_file.go new file mode 100644 index 0000000..71df02e --- /dev/null +++ b/examples/read_from_mmap_file/read_from_mmap_file.go @@ -0,0 +1,62 @@ +package main + +import ( + "fmt" + "log" + "time" + + "github.com/ESilva15/goirsdk" +) + +func msToKph(v float32) int { + return int((3600 * v) / 1000) +} + +func main() { + // Instantiate our iRacing SDK instance + irsdk, err := goirsdk.Init(goirsdk.Options{ + SourceType: goirsdk.SharedMemoryFile, + }) + if err != nil { + log.Fatalf("Failed to create iRacing interface: %v", err) + } + defer irsdk.Close() + + // Set up a loop to iterate our data + // TODO: revert this 240 back to 60 because i recorded the thing wrong or whatever + mainLoopTicker := time.NewTicker(time.Second / 240) + defer mainLoopTicker.Stop() + + for { + // Update the data that the SDK is holding with the next tick + _, err := irsdk.Update(100 * time.Millisecond) + if err != nil { + log.Printf("could not update data: %v", err) + continue + } + + // Vehicle Movement data gathered from the names we can find on the + // telemetry_docs.pdf file + // - I wish to make this less verbose if possible + if _, ok := irsdk.Vars.Vars["Gear"]; !ok { + log.Fatal("Field `Gear` doesn't exist") + } + + if _, ok := irsdk.Vars.Vars["RPM"]; !ok { + log.Fatal("Field `RPM` doesn't exist") + } + + if _, ok := irsdk.Vars.Vars["Speed"]; !ok { + log.Fatal("Field `Speed` doesn't exist") + } + + gear := int32(irsdk.Vars.Vars["Gear"].Value.(int)) + rpm := int32(irsdk.Vars.Vars["RPM"].Value.(float32)) + speed := int32(msToKph(irsdk.Vars.Vars["Speed"].Value.(float32))) + + fmt.Printf("\033[?25l\033[2J\033[H") + fmt.Printf("Gear: %d, RPM: %d, Speed: %d", gear, rpm, speed) + + <-mainLoopTicker.C + } +}