USB Device Emulation

= Emulated Devices =
== Human Interface Devices ==
The QuadStick appears on the USB bus to the Host PC or Game Console device as a Composite USB Device that consists of Gamepad, Mouse and Keyboard Devices. These devices are called Human Interface Devices (HID). They each have a specific data report they send to the host over the USB connection. From the perspective of the QuadStick, the data items in these reports are the Outputs to which we connect one of the Inputs from the joystick or Sip/Puff sensors. We call a collection of the Input to Output connections a Profile. The QuadStick configuration can contain several profiles, but only one is active at a time. The active profile can be changed from moment to moment, during a game, to match the mapping of inputs to outputs to the situation in the game. In this section, we will discuss the output data we can send for each device, then, in the section on configuration, how these are tied together with inputs using Profiles.
== Flash Drive ==
The QuadStick also appears on the USB bus as a small removable storage device, a Flash drive. This drive is used to hold the customized configuration file the user may wish to use for a particular game. 
=== Config.csv file ===
The QuadStick looks for a file with the name “config.csv” in its flash drive and reads the contents at start up or whenever the file changes. The outline|Configuration section describes how this file is created. The user simply copies a new config.csv file into the QuadStick drive to load the new configuration. The config.csv file is produced by the configuration spreadsheet.
Additional configuration .csv files stored in the flash can be loaded using voice commands.
=== Firmware update ===
Firmware updates are also copied into the flash drive to reprogram the device. Updates will be posted in the support section of the website. First, save your custom config.csv file, if necessary, then download and copy the new “firmware.bin” file into the QuadStick Flash drive. Wait for it to reprogram the CPU and reboot. The QuadStick will reboot with an empty flash drive and in the default profile. Copy your custom config.sys file back to the flash after the update.
== Gamepad ==
The PS3 Game Controller is designed to be held with both hands, with the thumbs operating two analog joysticks and a set of four buttons on each side. In addition, there are a pair of buttons for the index fingers and another pair of pull triggers for the middle fingers. Three buttons in the middle section are less frequently used during actual game play and serve to control overall operation of the game console. While several of the buttons appear to be simple on/off switches, in comparison to joysticks or triggers which are obviously analog, almost all the buttons measure the pressure too. The X, Circle, Square, Triangle, R1, L1 and the D-Pad buttons all include how hard they are being pressed in the data reported to the console.
The following illustration and Table contain the names of the PS3 outputs used in configuring the QuadStick. We break down compound controls, like the D-Pad or thumbsticks into each their individual elements to allow the greatest flexibility in choosing appropriate inputs to control them.
thumb|Illustration 1: PS3 Buttons & Controls
Output Name 	Description
dpad_N 	PS3 D-Pad Button North
dpad_NE 	PS3 D-Pad Buttons North and East
dpad_E 	PS3 D-Pad Button East
dpad_SE 	PS3 D-Pad Buttons South and East
dpad_S 	PS3 D-Pad Button South
dpad_SW 	PS3 D-Pad Buttons South and West
dpad_W 	PS3 D-Pad Button West
dpad_NW 	PS3 D-Pad Buttons North and West
left_joy_left 	PS3 Left Joystick Left side
left_joy_right 	PS3 Left Joystick Right side
left_joy_up 	PS3 Left Joystick Up
left_joy_down 	PS3 Left Joystick Down
right_joy_left 	PS3 Right Joystick Left side
right_joy_right	PS3 Right Joystick Right side
right_joy_up 	PS3 Right Joystick Up
right_joy_down 	PS3 Right Joystick Down
left_1 	PS3 Left Button 1
left_2 	PS3 Left Button 2 (trigger)
left_3 	PS3 Left Button 3 (Press joystick)
right_1 	PS3 Right Button 1
right_2 	PS3 Right Button 2 (trigger)
right_3 	PS3 Right Button 3 (Press joystick)
x 	PS3 Button X
square 	PS3 Button Square
triangle 	PS3 Button Triangle
circle 	PS3 Button Circle
ps3 	PS3 Home
select 	PS3 Select
start 	PS3 Start
Table 1: PS3 Output Commands
== Mouse ==
The Mouse is a simple device compared to the Gamepad but has different movement characteristics that need some explanation: Instead of linearly controlling the position of the screen cursor in direct proportion to the joystick position, for the mouse emulation, the screen cursor is “pushed” around the screen by moving the joystick away from the center position. The farther the joystick is deflected, the faster the cursor moves. Releasing the joystick stops the movement of the cursor and leaves it at its current location. If the mouse operated more like a gamepad joystick, releasing the joystick would return the cursor to the middle of the screen.
The speed at which the cursor moves versus the joystick deflection angle follows a parabolic curve. The speed is calculated from the Square of the deflection from the center position, not in linear proportion to the deflection. This gives the ability for slow and fine control near the center position but also a smooth transition to fast movement with more deflection.
The parameters controlling the mouse speed, maximum joystick deflection and center dead-zone are adjustable by the user.
thumb|none|Illustration 2: Mouse Buttons & Controls
Output Name 	Description
mouse_left 	Mouse Left movement
mouse_right 	Mouse Right movement
mouse_up 	Mouse Up movement
mouse_down 	Mouse Down movement
mouse_wheel_up 	Mouse Wheel Up rotation
mouse_wheel_down 	Mouse Wheel Down rotation
mouse_pan_left 	Mouse Pan Left tilt
mouse_pan_right 	Mouse Pan Right tilt
mouse_back 	Mouse Button Back
mouse_forward 	Mouse Button Forward
mouse_left_button 	Mouse Button Left
mouse_right_button 	Mouse Button Right
mouse_middle_button	Mouse Button Middle
Table 2: Mouse Outputs
== Keyboard ==
PC based games often use the keyboard instead of a gamepad. The QuadStick can send any of the key codes for a 104-key keyboard. This opens up the ability to play PC based games by directly sending the desired key-code instead of using gamepad to keyboard adapter software.
Key-codes are associated with the key itself, not necessarily with the character printed on the face of the key. This is more apparent for keys like 2-@, 3-#, etc, than it is for letter keys. (The numeric keypad keys represent 2-down-arrow, 3-page-down, etc.) The Shift, Control or Alt keys, when combined with the key-code, are used to determine how the key is read.
The key-codes are treated like the outputs of the other HID devices. An individual key-code output can be triggered by one of the sensor inputs or by a sequence of inputs in a specific order. The two methods of triggering key-codes are described below.
thumb|Illustration 3: Key-code names
=== Game play mode ===
WASD, named for the keys frequently used to move the cursor on a computer screen before the advent of the arrow keys, became popular with many early PC games and continues to be widely used. The QuadStick can be configured to have key-codes mapped directly to inputs, like joystick North to “w”, East to “d”, etc, in the WASD mapping, for rapid, direct response.
It is possible to create configurations which blend mouse, keyboard or even gamepad commands to give the user the best mix for individual games.
See the outline|Tribes Configuration section for an example of a WASD configuration which mixes keyboard and mouse commands.
thumb|top|Illustration 4: Online game "Tribes" keyboard
In the Tribes game, mouthpiece sips and puffs are bound to the WASD keys and the joystick movement is bound to the mouse, which aims the weapon.
=== Recognition mode ===
The QuadStick can also recognize a sequence of movements of the joystick (or any sequence of inputs) to trigger an output instead of just a simple single input. This gives the QuadStick the ability to, in-effect, recognize the shapes as letters. A sequence of up to eight input triggers, such as moving the joystick through its discrete zones (as shown in Figure 4), mixed with other inputs, can be strung together to trigger any output.
To use pattern recognition, the user moves the joystick into a zone and momentarily pauses to signal the QuadStick to detect that location. The QuadStick uses the velocity of the joystick dropping to a low value to determine the user's intention and flashes the center Blue LED when it registers that location while recording the pattern. If the user moves through a zone quickly, the QuadStick will not include that zone when matching the pattern, which makes it possible to create patterns that include non-adjacent zones.. 
Once the pattern matches the sequence of locations in the configuration for an output, the output is triggered. Nearly all patterns start and end at the joystick center position.
The following examples illustrate recognition patterns for the letters A, I and K. The full list of the current default recognition patterns can be found in the chapter on configuration:
thumb|Illustration 5: Pattern for Letter A
thumb|top|Illustration 6: Pattern for Letter I
thumb|top|Illustration 7: Pattern for Letter K
== Infrared Remote Control ==
The Infrared transmitter LED on the back panel can be programmed to send IR Remote Control codes. The IR command names are listed below are treated the same as outputs for other kinds of devices in a configuration profile sheet. The specific codes sent for each command are defined on a second sheet, named “IR Codes”, that contains the Philips Pronto Hex Code for the particular TV or A/V devices. An example of the Dish VIP-622 receiver is in a later chapter.
Output Name 	Description
ir_tv_channel_up 	Xmit IR code from command table
ir_tv_channel_down	Xmit IR code from command table
ir_tv_volume_up 	Xmit IR code from command table
ir_tv_volume_down 	Xmit IR code from command table
ir_tv_on_off 	Xmit IR code from command table
ir_tv_select_input	Xmit IR code from command table
ir_play 	Xmit IR code from command table
ir_stop 	Xmit IR code from command table
ir_fast_forward 	Xmit IR code from command table
ir_rewind 	Xmit IR code from command table
ir_skip_forward 	Xmit IR code from command table
ir_skip_back 	Xmit IR code from command table
ir_record 	Xmit IR code from command table
ir_pause 	Xmit IR code from command table
ir_mute 	Xmit IR code from command table
ir_guide 	Xmit IR code from command table
ir_menu 	Xmit IR code from command table
ir_cancel 	Xmit IR code from command table
ir_select 	Xmit IR code from command table
ir_up 	Xmit IR code from command table
ir_down 	Xmit IR code from command table
ir_left 	Xmit IR code from command table
ir_right 	Xmit IR code from command table
ir_aux1 	Xmit IR code from command table
ir_aux2 	Xmit IR code from command table
ir_aux3 	Xmit IR code from command table
ir_aux4 	Xmit IR code from command table
Table 3: Infrared Remote Control command list