qmk_firmware/assets/features_joystick.md.BeV1V2wB.js

16 lines
29 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.B9AX-CPi.js";
const __pageData = JSON.parse('{"title":"Joystick","description":"","frontmatter":{},"headers":[],"relativePath":"features/joystick.md","filePath":"features/joystick.md","lastUpdated":null}');
const _sfc_main = { name: "features/joystick.md" };
const _hoisted_1 = /* @__PURE__ */ createStaticVNode('<h1 id="joystick" tabindex="-1">Joystick <a class="header-anchor" href="#joystick" aria-label="Permalink to &quot;Joystick {#joystick}&quot;"></a></h1><p>This feature provides game controller input as a joystick device supporting up to 6 axes, 32 buttons and a hat switch. Axes can be read either from an <a href="./../drivers/adc">ADC-capable input pin</a>, or can be virtual, so that its value is provided by your code.</p><p>An analog device such as a <a href="https://en.wikipedia.org/wiki/Potentiometer" target="_blank" rel="noreferrer">potentiometer</a> found on an analog joystick&#39;s axes is based on a voltage divider, where adjusting the movable wiper controls the output voltage which can then be read by the microcontroller&#39;s ADC.</p><h2 id="usage" tabindex="-1">Usage <a class="header-anchor" href="#usage" aria-label="Permalink to &quot;Usage {#usage}&quot;"></a></h2><p>Add the following to your <code>rules.mk</code>:</p><div class="language-make vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">make</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">JOYSTICK_ENABLE = yes</span></span></code></pre></div><p>By default the joystick driver is <code>analog</code>, but you can change this with:</p><div class="language-make vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">make</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">JOYSTICK_DRIVER = digital</span></span></code></pre></div><p>When using <code>analog</code> with ARM, <a href="./../drivers/adc">you must use 3.3v with your Joystick</a>. Although ARM boards such as the <a href="https://keeb.supply/products/0xcb-helios" target="_blank" rel="noreferrer">Helios</a> have 5v pin output, the ADC driver does not support it.</p><h2 id="configuration" tabindex="-1">Configuration <a class="header-anchor" href="#configuration" aria-label="Permalink to &quot;Configuration {#configuration}&quot;"></a></h2><p>By default, two axes and eight buttons are defined, with a reported resolution of 8 bits (-127 to +127). This can be changed in your <code>config.h</code>:</p><div class="language-c vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Min 0, max 32</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> JOYSTICK_BUTTON_COUNT</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 16</span></span>\n<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Min 0, max 6: X, Y, Z, Rx, Ry, Rz</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> JOYSTICK_AXIS_COUNT</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span></span>\n<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Min 8, max 16</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> JOYSTICK_AXIS_RESOLUTION</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span></span></code></pre></div><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>You must define at least one button or axis. Also note that the maximum ADC resolution of the supported AVR MCUs is 10-bit, and 12-bit for most STM32 MCUs.</p></div><h3 id="hat-switch" tabindex="-1">Hat Switch <a class="header-anchor" href="#hat-switch" aria-label="Permalink to &quot;Hat Switch {#hat-switch}&quot;"></a></h3><p>To enable the 8-way hat switch, add the following to your <code>config.h</code>:</p><div class="language-c vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> JOYSTICK_HAS_HAT</span></span></code></pre></div><p>The position can be set by calling <code>joystick_set_hat(value)</code>. The range of values moves clockwise from the top (ie. north), with the default &quot;center&quot; position represented by a value of <code>-1</code>:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span> 0</span></span>\n<span class="line"><span> 7 N 1</span></span>\n<span class="line"><span> NW .--&#39;--. NE</span></span>\n<span class="line"><span> / \\</span></span>\n<span class="line"><span>6 W | -1 | E 2</span></span>\n<span class="line"><span> \\ /</span></span>\n<span class="line"><span> SW &#39;--.--&#39; SE</span></span>\n<span class="line"><span> 5 S 3</span></span>\n<span class="line"><span> 4</span></span></code></pre></div><p>Alternatively you can use these predefined names:</p><table><thead><tr><th>Define</th><th>Value</th><th>Angle</th></tr></thead><tbody><tr><td><code>JOYSTICK_HAT_CENTER</code></td><td><code>-1</code></td><td></td></tr><tr><td><code>JOYSTICK_HAT_NORTH</code></td><td><code>0</code></td><td>0°</td></tr><tr><td><code>JOYSTICK_HAT_NORTHEAST</code></td><td><code>1</code></td><td>45°</td></tr><tr><td><code>JOYSTICK_HAT_EAST</code></td><td><code>2</code></td><td>90°</td></tr><tr><td><code>JOYSTICK_HAT_SOUTHEAST</code></td><td><code>3</code></td><td>135°</td></tr><tr><td><code>JOYSTICK_HAT_SOUTH</code></td><td><code>4</code></td><td>180°</td></tr><tr><td><code>JOYSTICK_HAT_SOUTHWEST</code></td><td><code>5</code></td><td>225°</td></tr><tr><td><code>JOYSTICK_HAT_WEST</code></td><td><code>6</code></td><td>270°</td></tr><tr><td><code>JOYSTICK_HAT_NORTHWEST</code></td><td><code>7</code></td><td>315°</td></tr></tbody></table><h3 id="axes" tabindex="-1">Axes <a class="header-anchor" href="#axes" aria-label="Permalink to &quot;Axes {#axes}&quot;"></a></h3><p>When defining axes for your joystick, you must provide a definition array typically in your <code>keymap.c</code>.</p><p>For instance, the below example configures two axes. The X axis is read from the <code>A4</code> pin. With the default axis resolution of 8 bits, the range of values between 900 and 575 are scaled to -127 through 0, and values 575 to 285 are scaled to 0 through 127. The Y axis is configured as a virtual axis, and its value is not read from any pin. Instead, the user must update the axis value programmatically.</p><div class="language-c vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">joystick_config_t</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> joystick_axes</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[JOYSTICK_AXIS_COUNT] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>\n<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> JOYSTICK_AXIS_IN</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(A4, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">900</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">575</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">285</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">),</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> JOYSTICK_AXIS_VIRTUAL</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span></code></pre></div><p>Axes can be configured using one of the following macros:</p><ul><li><code>JOYSTICK_AXIS_IN(input_pin, low, rest, high)</code><br> The ADC samples the provided pin. <code>low</code>, <code>high</code> and <code>rest</code> correspond to the minimum, maximum, and resting (or centered) analog values of the axis, respectively.</li><li><code>JOYSTICK_AXIS_VIRTUAL</code><br> No ADC reading is performed. The value should be provided by user code.</li></ul><p>The <code>low</code> and <code>high</code> values can be swapped to effectively invert the axis.</p><h4 id="virtual-axes" tabindex="-1">Virtual Axes <a class="header-anchor" href="#virtual-axes" aria-label="Permalink to &quot;Virtual Axes {#virtual-axes}&quot;"></a></h4><p>The following example adjusts two virtual axes (X and Y) based on keypad presses, with <code>KC_P0</code> as a precision modifier:</p><div class="language-c vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">joystick_config_t</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> joystick_axes</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[JOYSTICK_AXIS_COUNT] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> JOYSTICK_AXIS_VIRTUAL,</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // x</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> JOYSTICK_AXIS_VIRTUAL</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // y</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>\n<span class="line"></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">static</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> bool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> precision </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">static</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> uint16_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> precision_mod </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 64</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">static</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> uint16_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> axis_val </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 127</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>\n<span class="line"></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">bool</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> process_record_user</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">uint16_t</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> keycode</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">keyrecord_t</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">record</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int16_t</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> precision_val </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> axis_val;</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (precision) {</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> precision_val </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> precision_mod;</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>\n<span class="line"></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> switch</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (keycode) {</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> KC_P8:</span></span>\n<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> joystick_set_axis</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, record</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">event.pressed </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">precision_val </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> KC_P2:</span></span>\n<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> joystick_set_axis</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, record</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">event.pressed </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> precision_val </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> KC_P4:</span></span>\n<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> joystick_set_axis</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, record</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">event.pressed </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">precision_val </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> KC_P6:</span></span>\n<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> joystick_set_axis</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, record</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">event.pressed </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> precision_val </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> KC_P0:</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> precision </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> record-&gt;event.pressed;</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h2 id="keycodes" tabindex="-1">Keycodes <a class="header-anchor" href="#keycodes" aria-label="Permalink to &quot;Keycodes {#keycodes}&quot;"></a></h2><table><thead><tr><th>Key</th><th>Aliases</th><th>Description</th></tr></thead><tbody><tr><td><code>QK_JOYSTICK_BUTTON_0</code></td><td><code>JS_0</code></td><td>Button 0</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_1</code></td><td><code>JS_1</code></td><td>Button 1</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_2</code></td><td><code>JS_2</code></td><td>Button 2</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_3</code></td><td><code>JS_3</code></td><td>Button 3</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_4</code></td><td><code>JS_4</code></td><td>Button 4</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_5</code></td><td><code>JS_5</code></td><td>Button 5</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_6</code></td><td><code>JS_6</code></td><td>Button 6</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_7</code></td><td><code>JS_7</code></td><td>Button 7</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_8</code></td><td><code>JS_8</code></td><td>Button 8</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_9</code></td><td><code>JS_9</code></td><td>Button 9</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_10</code></td><td><code>JS_10</code></td><td>Button 10</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_11</code></td><td><code>JS_11</code></td><td>Button 11</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_12</code></td><td><code>JS_12</code></td><td>Button 12</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_13</code></td><td><code>JS_13</code></td><td>Button 13</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_14</code></td><td><code>JS_14</code></td><td>Button 14</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_15</code></td><td><code>JS_15</code></td><td>Button 15</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_16</code></td><td><code>JS_16</code></td><td>Button 16</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_17</code></td><td><code>JS_17</code></td><td>Button 17</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_18</code></td><td><code>JS_18</code></td><td>Button 18</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_19</code></td><td><code>JS_19</code></td><td>Button 19</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_20</code></td><td><code>JS_20</code></td><td>Button 20</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_21</code></td><td><code>JS_21</code></td><td>Button 21</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_22</code></td><td><code>JS_22</code></td><td>Button 22</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_23</code></td><td><code>JS_23</code></td><td>Button 23</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_24</code></td><td><code>JS_24</code></td><td>Button 24</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_25</code></td><td><code>JS_25</code></td><td>Button 25</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_26</code></td><td><code>JS_26</code></td><td>Button 26</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_27</code></td><td><code>JS_27</code></td><td>Button 27</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_28</code></td><td><code>JS_28</code></td><td>Button 28</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_29</code></td><td><code>JS_29</code></td><td>Button 29</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_30</code></td><td><code>JS_30</code></td><td>Button 30</td></tr><tr><td><code>QK_JOYSTICK_BUTTON_31</code></td><td><code>JS_31</code></td><td>Button 31</td></tr></tbody></table><h2 id="api" tabindex="-1">API <a class="header-anchor" href="#api" aria-label="Permalink to &quot;API {#api}&quot;"></a></h2><h3 id="api-joystick-t" tabindex="-1"><code>struct joystick_t</code> <a class="header-anchor" href="#api-joystick-t" aria-label="Permalink to &quot;`struct joystick_t` {#api-joystick-t}&quot;"></a></h3><p>Contains the state of the joystick.</p><h4 id="api-joystick-t-members" tabindex="-1">Members <a class="header-anchor" href="#api-joystick-t-members" aria-label="Permalink to &quot;Members {#api-joystick-t-members}&quot;"></a></h4><ul><li><code>uint8_t buttons[]</code><br> A bit-packed array containing the joystick button states. The size is calculated as <code>(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1</code>.</li><li><code>int16_t axes[]</code><br> An array of analog values for each defined axis.</li><li><code>int8_t hat</code><br> The hat switch position.</li><li><code>bool dirty</code><br> Whether the current state needs to be sent to the host.</li></ul><hr><h3 id="api-joystick-config-t" tabindex="-1"><code>struct joystick_config_t</code> <a class="header-anchor" href="#api-joystick-config-t" aria-label="Permalink to &quot;`struct joystick_config_t` {#api-joystick-config-t}&quot;"></a></h3><p>Describes a single axis.</p><h4 id="api-joystick-config-t-members" tabindex="-1">Members <a class="header-anchor" href="#api-joystick-config-t-members" aria-label="Permalink to &quot;Members {#api-joystick-config-t-members}&quot;"></a></h4><ul><li><code>pin_t input_pin</code><br> The pin to read the analog value from, or <code>JS_VIRTUAL_AXIS</code>.</li><li><code>uint16_t min_digit</code><br> The minimum analog value.</li><li><code>uint16_t mid_digit</code><br> The resting or midpoint analog value.</li><li><code>uint16_t max_digit</code><br> The maximum analog value.</li></ul><hr><h3 id="api-joystick-flush" tabindex="-1"><code>void joystick_flush(void)</code> <a class="header-anchor" href="#api-joystick-flush" aria-label="Permalink to &quot;`void joystick_flush(void)` {#api-joystick-flush}&quot;"></a></h3><p>Send the joystick report to the host, if it has been marked as dirty.</p><hr><h3 id="api-register-joystick-button" tabindex="-1"><code>void register_joystick_button(uint8_t button)</code> <a class="header-anchor" href="#api-register-joystick-button" aria-label="Permalink to &quot;`void register_joystick_button(uint8_t button)` {#api-register-joystick-button}&quot;"></a></h3><p>Set the state of a button, and flush the report.</p><h4 id="api-register-joystick-button-arguments" tabindex="-1">Arguments <a class="header-anchor" href="#api-register-joystick-button-arguments" aria-label="Permalink to &quot;Arguments {#api-register-joystick-button-arguments}&quot;"></a></h4><ul><li><code>uint8_t button</code><br> The index of the button to press, from 0 to 31.</li></ul><hr><h3 id="api-unregister-joystick-button" tabindex="-1"><code>void unregister_joystick_button(uint8_t button)</code> <a class="header-anchor" href="#api-unregister-joystick-button" aria-label="Permalink to &quot;`void unregister_joystick_button(uint8_t button)` {#api-unregister-joystick-button}&quot;"></a></h3><p>Reset the state of a button, and flush the report.</p><h4 id="api-unregister-joystick-button-arguments" tabindex="-1">Arguments <a class="header-anchor" href="#api-unregister-joystick-button-arguments" aria-label="Permalink to &quot;Arguments {#api-unregister-joystick-button-arguments}&quot;"></a></h4><ul><li><code>uint8_t button</code><br> The index of the button to release, from 0 to 31.</li></ul><hr><h3 id="api-joystick-read-axis" tabindex="-1"><code>int16_t joystick_read_axis(uint8_t axis)</code> <a class="header-anchor" href="#api-joystick-read-axis" aria-label="Permalink to &quot;`int16_t joystick_read_axis(uint8_t axis)` {#api-joystick-read-axis}&quot;"></a></h3><p>Sample and process the analog value of the given axis.</p><h4 id="api-joystick-read-axis-arguments" tabindex="-1">Arguments <a class="header-anchor" href="#api-joystick-read-axis-arguments" aria-label="Permalink to &quot;Arguments {#api-joystick-read-axis-arguments}&quot;"></a></h4><ul><li><code>uint8_t axis</code><br> The axis to read.</li></ul><h4 id="api-joystick-read-axis-return" tabindex="-1">Return Value <a class="header-anchor" href="#api-joystick-read-axis-return" aria-label="Permalink to &quot;Return Value {#api-joystick-read-axis-return}&quot;"></a></h4><p>A signed 16-bit integer, where 0 is the resting or mid point.</p><h3 id="api-joystick-set-axis" tabindex="-1"><code>void joystick_set_axis(uint8_t axis, int16_t value)</code> <a class="header-anchor" href="#api-joystick-set-axis" aria-label="Permalink to &quot;`void joystick_set_axis(uint8_t axis, int16_t value)` {#api-joystick-set-axis}&quot;"></a></h3><p>Set the value of the given axis.</p><h4 id="api-joystick-set-axis-arguments" tabindex="-1">Arguments <a class="header-anchor" href="#api-joystick-set-axis-arguments" aria-label="Permalink to &quot;Arguments {#api-joystick-set-axis-arguments}&quot;"></a></h4><ul><li><code>uint8_t axis</code><br> The axis to set the value of.</li><li><code>int16_t value</code><br> The value to set.</li></ul><hr><h3 id="api-joystick-set-hat" tabindex="-1"><code>void joystick_set_hat(int8_t value)</code> <a class="header-anchor" href="#api-joystick-set-hat" aria-label="Permalink to &quot;`void joystick_set_hat(int8_t value)` {#api-joystick-set-hat}&quot;"></a></h3><p>Set the position of the hat switch.</p><h4 id="api-joystick-set-hat-arguments" tabindex="-1">Arguments <a class="header-anchor" href="#api-joystick-set-hat-arguments" aria-label="Permalink to &quot;Arguments {#api-joystick-set-hat-arguments}&quot;"></a></h4><ul><li><code>int8_t value</code><br> The hat switch position to set.</li></ul>', 71);
const _hoisted_72 = [
_hoisted_1
];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("div", null, _hoisted_72);
}
const joystick = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
__pageData,
joystick as default
};