82 lines
2.9 KiB
C++

//======================================================================================================
// Copyright 2023, NaturalPoint Inc.
//======================================================================================================
/**
* This is a simple device example that demonstrates basic setups for the external device plugin in Motive
* which uses the peripheralimport LIB.
*/
#include <memory>
#include <list>
// OptiTrack Peripheral Device API
#include "PluginDevice.h"
#include "PluginDeviceFactory.h"
using namespace AnalogSystem;
namespace OptiTrackPluginDevices
{
static const char* ExampleDeviceProp_Property1 = "ExampleProperty1";
static const char* ExampleDeviceProp_Property2 = "ExampleProperty2";
/**
* ExampleDeviceFactory creates a specific instance of an ExampleDevice and transfers ownership
* of the device pointer to the caller. Each peripheral device class should have a factory class
* that inherits from the PluginDeviceFactory as instance of the factory is used to instantiate
* devices in Motive.
*/
class ExampleDeviceFactory : public PluginDeviceFactory
{
public:
ExampleDeviceFactory(const char* deviceName) : PluginDeviceFactory(deviceName) {}
// return factory name
virtual const char* Name() const;
// return new instance of device (transfers ownership)
virtual std::unique_ptr<IDevice> Create() const;
};
/**
* ExampleDevice is a simple example of a Motive Plugin Device. This simple example is provided to demonstrate
* How a device class can be configured using the peripheralimport API. Example device is a simple device in Motive
* That will have 2-float channels in the data.
*/
class ExampleDevice : public cPluginDevice<float>
{
friend class ExampleDeviceFactory;
public:
ExampleDevice();
virtual ~ExampleDevice();
// IDevice
virtual bool Configure();
virtual bool Deconfigure();
virtual bool StartCapture();
virtual bool StopCapture();
virtual void OnPropertyChanged(const char* propertyName);
virtual void OnChannelPropertyChanged(const char* channelName, const char* propertyName);
// ExampleDevice Specific
void SetDeviceProperties();
private:
/**
* The following collection thread polls the hardware device data on a separate thread and populates
* the data channels.
*/
static unsigned long __stdcall CollectionThread(void* Context);
unsigned long DoCollectionThread();
void* mCollectionThread;
bool mCollecting;
/**
* Helper method for the example to simulate data from hardware.
*/
template<size_t N, size_t M> void ReadDataFromHardware(float(&deviceData)[M][N], int& channelsRead, int& framesRead);
};
}