37 #include "DTrackSDK.hpp" 45 static bool sentFeedback =
false;
48 static bool doFeedback(
int flystickId );
49 static bool data_error_to_console();
50 static void messages_to_console();
61 int main(
int argc,
char** argv )
65 std::cout <<
"Usage: example_flystick_feedback [<server host/ip>:]<data port>" << std::endl;
71 dt =
new DTrackSDK( (
const char *)argv[ 1 ] );
75 std::cout <<
"DTrackSDK init error" << std::endl;
79 std::cout <<
"connected to ATC '" << argv[ 1 ] <<
"', listening at local data port " << dt->
getDataPort() << std::endl;
89 std::cout <<
"Full access to ATC required!" << std::endl;
90 data_error_to_console();
91 messages_to_console();
103 std::cout <<
"Measurement start failed!" << std::endl;
104 data_error_to_console();
105 messages_to_console();
112 bool isRunning =
true;
126 if ( ! doFeedback(
id ) )
133 std::cout <<
"No suitable Flystick identified!" << std::endl;
139 data_error_to_console();
144 messages_to_console();
150 messages_to_console();
164 static bool doFeedback(
int flystickId )
169 std::cout <<
"DTrackSDK fatal error: invalid Flystick id " << flystickId << std::endl;
173 if ( fly->
button[ 0 ] != 0 )
178 if ( fly->
button[ 5 ] != 0 )
180 double beepDuration = 500.0 + fly->
joystick[ 0 ] * 450.0;
181 double beepFrequency = 5000.0 + fly->
joystick[ 1 ] * 3000.0;
183 if ( ! sentFeedback )
184 dt->
flystickBeep( flystickId, beepDuration, beepFrequency );
192 int vibrationPattern = 0;
193 if ( fly->
button[ 1 ] != 0 ) vibrationPattern = 1;
194 if ( fly->
button[ 2 ] != 0 ) vibrationPattern = 2;
195 if ( fly->
button[ 3 ] != 0 ) vibrationPattern = 3;
196 if ( fly->
button[ 4 ] != 0 ) vibrationPattern = 4;
197 if ( fly->
button[ 6 ] != 0 ) vibrationPattern = 5;
198 if ( fly->
button[ 7 ] != 0 ) vibrationPattern = 6;
200 if ( vibrationPattern > 0 )
202 if ( ! sentFeedback )
209 sentFeedback =
false;
219 static bool data_error_to_console()
227 std::cout <<
"--- timeout while waiting for tracking data" << std::endl;
231 std::cout <<
"--- error while receiving tracking data" << std::endl;
235 std::cout <<
"--- error while parsing tracking data" << std::endl;
245 std::cout <<
"--- timeout while waiting for Controller command" << std::endl;
249 std::cout <<
"--- error while receiving Controller command" << std::endl;
253 std::cout <<
"--- error while parsing Controller command" << std::endl;
266 static void messages_to_console()
int getNumFlyStick() const
Get number of calibrated Flysticks.
const DTrackFlyStick * getFlyStick(int id) const
Get Flystick data.
bool receive()
Receive and process one tracking data packet.
unsigned short getDataPort() const
Get UDP data port where tracking data is received.
bool isCommandInterfaceFullAccess()
Returns if TCP connection has full access for DTrack2/DTRACK3 commands.
A.R.T. Flystick data (6DOF + buttons).
DTrack SDK main class derived from DTrackParser.
std::string getMessageStatus() const
Get status of last DTrack2/DTRACK3 event message.
Errors getLastServerError() const
Get last error at exchanging commands with Controller (command transmission).
bool isCommandInterfaceValid() const
Returns if TCP connection for DTrack2/DTRACK3 commands is active.
bool flystickVibration(int flystickId, int vibrationPattern)
Send Flystick feedback command to start a vibration pattern on a specific Flystick.
std::string getMessageMsg() const
Get message text of last DTrack2/DTRACK3 event message.
int num_joystick
Number of joystick values.
bool flystickBeep(int flystickId, double durationMs, double frequencyHz)
Send Flystick feedback command to start a beep on a specific Flystick.
Error while parsing command.
int num_button
Number of buttons.
bool isDataInterfaceValid() const
Returns if UDP socket is open to receive tracking data on local machine.
bool getMessage()
Get DTrack2/DTRACK3 event message from the Controller.
Errors getLastDataError() const
Get last error at receiving tracking data (data transmission).
int button[DTRACKSDK_FLYSTICK_MAX_BUTTON]
Button state (1 pressed, 0 not pressed): 0 front, 1..n-1 right to left.
bool stopMeasurement()
Stop measurement.
bool startMeasurement()
Start measurement.
double joystick[DTRACKSDK_FLYSTICK_MAX_JOYSTICK]
Joystick value (-1.0 <= joystick <= 1.0); 0 horizontal, 1 vertical.