UbisenseSource.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00042
00043
00044
00045 #include "../tool/disable4786.h"
00046
00047 #include "UbisenseSource.h"
00048 #ifdef USE_UBISENSE
00049
00050 #ifdef WIN32
00051 #pragma comment(lib,"UClientAPI.lib")
00052 #endif
00053
00054 namespace ot {
00055
00056 UbisenseSource::UbisenseSource(const Object &object,const LocationClient &locationClient,DataClient &dataClient): Node(),button(0x0000),lastTime(0.),buttonTime(0.),event(),object(object),locationClient(locationClient),dataClient(dataClient)
00057 {
00058 #ifdef _DEBUG
00059 dataClient.notify(object,NotifyBeep);
00060 dataClient.notify(object,NotifyFlashGreen);
00061 #endif
00062 }
00063
00064 UbisenseSource::~UbisenseSource()
00065 {
00066 #ifdef _DEBUG
00067 dataClient.notify(object,NotifyBeep);
00068 dataClient.notify(object,NotifyFlashRed);
00069 #endif
00070 }
00071
00072 bool UbisenseSource::calcEvent()
00073 {
00074 Location location;
00075 MyNameClient client;
00076
00077 printf("\n");
00078
00079 UClientAPI::Map<Object,String> all_people = client.get_all_named(Type("Person"));
00080
00081
00082
00083
00084
00085 String found_name;
00086 if (!client.get_object_name(object,found_name))
00087 { std::cout << "Cannot get name of " << object.to_string();
00088 return false;
00089 }
00090 std::cout << "Ubitag name: " << found_name;
00091
00092 if (locationClient.get_object_location(object,location) && location.time_ > lastTime)
00093 {
00094 event.clearAttributes();
00095 event.getPosition()[0] = static_cast<float>(location.pos_.x_);
00096 event.getPosition()[1] = static_cast<float>(location.pos_.y_);
00097 event.getPosition()[2] = static_cast<float>(location.pos_.z_);
00098
00099
00100 printf("\n location x: %f", event.getPosition()[0]);
00101 printf("\n location y: %f", event.getPosition()[1]);
00102 printf("\n location z: %f\n\n", event.getPosition()[2]);
00103
00104 if (buttonTime > lastTime)
00105 {
00106 event.getButton() = button;
00107 button = 0x0000;
00108 }
00109 event.time = (location.time_ > buttonTime ? location.time_: buttonTime) * 1000.;
00110 event.getConfidence() = 1.f;
00111 lastTime = location.time_ > buttonTime ? location.time_: buttonTime;
00112 return true;
00113 }
00114 else
00115 if (buttonTime > lastTime)
00116 {
00117 event.getButton() = button;
00118 event.time = buttonTime * 1000.;
00119 event.getConfidence() = 1.f;
00120 button = 0x0000;
00121 lastTime = buttonTime;
00122 return true;
00123 }
00124 return false;
00125 }
00126
00127 void UbisenseSource::setButtonEvent(unsigned short button,double time)
00128 {
00129 UbisenseSource::button |= button;
00130 buttonTime = time;
00131 }
00132
00133 }
00134
00135
00136 #else
00137 #pragma message(">>> no Ubisense support")
00138 #endif // USE_UBISENSE
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154