norberttak / XPanel

XPlane 11/12 plugin to handle home cockpit panels
GNU General Public License v3.0
8 stars 3 forks source link

[BUG] Multiple instances of same type HID devices are messed up #99

Closed norberttak closed 4 months ago

norberttak commented 5 months ago

Followup bug of #90

if I connect only 1 radio it works as expected, but if I connect all my 3 radio devices, all 3 devices's display show same things (Top-Left display of first, second and third devices shows same thing, top-right same thing on all 3 devices and so on) and 3 devices are setted as below:

device 1 upper: COM1
device 1 lower: COM 2
device 2 upper: NAV 1
device 2 lower: NAV 2
device 3 upper: ADF
device 3 lower: XPDR

If I turn device 1 knobs, sometimes display of device 1 change, sometimes display of device 2, sometimes display of device 3. Same thing if I use knobs of device 2 or device 3.

I think that now the plugin have to distinguish the device when there are multiple devices of the same type.

norberttak commented 4 months ago

Hi @CyberGuerro It seems the issue with the 3 radio panels is caused by the same Configuration object being used by all threads. This is just an internal change and doesn't impact the config file itself. I hope with this version, all three radio panels will show the appropriate display values. Please test this version.

CyberGuerro commented 4 months ago

Tested: issue persist (are you sure that you send me correct version?) attached Log.txt xpanel.ini (remove .txt suffix) - used with Default Cessna 172 this is my udev.d rules:

KERNEL=="hidraw*", ATTRS{idVendor}=="06a3", ATTRS{idProduct}=="0d67", MODE="0666", SYMLINK+="saitekswitchpanel"
KERNEL=="hidraw*", ATTRS{idVendor}=="06a3", ATTRS{idProduct}=="0d05", MODE="0666", SYMLINK+="saitekradiopanel%n"
KERNEL=="hidraw*", ATTRS{idVendor}=="06a3", ATTRS{idProduct}=="0d06", MODE="0666", SYMLINK+="saitekmultipanel"
KERNEL=="hidraw*", ATTRS{idVendor}=="06a3", ATTRS{idProduct}=="0b4e", MODE="0666", SYMLINK+="saitekbippanel"
KERNEL=="hidraw*", ATTRS{idVendor}=="06a3", ATTRS{idProduct}=="0b4d", MODE="0666", SYMLINK+="saitektpmpanel"
SUBSYSTEM=="usb", ATTRS{idVendor}=="06a3", ATTRS{idProduct}=="0d05", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="06a3", ATTRS{idProduct}=="0d06", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="06a3", ATTRS{idProduct}=="0d67", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="06a3", ATTRS{idProduct}=="0b4e", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="06a3", ATTRS{idProduct}=="0b4d", MODE="0666"

Notice the "%n" suffix for saitek radio panel to distinguish the devices connected

norberttak commented 4 months ago

Sorry, it was my mistake. The rabbit's hole was deeper than I thought :-) I had to modify many parts of the code. Anyhow, I hope this version will work.

It's still work in progress but you can see the changes if you are interested: https://github.com/norberttak/XPanel/pull/101/files

CyberGuerro commented 4 months ago

Yess, it seems to work... .....at 99%.... ....it seems that ACT_STBY_UP and ACT_STBY_DOWN don't work..... could you verify?

this is config file:

; Aircraft specific handler for default C172 XPlane aircraft
;
; Copyright (C) 2022  Norbert Takacs <norberttak@gmail.com>
;
; SPDX-License-Identifier: GPL-3.0-or-later
;
; This program 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.
;
; This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.

;script_file="C172-arduino-home-cockpit.lua"
aircraft_acf="Cessna_172SP.acf"
log_level="DEBUG"

;---------------------- Saitek Radio Panel -------------------------
[device:id="saitek_radio"]
vid="6a3"
pid="d05"

[multi_display:id="RADIO_DISPLAY_ACTIVE_UP"]
line="on_select:SW_UP_COM1,dataref:sim/cockpit/radios/com1_freq_hz"
line="on_select:SW_UP_COM2,dataref:sim/cockpit/radios/com2_freq_hz"
line="on_select:SW_UP_NAV1,dataref:sim/cockpit/radios/nav1_freq_hz"
line="on_select:SW_UP_NAV2,dataref:sim/cockpit/radios/nav2_freq_hz"
line="on_select:SW_UP_ADF,dataref:sim/cockpit/radios/adf1_freq_hz"
line="on_select:SW_UP_DME,dataref:sim/cockpit/radios/nav1_dme_dist_m"
line="on_select:SW_UP_IDT,dataref:sim/cockpit/radios/transponder_code"

[multi_display:id="RADIO_DISPLAY_STBY_UP"]
line="on_select:SW_UP_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz"
line="on_select:SW_UP_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz"
line="on_select:SW_UP_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz"
line="on_select:SW_UP_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz"
line="on_select:SW_UP_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz"
line="on_select:SW_UP_DME,dataref:sim/cockpit/radios/nav2_dme_dist_m"

[button:id="KNOB_UP_BIG_PLUS"]
on_push="on_select:SW_UP_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_UP_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_UP_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_UP_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_UP_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:100:0:359"
on_push="on_select:SW_UP_IDT,dataref:sim/cockpit/radios/transponder_code:100:0:8888"

[button:id="KNOB_UP_BIG_MINUS"]
on_push="on_select:SW_UP_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_UP_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_UP_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_UP_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_UP_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:-100:0:359"
on_push="on_select:SW_UP_IDT,dataref:sim/cockpit2/radios/actuators/transponder_code:-100:0:8888"

[button:id="KNOB_UP_SMALL_PLUS"]
on_push="on_select:SW_UP_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:5:0:15000"
on_push="on_select:SW_UP_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:5:0:15000"
on_push="on_select:SW_UP_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:1:0:15000"
on_push="on_select:SW_UP_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:1:0:15000"
on_push="on_select:SW_UP_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:1:0:359"
on_push="on_select:SW_UP_IDT,dataref:sim/cockpit/radios/transponder_code:1:0:8888"

[button:id="KNOB_UP_SMALL_MINUS"]
on_push="on_select:SW_UP_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:-5:0:16000"
on_push="on_select:SW_UP_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:-5:0:16000"
on_push="on_select:SW_UP_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:-1:0:16000"
on_push="on_select:SW_UP_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:-1:0:16000"
on_push="on_select:SW_UP_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:-1:0:359"
on_push="on_select:SW_UP_IDT,dataref:sim/cockpit2/radios/actuators/transponder_code:-1:0:8888"

[button:id="ACT_STBY_UP"]
on_push="on_select:SW_UP_COM1,commandref:sim/radios/com1_standy_flip:once"
on_push="on_select:SW_UP_COM2,commandref:sim/radios/com2_standy_flip:once"
on_push="on_select:SW_UP_NAV1,commandref:sim/radios/nav1_standy_flip:once"
on_push="on_select:SW_UP_NAV2,commandref:sim/radios/nav2_standy_flip:once"
on_push="on_select:SW_UP_ADF,commandref:sim/radios/adf1_standy_flip:once"

[multi_display:id="RADIO_DISPLAY_ACTIVE_DOWN"]
line="on_select:SW_DOWN_COM1,dataref:sim/cockpit/radios/com1_freq_hz"
line="on_select:SW_DOWN_COM2,dataref:sim/cockpit/radios/com2_freq_hz"
line="on_select:SW_DOWN_NAV1,dataref:sim/cockpit/radios/nav1_freq_hz"
line="on_select:SW_DOWN_NAV2,dataref:sim/cockpit/radios/nav2_freq_hz"
line="on_select:SW_DOWN_ADF,dataref:sim/cockpit/radios/adf1_freq_hz"
line="on_select:SW_DOWN_DME,dataref:sim/cockpit/radios/nav1_dme_dist_m"
line="on_select:SW_DOWN_IDT,dataref:sim/cockpit/radios/transponder_code"

[multi_display:id="RADIO_DISPLAY_STBY_DOWN"]
line="on_select:SW_DOWN_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz"
line="on_select:SW_DOWN_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz"
line="on_select:SW_DOWN_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz"
line="on_select:SW_DOWN_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz"
line="on_select:SW_DOWN_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz"
line="on_select:SW_DOWN_DME,dataref:sim/cockpit/radios/nav2_dme_dist_m"

[button:id="KNOB_DOWN_BIG_PLUS"]
on_push="on_select:SW_DOWN_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_DOWN_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_DOWN_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_DOWN_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:100:0:15000"
on_push="on_select:SW_DOWN_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:100:0:359"
on_push="on_select:SW_DOWN_IDT,dataref:sim/cockpit/radios/transponder_code:100:0:8888"

[button:id="KNOB_DOWN_BIG_MINUS"]
on_push="on_select:SW_DOWN_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_DOWN_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_DOWN_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_DOWN_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:-100:0:16000"
on_push="on_select:SW_DOWN_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:-100:0:359"
on_push="on_select:SW_DOWN_IDT,dataref:sim/cockpit2/radios/actuators/transponder_code:-100:0:8888"

[button:id="KNOB_DOWN_SMALL_PLUS"]
on_push="on_select:SW_DOWN_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:5:0:15000"
on_push="on_select:SW_DOWN_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:5:0:15000"
on_push="on_select:SW_DOWN_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:1:0:15000"
on_push="on_select:SW_DOWN_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:1:0:15000"
on_push="on_select:SW_DOWN_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:1:0:359"
on_push="on_select:SW_DOWN_IDT,dataref:sim/cockpit/radios/transponder_code:1:0:8888"

[button:id="KNOB_DOWN_SMALL_MINUS"]
on_push="on_select:SW_DOWN_COM1,dataref:sim/cockpit/radios/com1_stdby_freq_hz:-5:0:16000"
on_push="on_select:SW_DOWN_COM2,dataref:sim/cockpit/radios/com2_stdby_freq_hz:-5:0:16000"
on_push="on_select:SW_DOWN_NAV1,dataref:sim/cockpit/radios/nav1_stdby_freq_hz:-1:0:16000"
on_push="on_select:SW_DOWN_NAV2,dataref:sim/cockpit/radios/nav2_stdby_freq_hz:-1:0:16000"
on_push="on_select:SW_DOWN_ADF,dataref:sim/cockpit/radios/adf1_stdby_freq_hz:-1:0:359"
on_push="on_select:SW_DOWN_IDT,dataref:sim/cockpit2/radios/actuators/transponder_code:-1:0:8888"

[button:id="ACT_STBY_DOWN"]
on_push="on_select:SW_DOWN_COM1,commandref:sim/radios/com1_standy_flip:once"
on_push="on_select:SW_DOWN_COM2,commandref:sim/radios/com2_standy_flip:once"
on_push="on_select:SW_DOWN_NAV1,commandref:sim/radios/nav1_standy_flip:once"
on_push="on_select:SW_DOWN_NAV2,commandref:sim/radios/nav2_standy_flip:once"
on_push="on_select:SW_DOWN_ADF,commandref:sim/radios/adf1_standy_flip:once"

Tested with one and multiple devices...

If I can I'd like to give you a suggestion: when I select IDT (where display is composed by 4 digit number), I'd like to view [blank]8888 on display instead 08888, and if I don't bind any dateref to display, I'd like to view blank display instead "00000". Is it possible to have this?

norberttak commented 4 months ago

Here it is the fixed version. It handles the ACT_STBY_UP and ACT_STBY_DOWN buttons correctly.

Regarding the IDT display digits: It's an excellent idea. I'll check how to do it in the code. But first, I have to finish the PR #101 . Many of my unit tests are broken now due to the modifications. I have to fix them.

CyberGuerro commented 4 months ago

I had to correct my previouse post (deleted) because now Radio devices work perfectly, but when I connect switch panel, X-Plane crash due XPanel plugin crash.... I suspect that you have to check new code with switch panel device and multipanel device (I don't use it)

norberttak commented 4 months ago

Please send me your full config (including switch panel config) and the log file. In my setup I have 2 radios, 1 switch, 1 multi and 1 FIP panel. I don't see any crash here. I'll check the details ...

CyberGuerro commented 4 months ago

Here they are: Log.txt xpanel.ini.txt (remove .txt suffix) xpanel-scripts.lua.txt (remove .txt suffix)

norberttak commented 4 months ago

It was an error in my code and it raised only with lua scripts defined for trigger_lit or trigger_unlit configs. Please do a test with this plugin version: https://github.com/norberttak/XPanel/actions/runs/8679705374/artifacts/1412202250

CyberGuerro commented 4 months ago

OK, now I tested all and it seems to work. What do you think about this issue? We can consider it .... .....FIXED?? (YESSS... ...YESSS... ...YESS)

norberttak commented 4 months ago

I think so :-) I have only one fail test case that I have to fix before merge the PR #101. I'll close this issue once the PR is merged.

May I ask you to open a new issue regarding the IDT display digits improvements mentioned earlier? I don't want to lose this idea when close this issue.