Re: FG Hardware Interace (FGInt)
Posted: Sat Apr 30, 2016 7:52 pm
Thanks,
i will begin feeding asap
i will begin feeding asap
An independent forum for FlightGear users and developers
https://www.thejabberwocky.net/
Code: Select all
#!/usr/bin/env python
# -*-coding:Utf-8 -*
###################################
# FarmerSoft FlightGear Interface
###################################
# Main Program
# FarmerSoft © 2015
# By Daweed
###################################
# System Module Import <= Module system needed to be imported
import os
import sys
import operator
import time
import struct
import socket
import datetime
# GPIO et PIGPIO Module Import <= that will be needed in the futur to manage interruption
import RPi.GPIO as GPIO
###################################
#
# Debug Mode :
# Level 0 : Debug mode off
# Level 1 : Debug mode on FarmerFGInt
# Level 2 : Debug mode on Device I2C
# Level 3 : Debug mode on Bus I2C
# Level 4 : Debug mode on Object I2C
#
###################################
##############################
# FarmerSoft Modules Import
##############################
from FarmerFGInt import FarmerFGInt as FGINT <= Here FGInt core class import
########################################
# Variables Initialisation
########################################
loop = True
########################################
loop = True
data = ""
props_tree_input_return = {}
props_tree_old = {}
state = '-'
now = datetime.datetime.now()
########################################
# Main
########################################
# Interface INT2 Creation
# The FGINT call return an FGInt python object
# In this case, it will use the int2.cfg file in the Config directory
INT2 = FGINT('int2.cfg', 1)
# Interface Devices Creation
# This methode list all devices declared in the config file
INT2.ListDevices()
# This methode will create all virtual device in the Interface scope
# Each create device can be access by a call like INT2.devices['devicename']
INT2.CreateDevices()
# I/O pack creation
# Here we get the first device named IOPACK1 which is defined in the config file.
# A pack is a mirror of a MCP23017, an object that will allow me to manage 16 I/O
IOPACK1 = INT2.GetDevice("IOPACK1")
# Same here for the second pack. 16 I/O more avail
IOPACK2 = INT2.GetDevice("IOPACK2")
# Liste des Switches dans la Configuration
# This method will list all switches declared in the config file (more usefull for debug)
INT2.ListSwitches()
# This method will create all switches defined, and each switches will be avail fomr
# INT2.switches["switchname']
INT2.CreateSwitches()
# Liste des Double Switches dans la Configuration
# Same here for double type switches
INT2.ListDblSwitches()
INT2.CreateDblSwitches()
# Liste des Rotary Switches dans la configuration
# and here for rotatry switches
INT2.ListRotSwitches()
INT2.CreateRotSwitches()
# Some debug trace
print("Initialisation de l'interface d'entrée")
print("\n")
# FG Connexion (connexion to simulation)
# This interface have a connexion From the interface and To FG and only in that way
print("Connexion au Serveur FG")
Sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host = '192.168.0.127'
port = 7700
Sock.connect((host, port))
# Starting the principal loop
print("Debut de la boucle principale")
while loop == True:
data = ""
if INT2.switches['mainswitch'].getSwitchState() == 1:
print("Etat du Main Switch : {}".format(INT2.switches['mainswitch'].getSwitchState()))
print("Fin de la boucle d'entrée de l'interface")
IOPACK1.configMCP(0, 0)
IOPACK2.configMCP(0, 0)
loop = False
i = 1
#what i do here is looping on the switches tab and get for each the actual state
#store in data var, then at the end of the loop send to FG information
for key, value in INT2.switcheslist:
if value != 'mainswitch':
data = data + str(INT2.switches[value].getSwitchState())
if i < len(INT2.switcheslist):
data = str(data + ":")
i += 1
i = 1
data = str(data) + ":"
for key, value in sorted(INT2.dblswitcheslist):
data = data + str(INT2.dblswitches[value].getSwitchState())
if i < len(INT2.dblswitcheslist):
data = str(data) + ":"
i += 1
i = 1
data= str(data) + ":"
for key, value in sorted(INT2.rotswitcheslist):
data = data + str(INT2.rotswitches[value].getSwitchState())
if i < len(INT2.rotswitcheslist):
data = str(data) + ":"
i += 1
i = 1
#print("DATA : {}".format(data))
# Here is sent the informations.
Sock.send(data)
Sock.send("\n")
time.sleep(0.001)
Code: Select all
for key, value in INT2.switcheslist:
if value != 'mainswitch':
data = data + str(INT2.switches[value].getSwitchState())
if i < len(INT2.switcheslist):
data = str(data + ":")
i += 1
Code: Select all
# Main Program
# FarmerSoft © 2015
# By Daweed
Code: Select all
# Main Program
# FarmerSoft © 2015
# By Daweed
#License GPL3+
Code: Select all
[INT]
intname=INT1
[DEVICES]
device001name=ledpack1
device002name=ledpack2
[SWLIGHTS]
swlight001name=ap1swlts
swlight002name=ap2swlts
swlight003name=athswlts
swlight004name=locswlts
swlight005name=expswlts
swlight006name=appswlts
swlight007name=apumstswlts
swlight008name=apumstswfltlts
swlight009name=apustrswlts
swlight010name=apustrswavaillts
swlight011name=eng1genswlts
swlight012name=eng1genswfltlts
swlight013name=eng2genswlts
swlight014name=eng2genswfltlts
swlight015name=ltkpump1swlts
swlight016name=ctkpump1swlts
swlight017name=rtkpump1swlts
swlight018name=batswlts
swlight019name=apugenswlts
swlight020name=extpwraswlts
swlight021name=extpwraavaillts
swlight022name=extpwrbswlts
swlight023name=extpwrbavaillts
swlight024name=pack1swlts
swlight025name=pack2swlts
swlight026name=eng1bldswlts
swlight027name=apubldswlts
swlight028name=eng2bldswlts
[DISPLAYS]
display001name=spddisplay
display002name=hdgdisplay
display003name=altdisplay
display004name=vsdisplay
display005name=qnhdisplay
Code: Select all
[SPDDISPLAY]
dispname=SPDDISPLAY
device=LEDPACK1
dispdigit=3
dispcom1=1
dispport=A
[HDGDISPLAY]
dispname=HDGDISPLAY
device=LEDPACK1
dispdigit=3
dispcom1=1
dispport=B
[ALTDISPLAY]
dispname=VSDISPLAY
device=LEDPACK1
dispdigit=5
dispcom1=4
dispport=A
[VSDISPLAY]
dispname=ALTDISPLAY
device=LEDPACK1
dispdigit=5
dispcom1=4
dispport=B
[QNHDISPLAY]
dispname=QNHDISPLAY
device=LEDPACK2
dispdigit=4
dispcom1=5
dispport=B
Code: Select all
[LOGOLTSW]
switchname=logoltsw
device=IOPACK2
port=A
pin1=6
pin2=7
values=0,1,2
valuestype=int
[DOMELTSW]
switchname=domeltsw
device=IOPACK2
port=A
pin1=3
pin2=4
values=0,0.5,1
valuestype=double
Code: Select all
[DOMELTSW]
switchname=domeltsw
device=IOPACK2
port=A
pin1=3
pin2=4
values=0,0.5,1
valuestype=double
Code: Select all
[SPDDISPLAY]
dispname=SPDDISPLAY
device=LEDPACK1
dispdigit=3
dispcom1=1
dispport=A