peripherals  1.4.2
RoadNarrows Robotics Hardware Peripherals Package
xbox360diag.cxx File Reference

Xbox360 diagnostic tool. More...

#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <errno.h>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <sstream>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/opts.h"
#include "rnr/hid/HID.h"
#include "rnr/hid/HIDXbox360.h"
#include "version.h"

Go to the source code of this file.

Macros

#define APP_EC_OK   0
 success exit code More...
 
#define APP_EC_GEN   1
 command-line options/arguments error exit code More...
 
#define APP_EC_ARGS   2
 command-line options/arguments error exit code More...
 
#define APP_EC_EXEC   4
 execution exit code More...
 

Functions

int main (int argc, char *argv[])
 Main. More...
 

Variables

static char * Argv0
 the command More...
 
static bool OptsDftThresholds = false
 do [not] use error thresholding More...
 
static OptsPgmInfo_T AppPgmInfo
 Program information. More...
 
static OptsInfo_T AppOptsInfo []
 Command line options information. More...
 

Detailed Description

Xbox360 diagnostic tool.

LastChangedDate
2014-03-07 11:57:26 -0700 (Fri, 07 Mar 2014)
Rev
3594
Author
Robin Knight (robin.nosp@m..kni.nosp@m.ght@r.nosp@m.oadn.nosp@m.arrow.nosp@m.s.co.nosp@m.m)

Definition in file xbox360diag.cxx.

Macro Definition Documentation

#define APP_EC_ARGS   2

command-line options/arguments error exit code

Definition at line 85 of file xbox360diag.cxx.

#define APP_EC_EXEC   4

execution exit code

Definition at line 86 of file xbox360diag.cxx.

Referenced by main().

#define APP_EC_GEN   1

command-line options/arguments error exit code

Definition at line 84 of file xbox360diag.cxx.

#define APP_EC_OK   0

success exit code

Definition at line 83 of file xbox360diag.cxx.

Referenced by main().

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Main.

Parameters
argcCommand-line argument count.
argvCommand-line argument list.
Returns
Returns exit code.

Definition at line 169 of file xbox360diag.cxx.

References APP_EC_EXEC, APP_EC_OK, AppOptsInfo, AppPgmInfo, Argv0, rnr::HIDXbox360::close(), rnr::HIDXbox360::debugPrintHdr(), rnr::HIDXbox360::debugPrintState(), rnr::HIDXbox360::getFeatureVal(), rnr::HIDInput::isConnected(), rnr::HIDXbox360::open(), OptsDftThresholds, PkgInfo, rnr::HIDXbox360::run(), rnr::HIDXbox360::setErrorThresholds(), rnr::HIDXbox360::setLED(), rnr::HIDXbox360::setRumble(), XBOX360_LED_PAT_NUMOF, rnr::Xbox360FeatIdBButton, rnr::Xbox360FeatIdLEDPat, rnr::Xbox360FeatIdLeftTrigger, rnr::Xbox360FeatIdRightBump, rnr::Xbox360FeatIdRightTrigger, and rnr::Xbox360FeatIdXButton.

170 {
171  int leftTrigger; // left trigger old value
172  int rightTrigger; // right trigger old value
173  int BButton; // B button value
174  int state; // current state of one button
175  int led; // led state
176  int rc; // return code
177 
178  // name of this process
179  Argv0 = basename(argv[0]);
180 
181  // parse input options
182  argv = OptsGet(Argv0, &PkgInfo, &AppPgmInfo, AppOptsInfo, true, &argc, argv);
183 
184  HIDXbox360 xbox;
185 
186  // turn off receive error thresholding for better diagnostics
187  if( !OptsDftThresholds )
188  {
189  xbox.setErrorThresholds(0, 0, 0);
190  }
191 
192  // connect to controller
193  if( (rc = xbox.open()) < 0 )
194  {
195  LOGERROR("Failed to open Xbox360 controller. Is it connected?");
196  return APP_EC_EXEC;
197  }
198 
199  leftTrigger = 0;
200  rightTrigger = 0;
201  BButton = 0;
202 
203  // start updated in thread
204  xbox.run();
205 
206  fprintf(stderr, " left trigger -> left rumble;"
207  " right trigger -> right rumble;"
208  " B button -> next LED pattern;"
209  " right bumper -> refresh;"
210  " X button -> exit\n");
211 
212  xbox.debugPrintHdr();
213 
214  //
215  //
216  while( xbox.isConnected() )
217  {
219 
220  if( state != leftTrigger )
221  {
222  leftTrigger = state;
223  xbox.setRumble(leftTrigger, rightTrigger);
224  }
225 
227 
228  if( state != rightTrigger )
229  {
230  rightTrigger = state;
231  xbox.setRumble(leftTrigger, rightTrigger);
232  }
233 
234  state = xbox.getFeatureVal(Xbox360FeatIdBButton);
235 
236  if( state && !BButton )
237  {
239  led = (led +1) % XBOX360_LED_PAT_NUMOF;
240  xbox.setLED(led);
241  }
242 
243  BButton = state;
244 
245  state = xbox.getFeatureVal(Xbox360FeatIdXButton);
246 
247  if( state )
248  {
249  break;
250  }
251 
253 
254  if( state )
255  {
256  fprintf(stderr, "\n\n");
257  xbox.debugPrintHdr();
258  }
259 
260  xbox.debugPrintState();
261 
262  usleep(20000);
263  }
264 
265  xbox.close();
266 
267  fprintf(stderr, "\n\nEnd Diagnostics\n");
268 
269  // exit
270  return APP_EC_OK;
271 }
#define APP_EC_OK
success exit code
Definition: xbox360diag.cxx:83
virtual int close()
Close connection to an opened USB Xbox360 controller.
Definition: HIDXbox360.cxx:230
B button [0,1].
Definition: HIDXbox360.h:631
virtual int open()
Open connection to an USB Xbox360 controller.
Definition: HIDXbox360.cxx:159
void debugPrintState()
Simple debug print state.
right trigger [0-255]
Definition: HIDXbox360.h:635
void setErrorThresholds(int nErrorRcvTimeoutTh=NErrorRcvTimeoutThDft, int nErrorRcvTh=NErrorRcvThDft, int nErrorTotalTh=NErrorTotalThDft)
Set error count thresholds.
Definition: HIDXbox360.h:912
void debugPrintHdr()
Simple debug print header.
int setRumble(int nLeftMot, int nRightMot)
Set the rumble instensity.
Definition: HIDXbox360.cxx:492
virtual int getFeatureVal(int iMnem)
Get the value associated with the mapped user mnemonic.
Definition: HIDXbox360.h:720
Xbox360 controller HID input class.
Definition: HIDXbox360.h:651
virtual bool isConnected()
Query if HID is connected.
Definition: HID.h:167
LED pattern feature.
Definition: HIDXbox360.h:642
static const PkgInfo_T PkgInfo
Definition: version.h:45
int setLED(int nPattern)
Set the LED pattern.
Definition: HIDXbox360.cxx:623
static bool OptsDftThresholds
do [not] use error thresholding
Definition: xbox360diag.cxx:93
#define APP_EC_EXEC
execution exit code
Definition: xbox360diag.cxx:86
virtual int run(float hz=30.0)
Create and run USB update in thread.
Definition: HIDXbox360.cxx:292
right bump (right shoulder) [0,1]
Definition: HIDXbox360.h:628
static char * Argv0
the command
Definition: xbox360diag.cxx:92
#define XBOX360_LED_PAT_NUMOF
number of patterns
Definition: HIDXbox360.h:586
static OptsPgmInfo_T AppPgmInfo
Program information.
X button [0,1].
Definition: HIDXbox360.h:632
left trigger [0-255]
Definition: HIDXbox360.h:634
static OptsInfo_T AppOptsInfo[]
Command line options information.

Variable Documentation

OptsInfo_T AppOptsInfo[]
static
Initial value:
=
{
{
"thresholds",
't',
no_argument,
true,
OptsCvtArgBool,
OptsFmtBool,
NULL,
"Use error threshold defaults."
},
{NULL, }
}
static bool OptsDftThresholds
do [not] use error thresholding
Definition: xbox360diag.cxx:93

Command line options information.

Definition at line 141 of file xbox360diag.cxx.

Referenced by main().

OptsPgmInfo_T AppPgmInfo
static
Initial value:
=
{
NULL,
"Xbox360 diagnostic tool.",
"The %P tool debugs the libhid interface to Xbox360 controllers.\n"
" Button states are 0 or 1.\n"
" Triggers are 0 - 255.\n"
" Joysticks are -32767 - 32767.\n"
" LEDs and rumble motors are outputs to the Xbox360.\n"
" Link is determined by the libhid and is true or false.\n"
" Status is sent by the dongle when wireless link wth Xbox360 has changed.\n"
" Battery status is sent by Xbox360 occasionally.\n"
" Error counts:\n"
" ERTO consecutive Receive Error TimeOut count.\n"
" ER consecutive Receive Error count.\n"
" ES consecutive Send Error count.\n"
" ETOT Total Error count.",
NULL
}

Program information.

Definition at line 111 of file xbox360diag.cxx.

Referenced by main().

char* Argv0
static

the command

Definition at line 92 of file xbox360diag.cxx.

Referenced by main().

bool OptsDftThresholds = false
static

do [not] use error thresholding

Definition at line 93 of file xbox360diag.cxx.

Referenced by main().