micmonay / simconnect

Golang SimConnect for FS2020 ✈️
MIT License
27 stars 5 forks source link

send event stops geting vars #4

Open SchmidtDawid opened 3 years ago

SchmidtDawid commented 3 years ago

Is someone is able to help me?

func main() {
    sc, err := simconnect.NewEasySimConnect()
    if err != nil {
        panic(err)
    }
    go connectToSimVars(sc)

    time.Sleep(3 * time.Second)
    event := sc.NewSimEvent(simconnect.KeyAutopilotOff)
    event.Run()

    for {
                fmt.Println(sc.IsAlive())
        time.Sleep(time.Second * 3)
    }
}

func connectToSimVars(sc *simconnect.EasySimConnect) <-chan []simconnect.SimVar {
    cSimVar, err := sc.ConnectToSimVar(
        simconnect.SimVarPlaneAltitude(),
        simconnect.SimVarAutopilotMaster(),
    )
    if err != nil {
        panic(err)
    }

    for {
        result := <-cSimVar
        fmt.Println(result)
    }
}

after i run this program i get updated sim data few time every second. After i send event to sc loop in connectToSimVars() stops. But i still get info that sc is alive (last loop)

jagobagascon commented 3 years ago

Not sure if this is related but event.Run() returns a <-chan int32 that triggers when the event finishes. You are not reading from that channel so maybe the code is getting stuck somewhere? Have you tried to run <-event.Run() ? Its working fine for me.