Esempio n. 1
0
class ppBousoleWidget(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self._y = 0
        self._frame = QFrame()
        self._lYaw = QLabel(str(0))
        self._lYaw.setMaximumWidth(35)
        self.setMaximumSize(85, 50)
        llayout = QVBoxLayout()
        llayout.setSpacing(0)
        llayout.setMargin(0)
        llayout.addWidget(self._lYaw)
        layout = QHBoxLayout()
        layout.setSpacing(0)
        layout.setMargin(0)
        layout.addWidget(self._frame)
        layout.addLayout(llayout)
        self.setLayout(layout)

    def __del__(self):
        pass

    def paintEvent(self, paintEvent):
        painter = QPainter(self)
        r = self._frame.rect()
        r -= QMargins(3, 3, 3, 4)
        painter.drawRect(r)
        painter.translate(r.width() / 2 + r.left(), r.height() / 2 + r.top())
        painter.drawLine(0, r.height() / 3, 0, -r.height() / 3)
        painter.rotate(self._y)
        painter.drawLine(0, -r.height() / 2, 3, -r.height() / 2 + 7)
        painter.drawLine(-3, -r.height() / 2 + 7, 3, -r.height() / 2 + 7)
        painter.drawLine(-3, -r.height() / 2 + 7, 0, -r.height() / 2)

        painter.drawLine(-r.height() / 2, 0, -r.height() / 2 + 5, 0)
        painter.drawLine(r.height() / 2, 0, r.height() / 2 - 5, 0)
        painter.drawLine(0, r.height() / 2, 0, r.height() / 2 - 5)
        for i in range(0, 360, 10):
            painter.drawLine(0, -r.height() / 2, 0, -r.height() / 2 + 3)
            painter.rotate(10)

    @property
    def yaw(self):
        return self._y

    @yaw.setter
    def yaw(self, v):
        self._y = v
        self._lYaw.setText(str(round(v)))
        self.update()

    def resizeEvent(self, event):
        pass
Esempio n. 2
0
class ppControlWidget(QWidget, QThread):
    def __init__(self):
        QWidget.__init__(self)
        QThread.__init__(self)

        pygame.init()
        pygame.joystick.init()
        self._joycnt = pygame.joystick.get_count()
        print(self._joycnt)
        if (self._joycnt == 0):
            print('no joystick found')
            #sys.exit(0)
        else:
            pygame.joystick.Joystick(0).init()
            if (pygame.joystick.Joystick(0).get_numaxes() < 4):
                self._joycnt = 0

        self._running = True
        self._instance = None
        self._periodicity = 0.05  #time period between loops
        self.frame = QFrame()
        self.frame.setFixedSize(100, 50)
        self.btconfig = QPushButton(QIcon("res/config.png"), "")
        self.setFixedSize(140, 50)
        self.layout = QHBoxLayout()
        self.layout.addWidget(self.frame)
        self.layout.addWidget(self.btconfig)
        self.setLayout(self.layout)
        if (self._joycnt > 0):
            self._joystick = pygame.joystick.Joystick(0)
            self._joystick.init()
            print(self._joystick.get_name())
            pygame.event.pump()
            self._Sticks = {
                'gaz':
                self._joystick.get_axis(joytofunc['functoaxis']['gaz']) *
                joytofunc['funcreverse']['gaz'],
                'yaw':
                self._joystick.get_axis(joytofunc['functoaxis']['yaw']) *
                joytofunc['funcreverse']['yaw'],
                'pitch':
                self._joystick.get_axis(joytofunc['functoaxis']['pitch']) *
                joytofunc['funcreverse']['pitch'],
                'roll':
                self._joystick.get_axis(joytofunc['functoaxis']['roll']) *
                joytofunc['funcreverse']['roll']
            }
            self._Switchs = {
                'start':
                self._joystick.get_button(joytofunc['functoswitch']['start']),
                'rth':
                self._joystick.get_button(joytofunc['functoswitch']['rth'])
            }
        else:
            self._joystick = None
            self._Sticks = {'gaz': 0, 'yaw': 0, 'pitch': 0, 'roll': 0}
            self._Switchs = {'start': 0, 'rth': 0}
        self.btconfig.clicked.connect(self.config)
        self.ConfigDialog = ppConfigControlWindow(parent=self)
        self.start()

    def __del__(self):
        self._running = False
        pygame.quit()

    def paintEvent(self, paintEvent):
        painter = QPainter(self)
        r = self.frame.rect()
        r -= QMargins(0, 0, 1, 1)
        painter.drawRect(r)
        c1 = QPoint(r.width() / 4, r.height() / 2)
        c2 = QPoint(3 * r.width() / 4, r.height() / 2)
        r1 = (r.height() * 0.90) / 2
        rc = (r.height() * 0.1) / 2
        painter.drawEllipse(c1, r1, r1)
        painter.drawEllipse(c2, r1, r1)
        c1 = QPoint(r.width() / 4 + (self._Sticks['yaw'] * r1),
                    r.height() / 2 - (self._Sticks['gaz'] * r1))
        c2 = QPoint(3 * r.width() / 4 + (self._Sticks['roll'] * r1),
                    r.height() / 2 - (self._Sticks['pitch'] * r1))
        painter.drawEllipse(c1, rc, rc)
        painter.drawEllipse(c2, rc, rc)

    def resizeEvent(self, event):
        pass

    def run(self):
        global bindaxis
        while (self._running):
            pygame.event.pump()
            if (self._joycnt > 0):
                self._Sticks = {
                    'gaz':
                    self._joystick.get_axis(joytofunc['functoaxis']['gaz']) *
                    joytofunc['funcreverse']['gaz'],
                    'yaw':
                    self._joystick.get_axis(joytofunc['functoaxis']['yaw']) *
                    joytofunc['funcreverse']['yaw'],
                    'pitch':
                    self._joystick.get_axis(joytofunc['functoaxis']['pitch']) *
                    joytofunc['funcreverse']['pitch'],
                    'roll':
                    self._joystick.get_axis(joytofunc['functoaxis']['roll']) *
                    joytofunc['funcreverse']['roll']
                }
                self._Switchs = {
                    'start':
                    self._joystick.get_button(
                        joytofunc['functoswitch']['start']),
                    'rth':
                    self._joystick.get_button(joytofunc['functoswitch']['rth'])
                }

            p = round(100 * self._Sticks['pitch'])
            r = round(100 * self._Sticks['roll'])
            y = round(100 * self._Sticks['yaw'])
            t = round(100 * self._Sticks['gaz'])
            to = self._Switchs['start']
            rt = self._Switchs['rth']

            self.ConfigDialog.freshValues(p, r, y, t, to, rt)

            if (self._instance is not None):
                self._instance.PCMD(p, r, y, t)

            for event in pygame.event.get():  # User did something
                if not (bindaxis == None):
                    if event.type == pygame.JOYAXISMOTION:
                        if abs(event.value) > 0.5:
                            joytofunc['functoaxis'][bindaxis] = event.axis
                            bindaxis = None
                    if event.type == pygame.JOYBUTTONDOWN:
                        joytofunc['functoswitch'][bindaxis] = event.button
                        bindaxis = None

                if event.type == pygame.JOYBUTTONDOWN:
                    if (event.button in joytofunc['switchtofunc'].keys()):
                        if (joytofunc['switchtofunc'][event.button] == 'start'
                            ):
                            try:
                                self._instance.tkof_lnd_emcy()
                            except:
                                print("no device selected")
                        if (joytofunc['switchtofunc'][event.button] == 'rth'):
                            try:
                                self._instance.rth()
                            except:
                                print("no device selected")

            self.update()
            time.sleep(self._periodicity)

    def config(self):
        w = self.ConfigDialog
        w.show()

    @property
    def Sticks(self):
        return self._Sticks

    @property
    def device(self):
        return self._instance

    @device.setter
    def device(self, dev):
        if dev is not None:
            self._instance = dev
Esempio n. 3
0
class ppHorizonWidget(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self._r = 0
        self._p = 0
        self._y = 0

        self._frame = QFrame()
        self._lRoll = QLabel(str(0))
        self._lRoll.setMaximumWidth(35)
        self._lPitch = QLabel(str(0))
        self._lPitch.setMaximumWidth(35)
        self.setMaximumSize(150, 50)
        llayout = QVBoxLayout()
        llayout.setSpacing(0)
        llayout.setMargin(0)
        llayout.addWidget(self._lPitch)
        llayout.addWidget(self._lRoll)
        layout = QHBoxLayout()
        layout.setSpacing(0)
        layout.setMargin(0)
        layout.addWidget(self._frame)
        layout.addLayout(llayout)
        self.setLayout(layout)

    def __del__(self):
        pass

    def paintEvent(self, paintEvent):
        painter = QPainter(self)
        r = self._frame.rect()
        r -= QMargins(3, 3, 3, 4)
        painter.drawRect(r)
        painter.translate(r.width() / 2 + r.left(), r.height() / 2 + r.top())
        dp = math.degrees(self._p)
        pr = r.height() / 90
        painter.translate(0, pr * dp)
        d = math.degrees(self._r)
        painter.rotate(d)
        painter.drawLine(-r.width() / 2, 0, r.width() / 2, 0)
        painter.drawLine(0, r.height() / 2, 0, -r.height() / 2)

    @property
    def roll(self):
        return self._r

    @property
    def pitch(self):
        return self._p

    @property
    def yaw(self):
        return self._y

    @roll.setter
    def roll(self, v):
        self._r = v
        self._lRoll.setText(str(round(math.degrees(v))) + '°')
        self.update()

    @pitch.setter
    def pitch(self, v):
        self._p = v
        self._lPitch.setText(str(round(math.degrees(v))) + '°')
        self.update()

    @yaw.setter
    def yaw(self, v):
        self._y = v
        self.update()

    def resizeEvent(self, event):
        pass
Esempio n. 4
0
class ppGraphWidget(QWidget):
    def __init__(self, p, title):
        QWidget.__init__(self)
        title = QLabel(title)
        self._frame = QFrame()
        self._lMax = QLabel(str(0))
        self._lMax.setMaximumWidth(35)
        self._lVal = QLabel(str(0))
        self._lVal.setMaximumWidth(35)
        self.setMaximumSize(200, 50)
        llayout = QVBoxLayout()
        llayout.setSpacing(0)
        llayout.setMargin(0)
        llayout.addWidget(title)
        llayout.addWidget(self._lMax)
        llayout.addWidget(self._lVal)
        layout = QHBoxLayout()
        layout.setSpacing(0)
        layout.setMargin(0)
        layout.addWidget(self._frame)
        layout.addLayout(llayout)

        self.setLayout(layout)
        self._history = []
        self._length = 10  # time to display in sec
        self._max = 0.1
        self._min = -0.1
        self._val = 0
        self._maxoflength = 0
        self._periodicity = p  #time period between value in sec

    def __del__(self):
        pass

    @property
    def period(self):
        return self._periodicity

    @period.setter
    def period(self, v):
        self._periodicity = v

    def paintEvent(self, paintEvent):
        painter = QPainter(self)
        r = self._frame.rect()
        r -= QMargins(3, 3, 3, 4)
        painter.drawRect(r)
        h = len(self._history)
        if (h > 5):
            csmp = round(self._length / self._periodicity)
            xr = r.width() / (self._length / self._periodicity)
            yr = r.height() / (self._max - self._min)
            i = csmp  #sample count to display
            c = h - 1  #index to display
            while (c > 0 and i > 0):
                x1 = r.left() + xr * i
                x2 = r.left() + xr * (i - 1)
                v1 = self._history[c] - self._min
                v2 = self._history[c - 1] - self._min
                y1 = r.top() + r.height() - v1 * yr
                y2 = r.top() + r.height() - v2 * yr
                painter.drawLine(x1, y1, x2, y2)
                i -= 1
                c -= 1

    def resizeEvent(self, event):
        pass

    def addValue(self, v):
        self._max = max(v, self._max)
        self._min = min(v, self._min)
        self._val = v
        self._lMax.setText(str(round(self._max)))
        self._lVal.setText(str(round(self._val)))
        self._history.append(v)
        self.update()