YARP
Yet Another Robot Platform
JoypadControlServer.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #include "JoypadControlServer.h"
7 #include <map>
8 #include <vector>
9 #include <yarp/os/LogComponent.h>
10 #include <yarp/os/LogStream.h>
11 
12 #define DEFAULT_THREAD_PERIOD 0.010 //s
13 
14 using namespace yarp::dev;
15 using namespace yarp::os;
16 using namespace yarp::sig;
17 
18 namespace {
19 YARP_LOG_COMPONENT(JOYPADCONTROLSERVER, "yarp.device.JoypadControlServer")
20 }
21 
22 
24 
25 inline void cat(Vector& a, const Vector& b)
26 {
27  for (size_t i = 0; i < b.size(); i++)
28  {
29  a.push_back(b[i]);
30  }
31 }
32 
34 {
35  bool ret;
36  if(interface)
37  {
38  device = interface;
39  ret = true;
40  }
41  else
42  {
43  device = nullptr;
44  ret = false;
45  }
46 
47  countGetters.insert(std::make_pair(VOCAB_BUTTON, &IJoypadController::getButtonCount));
48  countGetters.insert(std::make_pair(VOCAB_HAT, &IJoypadController::getHatCount));
49  countGetters.insert(std::make_pair(VOCAB_TRACKBALL, &IJoypadController::getTrackballCount));
50  countGetters.insert(std::make_pair(VOCAB_AXIS, &IJoypadController::getAxisCount));
51  countGetters.insert(std::make_pair(VOCAB_STICK, &IJoypadController::getStickCount));
52  countGetters.insert(std::make_pair(VOCAB_TOUCH, &IJoypadController::getTouchSurfaceCount));
53 
54  return ret;
55 }
56 
58 {
59  bool ret;
60 
61  ret = false;
62  if(cmd.get(0).asVocab32() != VOCAB_IJOYPADCTRL || !cmd.get(1).isVocab32() || !cmd.get(2).isVocab32() || !cmd.get(3).isVocab32())
63  {
64  response.addVocab32(VOCAB_FAILED);
65  return ret;
66  }
67 
68  if(cmd.get(1).asVocab32() == VOCAB_GET)
69  {
70  int toGet;
71 
72  toGet = cmd.get(2).asVocab32();
73 
74  if(cmd.get(3).asVocab32() == VOCAB_COUNT)
75  {
76  if(countGetters.find(toGet) != countGetters.end())
77  {
78  unsigned int count;
79  getcountmethod getter;
80  getter = countGetters[toGet];
81  if((device->*getter)(count))
82  {
83  response.addVocab32(VOCAB_OK);
84  response.addInt32(count);
85  ret = true;
86  }
87  }
88  else if (toGet == VOCAB_STICKDOF && cmd.get(4).isInt32())
89  {
90  unsigned int count;
91  if (device->getStickDoF(cmd.get(4).asInt32(), count))
92  {
93  response.addVocab32(VOCAB_OK);
94  response.addInt32(count);
95  ret = true;
96  }
97  else
98  {
99  response.addVocab32(VOCAB_FAILED);
100  ret = false;
101  }
102  }
103  else
104  {
105  response.addVocab32(VOCAB_FAILED);
106  ret = false;
107  }
108  }
109  else if(cmd.get(3).asVocab32() == VOCAB_VALUE)
110  {
111  switch (cmd.get(2).asVocab32()) {
112  case VOCAB_BUTTON:
113  {
114  float value;
115  if(cmd.get(4).isInt32() && device->getButton(cmd.get(4).asInt32(), value))
116  {
117  response.addVocab32(VOCAB_OK);
118  response.addFloat64(value);
119  ret = true;
120  }
121  break;
122  }
123  case VOCAB_AXIS:
124  {
125  double value;
126  if(cmd.get(4).isInt32() && device->getAxis(cmd.get(4).asInt32(), value))
127  {
128  response.addVocab32(VOCAB_OK);
129  response.addFloat64(value);
130  ret = true;
131  }
132  break;
133  }
134  case VOCAB_STICK:
135  {
136  if(cmd.get(4).isVocab32())
137  {
138  yarp::sig::Vector frame;
139 
141  if(cmd.get(5).isInt32() && device->getStick(cmd.get(5).asInt32(), frame, mode))
142  {
143  response.addVocab32(VOCAB_OK);
144  for(size_t i = 0; i < frame.size(); ++i)
145  {
146  response.addFloat64(frame[i]);
147  }
148 
149  ret = true;
150  }
151  }
152  break;
153  }
154  case VOCAB_STICKDOF:
155  {
156 
157  unsigned int dofCount;
158 
159  if(cmd.get(5).isInt32() && device->getStickDoF(cmd.get(5).asInt32(), dofCount))
160  {
161  response.addVocab32(VOCAB_OK);
162  response.addInt32(dofCount);
163  ret = true;
164  }
165 
166  break;
167  }
168  case VOCAB_TOUCH:
169  {
170  yarp::sig::Vector pos;
171  unsigned int id;
172 
173  id = cmd.get(4).asInt32();
174  if(cmd.get(4).isInt32() && device->getTouch(id, pos))
175  {
176  response.addVocab32(VOCAB_OK);
177  for(size_t i = 0; i < pos.size(); ++i)
178  {
179  response.addFloat64(pos[i]);
180  }
181  ret = true;
182  }
183  break;
184  }
185  case VOCAB_TRACKBALL:
186  {
187  yarp::sig::Vector axes;
188  unsigned int id;
189 
190  id = cmd.get(4).asInt32();
191  if(cmd.get(4).isInt32() && device->getTrackball(id, axes))
192  {
193  response.addVocab32(VOCAB_OK);
194  for(size_t i = 0; i < axes.size(); ++i)
195  {
196  response.addFloat64(axes[i]);
197  }
198  ret = true;
199  }
200  break;
201  }
202  case VOCAB_HAT:
203  {
204  unsigned char value;
205  if(cmd.get(4).isInt32() && device->getHat(cmd.get(4).asInt32(), value))
206  {
207  response.addVocab32(VOCAB_OK);
208  response.addInt32(value);
209  ret = true;
210  }
211  break;
212  }
213  default:
214  break;
215  }
216  }
217  }
218  return ret;
219 
220 }
221 
222 
224  m_period(DEFAULT_THREAD_PERIOD),
225  m_device(nullptr),
226  m_subDeviceOwned(nullptr),
227  m_isSubdeviceOwned(false),
228  m_separatePorts(false),
229  m_profile(false),
230  m_coordsMode(yarp::dev::IJoypadController::JoypadCtrl_coordinateMode::JypCtrlcoord_POLAR)
231 {
232 
233 }
234 
236 {
237  if(m_subDeviceOwned)
238  {
239  delete m_subDeviceOwned;
240  }
241  m_subDeviceOwned = nullptr;
242  m_device = nullptr;
243 }
244 
246 {
247  if(params.check("help"))
248  {
249  yCInfo(JOYPADCONTROLSERVER)
250  << "parameters:\n\n"
251  << "period - refresh period of the broadcasted values in ms.. default" << DEFAULT_THREAD_PERIOD * 1000 << "\n"
252  << "use_separate_ports - set it to 1 to use separate ports (buttons, axes, trackballs, hats) and 0 to stream all in one single port\n"
253  << "name - Prefix name of the ports opened by the JoypadControlServer, e.g. /robotName/joypad\n"
254  << "subdevice - name of the subdevice to open\n"
255  << "profile - print the joypad data for debugging purpose";
256  return false;
257  }
258  std::string rootName;
259  if (!params.check("period", "refresh period of the broadcasted values in ms"))
260  {
261  yCInfo(JOYPADCONTROLSERVER) << "Using default 'period' parameter of" << DEFAULT_THREAD_PERIOD << "s";
262  }
263  else
264  {
265  m_period = params.find("period").asInt32() / 1000.0;
266  }
267 
268  m_profile = params.check("profile");
269 
270  if(params.check("use_separate_ports"))
271  {
272  m_separatePorts = params.find("use_separate_ports").asBool();
273  if(!m_separatePorts)
274  {
275  yCError(JOYPADCONTROLSERVER) << "Single port mode not supported at the moment";
276  return false;
277  }
278  }
279  else
280  {
281  yCError(JOYPADCONTROLSERVER) << "Missing use_separate_ports in configuration";
282  return false;
283  }
285  rootName = params.check("name",Value("/"), "starting '/' if needed.").asString();
286 
287  if (!params.check("name", "Prefix name of the ports opened by the JoypadControlServer."))
288  {
289  yCError(JOYPADCONTROLSERVER) << "Missing 'name' parameter. Check you configuration file; it must be like:";
290  yCError(JOYPADCONTROLSERVER) << " name: Prefix name of the ports opened by the JoypadControlServer, e.g. /robotName/joypad";
291  return false;
292  }
293 
294  rootName = params.find("name").asString();
295  m_rpcPortName = rootName + "/rpc:i";
296  m_portButtons.name = rootName + "/buttons:o";
297  m_portAxis.name = rootName + "/axis:o";
298  m_portStick.name = rootName + "/stick:o";
299  m_portTouch.name = rootName + "/touch:o";
300  m_portTrackball.name = rootName + "/trackball:o";
301  m_portHats.name = rootName + "/hat:o";
302 
303 
304  // check if we need to create subdevice or if they are
305  // passed later on thorugh attachAll()
306  if(params.check("subdevice"))
307  {
308  m_isSubdeviceOwned=true;
309  if(!openAndAttachSubDevice(params))
310  {
311  yCError(JOYPADCONTROLSERVER) << "Error while opening subdevice";
312  return false;
313  }
314  }
315  else
316  {
317  m_isSubdeviceOwned=false;
318  }
319  return true;
320 }
321 
322 bool JoypadControlServer::openAndAttachSubDevice(Searchable& prop)
323 {
324  Property p;
325 
326  m_subDeviceOwned = new PolyDriver;
327 
328  p.fromString(prop.toString());
329  p.setMonitor(prop.getMonitor(), "subdevice"); // pass on any monitoring
330  p.unput("device");
331  p.put("device",prop.find("subdevice").asString()); // subdevice was already checked before
332 
333  // if errors occurred during open, quit here.
334  m_subDeviceOwned->open(p);
335 
336  if (!m_subDeviceOwned->isValid())
337  {
338  yCError(JOYPADCONTROLSERVER) << "Opening subdevice... FAILED";
339  return false;
340  }
341  m_isSubdeviceOwned = true;
342  if (!attach(m_subDeviceOwned)) {
343  return false;
344  }
345 
346  if(!m_parser.configure(m_device) )
347  {
348  yCError(JOYPADCONTROLSERVER) << "Error configuring interfaces for parsers";
349  return false;
350  }
351 
352  openPorts();
353  PeriodicThread::setPeriod(m_period);
354  return PeriodicThread::start();
355 }
356 
358 {
359  if (poly) {
360  poly->view(m_device);
361  }
362 
363  if(m_device == nullptr)
364  {
365  yCError(JOYPADCONTROLSERVER) << "Attached device has no valid IJoypadController interface.";
366  return false;
367  }
368  return true;
369 }
370 
372 {
373  if(s == nullptr)
374  {
375  yCError(JOYPADCONTROLSERVER) << "Attached device has no valid IJoystickController interface.";
376  return false;
377  }
378  m_device = s;
379  return true;
380 }
381 
383 {
384  m_device = nullptr;
385  return true;
386 }
387 
389 {
390  // Get interface from attached device if any.
391  return true;
392 }
393 
395 {
396  // Detach() calls stop() which in turns calls this functions, therefore no calls to detach here!
397 }
398 
399 bool JoypadControlServer::openPorts()
400 {
401  if(!m_device)
402  {
403  return false;
404  }
405 
406  if(!m_rpcPort.open(m_rpcPortName))
407  {
408  yCError(JOYPADCONTROLSERVER) << "Unable to open rpc Port" << m_rpcPortName.c_str();
409  return false;
410  }
411  m_rpcPort.setReader(m_parser);
412 // dumb(or K.I.S.S.) version of the method:
413 // unsigned int count;
414 // if(m_device->getAxisCount(count))
415 // {
416 // if(count == 0)
417 // {
418 // m_portAxis.valid = false;
419 // }
420 // else
421 // {
422 // m_portAxis.open();
423 // m_portAxis.valid = true;
424 // }
425 // }
426 // else
427 // {
428 // return false;
429 // }
430 //
431 // if(m_device->getButtonCount(count))
432 // {
433 // if(count == 0)
434 // {
435 // m_portButton.valid = false;
436 // }
437 // else
438 // {
439 // m_portButton.open();
440 // m_portButton.valid = true;
441 // }
442 // }
443 // else
444 // {
445 // return false;
446 // }
447 //
448 // if(m_device->getStickCount(count))
449 // {
450 // if(count == 0)
451 // {
452 // m_portStick.valid = false;
453 // }
454 // else
455 // {
456 // m_portStick.open();
457 // m_portStick.valid = true;
458 // }
459 // }
460 // else
461 // {
462 // return false;
463 // }
464 //
465 // if(m_device->getTouchSurfaceCount(count))
466 // {
467 // if(count == 0)
468 // {
469 // m_portTouch.valid = false;
470 // }
471 // else
472 // {
473 // m_portTouch.open();
474 // m_portTouch.valid = true;
475 // }
476 // }
477 // else
478 // {
479 // return false;
480 // }
481 // if(m_device->getTrackballCount(count))
482 // {
483 // if(count == 0)
484 // {
485 // m_portTrackball.valid = false;
486 // }
487 // else
488 // {
489 // m_portTrackball.open();
490 // m_portTrackball.valid = true;
491 // }
492 // }
493 // else
494 // {
495 // return false;
496 // }
497 //
498 // if(m_device->getHatCount(count))
499 // {
500 // if(count == 0)
501 // {
502 // m_portHats.valid = false;
503 // }
504 // else
505 // {
506 // m_portHats.open();
507 // m_portHats.valid = true;
508 // }
509 // }
510 // else
511 // {
512 // return false;
513 // }
514 // return true;
515  if(m_separatePorts)
516  {
517  using countGet = bool (IJoypadController::*)(unsigned int&);
518 
519  struct solver
520  {
521  countGet getter;
523 
524  solver(countGet a, JoypadControl::LoopablePort* b) : getter(a), port(b)
525  {}
526  };
527 
528  std::vector<solver> getters;
529 
530  getters.emplace_back(&IJoypadController::getAxisCount, &m_portAxis );
531  getters.emplace_back(&IJoypadController::getButtonCount, &m_portButtons );
532  getters.emplace_back(&IJoypadController::getStickCount, &m_portStick );
533  getters.emplace_back(&IJoypadController::getTouchSurfaceCount, &m_portTouch );
534  getters.emplace_back(&IJoypadController::getTrackballCount, &m_portTrackball);
535  getters.emplace_back(&IJoypadController::getHatCount, &m_portHats );
536 
537  for(auto& getter : getters)
538  {
539  if((m_device->*(getter.getter))(getter.port->count))
540  {
541  if(getter.port->count == 0)
542  {
543  getter.port->valid = false;
544  }
545  else
546  {
547  getter.port->contactable->open(getter.port->name);
548  getter.port->valid = true;
549  }
550  }
551  else
552  {
553  return false;
554  }
555  }
556 
557  return true;
558  }
559  else
560  {
561  return false;
562  //m_godPort.open(m_name + "/joydata:o");
563  }
564 }
565 
566 void JoypadControlServer::profile()
567 {
568  std::string message;
569  unsigned int count;
570 
571  message = "Axes: ";
572  m_device->getAxisCount(count);
573  for(unsigned int i = 0; i < count; ++i)
574  {
575  double data;
576  m_device->getAxis(i, data);
577  message += std::to_string(data) + " ";
578  }
579  yCInfo(JOYPADCONTROLSERVER) << message;
580 
581  message = "Hats: ";
582  m_device->getHatCount(count);
583  for(unsigned int i = 0; i < count; ++i)
584  {
585  unsigned char data;
586  m_device->getHat(i, data);
587  message += std::to_string(data) + " ";
588  }
589  yCInfo(JOYPADCONTROLSERVER) << message;
590 
591  message = "Buttons: ";
592  m_device->getButtonCount(count);
593  for(unsigned int i = 0; i < count; ++i)
594  {
595  float data;
596  m_device->getButton(i, data);
597  message += std::to_string(data) + " ";
598  }
599  yCInfo(JOYPADCONTROLSERVER) << message;
600 
601  message = "Stick: ";
602  m_device->getStickCount(count);
603  for(unsigned int i = 0; i < count; ++i)
604  {
605  Vector data;
607  message += "n_" + std::to_string(i) + ": ";
608  for (size_t j = 0; j < data.size(); ++j)
609  {
610  message += std::to_string(data[j]) + " ";
611  }
612  message += "\n";
613 
614  }
615  yCInfo(JOYPADCONTROLSERVER) << message;
616 
617  message = "trackball: ";
618  m_device->getTrackballCount(count);
619  for(unsigned int i = 0; i < count; ++i)
620  {
621  Vector data;
622  m_device->getTrackball(i, data);
623  message += "n_" + std::to_string(i) + ": ";
624  for (size_t j = 0; j < data.size(); ++j)
625  {
626  message += std::to_string(data[j]) + " ";
627  }
628  message += "\n";
629  }
630 
631  message = "touch Surface: ";
632  m_device->getTouchSurfaceCount(count);
633  for(unsigned int i = 0; i < count; ++i)
634  {
635  Vector data;
636  m_device->getTouch(i, data);
637  message += "n_" + std::to_string(i) + ": ";
638  for (size_t j = 0; j < data.size(); ++j)
639  {
640  message += std::to_string(data[j]) + " ";
641  }
642  message += "\n";
643  }
644  yCInfo(JOYPADCONTROLSERVER) << message;
645 }
646 
648 {
649  if(m_separatePorts)
650  {
651  if (m_portButtons.valid)
652  {
653  bool write;
654  write = true;
655  Vector& b = m_portButtons.prepare();
656  b.clear();
657  for(size_t i = 0; i < m_portButtons.count; ++i)
658  {
659  float v;
660  if(!m_device->getButton(i, v))
661  {
662  write = false;
663  break;
664  }
665  b.push_back(v);
666  }
667  if (write) {
668  m_portButtons.write();
669  }
670  }
671 
672  if (m_portHats.valid)
673  {
674  bool write;
675 
676  write = true;
677  VecOfChar& b = m_portHats.prepare();
678  b.clear();
679  for(size_t i = 0; i < m_portHats.count; ++i)
680  {
681  unsigned char v;
682  if(!m_device->getHat(i, v))
683  {
684  write = false;
685  break;
686  }
687  b.push_back(v);
688  }
689  if (write) {
690  m_portHats.write();
691  }
692  }
693 
694  if (m_portAxis.valid)
695  {
696  bool write;
697 
698  write = true;
699  Vector& b = m_portAxis.prepare();
700  b.clear();
701  for(size_t i = 0; i < m_portAxis.count; ++i)
702  {
703  double v;
704  if(!m_device->getAxis(i, v))
705  {
706  yCError(JOYPADCONTROLSERVER) << "Cannot get axis with id" << i;
707  write = false;
708  break;
709  }
710  b.push_back(v);
711  }
712  if (write) {
713  m_portAxis.write();
714  }
715  }
716 
717  if (m_portTrackball.valid)
718  {
719  bool write;
720 
721  write = true;
722  Vector& b = m_portTrackball.prepare();
723  b.clear();
724  for(size_t i = 0; i < m_portTrackball.count; ++i)
725  {
726  Vector v;
727  if(!m_device->getTrackball(i, v))
728  {
729  yCError(JOYPADCONTROLSERVER) << "Cannot get axis with id" << i;
730  write = false;
731  break;
732  }
733  cat(b, v);
734  }
735  if (write) {
736  m_portTrackball.write();
737  }
738  }
739 
740  if (m_portStick.valid)
741  {
742  bool write;
743  write = true;
744  Vector& b = m_portStick.prepare();
745  b.clear();
746  for(size_t i = 0; i < m_portStick.count; ++i)
747  {
748  Vector v;
749  unsigned int dofCount;
750  if(!m_device->getStick(i, v, m_coordsMode) || !m_device->getStickDoF(i, dofCount) || v.size() != dofCount)
751  {
752  write = false;
753  break;
754  }
755  cat(b, v);
756  }
757  if (write) {
758  m_portStick.write();
759  }
760  }
761 
762  if (m_portTouch.valid)
763  {
764  bool write;
765  write = true;
766  Vector& b = m_portTouch.prepare();
767  b.clear();
768  for(unsigned int i = 0; i < m_portTouch.count; ++i)
769  {
770  Vector v;
771  if(!m_device->getTouch(i, v))
772  {
773  write = false;
774  break;
775  }
776  cat(b, v);
777  }
778 
779  if (write) {
780  m_portTouch.write();
781  }
782  }
783  }
784  else
785  {
786  return;
787  //JoyData& message = m_godPort.prepare();
788  //for(size_t i = 0; i < m_device->getAxisCount();)
789  //message.Axes
790  }
791 
792  if(m_profile)
793  {
794  profile();
795  }
796 }
797 
799 {
800  if (p.size() != 1)
801  {
802  yCError(JOYPADCONTROLSERVER) << "Cannot attach more than one device";
803  return false;
804  }
805 
806  yarp::dev::PolyDriver* Idevice2attach = p[0]->poly;
807  if(p[0]->key == "IJoypadController")
808  {
809  yCInfo(JOYPADCONTROLSERVER) << "Good name!";
810  }
811  else
812  {
813  yCInfo(JOYPADCONTROLSERVER) << "Bad name!";
814  }
815 
816  if (!Idevice2attach->isValid())
817  {
818  yCError(JOYPADCONTROLSERVER) << "Device " << p[0]->key << " to attach to is not valid ... cannot proceed";
819  return false;
820  }
821 
822  Idevice2attach->view(m_device);
823  if (!attach(m_device)) {
824  return false;
825  }
826 
827  PeriodicThread::setPeriod(m_period);
828  if (!PeriodicThread::start()) {
829  return false;
830  }
831 
832  openPorts();
833  return true;
834 }
835 
837 {
840  }
841 
842  //check if we already instantiated a subdevice previously
843  if (m_isSubdeviceOwned) {
844  return false;
845  }
846 
847  m_device = nullptr;
848  return true;
849 }
850 
852 {
853  detachAll();
854 
855  // close subdevice if it was created inside the open (--subdevice option)
856  if(m_isSubdeviceOwned)
857  {
858  if (m_subDeviceOwned) {
859  m_subDeviceOwned->close();
860  }
861 
862  m_subDeviceOwned = nullptr;
863  m_device = nullptr;
864  m_isSubdeviceOwned = false;
865  }
866 
867  // Closing port
868  std::vector<JoypadControl::LoopablePort*> portv;
869  portv.push_back(&m_portButtons);
870  portv.push_back(&m_portAxis);
871  portv.push_back(&m_portStick);
872  portv.push_back(&m_portTouch);
873  portv.push_back(&m_portTrackball);
874  portv.push_back(&m_portHats);
875 
876  for(auto p : portv)
877  {
878  //p->contactable->interrupt();
879  p->contactable->close();
880  }
881 
882  m_rpcPort.close();
883  return true;
884 }
constexpr yarp::conf::vocab32_t VOCAB_OK
Definition: GenericVocabs.h:15
constexpr yarp::conf::vocab32_t VOCAB_GET
Definition: GenericVocabs.h:13
constexpr yarp::conf::vocab32_t VOCAB_FAILED
Definition: GenericVocabs.h:16
constexpr yarp::conf::vocab32_t VOCAB_VALUE
Definition: GenericVocabs.h:38
constexpr yarp::conf::vocab32_t VOCAB_COUNT
Definition: GenericVocabs.h:37
constexpr yarp::conf::vocab32_t VOCAB_BUTTON
constexpr yarp::conf::vocab32_t VOCAB_IJOYPADCTRL
constexpr yarp::conf::vocab32_t VOCAB_TOUCH
constexpr yarp::conf::vocab32_t VOCAB_HAT
constexpr yarp::conf::vocab32_t VOCAB_TRACKBALL
constexpr yarp::conf::vocab32_t VOCAB_CARTESIAN
constexpr yarp::conf::vocab32_t VOCAB_STICKDOF
constexpr yarp::conf::vocab32_t VOCAB_AXIS
constexpr yarp::conf::vocab32_t VOCAB_STICK
bool ret
#define DEFAULT_THREAD_PERIOD
void cat(Vector &a, const Vector &b)
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
void threadRelease() override
Release method.
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
bool attachAll(const yarp::dev::PolyDriverList &p) override
Attach to a list of objects.
bool close() override
Close the DeviceDriver.
bool detach() override
Detach the object (you must have first called attach).
void run() override
Loop function.
bool threadInit() override
Initialization method.
bool detachAll() override
Detach the object (you must have first called attach).
bool configure(yarp::dev::IJoypadController *interface)
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
bool view(T *&x)
Get an interface to the device driver.
Definition: DeviceDriver.h:88
virtual bool getHatCount(unsigned int &Hat_count)=0
Get number of hats.
virtual bool getTrackballCount(unsigned int &Trackball_count)=0
Get number of trackballs.
virtual bool getTouchSurfaceCount(unsigned int &touch_count)=0
Get the number of touch surface.
virtual bool getButton(unsigned int button_id, float &value)=0
Get the value of a button.
virtual bool getAxisCount(unsigned int &axis_count)=0
Get number of axes.
virtual bool getAxis(unsigned int axis_id, double &value)=0
Get the value of an axis if present, return false otherwise.
virtual bool getStickCount(unsigned int &stick_count)=0
Get the number of the sticks.
virtual bool getTrackball(unsigned int trackball_id, yarp::sig::Vector &value)=0
Get the axes change of a Trackball.
virtual bool getStick(unsigned int stick_id, yarp::sig::Vector &value, JoypadCtrl_coordinateMode coordinate_mode)=0
Get the value of a stick if present, return false otherwise.
virtual bool getStickDoF(unsigned int stick_id, unsigned int &DoF)=0
Get the Degree Of Freedom count for desired stick.
virtual bool getHat(unsigned int hat_id, unsigned char &value)=0
Get the value of an Hat.
virtual bool getButtonCount(unsigned int &button_count)=0
Get number of buttons.
virtual bool getTouch(unsigned int touch_id, yarp::sig::Vector &value)=0
Get the value of a touch if present, return false otherwise.
A container for a device driver.
Definition: PolyDriver.h:23
bool close() override
Close the DeviceDriver.
Definition: PolyDriver.cpp:173
bool isValid() const
Check if device is valid.
Definition: PolyDriver.cpp:196
bool open(const std::string &txt)
Construct and configure a device by its common name.
Definition: PolyDriver.cpp:140
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Definition: Bottle.cpp:164
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Definition: Bottle.cpp:158
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:246
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition: Bottle.cpp:140
An abstraction for a periodic thread.
bool isRunning() const
Returns true when the thread is started, false otherwise.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
void setReader(PortReader &reader) override
Set an external reader for port data.
Definition: Port.cpp:511
void close() override
Stop port activity.
Definition: Port.cpp:363
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition: Port.cpp:79
A class for storing options and configuration information.
Definition: Property.h:33
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
Definition: Property.cpp:1063
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition: Property.cpp:1015
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
Definition: Property.cpp:1046
A base class for nested structures that can be searched.
Definition: Searchable.h:63
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
A single value (typically within a Bottle).
Definition: Value.h:43
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
Definition: Value.cpp:228
virtual bool asBool() const
Get boolean value.
Definition: Value.cpp:186
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:204
virtual bool isInt32() const
Checks if value is a 32-bit integer.
Definition: Value.cpp:132
virtual bool isVocab32() const
Checks if value is a vocabulary identifier.
Definition: Value.cpp:174
virtual std::string asString() const
Get string value.
Definition: Value.cpp:234
size_t size() const
Definition: Vector.h:321
void push_back(const T &elem)
Push a new element in the vector: size is changed.
Definition: Vector.h:248
#define yCInfo(component,...)
Definition: LogComponent.h:171
#define yCError(component,...)
Definition: LogComponent.h:213
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:76
std::string to_string(IntegerType x)
Definition: numeric.h:115
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:1091
The main, catch-all namespace for YARP.
Definition: dirs.h:16