Question : sensors
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    beworld
    Posts: 590 from 2010/2/10
    From: FRANCE
    Hi,

    I try to implement sensors in SDL2 library.
    Original code : https://github.com/BSzili/SDL/blob/mos-sdl2/src/joystick/morphos/SDL_sysjoystick.c

    I have a PS4 gamepad connected (xbox360.class on trident) to test.

    I have a lot of questions : i try to explain, sorry for my english.....

    1. initialization of sensors ?

    Code:

    static const size_t sensortags[] = { SENSORS_Class, SensorClass_HID, SENSORS_Type, SensorType_HID_Gamepad, TAG_DONE };
    sensorlist = ObtainSensorsList((struct TagItem *)&sensortags), sensor = NULL;


    After MorphOS startup, i need to launch Trident to see my controller into Sensorlist.
    Exist any code to initialize sensors ?
    in library i open library here : https://github.com/BSzili/SDL/blob/mos-sdl2/src/core/morphos/SDL_library.c#L384

    2. when i see my controller :

    In original code of Itix, SENSORS_HID_Serial return nothing ?!

    Code:

    CONST_STRPTR serial = NULL;
    size_t qt[] = { SENSORS_HIDInput_Name_Translated, SENSORS_HID_Serial, (size_t)&serial, TAG_DONE };


    In trident, same i dont have Serial (serial #: n/a), so how to generate a serial ?

    3. Examples sensors.library codes

    I search somes examples how use sensors.library but it's really rare....
    I only find : https://bitbucket.org/BSzili/joysensors/src/master/joysensors.c

    Done for this first step..

    Thanks you
    IMac G5 2.1,PowerBook G4 1.5,MacMini 1.5, PowerMac G5 2.7 died !!!
    My MOS ports
  • »21.04.20 - 08:17
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    polluks
    Posts: 779 from 2007/10/23
    From: Gelsenkirchen,...
    Hi!
    Please take a look at ACE, the source of the joystick plug-in uses this library. I was just discussing with Philippe about my joystick...

    [ Editiert durch polluks 21.04.2020 - 10:10 ]
    Pegasos II G4: MorphOS 3.9, Zalman M220W · iMac G5 12,1 17", MorphOS 3.18
    Power Mac G3: OSX 10.3 · PowerBook 5,8: OSX 10.5, MorphOS 3.18
  • »21.04.20 - 08:55
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    BSzili
    Posts: 559 from 2012/6/8
    From: Hungary
    Quote:

    polluks wrote:
    Hi!
    Please take a look at ACE, the source of the joystick plug-in uses this library...


    The Plugin SDK contains the sources for only one plugin: AMX Mouse.

    [ Edited by BSzili 21.04.2020 - 10:11 ]
    This is just like television, only you can see much further.
  • »21.04.20 - 09:10
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    polluks
    Posts: 779 from 2007/10/23
    From: Gelsenkirchen,...
    @BSzili
    No no, it's a lhasa bug, all plug-ins are included.
    Pegasos II G4: MorphOS 3.9, Zalman M220W · iMac G5 12,1 17", MorphOS 3.18
    Power Mac G3: OSX 10.3 · PowerBook 5,8: OSX 10.5, MorphOS 3.18
  • »21.04.20 - 11:12
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    BSzili
    Posts: 559 from 2012/6/8
    From: Hungary
    I see, then the aminet file list is wrong too.
    This is just like television, only you can see much further.
  • »21.04.20 - 11:15
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 2971 from 2003/3/5
    From: Canada
    Quote:

    beworld wrote:
    After MorphOS startup, i need to launch Trident to see my controller into Sensorlist.



    Just 'Save' your USB settings and the xbox360.class will remain on the list.

    Quote:


    Exist any code to initialize sensors ?



    Sensors.library is initialized on boot. You might want to force-load the xbox360.class though.

    Quote:


    In original code of Itix, SENSORS_HID_Serial return nothing ?!
    In trident, same i dont have Serial (serial #: n/a), so how to generate a serial ?



    Some devices do not report one. There's nothing for you to generate.
  • »21.04.20 - 12:10
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    beworld
    Posts: 590 from 2010/2/10
    From: FRANCE
    @Jaca : thanks.

    Other question.

    When new Sensor is detected by SensorsNotificationMessage,
    how to put it in exist sensorlist (opened before) ?

    I dint want use ReleaseSensorsList and ObtainSensorsList again because
    i lost all child sensor on other joystick after that.

    Code is an example incomplete : Init call first, and Update is call non-stop (SDL2)

    Code:

    APTR sensorlist;
    APTR sensorchild_list[32];
    struct MsgPort *notifyPort
    APTR sensorsNotify;
    ULONG joystick_count;

    static void Init() {
    APTR sensor = NULL;
    ULONG count = 0;
    sensorlist = ObtainSensorsListTags(SENSOR_Class, SensorClass_HID, TAG_DONE);
    while (sensor = NextSensor(sensor, sensorlist, NULL)) {
    sensorchild_list[count++] = sensor;
    }
    joystick_count = count;
    if (notifyPort = CreateMsgPort()) {
    sensorsNotify = StartSensorNotifyTags(NULL,
    SENSORS_Notification_Destination, (IPTR)notifyPort,
    SENSORS_Class, SensorClass_HID,
    SENSORS_Notification_ClassListChanged, TRUE,
    SENSORS_Notification_Removed, FALSE,
    TAG_DONE);
    }

    }

    static void update()
    {
    if (notifyPort) {
    struct SensorsNotificationMessage *notifyMsg;
    while ((notifyMsg = (struct SensorsNotificationMessage *)GetMsg(notifyPort))) {
    sensorchild_list[joystick_count] = notifyMsg->Sensor;
    joystick_count++;
    ReplyMsg(notifyMsg);
    }

    }



    in Update, notifyMsg->Sensor give a new Sensor, but i can read it after because not present in sensoslist...
    Any little help, thanks, I hope it's understandable...

    BeWorld


    [ Edité par beworld 04.05.2020 - 16:36 ]
    IMac G5 2.1,PowerBook G4 1.5,MacMini 1.5, PowerMac G5 2.7 died !!!
    My MOS ports
  • »04.05.20 - 15:25
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 2971 from 2003/3/5
    From: Canada
    You are not allowed to modify the list returned by ObtainSensorsList - and you should NOT keep that list around. That prevents removing the sensors from the system if a gamepad is unplugged.

    What you should do instead is:
    - ObtainSensorsList() to find the gamepad you need; make a copy of sensors and their attributes if you need to keep your own list,
    - StartSensorNotify for gamepads you've selected for use in game
    - ReleaseSensorsList()

    Then if you get a notify that the gamepads list has changed, obtain the sensors list again, see if the gamepads you have a notify pending on are still there. If yes, keep them around. If no, StopSensorNotify on them and pick new ones.

    Hope this explains it.
  • »04.05.20 - 19:42
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    beworld
    Posts: 590 from 2010/2/10
    From: FRANCE
    Thanks you very much again... i see the light now :-)

    Need to rebase some codes on SDL2.
    IMac G5 2.1,PowerBook G4 1.5,MacMini 1.5, PowerMac G5 2.7 died !!!
    My MOS ports
  • »05.05.20 - 14:05
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    polluks
    Posts: 779 from 2007/10/23
    From: Gelsenkirchen,...
    @jacadcaps
    Apropos sensors, if I boot the ISO then my joystick is part of the list.
    If I boot the system, even without startup-sequence, it's lost.
    I removed the Poseidon settings, still no joystick. Have you got any idea?
    Pegasos II G4: MorphOS 3.9, Zalman M220W · iMac G5 12,1 17", MorphOS 3.18
    Power Mac G3: OSX 10.3 · PowerBook 5,8: OSX 10.5, MorphOS 3.18
  • »06.05.20 - 11:51
    Profile
  • MorphOS Developer
    jacadcaps
    Posts: 2971 from 2003/3/5
    From: Canada
    You need to perform a class scan and save the prefs.
  • »06.05.20 - 13:53
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    Cool_amigaN
    Posts: 745 from 2011/11/30
    Speaking of sensors, usb joysticks, mapping etc, is it possible for anyone from MorphOS Team, to create a similar utility for Prefs with Joystick Calibration for Windows using the new Sensors? Will the new Sensors ease their job somehow?
    Amiga gaming Tribute: Watch, rate, comment :)
  • »07.05.20 - 07:47
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 2971 from 2003/3/5
    From: Canada
    I did not initially bother with that because the support was created with original Xbox gamepads in mind and these are factory calibrated. That said, the sensors API makes it perfectly possible for a 3rd party to write such an app.

    [ Edited by jacadcaps 07.05.2020 - 14:22 ]
  • »07.05.20 - 13:21
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    beworld
    Posts: 590 from 2010/2/10
    From: FRANCE
    @jacadcaps
    Thanks

    How can we have a unique identifiers on HID devices same as childs-sensors (SENSORS_HIDInput_ID) ?
    IMac G5 2.1,PowerBook G4 1.5,MacMini 1.5, PowerMac G5 2.7 died !!!
    My MOS ports
  • »09.05.20 - 07:17
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 2971 from 2003/3/5
    From: Canada
    Why would you need that?
  • »09.05.20 - 13:19
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    beworld
    Posts: 590 from 2010/2/10
    From: FRANCE
    In SDL2, there is an function to Init Joystick, this fonction just store device in list. (and return number of deveice)

    In my first version, i dont have any problem because i dont use notification support (no hotplug).
    But if i want to support it, i need to rewrite all with notification support.

    Actualy Sources: https://github.com/BSzili/SDL/blob/mos-sdl2/src/joystick/morphos/SDL_sysjoystick.c
    Code:
    static int
    SDL_SYS_JoystickInit(void)
    {
    int rc = -1;

    APTR sensor = NULL;
    ULONG count = 0;

    D("[%s] Obtain sensor list...n", __FUNCTION__);
    sensorlist = ObtainSensorsListTags(SENSORS_Class, SensorClass_HID, /*SENSORS_Type, SensorType_HID_Gamepad,*/ TAG_DONE);
    while ((sensor = NextSensor(sensor, sensorlist, NULL)) && count < MAX_JOYSTICKS)
    {
    JoySensor[count++] = sensor;
    }

    D("[%s] Found %ld joysticks...n", __FUNCTION__, count);
    joystick_count = count;
    rc = count;
    return rc;
    }



    If i have an ID unique for it, i could store just this ID on my joystick list, no need to store Sensor or SensorNotify on my list and no need to start Notify on joystick (maybe just need StartSensorNotify to detect new device)

    When i open Joystick, i could start all notifications on device and close it when i close my joystick.

    And with that i can identify easily witch device plug or unplug and find it in my first list..
    IMac G5 2.1,PowerBook G4 1.5,MacMini 1.5, PowerMac G5 2.7 died !!!
    My MOS ports
  • »09.05.20 - 14:57
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 2971 from 2003/3/5
    From: Canada
    Give me a couple of days, I'll write the code for you guys.
  • »09.05.20 - 20:09
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    beworld
    Posts: 590 from 2010/2/10
    From: FRANCE
    Oh thanks you very very much !
    IMac G5 2.1,PowerBook G4 1.5,MacMini 1.5, PowerMac G5 2.7 died !!!
    My MOS ports
  • »09.05.20 - 20:47
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    beworld
    Posts: 590 from 2010/2/10
    From: FRANCE
    hi, i try Rumbles Sensors, i can't stop Rumble in progress :

    SDL2 launch a first call with no duration (so i put 5000 ms in Rumble_Duration to test)
    in second call SDL2 launch a stop Rumble (with 0 in duration and 0 in power), but
    SetSensorAttrsTags doesnt to take effect with 0 in value Rumble_Power and 0 in Rumble_Duration.

    Any hit to stop Rumble ?
    Thanks
    IMac G5 2.1,PowerBook G4 1.5,MacMini 1.5, PowerMac G5 2.7 died !!!
    My MOS ports
  • »15.05.20 - 12:03
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 2971 from 2003/3/5
    From: Canada
    Sorry, I haven't had a chance to look into this yet. Probably during the weekend...

    Which gamepad was that? (for the rumble)
  • »15.05.20 - 15:03
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    beworld
    Posts: 590 from 2010/2/10
    From: FRANCE
    ok no problem.

    i have Xbox360 Controller (WIRED), i see 2 rumbles : "Large Rumble Motor" and "Small Rumble Motor"
    In PS4 Dualshock, drivers doesnt see Rumbles.
    IMac G5 2.1,PowerBook G4 1.5,MacMini 1.5, PowerMac G5 2.7 died !!!
    My MOS ports
  • »15.05.20 - 15:12
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 2971 from 2003/3/5
    From: Canada
    https://pastebin.com/AyMXdy3g

    Take a look at the proposed API of the lib. This should be very easy to integrate into SDL.
  • »21.05.20 - 03:44
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 2971 from 2003/3/5
    From: Canada
    Guys, I've invited both of you to the github project where I'm working on this.

    To address some initial concerns: there will be NO problems with hotplug and HID-joysticks and co will be supported by the lib. They'll simply be mapped as best as possible to the standard gamepad layout.

    As you can see the code doesn't really work yet. Give me a couple of days...
  • »23.05.20 - 04:30
    Profile Visit Website