Soft and hard combined virtual joystick display and control method under QT platform
Through the virtual joystick display and control method combining soft and hard under the QT platform, the semaphore event is used to transmit the joystick force-sensitive coordinates and simulate mouse events, which solves the problems of joystick equipment failure and type limitation under the Linux system, and realizes the joystick Graphical virtual control and a variety of control methods provide users with an intuitive control experience.
Patent Information
- Application Number
- CN202411450955.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-17
- Publication Date
- 2025-01-10
AI Technical Summary
The existing joystick display and control technology fails to effectively handle hardware device failures under Linux systems, and limits the type of joystick device accessed by the system, and cannot provide visual virtual joystick simulation and multiple control methods.
A virtual joystick display and control method combining soft and hard under the QT platform is designed. The joystick force-sensitive coordinates are transmitted through semaphore events, simulating mouse events, and realizing the virtual control of the joystick, including initializing drivers, parsing events, and rewriting controls. Events, display and control image initialization and mouse event simulation.
It realizes graphical virtual control of the joystick under the Linux system, and can simulate the joystick output through the mouse when the hardware device fails, providing a variety of control means, improving the user experience.
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of joystick control under Linux system, and relates to a virtual joystick display and control method combining software and hardware under QT platform. Background Art
[0002] The joystick is a common input device in weapon systems. By turning the joystick handle to a certain angle, directional control can be achieved in the up, down, left, and right directions.
[0003] In order to make the joystick device work properly as a serial port device under Linux system, it is necessary to provide users with a visual control interface to simulate the joystick movement process. At present, mature joystick display and control technologies include windml multi-pointer implementation, using the system's standard serial port driver as a low-level input driver, using the high-level input driver for the driver content, and simulating windml's message mechanism for ps / 2 mouse to perform the same display and control design on the serial port joystick; however, the above method does not consider how to virtually simulate the device when the hardware device fails, and also limits the type of joystick device connected to the system. Summary of the invention
[0004] (I) Purpose of the invention
[0005] The purpose of the present invention is: in an application scenario where the system is Linux, according to the system platform characteristics and the serial port data characteristics of the hardware joystick device, the joystick force-sensitive coordinates are transmitted through semaphore events, and the mouse events can be simulated with the joystick device, so as to design and implement a virtual joystick display and control method combining software and hardware under the QT platform.
[0006] (II) Technical solution
[0007] In order to solve the above technical problems, the present invention provides a virtual joystick display and control method combining software and hardware under a QT platform, which comprises the following steps:
[0008] S1: Initialize joystick driver
[0009] First, call the driver function to initialize the device, and then set the entry name of the callback function after the device movement event occurs;
[0010] S2: Get the event in the callback function and parse the data
[0011] According to the event in the callback function, analyze the event type and obtain the joystick movement coordinate value;
[0012] S3: Rewrite the drawing event of the display control;
[0013] S4: Initialize the joystick display control image according to the event button state;
[0014] S5: simulating a joystick manipulation process according to a movement value of an event movement event;
[0015] S6: Rewrite the mouse movement event in the control to simulate the joystick movement process;
[0016] S7: Override mouse release events within controls to simulate joystick release events.
[0017] Wherein, step S2 includes the following sub-steps:
[0018] S21: Get the event object in the callback function;
[0019] S22: Determine whether the channel number of the event object is legal, if not, exit the process, otherwise proceed to the next step;
[0020] S23: Determine the event type submitted by the event object;
[0021] S24: If the event is a joystick pressing event: send the event to process the key value according to the button status of left, middle or right;
[0022] S25: If the event is a joystick lift event: send the event and process the key value according to the left, middle, or right state of the key to eliminate the state change caused by the press event;
[0023] S26: If the event is a moving event: obtaining the position point of the moving relative origin, that is, the amplitude of the joystick;
[0024] S27: If the event is a press and move event: send the key state and move position parameters at the same time;
[0025] S28: If the event is a lift and move event: send the button state and movement position parameters simultaneously, eliminate the state change of the button being pressed, and record the position of the moving point.
[0026] Wherein, step S3 includes the following sub-steps:
[0027] S3: Override the drawing events of the display control
[0028] S31: Create a new drawing brush object;
[0029] S32: Setting a brush to eliminate jagged shapes;
[0030] S33: Create a large icon pixel map object;
[0031] S34: Loading the mapping object with a large icon image;
[0032] S35: Use the brush object to draw a large icon image on the display control interface;
[0033] S36: Create a small icon pixel map object;
[0034] S37: Loading a small icon image into the mapping object;
[0035] S38: Use the brush object to draw a small icon image on the display control interface.
[0036] Among them, in step S4, when it is determined that the state of the button is that the left button is pressed, the display control image is updated; when it is determined that the state of the button is that the left button is released, the pressed flag is set to 0.
[0037] In step S4, the process of updating the display control image is as follows:
[0038] S41: Set the pressed flag to 1;
[0039] S42: setting the center position value of the small icon for display control movement to be consistent with the center position value of the large icon within the display control range;
[0040] S43: Set the cursor position back to the large icon dot position (x0, y0);
[0041] S44: Update the drawing event, and return the small icon representing the movement of the joystick to the original position in the display control area.
[0042] The implementation process of step S5 is as follows:
[0043] S501: Determine whether the horizontal value x1 of the movement event is the maximum negative value. If so, set the horizontal coordinate value x2 of the current moving position to the radius R0 of the moving large icon in negative form. Otherwise, set the horizontal coordinate value x2 of the current moving position to x1*R0 / L0, where L0 represents the maximum distance between the operating rod and the origin.
[0044] S502: Determine whether the horizontal movement value y1 in the moving event is the negative maximum value. If so, set the vertical coordinate value y2 of the current moving position to the radius R0 of the moving large icon in negative form. Otherwise, set the vertical coordinate value y of the current moving position to y1*R0 / L0.
[0045] S503: Setting the current display control chart moving coordinates to a horizontal coordinate of x3=x2+x0 and a vertical coordinate of y3=y2+x0;
[0046] S504: Determine whether the button state is pressed, if yes, proceed to the next step, otherwise exit the process;
[0047] S505: Calculate the sum of the square of the difference between the current moving point position x3 and the center of the large icon x0 and the square of the difference between the current moving point position y3 and the center of the large icon y0;
[0048] S506: Determine whether the sum of squares is greater than the square of the radius of the large circle, if so, proceed to the next step, otherwise jump to step S512;
[0049] S507: Calculate the horizontal displacement of the horizontal coordinate x3 of the current moving point position Lx = int(R0*cos(atans(abs(x3-x0,), abs(y3-y0)), and the vertical displacement of the vertical coordinate Ly = int(R0*sin(atans(abs(x3-x0,), abs(y3-y0));
[0050] S508: Determine whether the horizontal coordinate x3 of the current moving point position is greater than the center x0 of the large icon, and whether the vertical coordinate y3 is greater than the center y0 of the large icon. If so, set the center xs of the small icon to (Lx+x0) and ys to (Ly+y0). Otherwise, proceed to the next step.
[0051] S509: Determine whether the horizontal coordinate x3 of the current moving point position is less than the center x0 of the large icon, and whether the vertical coordinate y3 is greater than the center y0 of the large icon. If so, set the center xs of the small icon to (x0-Lx), and ys to (Ly+y0);
[0052] S510: Determine whether the horizontal coordinate x3 of the current moving point position is smaller than the center x0 of the large icon, and whether the vertical coordinate y3 is smaller than the center y0 of the large icon. If so, set the center xs of the small icon to (x0-Lx) and ys to (y0-Ly).
[0053] S511: Determine whether the horizontal coordinate x3 of the current moving point position is greater than the center x0 of the large icon, and whether the vertical coordinate y3 is less than the center y0 of the large icon. If so, set the center xs of the small icon to (x0+Lx) and ys to (y0-Ly);
[0054] S512: Set the center of the small icon to the current moving point position (x3, y3);
[0055] S513: redraw the interface and call step S4 to update the display control image.
[0056] Among them, in step S6, the mouseMoveEvent function is initialized and defined, the coordinate position in the event is obtained and assigned to the current moving point position (x3, y3); S504-S512 in step S5 is performed to obtain the center position of the small icon.
[0057] The implementation process of step S7 is as follows:
[0058] S71: Set the mouse pressed flag to 0;
[0059] S72: setting the center of the small icon to the center of the large icon, that is, resetting the virtual joystick to move the object to the origin;
[0060] S73: Redraw the interface and call step S4 to update the display and control image.
[0061] (III) Beneficial effects
[0062] The above technical solution provides a virtual joystick display and control method that combines software and hardware under the QT platform, which graphically displays the movement process of the joystick of the physical device. At the same time, it is set by default that when the hardware device cannot be used normally, the mouse is used to simulate the joystick output display, providing users with a variety of control methods. DETAILED DESCRIPTION
[0063] In order to make the purpose, content and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with embodiments.
[0064] In order to solve the display and control problem of the joystick under the Linux system, a method for realizing a virtual mouse based on windml is adopted. The virtual joystick display and control method combining software and hardware under the QT platform of this embodiment includes the following steps:
[0065] S1: Initialize joystick driver
[0066] First, call the driver function to initialize the device, and then set the entry name of the callback function after the device movement event occurs.
[0067] S2: Get the event in the callback function and parse the data
[0068] According to the event in the callback function, analyze the event type and obtain the joystick movement coordinate value. The specific steps are as follows:
[0069] S21: Get the event object in the callback function;
[0070] S22: Determine whether the channel number of the event object is legal, if not, exit the process, otherwise proceed to the next step;
[0071] S23: Determine the event type submitted by the event object;
[0072] S24: If the event is a joystick pressing event: send the event to process the key value according to the button status of left, middle or right;
[0073] S25: If the event is a joystick lift event: send the event and process the key value according to the left, middle, or right state of the key to eliminate the state change caused by the press event;
[0074] S26: If the event is a moving event: obtaining the position point of the moving relative origin, that is, the amplitude of the joystick;
[0075] S27: If the event is a press and move event: send the key state and move position parameters at the same time;
[0076] S28: If the event is a lift and move event: send the button state and movement position parameters simultaneously, eliminate the state change of the button being pressed, and record the position of the moving point.
[0077] S3: Override the drawing events of the display control
[0078] S31: Create a new drawing brush object;
[0079] S32: Setting a brush to eliminate jagged shapes;
[0080] S33: Create a large icon pixel map object;
[0081] S34: Loading the mapping object with a large icon image;
[0082] S35: Use the brush object to draw a large icon image on the display control interface;
[0083] S36: Create a small icon pixel map object;
[0084] S37: Loading a small icon image into the mapping object;
[0085] S38: Use the brush object to draw a small icon image on the display control interface.
[0086] S4: Initialize the joystick display control image according to the event button status
[0087] When the state of the button is judged to be the left button pressed, the display control image is updated; when the state of the button is judged to be the left button released, the pressed flag is set to 0.
[0088] The process of display and control image update is as follows:
[0089] S41: Set the pressed flag to 1;
[0090] S42: setting the center position value of the small icon for display control movement to be consistent with the center position value of the large icon within the display control range;
[0091] S43: Set the cursor position back to the large icon dot position (x0, y0);
[0092] S44: Update the drawing event, and return the small icon representing the movement of the joystick to the original position in the display control area.
[0093] S5: Simulate the joystick control process according to the movement value of the event movement event
[0094] The specific steps are as follows:
[0095] S501: Determine whether the horizontal value x1 of the movement event is the maximum negative value. If so, set the horizontal coordinate value x2 of the current moving position to the radius R0 of the moving large icon in negative form. Otherwise, set the horizontal coordinate value x2 of the current moving position to x1*R0 / L0, where L0 represents the maximum distance between the operating rod and the origin.
[0096] S502: Determine whether the horizontal movement value y1 in the moving event is the negative maximum value. If so, set the vertical coordinate value y2 of the current moving position to the radius R0 of the moving large icon in negative form. Otherwise, set the vertical coordinate value y of the current moving position to y1*R0 / L0.
[0097] S503: Setting the current display control chart moving coordinates to a horizontal coordinate of x3=x2+x0 and a vertical coordinate of y3=y2+x0;
[0098] S504: Determine whether the button state is pressed, if yes, proceed to the next step, otherwise exit the process;
[0099] S505: Calculate the sum of the square of the difference between the current moving point position x3 and the center of the large icon x0 and the square of the difference between the current moving point position y3 and the center of the large icon y0;
[0100] S506: Determine whether the sum of squares is greater than the square of the radius of the large circle, if so, proceed to the next step, otherwise jump to step S512;
[0101] S507: Calculate the horizontal displacement of the horizontal coordinate x3 of the current moving point position Lx = int(R0*cos(atans(abs(x3-x0,), abs(y3-y0)), and the vertical displacement of the vertical coordinate Ly = int(R0*sin(atans(abs(x3-x0,), abs(y3-y0));
[0102] S508: Determine whether the horizontal coordinate x3 of the current moving point position is greater than the center x0 of the large icon, and whether the vertical coordinate y3 is greater than the center y0 of the large icon. If so, set the center xs of the small icon to (Lx+x0) and ys to (Ly+y0). Otherwise, proceed to the next step.
[0103] S509: Determine whether the horizontal coordinate x3 of the current moving point position is less than the center x0 of the large icon, and whether the vertical coordinate y3 is greater than the center y0 of the large icon. If so, set the center xs of the small icon to (x0-Lx), and ys to (Ly+y0);
[0104] S510: Determine whether the horizontal coordinate x3 of the current moving point position is smaller than the center x0 of the large icon, and whether the vertical coordinate y3 is smaller than the center y0 of the large icon. If so, set the center xs of the small icon to (x0-Lx) and ys to (y0-Ly).
[0105] S511: Determine whether the horizontal coordinate x3 of the current moving point position is greater than the center x0 of the large icon, and whether the vertical coordinate y3 is less than the center y0 of the large icon. If so, set the center xs of the small icon to (x0+Lx) and ys to (y0-Ly);
[0106] S512: Set the center of the small icon to the current moving point position (x3, y3);
[0107] S513: redraw the interface, calling step S4 to update the display control image;
[0108] S6: Rewrite the mouse movement event in the control to simulate the joystick movement process
[0109] Initialize and define the mouseMoveEvent function, obtain the coordinate position in the event and assign it to the current moving point position (x3, y3); perform S504-S512 in step S5 to obtain the center position of the small icon;
[0110] S7: Override the mouse release event in the control to simulate the joystick release event
[0111] S71: Set the mouse pressed flag to 0;
[0112] S72: setting the center of the small icon to the center of the large icon, that is, resetting the virtual joystick to move the object to the origin;
[0113] S73: Redraw the interface and call step S4 to update the display and control image.
[0114] By using the above scheme and the above operation steps, the present invention can realize the problem of joystick display control processing under Linux system. The method has been verified by algorithm and experimentally tested. The results show that the scheme can simulate joystick response events and use the mouse to virtualize the joystick device when the joystick device cannot be used, providing intuitive control movement process display for the upper application level.
[0115] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A virtual joystick display and control method combining software and hardware under QT platform, characterized in that: The following steps are involved: S1: Initialize joystick driver First, call the driver function to initialize the device, and then set the entry name of the callback function after the device movement event occurs; S2: Get the event in the callback function and parse the data According to the event in the callback function, analyze the event type and obtain the joystick movement coordinate value; S3: Rewrite the drawing event of the display control; S4: Initialize the joystick display control image according to the event button state; S5: simulating a joystick manipulation process according to a movement value of an event movement event; S6: Rewrite the mouse movement event in the control to simulate the joystick movement process; S7: Override mouse release events within controls to simulate joystick release events.
2. The virtual joystick display and control method combining software and hardware under the QT platform as claimed in claim 1, characterized in that: Step S2 includes the following sub-steps: S21: Get the event object in the callback function; S22: Determine whether the channel number of the event object is legal, if not, exit the process, otherwise proceed to the next step; S23: Determine the event type submitted by the event object; S24: If the event is a joystick pressing event: send the event to process the key value according to the button status of left, middle or right; S25: If the event is a joystick lift event: send the event and process the key value according to the left, middle, or right state of the key to eliminate the state change caused by the press event; S26: If the event is a moving event: obtaining the position point of the moving relative origin, that is, the amplitude of the joystick; S27: If the event is a press and move event: send the key state and move position parameters at the same time; S28: If the event is a lift and move event: send the button state and movement position parameters simultaneously, eliminate the state change of the button being pressed, and record the position of the moving point.
3. The virtual joystick display and control method combining software and hardware under the QT platform as claimed in claim 2, characterized in that: Step S3 includes the following sub-steps: S3: Override the drawing events of the display control S31: Create a new drawing brush object; S32: Setting a brush to eliminate jagged shapes; S33: Create a large icon pixel map object; S34: Loading the mapping object with a large icon image; S35: Use the brush object to draw a large icon image on the display control interface; S36: Create a small icon pixel map object; S37: Loading a small icon image into the mapping object; S38: Use the brush object to draw a small icon image on the display control interface.
4. The virtual joystick display and control method combining software and hardware under the QT platform as claimed in claim 3, characterized in that: In step S4, when it is determined that the state of the button is that the left button is pressed, the display control image is updated; when it is determined that the state of the button is that the left button is released, the pressed flag is set to 0.
5. The virtual joystick display and control method combining software and hardware under the QT platform as claimed in claim 4, characterized in that: In step S4, the process of updating the display control image is as follows: S41: Set the pressed flag to 1; S42: setting the center position value of the small icon for display control movement to be consistent with the center position value of the large icon within the display control range; S43: Set the cursor position back to the large icon dot position (x0, y0); S44: Update the drawing event, and return the small icon representing the movement of the joystick to the original position in the display control area.
6. The virtual joystick display and control method combining software and hardware under the QT platform as claimed in claim 5, characterized in that: The implementation process of step S5 is: S501: Determine whether the horizontal value x1 of the movement event is the maximum negative value. If so, set the horizontal coordinate value x2 of the current moving position to the radius R0 of the moving large icon in negative form. Otherwise, set the horizontal coordinate value x2 of the current moving position to x1*R0 / L0, where L0 represents the maximum distance between the operating rod and the origin. S502: Determine whether the horizontal movement value y1 in the moving event is the negative maximum value. If so, set the vertical coordinate value y2 of the current moving position to the radius R0 of the moving large icon in negative form. Otherwise, set the vertical coordinate value y of the current moving position to y1*R0 / L0. S503: Setting the current display control chart moving coordinates to a horizontal coordinate of x3=x2+x0 and a vertical coordinate of y3=y2+x0; S504: Determine whether the button state is pressed, if yes, proceed to the next step, otherwise exit the process; S505: Calculate the sum of the square of the difference between the current moving point position x3 and the center of the large icon x0 and the square of the difference between the current moving point position y3 and the center of the large icon y0; S506: Determine whether the sum of squares is greater than the square of the radius of the large circle, if so, proceed to the next step, otherwise jump to step S512; S507: Calculate the horizontal displacement of the horizontal coordinate x3 of the current moving point position Lx = int(R0*cos(atans(abs(x3-x0,), abs(y3-y0)), and the vertical displacement of the vertical coordinate Ly = int(R0*sin(atans(abs(x3-x0,), abs(y3-y0)); S508: Determine whether the horizontal coordinate x3 of the current moving point position is greater than the center x0 of the large icon, and whether the vertical coordinate y3 is greater than the center y0 of the large icon. If so, set the center xs of the small icon to (Lx+x0) and ys to (Ly+y0). Otherwise, proceed to the next step. S509: Determine whether the horizontal coordinate x3 of the current moving point position is less than the center x0 of the large icon, and whether the vertical coordinate y3 is greater than the center y0 of the large icon. If so, set the center xs of the small icon to (x0-Lx), and ys to (Ly+y0); S510: Determine whether the horizontal coordinate x3 of the current moving point position is smaller than the center x0 of the large icon, and whether the vertical coordinate y3 is smaller than the center y0 of the large icon. If so, set the center xs of the small icon to (x0-Lx) and ys to (y0-Ly). S511: Determine whether the horizontal coordinate x3 of the current moving point position is greater than the center x0 of the large icon, and whether the vertical coordinate y3 is less than the center y0 of the large icon. If so, set the center xs of the small icon to (x0+Lx) and ys to (y0-Ly); S512: Set the center of the small icon to the current moving point position (x3, y3); S513: redraw the interface and call step S4 to update the display control image.
7. The virtual joystick display and control method combining software and hardware under the QT platform as claimed in claim 6, characterized in that: In step S6, the mouseMoveEvent function is initialized and defined, the coordinate position in the event is obtained and assigned to the current moving point position (x3, y3); S504-S512 in step S5 are performed to obtain the center position of the small icon.
8. The virtual joystick display and control method combining software and hardware under the QT platform as claimed in claim 7, characterized in that: The implementation process of step S7 is: S71: Set the mouse pressed flag to 0; S72: setting the center of the small icon to the center of the large icon, that is, resetting the virtual joystick to move the object to the origin; S73: Redraw the interface and call step S4 to update the display and control image.
9. An application of a virtual joystick display and control method combining software and hardware under a QT platform according to any one of claims 1 to 8 in the field of joystick control technology under a Linux system.
10. A virtual joystick display and control system under Linux system, characterized in that: The display control is realized by using the virtual joystick display control method combining software and hardware under the QT platform as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Operating lever serial port drive design method based on semaphore event under vxworks system
CN111870939A
Mooring multi-rotor day and night photoelectric ground simulation control system
CN117420883A
Virtual joystick graphical user interface control with one and two dimensional operation
US6515687B1