Device.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * TI Voxel Lib component.
  3. *
  4. * Copyright (c) 2014 Texas Instruments Inc.
  5. */
  6. #ifndef VOXEL_DEVICE_H
  7. #define VOXEL_DEVICE_H
  8. #include "Common.h"
  9. #include <sstream>
  10. namespace Voxel
  11. {
  12. /**
  13. * \addtogroup CamSys
  14. * @{
  15. */
  16. class VOXEL_EXPORT Device
  17. {
  18. public:
  19. enum Interface {
  20. USB = 0,
  21. LPT = 1,
  22. SERIAL = 2,
  23. I2C = 3
  24. };
  25. protected:
  26. String _id; // in the format interface::device::serialnumber. "device" for USB devices is "vendorid:productid"
  27. Interface _interfaceID;
  28. String _deviceID;
  29. String _serialNumber;
  30. String _serialIndex;
  31. bool _showSerialIndex;
  32. String _description;
  33. int _channelID; // Channel ID for multi-channel devices
  34. void _makeID()
  35. {
  36. std::ostringstream s;
  37. s << _interfaceID << "::" << _deviceID << "::" << _serialNumber;
  38. if(_showSerialIndex)
  39. s << ":" << _serialIndex;
  40. if(_channelID >= 0)
  41. s << "::" << _channelID;
  42. _id = s.str();
  43. }
  44. public:
  45. Device(Interface interfaceid, const String &deviceid, const String &serialnumber, int channelID = -1, const String &description = "", const String &serialIndex = "", bool showSerialIndex = false): _interfaceID(interfaceid),
  46. _deviceID(deviceid), _serialNumber(serialnumber), _description(description), _channelID(channelID), _serialIndex(serialIndex), _showSerialIndex(showSerialIndex)
  47. {
  48. _makeID();
  49. }
  50. // Need to implement in all derived classes
  51. virtual Vector<Ptr<Device>> getDevices(const Vector<int> &channels) const { return Vector<Ptr<Device>>(); }
  52. inline const String &id() const { return _id; }
  53. inline Interface interfaceID() const { return _interfaceID; }
  54. inline const String &deviceID() const { return _deviceID; }
  55. inline const String &serialNumber() const { return _serialNumber; }
  56. inline void setSerialNumber(const String &s) { _serialNumber = s; }
  57. inline const String &serialIndex() const { return _serialIndex; }
  58. inline void showSerialIndex() { _showSerialIndex = true; _makeID(); }
  59. inline void dontShowSerialIndex() { _showSerialIndex = false; _makeID(); }
  60. inline const int channelID() const { return _channelID; }
  61. inline const String &description() const { return _description; }
  62. virtual ~Device() {}
  63. };
  64. typedef Ptr<Device> DevicePtr;
  65. class VOXEL_EXPORT USBDevice : public Device
  66. {
  67. uint16_t _vendorID, _productID;
  68. public:
  69. USBDevice(uint16_t vendorid, uint16_t productid, const String &serialnumber, int channelID = -1, const String &description = "", const String &serialIndex = "", bool showSerialIndex = false):
  70. Device(Device::USB, getHex(vendorid) + ":" + getHex(productid), serialnumber, channelID, description, serialIndex, showSerialIndex), _vendorID(vendorid), _productID(productid) {}
  71. virtual Vector<DevicePtr> getDevices(const Vector<int> &channels) const;
  72. inline uint16_t vendorID() const { return _vendorID; }
  73. inline uint16_t productID() const { return _productID; }
  74. virtual ~USBDevice() {}
  75. };
  76. class VOXEL_EXPORT DeviceScanner
  77. {
  78. protected:
  79. virtual Vector<DevicePtr> _scan() = 0;
  80. public:
  81. static Vector<DevicePtr> scan();
  82. virtual ~DeviceScanner() {}
  83. };
  84. class VOXEL_EXPORT USBDeviceScanner : public DeviceScanner
  85. {
  86. protected:
  87. virtual Vector<DevicePtr> _scan();
  88. friend class DeviceScanner;
  89. virtual ~USBDeviceScanner() {}
  90. };
  91. /**
  92. * @}
  93. */
  94. }
  95. #endif // DEVICE_H