23 #include "remote_bb_poster.h" 25 #include <core/exceptions/system.h> 26 #include <utils/system/argparser.h> 27 #include <logging/console.h> 28 #include <utils/system/getkey.h> 29 #include <utils/time/time.h> 34 #include <interfaces/JoystickInterface.h> 41 print_usage(
const char *program_name)
43 printf(
"Usage: %s [-h] [-r host[:port]]\n" 44 " -h This help message\n" 45 " -r host[:port] Remote host (and optionally port) to connect to\n" 46 " -d device Joystick device to use\n" 47 " -l Start in logging mode - print data read from bb\n",
58 main(
int argc,
char **argv)
63 if ( argp.has_arg(
"h") ) {
69 char *host = (
char *)
"localhost";
70 unsigned short int port = 1910;
71 bool free_host = argp.parse_hostport(
"r", &host, &port);
75 jbp.joystick_plugged(3, 10);
76 float axis[3], new_axis[3];
77 unsigned int button, new_button;
80 axis[0] = axis[1] = 0.;
82 new_axis[0] = new_axis[1] = new_axis[2] = 0.;
83 button = new_button = 0;
94 if ( (now - &last) < 0.5) {
101 new_axis[0] = new_axis[1] = 0;
104 }
else if (key == 27) {
108 new_axis[0] = new_axis[1] = 0;
111 if (key != 91)
continue;
114 if (key == 0)
continue;
117 case 65: new_axis[0] = +1.;
break;
118 case 66: new_axis[0] = -1.;
break;
119 case 67: new_axis[1] = -1.;
break;
120 case 68: new_axis[1] = +1.;
break;
124 }
else if (key ==
'+') {
125 if ((axis[2] + 0.1) <= 1.0) {
130 }
else if (key ==
'-') {
131 if ((axis[2] - 0.1) >= 0.) {
136 }
else if (key ==
'1') {
138 }
else if (key ==
' ') {
140 }
else if (key ==
'2') {
142 }
else if (key ==
'3') {
144 }
else if (key ==
'4') {
146 }
else if (key ==
'5') {
148 }
else if (key ==
'6') {
150 }
else if (key ==
'7') {
152 }
else if (key ==
'8') {
154 }
else if (key ==
'9') {
156 }
else if (key ==
'0') {
160 if ((axis[0] != new_axis[0]) || (axis[1] != new_axis[1]) ||
161 (axis[2] != new_axis[2]) || (button != new_button))
163 axis[0] = new_axis[0];
164 axis[1] = new_axis[1];
165 axis[2] = new_axis[2];
167 jbp.joystick_changed(button, axis);
171 jbp.joystick_unplugged();
173 if (free_host) free(host);
176 printf(
"Error: Unknown Argument\n\n");
177 print_usage(argv[0]);
static const uint32_t BUTTON_4
BUTTON_4 constant.
static const uint32_t BUTTON_1
BUTTON_1 constant.
static const uint32_t BUTTON_7
BUTTON_7 constant.
Interface for logging to stderr.
Fawkes library namespace.
Parse command line arguments.
A class for handling time.
static const uint32_t BUTTON_8
BUTTON_8 constant.
char getkey(int timeout_decisecs)
Get value of a single key-press non-blocking.
static const uint32_t BUTTON_6
BUTTON_6 constant.
Glue to post new data to a RemoteBlackBoard.
static const uint32_t BUTTON_10
BUTTON_10 constant.
static const uint32_t BUTTON_2
BUTTON_2 constant.
static const uint32_t BUTTON_9
BUTTON_9 constant.
Time & stamp()
Set this time to the current time.
static const uint32_t BUTTON_3
BUTTON_3 constant.
Thrown if unknown argument was supplied.
static const uint32_t BUTTON_5
BUTTON_5 constant.