Coder Social home page Coder Social logo

simconnect's Introduction

Golang SimConnect binding for FS2020 ✈️

This library is in developement and I have write little documentation. Please considerate this library as a testing version. It is possible non backwards compatible in the future version. But you can enjoy 🥳 and good fly !

For more information on how to use this library, please read example_test.go.

With this library you can in simulator:

  • Read SimVar. (ex: Altitude, Longitude, Latitude, AP master status, Fuel, Engine...)
  • Write SimVar. All the SimVar have not a possibility to be written show SimVar.Settable
  • Send SimEvent for change Throttle or other
  • Receive system event (ex: When the aircraft crash). Not all implemented
  • Show text in the screen on the simulator

A simple example of how to use this library

package main

import (
	"fmt"
	"log"
	"strings"
	"time"

	sim "github.com/micmonay/simconnect"
)

func main() {
	sc, err := sim.NewEasySimConnect()
	if err != nil {
		panic(err)
	}
	sc.SetLoggerLevel(sim.LogInfo) // It is better if you the set before connect
	c, err := sc.Connect("MyApp")
	if err != nil {
		panic(err)
	}
	<-c // Wait connection confirmation
	cSimVar, err := sc.ConnectToSimVar(
		sim.SimVarPlaneAltitude(),
		sim.SimVarPlaneLatitude(sim.UnitDegrees), // You can force the units
		sim.SimVarPlaneLongitude(),
		sim.SimVarIndicatedAltitude(),
		sim.SimVarGeneralEngRpm(1),
		sim.SimVarAutopilotMaster(),
	)
	if err != nil {
		panic(err)
	}
	cSimStatus := sc.ConnectSysEventSim()
	//wait sim start
	for {
		if <-cSimStatus {
			break
		}
	}
	crashed := sc.ConnectSysEventCrashed()
	for {
		select {
		case result := <-cSimVar:
			for _, simVar := range result {
				var f float64
				var err error
				if strings.Contains(string(simVar.Unit), "String") {
					log.Printf("%s : %#v\n", simVar.Name, simVar.GetString())
				} else if simVar.Unit == "SIMCONNECT_DATA_LATLONALT" {
					data, _ := simVar.GetDataLatLonAlt()
					log.Printf("%s : %#v\n", simVar.Name, data)
				} else if simVar.Unit == "SIMCONNECT_DATA_XYZ" {
					data, _ := simVar.GetDataXYZ()
					log.Printf("%s : %#v\n", simVar.Name, data)
				} else if simVar.Unit == "SIMCONNECT_DATA_WAYPOINT" {
					data, _ := simVar.GetDataWaypoint()
					log.Printf("%s : %#v\n", simVar.Name, data)
				} else {
					f, err = simVar.GetFloat64()
					log.Println(simVar.Name, fmt.Sprintf("%f", f))
				}
				if err != nil {
					log.Println("return error :", err)
				}
			}

		case <-crashed:
			log.Println("Your are crashed !!")
			<-sc.Close() // Wait close confirmation
			return       // This example close after crash in the sim
		}

	}

}

simconnect's People

Contributors

micmonay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

simconnect's Issues

The sample can not continue when i start a new flight

I use your sample code in my program. When my first flight is over,the get var stoped.But when i back to the home page and start a new flight,the program did not continue to run.I have to close and open it again.can you help me ?

G1000 events doesn't work

I have problem with all g1000 events. None of them work for me. I have no problems with other events like AUTOPILOT_ON, COM_RADIO_FRACT_INC etc. But all events for G1000 like G1000_PFD_MENU_BUTTON, G1000_PFD_SOFTKEY1 does not work with cessna 172 skyhawk.

Do i have to pass any value? I tried 0,1,2,10,100. I don’t have any g1000 mod.

send event stops geting vars

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.