<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>HID Joystick</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/16427/hid-joystick</link><description>Does anybody develop bluetooth JOYSTICK?
Could you please help me with some code samples to understand how to do Joystick on NRF products. 
 Best regards.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 17 Sep 2018 21:43:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/16427/hid-joystick" /><item><title>RE: HID Joystick</title><link>https://devzone.nordicsemi.com/thread/149119?ContentTypeID=1</link><pubDate>Mon, 17 Sep 2018 21:43:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81934268-a504-4a56-99b5-6b67271fe7b0</guid><dc:creator>StephaneAG</dc:creator><description>&lt;p&gt;Hi there !&lt;/p&gt;
&lt;p&gt;I think the following could be quite useful to you ;)&lt;/p&gt;
&lt;p&gt;I couldn&amp;#39;t get it to work as intended ( using &amp;quot;Espruino&amp;quot; &amp;#39;s bluetooth stack ), but it works fine as USB HID GamePad&lt;/p&gt;
&lt;p&gt;To use it as you wish, take the report descriptor stuff &amp;amp; use that as device, then write to that using Nordic&amp;#39;s API wrapper ( I guess - I don&amp;#39;t know enough yet on Nordic&amp;#39;s neat chip: gotta digg deeper .. )&lt;pre class="ui-code" data-mode="javascript"&gt;/* Copyright (c) 2018 Stephane Adam Garnier ( StephaneAG ) - SeedsDesign. See the file LICENSE for copying permission.
    == Espruino GamePad v0.1a ==
    R: this module is in huge wip ( it &amp;#39;ll soon include a wrapper to ease pressing/releasing btns &amp;amp; moving joysticks .. )
*/
/*
Usage:
  var gamepad = require(&amp;quot;ble_hid_gamepad&amp;quot;);
  NRF.setServices(undefined, { hid : gamepad.report });
  gamepad.sendGamepadState(0b1111111111111111, 127, -127, 127, -127);
*/
// http://www.usb.org/developers/hidpage/Hut1_12v2.pdf
exports.report = new Uint8Array([
  0x05,   0x01,                    // USAGE_PAGE (Generic Desktop)
  0x09,   0x05,                    // USAGE (Game Pad) - Hut1_12v2.pdf p28 of 128
  0xA1,   0x01,                    // COLLECTION (Application)

  0xA1,   0x00,                    //   COLLECTION (Physical)
  0x05,   0x09,                    //     USAGE_PAGE (Button)
  0x19,   0x01,                    //     USAGE_MINIMUM (Button 1)
  0x29,   0x10,                    //     USAGE_MAXIMUM (Button 16)

  0x15,   0x00,                    //     LOGICAL_MINIMUM (0)
  0x25,   0x01,                    //     LOGICAL_MAXIMUM (1)
  0x95,   0x10,                    //     REPORT_COUNT (16)
  0x75,   0x01,                    //     REPORT_SIZE (1)

  0x81,   0x02,                    //     INPUT (Data,Var,Abs)

  0x05,   0x01,                    //     USAGE_PAGE (Generic Desktop)
  0x09,   0x30,                    //     USAGE (X)
  0x09,   0x31,                    //     USAGE (Y)
  0x09,   0x32,                    //     USAGE (Z) - Hut1_12v2.pdf p26 = represents R X-axis
  0x09,   0x33,                    //     USAGE (Rx) - Hut1_12v2.pdf p26 = represents R Y-axis

  0x15,   0x81,                    //     LOGICAL_MINIMUM (-127)
  0x25,   0x7F,                    //     LOGICAL_MAXIMUM (127)
  0x75,   0x08,                    //     REPORT_SIZE (8)
  0x95,   0x04,                    //     REPORT_COUNT (4)

  0x81,   0x06,                    //     INPUT (Data,Var,Abs) - absolute for joysticks ( != rel for mouse )
  0xC0,                            //   END_COLLECTION

  0xc0 ]                           // END_COLLECTION
);

exports.sendGamepadState = function(btnState, x1, y1, x2, y2, cb){
  NRF.sendHIDReport([
    //0x06,                 // bLength
    //0x01,                 // bDescriptorType - constant ( String assigned by USB )
    btnState &amp;amp; 0xFF,      // Byte0
    (btnState&amp;gt;&amp;gt;8) &amp;amp; 0xFF, // Byte1
    x1,                   // Byte2
    y1,                   // Byte3
    x2,                   // Byte4
    y2,                   // Byte5
  ]);
  if (cb) cb();
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you get it working, please come back with the right code so that I can issue a commit for the Espruino community :))&lt;/p&gt;
&lt;p&gt;This being said &amp;amp; as an &amp;quot;aside quest&amp;quot;, I&amp;#39;m currently diggin deeper on how to implement an Xbox360 controller using either ATmega/STMF32/NRF51822: this doesn&amp;#39;t use HID but &amp;quot;X-INPUT&amp;quot; instead ( so I guess a whole lotta mess for modding stuff ? .. )&lt;/p&gt;
&lt;p&gt;Hoping the above &amp;#39;ll help, keep up the good work ! +&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HID Joystick</title><link>https://devzone.nordicsemi.com/thread/62850?ContentTypeID=1</link><pubDate>Fri, 16 Sep 2016 10:54:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:842c1208-b211-492b-a432-38dd981ab5cb</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;I have not developed a bluetooth hid joystick and do not know of any code available that works with the nRF5x SDK.&lt;/p&gt;
&lt;p&gt;I would start with the keyboard or mouse example. First change the report_map_data in hids_init. You can use the array defined &lt;a href="https://github.com/NordicSemiconductor/ble-sdk-arduino/blob/master/libraries/BLE/examples/ble_HID_template/USD%20HID%20Report%20Descriptor%20-%20Joystick.txt"&gt;here&lt;/a&gt; (nRF8001 example code). Then you need to make your own send function for sending joystick data notifications and you should be ready to go.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>