Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gamepad light indicator extension #143

Open
wants to merge 14 commits into
base: gh-pages
Choose a base branch
from
111 changes: 111 additions & 0 deletions extensions.html
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,109 @@ <h2><dfn>GamepadPose</dfn> Interface</h2>
</dd>
</dl>
</section>

<section>
<h2><dfn>GamepadLightIndicatorType</dfn> Enum</h2>
<p>
This enum defines the type of light indicators supported by gamepads.
</p>

<pre class="idl">
enum GamepadLightIndicatorType {
"on-off",
"rgb"
};
</pre>

<dl data-dfn-for="GamepadLightIndicatorType">
<dt>"<dfn>on-off</dfn>"</dt>
<dd>
Light indicator that supports a single color.
</dd>

<dt>"<dfn>rgb</dfn>"</dt>
<dd>
Light indicator that supports multiple colors.
</dd>
</dl>
</section>

<section>
<h2><dfn>GamepadLightColor</dfn></h2>
marcoscaceres marked this conversation as resolved.
Show resolved Hide resolved
<p>
This represents the color of a light indicator. The default value should
be set to 0 for red, green, and blue.
marcoscaceres marked this conversation as resolved.
Show resolved Hide resolved
</p>

<pre class="idl">
dictionary GamepadLightColor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should investigate what existing color objects we could use from the platform here.

required octet red;
required octet green;
required octet blue;
};
fernando-80 marked this conversation as resolved.
Show resolved Hide resolved
fernando-80 marked this conversation as resolved.
Show resolved Hide resolved
</pre>

<dl data-dfn-for="GamepadLightColor">
<dt><dfn>red</dt></dfn>
fernando-80 marked this conversation as resolved.
Show resolved Hide resolved
<dd>
Red component of the light color, or non-zero value for an
<code>on-off</code> light indicator that indicates ON.
</dd>

<dt><dfn>green</dt></dfn>
fernando-80 marked this conversation as resolved.
Show resolved Hide resolved
<dd>
Blue component of the light color, or non-zero value for an
<code>on-off</code> light indicator that indicates ON.
</dd>

<dt><dfn>blue</dt></dfn>
fernando-80 marked this conversation as resolved.
Show resolved Hide resolved
<dd>
Green component of the light color, or non-zero value for an
<code>on-off</code> light indicator that indicates ON.
</dd>
</dl>
</section>

<section>
<h2><dfn>GamepadLightIndicator</dfn></h2>
<p>
This interface defines a light indicator.
</p>

<pre class="idl">
[Exposed=Window, SecureContext]
interface GamepadLightIndicator {
readonly attribute GamepadLightIndicatorType type;

Promise&lt;long&gt; setColor(GamepadLightColor color);
marcoscaceres marked this conversation as resolved.
Show resolved Hide resolved
};
</pre>

<dl data-dfn-for="GamepadLightIndicator">
<dt><dfn>type</dt></dfn>
<dd>
Type of light indicator supported by the gamepad.
</dd>

<dt><dfn>setColor</dt></dfn>
fernando-80 marked this conversation as resolved.
Show resolved Hide resolved
<dd>
Sets the color of a light indicator, or sets the light indicator to ON
or OFF.

For <code>on-off</code> light indicators, one or more non zero values
denotes the light indicator is ON, whereas a zero value for all
components indicates the light indicator is OFF.
fernando-80 marked this conversation as resolved.
Show resolved Hide resolved

For RGB light indicators, one or more non zero values specify the
color of the light indicator, whereas all zero values indicate the
light indicator is OFF.

The returned Promise will resolve <code>true</code> when setting the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this can be guaranteed to succeed. @nondebug, do you have an opinion about this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically don't get a signal that the color was changed successfully so we shouldn't claim that in the spec. I think we should reword this so we resolve when the LED color change command is sent and reject if the command couldn't be sent.

Copy link
Member

@marcoscaceres marcoscaceres Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so yeah... it shouldn't resolve with true either.

We probably need to rewrite this whole section. I'd suggest having a look at:
https://w3c.github.io/web-share/#share-method

Basically, we need to do a few checks that can cause the promise to reject... the controller has been disconnected/no longer available, etc. There might be a SecurityError if the permission has been changed before .setColor() is called. Also, what should happen if:

while (true) {
   x.setColor(randomRGB());
}

Rate limit? Drop requests on the floor?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this and couldn't come up with any compelling reasons to keep the Promise. It's unlikely that we'll receive any error indication from the device and there isn't any way we can lose permission for a Gamepad. Let's remove the promise and treat setColor as fire-and-forget.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The returned Promise will resolve <code>true</code> when setting the
The returned Promise will resolve `undefined` when setting the

color has succeeded, and will reject the device API error code on
failure.
fernando-80 marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +441 to +442
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to reject with a an actual DOM Exception of some kind. I think this is overly broad/underspecified tho...

</dd>
</dl>
</section>

<section>
<h2>Partial <dfn>Gamepad</dfn> Interface</h2>
Expand All @@ -347,6 +450,8 @@ <h2>Partial <dfn>Gamepad</dfn> Interface</h2>
readonly attribute GamepadHand hand;
readonly attribute FrozenArray&lt;GamepadHapticActuator> hapticActuators;
readonly attribute GamepadPose? pose;
readonly attribute FrozenArray&lt;GamepadLightIndicator>?
lightIndicators;
fernando-80 marked this conversation as resolved.
Show resolved Hide resolved
};
</pre>

Expand All @@ -371,6 +476,12 @@ <h2>Partial <dfn>Gamepad</dfn> Interface</h2>
hardware cannot supply any pose values, MUST be set to
<code>null</code>.
</dd>

<dt><dfn>lightIndicators</dfn></dt>
<dd>
A list of all light indicators in the gamepad. <code>null</code> if
the gamepad does not have or does not support a light indicator.
fernando-80 marked this conversation as resolved.
Show resolved Hide resolved
</dd>
</dl>
</section>
</body>
Expand Down