Facility Control

 View Only
  • 1.  Dashboard Game Controller buttons not updating?

    Posted 01-31-2024 19:28

    I'm certain the answer to this is simple, but I've got a basic panel that has two buttons and a USB game controller hooked up.  When either button 1 or 2 on the game controller is pressed, I want the button background in Dashboard to be red.  When it's not pressed, it should be green.  I have it working except for the fact that I have to click on "Apply Changes" in the component editor to see the Dashboard buttons update.  How do I set it to constantly listen and respond instantly to changes on the game controller?  Script is below, thanks in advance for any help!!

    <abs contexttype="opengear" gpiport="7799" id="_top" keepalive="true">
       <context contexttype="opengear" dblinqport="2222" id="DB-Joystick.1" objectid="com.rossvideo.joystick.Unknown:0:Controller (Xbox One For Windows)" objecttype="DB-Joystick" subscriptions="false"/>
       <context contexttype="opengear" id="Button A trigger" objectid="50232857086&lt;br&gt;Slot 6&lt;br&gt;MC1-MK" objecttype="MC1-MK" subscriptions="false">
          <ogscript handles="onchange,onload">
    
    
    /*! block id=1114,1130,1115,1131 !*/
    switch (params.getParam('DB-Joystick.1', 'params.joy.button.1.mappings.0.value', 0).getValue())
    {
    	case 0:
    		ogscript.setStyle("BUTTONB", "bg#green;");
    		break;
    	case 1:
    		ogscript.setStyle("BUTTONB", "bg#red;");
    		break;
    }
    /*! block id=1134,1133,1135,1136 !*/
    switch (params.getParam('DB-Joystick.1', 'params.joy.button.0.mappings.0.value', 0).getValue())
    {
    	case 0:
    		ogscript.setStyle("ButtonA", "bg#green;");
    		break;
    	case 1:
    		ogscript.setStyle("ButtonA", "bg#red;");
    		break;
    }
    /*!!
     &lt;block id="1114" type="switch" x="33" y="166" w="268" VALUE="ID:1130" STATEMENT="ID:1115" statementtag_STATEMENT="0" STATEMENT_0="ID:1131" statementtag_STATEMENT_0="1" STATEMENT_1="" /&gt;
    &lt;block id="1130" type="param_getvalue" x="26" y="53" w="318" PARAM="[root, Test Controller (Game Controllers slot 1), Not In Menu, Joystick Buttons (params.joy.button), Joystick Buttons[1], Mappings (params.joy.button.1.mappings), Mappings[0], Value (params.joy.button.1.mappings.0.value)]" PARAM_DATA="DB-Joystick.1&amp;amp;params.joy.button.1.mappings.0.value[0]" /&gt;
    &lt;block id="1115" type="ogscript_setstyle" x="39" y="369" w="243" ID="BUTTONB" STYLE="bg#green;" /&gt;
    &lt;block id="1131" type="ogscript_setstyle" x="307" y="364" w="243" ID="BUTTONB" STYLE="bg#red;" /&gt;
    &lt;block id="1134" type="switch" x="467" y="150" w="268" VALUE="ID:1133" STATEMENT="ID:1135" statementtag_STATEMENT="0" STATEMENT_0="ID:1136" statementtag_STATEMENT_0="1" STATEMENT_1="" /&gt;
    &lt;block id="1133" type="param_getvalue" x="359" y="38" w="318" PARAM="[root, Test Controller (Game Controllers slot 1), Not In Menu, Joystick Buttons (params.joy.button), Joystick Buttons[0], Mappings (params.joy.button.0.mappings), Mappings[0], Value (params.joy.button.0.mappings.0.value)]" PARAM_DATA="DB-Joystick.1&amp;amp;params.joy.button.0.mappings.0.value[0]" /&gt;
    &lt;block id="1135" type="ogscript_setstyle" x="519" y="276" w="243" ID="ButtonA" STYLE="bg#green;" /&gt;
    &lt;block id="1136" type="ogscript_setstyle" x="596" y="427" w="243" ID="ButtonA" STYLE="bg#red;" /&gt;
    !!*/
    /*!!&lt;checksum&gt;c0a075b8c55e3b386d29ef301a45d0d8&lt;/checksum&gt;!!*/</ogscript>
       </context>
       <abs height="250" id="BUTTONB" left="450" name="Button B" top="260" width="440">
          <label height="250" left="0" name="BUTTON B" style="txt-align:center;size:Biggest;" top="0" width="440"/>
       </abs>
       <abs height="250" id="ButtonA" left="450" name="Button A" top="520" width="440">
          <label height="250" left="0" name="BUTTON A" style="txt-align:center;size:Biggest;" top="0" width="440"/>
       </abs>
    </abs>
    


    ------------------------------
    Aaron
    ------------------------------


  • 2.  RE: Dashboard Game Controller buttons not updating?

    Ross Staff
    Posted 02-01-2024 17:07

    Hi Aaron,

    I've attached an example grid below, modified from your provided grid. This example grid has been simplified, but the changes here can be adapted to fit your controller parameters and device context.

    One way to accomplish what you're looking for is to attach your existing task to the controller button parameter, and trigger this task onchange and onload:

    In the attached panel, I've inserted the param 'params.joy.button.0.mappings.0.value' (Button 1 from your joystick). The task used to change the colours of 'ButtonA' was attached to this parameter. Here, it's given a tasktype of onchange and onload:

    <param expand="true" height="100" id="params.joy.button.0.mappings.0.value" left="40" name="params.joy.button.0.mappings.0.value" oid="params.joy.button.0.mappings.0.value" showlabel="false" top="240" widget="text-display" width="240">
          <task tasktype="onchange,onload">
    ...
    </task>

    With this attached task, whenever the value of the parameter changes (e.g. on a button press), the task is triggered, and changes the colour of the button elements accordingly.

    In the example panel, an additional button ('Toggle Controller Button Value') is used to emulate this parameter value change, but in your case you should be able to change the parameter value by pressing the button on the controller.

    Then, you can do the same with 'params.joy.button.0.mappings.0.value', attaching its own task to be triggered onchange to change the colour of 'ButtonB'.

    Hopefully this helps, please let me know if you have any further questions!

    Example Grid:

    <abs contexttype="opengear" gpiport="7799" gridsize="20" id="_top" keepalive="true">
       <meta>
          <params>
             <param access="1" constrainttype="INT_CHOICE" name="params.joy.button.0.mappings.0.value" oid="params.joy.button.0.mappings.0.value" precision="0" type="INT16" value="1" widget="toggle">
                <constraint key="0">Controller Button 1 Not Pressed</constraint>
                <constraint key="1">Controller Button 1 Pressed</constraint>
             </param>
          </params>
       </meta>
       <abs height="250" id="ButtonA" left="450" name="Button A" top="520" width="440">
          <label height="250" id="BUTTON A" left="0" name="BUTTON A" style="txt-align:center;size:Biggest;" top="0" width="440"/>
       </abs>
       <param expand="true" height="100" id="params.joy.button.0.mappings.0.value" left="40" name="params.joy.button.0.mappings.0.value" oid="params.joy.button.0.mappings.0.value" showlabel="false" top="240" widget="text-display" width="240">
          <task tasktype="onchange,onload">
    
    
    /*! block id=1134,1133,1135,1136 !*/
    switch (params.getValue('params.joy.button.0.mappings.0.value', 0))
    {
    	case 0:
    		ogscript.setStyle("ButtonA", "bg#green;");
    		break;
    	case 1:
    		ogscript.setStyle("ButtonA", "bg#red;");
    		break;
    }
    /*!!
     &lt;block id="1134" type="switch" x="358" y="216" w="268" VALUE="ID:1133" STATEMENT="ID:1135" statementtag_STATEMENT="0" STATEMENT_0="ID:1136" statementtag_STATEMENT_0="1" STATEMENT_1="" /&gt;
    &lt;block id="1133" type="param_getvalue" x="10" y="216" w="318" PARAM="[root, Params for Controller%20Button%20Example%202.grid, Not In Menu, params.joy.button.0.mappings.0.value (params.joy.button.0.mappings.0.value)]" PARAM_DATA="_top&amp;amp;params.joy.button.0.mappings.0.value[0]" /&gt;
    &lt;block id="1135" type="ogscript_setstyle" x="656" y="306" w="243" ID="ButtonA" STYLE="bg#green;" /&gt;
    &lt;block id="1136" type="ogscript_setstyle" x="929" y="266" w="243" ID="ButtonA" STYLE="bg#red;" /&gt;
    !!*/
    /*!!&lt;checksum&gt;90fe5fa10ceb42dfbe99e3725b14a948&lt;/checksum&gt;!!*/</task>
       </param>
       <button buttontype="toggle" height="100" left="40" name="Toggle Controller Button Value" top="360" width="240">
          <task tasktype="ogscript">
    
    
    /*! block id=1144,1149,1145,1149,1146,1149 !*/
    if (params.getValue('params.joy.button.0.mappings.0.value', 0)  ==  0)
    {
    	params.setValue('params.joy.button.0.mappings.0.value', 0, 1)
    } else {
    	params.setValue('params.joy.button.0.mappings.0.value', 0, 0)
    }
    /*!!
     &lt;block id="1144" type="if" x="291" y="84" w="268" INPUT1="ID:1149" OPERATION="equals" INPUT2="0" TRUE="ID:1145" FALSE="ID:1146" IGNORE="" /&gt;
    &lt;block id="1149" type="param__top&amp;amp;params.joy.button.0.mappings.0.value (params.joy.button.0.mappings.0.value)[0]" x="13" y="62" w="243" SET="" /&gt;
    &lt;block id="1145" type="param_setvalue" x="647" y="157" w="318" PARAM="ID:1149" VALUE="1" /&gt;
    &lt;block id="1149" type="param__top&amp;amp;params.joy.button.0.mappings.0.value (params.joy.button.0.mappings.0.value)[0]" x="13" y="62" w="243" SET="" /&gt;
    &lt;block id="1146" type="param_setvalue" x="726" y="315" w="318" PARAM="ID:1149" VALUE="0" /&gt;
    &lt;block id="1149" type="param__top&amp;amp;params.joy.button.0.mappings.0.value (params.joy.button.0.mappings.0.value)[0]" x="13" y="62" w="243" SET="" /&gt;
    !!*/
    /*!!&lt;checksum&gt;477cf072634e432b17e92b4b290a35aa&lt;/checksum&gt;!!*/</task>
       </button>
    </abs>
    


    ------------------------------
    Michael Quach
    ------------------------------



  • 3.  RE: Dashboard Game Controller buttons not updating?

    Ross Staff
    Posted 02-02-2024 10:50

    Hi Aaron,

    To amend my previous answer and give an easier way to accomplish this, I've attached another grid below.

    The <ogscript/> tag adds the joystick parameter to its oid attribute, so that it can correctly register when this parameter value is changing - such as when the button is pressed down. It will look like this now:

    <ogscript handles="onchange,onload" oid="params.joy.button.1.mappings.0.value">

    Secondly, the <ogscript/> tag was moved to the "DB-Joystick.1" context, where it can be registered to the joystick parameter.

    Example Grid:

    <abs contexttype="opengear" gpiport="7799" id="_top" keepalive="true">
       <context contexttype="opengear" dblinqport="2222" id="DB-Joystick.1" objectid="com.rossvideo.joystick.Unknown:0:Controller (Xbox One For Windows)" objecttype="DB-Joystick" subscriptions="false">
          <ogscript handles="onchange,onload" oid="params.joy.button.1.mappings.0.value">
    
    
    /*! block id=1114,1130,1115,1131 !*/
    switch (params.getParam('DB-Joystick.1', 'params.joy.button.1.mappings.0.value', 0).getValue())
    {
    	case 0:
    		ogscript.setStyle("BUTTONB", "bg#green;");
    		break;
    	case 1:
    		ogscript.setStyle("BUTTONB", "bg#red;");
    		break;
    }
    /*! block id=1134,1133,1135,1136 !*/
    switch (params.getParam('DB-Joystick.1', 'params.joy.button.0.mappings.0.value', 0).getValue())
    {
    	case 0:
    		ogscript.setStyle("ButtonA", "bg#green;");
    		break;
    	case 1:
    		ogscript.setStyle("ButtonA", "bg#red;");
    		break;
    }
    /*!!
     &lt;block id="1114" type="switch" x="33" y="166" w="268" VALUE="ID:1130" STATEMENT="ID:1115" statementtag_STATEMENT="0" STATEMENT_0="ID:1131" statementtag_STATEMENT_0="1" STATEMENT_1="" /&gt;
    &lt;block id="1130" type="param_getvalue" x="26" y="53" w="318" PARAM="[root, Test Controller (Game Controllers slot 1), Not In Menu, Joystick Buttons (params.joy.button), Joystick Buttons[1], Mappings (params.joy.button.1.mappings), Mappings[0], Value (params.joy.button.1.mappings.0.value)]" PARAM_DATA="DB-Joystick.1&amp;amp;params.joy.button.1.mappings.0.value[0]" /&gt;
    &lt;block id="1115" type="ogscript_setstyle" x="39" y="369" w="243" ID="BUTTONB" STYLE="bg#green;" /&gt;
    &lt;block id="1131" type="ogscript_setstyle" x="307" y="364" w="243" ID="BUTTONB" STYLE="bg#red;" /&gt;
    &lt;block id="1134" type="switch" x="467" y="150" w="268" VALUE="ID:1133" STATEMENT="ID:1135" statementtag_STATEMENT="0" STATEMENT_0="ID:1136" statementtag_STATEMENT_0="1" STATEMENT_1="" /&gt;
    &lt;block id="1133" type="param_getvalue" x="359" y="38" w="318" PARAM="[root, Test Controller (Game Controllers slot 1), Not In Menu, Joystick Buttons (params.joy.button), Joystick Buttons[0], Mappings (params.joy.button.0.mappings), Mappings[0], Value (params.joy.button.0.mappings.0.value)]" PARAM_DATA="DB-Joystick.1&amp;amp;params.joy.button.0.mappings.0.value[0]" /&gt;
    &lt;block id="1135" type="ogscript_setstyle" x="519" y="276" w="243" ID="ButtonA" STYLE="bg#green;" /&gt;
    &lt;block id="1136" type="ogscript_setstyle" x="596" y="427" w="243" ID="ButtonA" STYLE="bg#red;" /&gt;
    !!*/
    /*!!&lt;checksum&gt;c0a075b8c55e3b386d29ef301a45d0d8&lt;/checksum&gt;!!*/</ogscript>
       </context>
       <context contexttype="opengear" id="Button A trigger" objectid="50232857086&lt;br&gt;Slot 6&lt;br&gt;MC1-MK" objecttype="MC1-MK" subscriptions="false">
    
       </context>
       <abs height="250" id="BUTTONB" left="450" name="Button B" top="260" width="440">
          <label height="250" left="0" name="BUTTON B" style="txt-align:center;size:Biggest;" top="0" width="440"/>
       </abs>
       <abs height="250" id="ButtonA" left="450" name="Button A" top="520" width="440">
          <label height="250" left="0" name="BUTTON A" style="txt-align:center;size:Biggest;" top="0" width="440"/>
       </abs>
    </abs>


    ------------------------------
    Michael Quach
    ------------------------------