<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Move the joystick according to serial data]]></title><description><![CDATA[<p dir="auto">Hi everone. Im reading some datas in serial. Here is my code for it:</p>
<pre><code>void MainWindow::on_Read_clicked() //dogru calisiyor mu bilinmiyor ---&gt; read from serial
{

if(serial-&gt;isOpen()) {

    int16_t dizi[11];
    int s;
    QByteArray data = serial-&gt;readAll();
   // m_console-&gt;putData(data);
  // qDebug() &lt;&lt; "okuyor" &lt;&lt; data;
    s= data.size();
    if (s&gt;22)
        s=22;

    memcpy(dizi, data.constData(), 22);
    qDebug() &lt;&lt; "--&gt;"&lt;&lt; dizi[1] &lt;&lt; dizi[2]&lt;&lt; dizi[3]&lt;&lt; dizi[4]&lt;&lt; dizi[5]&lt;&lt; dizi[6]&lt;&lt; dizi[7]&lt;&lt; dizi[8]&lt;&lt; dizi[9]&lt;&lt; dizi[10];

}

else {
    msgBox.setText("port acik degil!!!!");
msgBox.exec();
}
</code></pre>
<p dir="auto">I have 2 joystick. I want to move them according to that datas. Here is my joystick code for it. But now, it moves according to my mouse event.</p>
<pre><code>import QtQuick 2.0

Rectangle {
    id: root2
    width: joystick2.width
    height: joystick2.height
    color: "transparent"

    signal joystick2_moved2(double x2, double y2);
    Image {
        id: joystick2

        property real angle : 0
        property real distance : 0

        source: "background.png"
        anchors.centerIn: parent

        ParallelAnimation {
            id: returnAnimation
            NumberAnimation { target: thumb.anchors; property: "horizontalCenterOffset";
                to: 0; duration: 200; easing.type: Easing.OutSine }
            NumberAnimation { target: thumb.anchors; property: "verticalCenterOffset";
                to: 0; duration: 200; easing.type: Easing.OutSine }
        }



        MouseArea {
            id: mouse
            property real fingerAngle : Math.atan2(mouseX, mouseY)
            property int mcx : mouseX - width * 0.5
            property int mcy : mouseY - height * 0.5
            property bool fingerInBounds : fingerDistance2 &lt; distanceBound2
            property real fingerDistance2 : mcx * mcx + mcy * mcy
            property real distanceBound : width * 0.5 - thumb.width * 0.5
            property real distanceBound2 : distanceBound * distanceBound

            property double signal_x : (mouseX - joystick2.width/2) / distanceBound
            property double signal_y : -(mouseY - joystick2.height/2) / distanceBound


            anchors.fill: parent

            onPressed: {
                returnAnimation.stop();
            }

            onReleased: {
                returnAnimation.restart()
                joystick2_moved2(0, 0);
            }

            onPositionChanged: {
                if (fingerInBounds) {
                    thumb.anchors.horizontalCenterOffset = mcx
                    thumb.anchors.verticalCenterOffset = mcy
                } else {
                    var angle = Math.atan2(mcy, mcx)
                    thumb.anchors.horizontalCenterOffset = Math.cos(angle) * distanceBound
                    thumb.anchors.verticalCenterOffset = Math.sin(angle) * distanceBound
                }

                // Fire the signal to indicate the joystick has moved
                angle = Math.atan2(signal_y, signal_x)

                if(fingerInBounds) {
                    joystick2_moved2(
                        Math.cos(angle) * Math.sqrt(fingerDistance2) / distanceBound,
                        Math.sin(angle) * Math.sqrt(fingerDistance2) / distanceBound
                    );
                } else {
                    joystick2_moved2(
                        Math.cos(angle) * 500,
                        Math.sin(angle) * 500
                    );
                }
            }
        }

        Image {
            id: thumb
            source: "finger.png"
            anchors.centerIn: parent
        }
    }
}
</code></pre>
]]></description><link>https://forum.qt.io/topic/124079/move-the-joystick-according-to-serial-data</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 15:36:50 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/124079.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 23 Feb 2021 13:26:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Move the joystick according to serial data on Wed, 24 Feb 2021 01:50:54 GMT]]></title><description><![CDATA[<p dir="auto">joysticks are input devices.  they generate input data.  they don't receive it.</p>
]]></description><link>https://forum.qt.io/post/646042</link><guid isPermaLink="true">https://forum.qt.io/post/646042</guid><dc:creator><![CDATA[Kent-Dorfman]]></dc:creator><pubDate>Wed, 24 Feb 2021 01:50:54 GMT</pubDate></item></channel></rss>