Witam,
napisalem prosty skrypt pobierajacy dane ze z GPS na Raspberry Pi. Chcialbym te dane pokazac na mapie uzywajac OpenStreet'a. Tylko mam problem, jezeli chodzi o wyswietlanie danych, bo nie wiem jak je przekazac. Skrypt pobierajacy dane z GPS nie jest w projekcie z Qt, ale mysle, ze to nie bedzie problem, bo wkleje tyllko caly skrypt a pozniej dokleje go do projektu.
import serial
import time
goToInformationOfGPS = serial.Serial("/dev/ttyUSB0", baudrate = 9600)#access to the usb0
#filename = "file_" + str(time.asctime()) + '.txt'
filename = "file_" + str(time.strftime("%a_%d_%b_%Y_%H:%M:%S")) + '.txt'
while True:
#time.sleep(5)
line = goToInformationOfGPS.readline()
information = line.split(",".encode())
if (information[0] =="$GPRMC"):
if (information[2]=="A"):
try:
#print (information [3] , information [4])
#print (information [5] , information [6])
try:
x = float(information [3]) / 100
y = float(information [5]) / 100
finally:
#print (x)
#print (y)
listax = [str(x),";", information [4], '\n']
listay = [str(y),";", information [6], '\n']
except ValueError:
pass
try:
#plik = open('dane.txt', 'a')
plik = open (filename, 'a')
try:
plik.writelines(listax)
plik.writelines(listay)
plik.flush()
finally:
plik.close()
except IOError:
pass
A tu czesc od qml
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Window 2.0
import QtLocation 5.6
import QtPositioning 5.6
Plugin {
id: mapPlugin
name: "osm"
//PluginParameter { name: "osm.useragent"; value: "My great Qt OSM application" }
//PluginParameter { name: "osm.mapping.host"; value: "http://osm.tile.server.address/" }
//PluginParameter { name: "osm.mapping.copyright"; value: "All mine" }
//PluginParameter { name: "osm.routing.host"; value: "http://osrm.server.address/viaroute" }
//PluginParameter { name: "osm.geocoding.host"; value: "http://geocoding.server.address" }
}
ApplicationWindow {
id: app_window
visible: true
width: 1024
height: 800
title: qsTr("Navigation")
Rectangle {
width: 500
height: 500
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
Map {
id: map
anchors.fill: parent
plugin: mapPlugin
center {
latitude: 59.91//länge
longitude: 10.75//breite
}
zoomLevel: 14
//******************************START POINT******************************//
MapCircle {
center {
latitude: 59.91
longitude: 10.75
}
radius: 100.0
color: 'green'
border.width: 3
}
//******************************FINISH POINT******************************//
MapCircle {
center {
latitude: 59.91
longitude: 10.75
}
radius: 100.0
color: 'red'
border.width: 3
}
}// Map
} //Rectangle
PositionSource {
nmeaSource: "socket://127.0.0.1:12345"
}
}
Teoretycznie stworzenie zmiennej w QML to nie problem, tylko nie wiem jak moge przeslac zmienna stworzona w pythonie do zmiennej w qml.
Pozdrawiam
DragonCoder