-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamino-qtGiu.py
executable file
·111 lines (93 loc) · 3.62 KB
/
camino-qtGiu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# This file is part of Camino.
# Copyright (C) 2017 Manuel Luitz <[email protected]>
#
# Camino is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Camino is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Camino. If not, see <http://www.gnu.org/licenses/>.
#
__author__ = "Manuel P. Luitz"
__copyright__ = "Copyright 2017"
__license__ = "GPL"
__email__ = "[email protected]"
import sys,os
from PyQt4 import QtGui
from PyQt4 import QtCore
from serial import Serial,serial_for_url
from input_parser import InputParser
import main_window_overlay
from camino_api_wrapper import CaminoApiWrapper
from settings import Settings
import signal
class SerialListener(QtCore.QThread):
new_data = QtCore.pyqtSignal(object)
sig_disconnect = QtCore.pyqtSignal(object)
def __init__(self, device):
self.device = device
QtCore.QThread.__init__(self)
def run(self):
self.request_stop = False
while self.request_stop is False:
try:
line = self.device.readline()
self.new_data.emit(line)
except:
self.sig_disconnect.emit(line)
def quit(self):
self.request_stop = True
class CaminoProgrammer(QtGui.QMainWindow,
main_window_overlay.UiOverlayWindow,
CaminoApiWrapper):
serialListener = None
serialDevice = None
def __init__(self, parent=None):
super(CaminoProgrammer, self).__init__(parent)
self.setupUi(self)
self.actionExit.triggered.connect(QtGui.qApp.quit)
self.actionConnect.triggered.connect(self.connectCamino)
self.actionDisconnect.triggered.connect(self.disconnectCamino)
self.pushButtonConfigureDevice.clicked.connect(self.programCamino)
self.pushButtonReadDevice.clicked.connect(self.readCamino)
self.inputParser = InputParser(self)
# Instance of the settings device
self.settings = Settings(self)
self.actionSettings.triggered.connect(self.settings.show)
def connectCamino(self):
if self.serialDevice is None:
self.serialDevice = Serial(self.settings.serial_port, 115200, timeout=5)
#self.serialDevice = serial_for_url('socket://192.168.10.22:10108')
if self.serialListener is None:
self.serialListener = SerialListener(self.serialDevice)
self.serialListener.new_data.connect(self.inputParser.update)
self.serialListener.sig_disconnect.connect(self.disconnectCamino)
self.serialListener.start()
self.setStatusConnected(self.settings.serial_port)
self.getDeviceInfo()
def disconnectCamino(self):
self.setStatusDisconnected()
self.clearGPSViews()
if self.serialListener is not None:
self.serialListener.quit()
self.serialListener.wait()
del(self.serialListener)
if self.serialDevice is not None:
del(self.serialDevice)
def main():
signal.signal(signal.SIGINT, signal.SIG_DFL)
app = QtGui.QApplication(sys.argv)
form = CaminoProgrammer()
form.show()
app.exec_()
if __name__ == '__main__':
main()