Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
remote_bb_poster.cpp
1
2
/***************************************************************************
3
* remote_bb_poster.h - Joystick handler writing to remote blackboard
4
*
5
* Created: Sat Jan 29 12:10:53 2011
6
* Copyright 2006-2011 Tim Niemueller [www.niemueller.de]
7
*
8
****************************************************************************/
9
10
/* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Library General Public License for more details.
19
*
20
* Read the full text in the LICENSE.GPL file in the doc directory.
21
*/
22
23
#include "remote_bb_poster.h"
24
25
#include <blackboard/remote.h>
26
#include <logging/logger.h>
27
#include <interfaces/JoystickInterface.h>
28
29
using namespace
fawkes;
30
31
/** @class JoystickRemoteBlackBoardPoster "remote_bb_poster.h"
32
* Glue to post new data to a RemoteBlackBoard.
33
* @author Tim Niemueller
34
*/
35
36
/** Constructor.
37
* @param host remote bb host to connect to
38
* @param port remote bb port to connect to
39
* @param logger logger
40
*/
41
JoystickRemoteBlackBoardPoster::JoystickRemoteBlackBoardPoster
(
const
char
*host,
42
unsigned
short
int
port,
43
Logger
*logger)
44
: __logger(logger)
45
{
46
__bb =
new
RemoteBlackBoard
(host, port);
47
48
__joystick_if = __bb->
open_for_writing
<
JoystickInterface
>(
"Joystick"
);
49
__warning_printed =
false
;
50
}
51
52
/** Destructor. */
53
JoystickRemoteBlackBoardPoster::~JoystickRemoteBlackBoardPoster
()
54
{
55
__bb->
close
(__joystick_if);
56
delete
__bb;
57
}
58
59
void
60
JoystickRemoteBlackBoardPoster::joystick_changed
(
unsigned
int
pressed_buttons,
61
float
*axis_values)
62
{
63
if
( ! __bb->
is_alive
() ) {
64
if
( __bb->
try_aliveness_restore
() ) {
65
__logger->
log_info
(
"Joystick"
,
"Connection re-established, writing data"
);
66
__warning_printed =
false
;
67
}
68
}
69
70
try
{
71
__joystick_if->
set_pressed_buttons
(pressed_buttons);
72
__joystick_if->
set_axis
(axis_values);
73
__joystick_if->
write
();
74
}
catch
(
Exception
&e) {
75
if
( ! __warning_printed ) {
76
e.
print_trace
();
77
__logger->
log_warn
(
"Joystick"
,
"Lost connection to BlackBoard, "
78
"will try to re-establish"
);
79
__warning_printed =
true
;
80
}
81
}
82
}
83
84
void
85
JoystickRemoteBlackBoardPoster::joystick_plugged
(
char
num_axes,
char
num_buttons)
86
{
87
__joystick_if->
set_num_axes
( num_axes );
88
__joystick_if->
set_num_buttons
( num_buttons );
89
__joystick_if->
write
();
90
}
91
92
void
93
JoystickRemoteBlackBoardPoster::joystick_unplugged
()
94
{
95
__joystick_if->
set_num_axes
( 0 );
96
__joystick_if->
set_num_buttons
( 0 );
97
__joystick_if->
write
();
98
}
src
plugins
joystick
remote_bb_poster.cpp
Generated by
1.8.1.1