UsbHidPeripheral.h
/*
* Copyright (c) 2013-14, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _UsbHidPeripheral_h_
#define _UsbHidPeripheral_h_
#include "Peripheral.h"
#include "hidapi.h"
namespace blfwk
{
class UsbHidPeripheral : public Peripheral
{
public:
enum _usbhid_contants
{
kDefault_Vid = 0x15a2,
kDefault_Pid = 0x0073,
};
public:
UsbHidPeripheral();
UsbHidPeripheral(unsigned short vendor_id, unsigned short product_id, const char *serial_number);
virtual ~UsbHidPeripheral();
virtual status_t read(uint8_t *buffer, uint32_t requestedBytes, uint32_t *actualBytes, uint32_t timeoutMS);
virtual status_t write(const uint8_t *buffer, uint32_t byteCount) { return kStatus_Success; }
status_t write(const uint8_t *buffer, uint32_t byteCount, uint32_t timeoutMS);
unsigned short getVendorId() { return m_vendor_id; }
unsigned short getProductId() { return m_product_id; }
const wchar_t *getSerialNumber() { return m_serial_number.c_str(); }
private:
bool init();
unsigned short m_vendor_id;
unsigned short m_product_id;
std::wstring m_serial_number;
hid_device *m_device;
};
} // namespace blfwk
#endif // _UsbHidPeripheral_h_
// EOF
blfwk
Definition: BlfwkErrors.h:16
blfwk::UsbHidPeripheral::write
virtual status_t write(const uint8_t *buffer, uint32_t byteCount)
Write bytes. This is a do nothing function implemented here to satisfy abstract base class requiremen...
Definition: UsbHidPeripheral.h:84
blfwk::UsbHidPeripheral::read
virtual status_t read(uint8_t *buffer, uint32_t requestedBytes, uint32_t *actualBytes, uint32_t timeoutMS)
Read bytes.
Definition: UsbHidPeripheral.cpp:100
blfwk::UsbHidPeripheral::kDefault_Pid
PID for KL25Z48M.
Definition: UsbHidPeripheral.h:54
blfwk::UsbHidPeripheral::kDefault_Vid
Freescale VID.
Definition: UsbHidPeripheral.h:53
blfwk::UsbHidPeripheral::getProductId
unsigned short getProductId()
Return USB Product ID.
Definition: UsbHidPeripheral.h:95
blfwk::UsbHidPeripheral::UsbHidPeripheral
UsbHidPeripheral()
Default constructor.
Definition: UsbHidPeripheral.cpp:45
blfwk::UsbHidPeripheral::_usbhid_contants
_usbhid_contants
Constants.
Definition: UsbHidPeripheral.h:51
blfwk::UsbHidPeripheral::getVendorId
unsigned short getVendorId()
Return USB Vendor ID.
Definition: UsbHidPeripheral.h:93
blfwk::UsbHidPeripheral::getSerialNumber
const wchar_t * getSerialNumber()
Return USB Serial Number.
Definition: UsbHidPeripheral.h:97
blfwk::UsbHidPeripheral::~UsbHidPeripheral
virtual ~UsbHidPeripheral()
Destructor.
Definition: UsbHidPeripheral.cpp:89
blfwk::UsbHidPeripheral
Represents a USB HID peripheral.
Definition: UsbHidPeripheral.h:47
blfwk::Peripheral
Represents a peripheral.
Definition: Peripheral.h:48