Click here to Skip to main content
15,886,578 members
Articles / Programming Languages / C++

Writing a Sensor Driver for the Wiimote on Windows 7

Rate me:
Please Sign up or sign in to vote.
4.93/5 (61 votes)
16 Feb 2010CPOL30 min read 275.2K   16.7K   106  
How to write a Sensor driver that provides access to the 3-axis accelerometer on a Nintendo Wiimote on Windows 7
#include "internal.h"
#include "Defines.h"
#include "DeviceProperty.h"
#include "PortableDeviceProps.h"
#include "ObjectLock.h"
#include "SensorDdi.h"
#include "Sensor.h"
#include "SensorRegistry.h"
#include "SensorDevice.h"
#include "SensorDevice.tmh"

//
// implement the sensor
//
IMPLEMENT_SENSOR(CSensorDevice);

CSensorDevice::CSensorDevice(void)
{
}

CSensorDevice::~CSensorDevice(void)
{
}

HRESULT CSensorDevice::Init(IWDFDevice *pDevice, CSensorDDI *pSensorDDI)
{
	CObjectLock lock(this);

	//
	// call the base implementation first
	//
	HRESULT hr = CSensor::Init(pDevice, pSensorDDI);
	if(FAILED(hr))
		return hr;

	//
	// add sensor supported properties
	//
	hr = m_Properties.AddProps(DEVPROPS(
		MAKEPROP(WPD_DEVICE_FIRMWARE_VERSION, DEVICE_FIRMWARE_VERSION_VALUE),
		MAKEPROP(WPD_DEVICE_POWER_LEVEL, DEVICE_POWER_LEVEL_VALUE),
		MAKEPROP(WPD_DEVICE_POWER_SOURCE, (ULONG)WPD_POWER_SOURCE_EXTERNAL),
		MAKEPROP(WPD_DEVICE_PROTOCOL, DEVICE_PROTOCOL_VALUE),
		MAKEPROP(WPD_DEVICE_MODEL, DEVICE_MODEL_VALUE),
		MAKEPROP(WPD_DEVICE_SERIAL_NUMBER, DEVICE_SERIAL_NUMBER_VALUE),
		MAKEPROP(WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, (BOOL)DEVICE_SUPPORTS_NONCONSUMABLE_VALUE),
		MAKEPROP(WPD_DEVICE_MANUFACTURER, DEVICE_MANUFACTURER_VALUE),
		MAKEPROP(WPD_DEVICE_FRIENDLY_NAME, DEVICE_FRIENDLY_NAME_VALUE),
		MAKEPROP(WPD_DEVICE_TYPE, WPD_DEVICE_TYPE_GENERIC)
	));

	SetState(SENSOR_STATE_READY);
	return hr;
}

void CSensorDevice::OnStateChange(SensorState, SensorState)
{
	//
	// since this is not a real device we don't notify anyone
	//
}

wstring CSensorDevice::GetId() const
{
	return WPD_DEVICE_OBJECT_ID;
}

wstring CSensorDevice::GetName() const
{
	return WPD_DEVICE_OBJECT_ID;
}

wstring CSensorDevice::GetParentId() const
{
	//
	// the "DEVICE" object does not have a parent
	//
	return L"";
}

GUID CSensorDevice::GetFunctionalObjectCategory() const
{
	return WPD_FUNCTIONAL_CATEGORY_DEVICE;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Microsoft
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions