Skip to content

Instantly share code, notes, and snippets.

@stephenquan
Last active April 6, 2018 04:10
Show Gist options
  • Save stephenquan/9ec12ecbeeb6d982f36f3a7059eb566b to your computer and use it in GitHub Desktop.
Save stephenquan/9ec12ecbeeb6d982f36f3a7059eb566b to your computer and use it in GitHub Desktop.
appstudio-nmeasource-sample.qml
import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.1
import ArcGIS.AppFramework.Devices 1.0
import ArcGIS.AppFramework.Positioning 1.0
Item {
property DeviceListModel deviceListModel: discoveryAgent.devices
property Device currentDevice
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
ComboBox {
id: comboBox
Layout.fillWidth: true
model: deviceListModel
textRole: "name"
onCurrentTextChanged: selectDevice(deviceListModel.get(currentIndex))
}
ListView {
Layout.fillWidth: true
Layout.fillHeight: true
model: messagesListModel
delegate: Text { text: msg }
}
}
DeviceDiscoveryAgent {
id: discoveryAgent
}
NmeaSource {
id: nmeaSource
onReceivedNmeaData: log(nmeaSource.receivedSentence.trim())
}
PositionSource {
id: positionSource
active: false
nmeaSource: nmeaSource
}
ListModel {
id: messagesListModel
}
Connections {
target: deviceListModel
onCountChanged: if (comboBox.currentIndex == -1 && deviceListModel.count > 0) { comboBox.currentIndex = 0; }
}
function selectDevice(device) {
positionSource.active = false;
currentDevice = device;
nmeaSource.source = currentDevice;
messagesListModel.clear();
JSON.stringify(currentDevice, undefined, 2).split("\n").forEach(log);
positionSource.active = true;
}
function log(txt) {
console.log(txt);
messagesListModel.append( { msg: txt } );
if (messagesListModel.count > 20) { messagesListModel.remove(0); }
}
Component.onCompleted: discoveryAgent.start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment