Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/decoder/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int main(int argc, char **args) {
printHidDescriptor(descriptor);

idf::HidDecoder decoder;
idf::HidDecoded devDecoded = *decoder.parseDescriptor(descriptor);
idf::HidDescriptor devDecoded = *decoder.parseDescriptor(descriptor);

unsigned char readTest[devDecoded.maxReportLength];
unsigned char data[devDecoded.maxReportLength];
Expand Down
26 changes: 26 additions & 0 deletions include/idf/GenericJoystick.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public:
// left-right pivoting
SingleInput leftRightPivot;

// forward-backward Translation
SingleInput forwardBackwardTranslation;

// left-right transation
SingleInput leftRightTranslation;

// twisting
SingleInput twist;

Expand All @@ -52,6 +58,9 @@ public:
// the slider
SingleInput slider;

// scroll wheel
SingleInput wheel;

// Hat Directions
SingleInput HatNorth;
SingleInput HatNorthEast;
Expand All @@ -62,6 +71,23 @@ public:
SingleInput HatWest;
SingleInput HatNorthWest;

/**
* @brief Indicates whether an Rx axis exists, which may be used
* for a forwardBackwardTranslation
*/
bool rxExists = false; // TODO: make use of this

/**
* @brief Indicates whether an Ry axis exists, which may be used
* for a LeftRightTranslation
*/
bool ryExists = false;

/**
* @brief Indicates whether a Scroll Wheel exists
*/
bool wheelExists = false;

/**
* @brief Get the Nth Button object
*
Expand Down
22 changes: 12 additions & 10 deletions include/idf/HidDecoder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ struct HidReport
bool has_report_byte;
};

struct HidDecoded
struct HidDescriptor
{
unsigned short vendor;
unsigned short product;
unsigned short interface;
std::wstring vendor_string;
std::wstring product_string;
std::string type;
std::vector<HidReport> reports;
int maxReportLength;
Expand Down Expand Up @@ -120,18 +125,18 @@ public:
* Report Descriptor. Only @a Input items are kept. @a Output and
* @a feature items are discarded
*
* @param descriptor binary HID report descriptor.
* @return HidDecoded struct with a list of HidReports and some metadata
* @param descriptor binary HID Report Descriptor.
* @return HidDescriptor struct with a list of HidReports and some metadata
*/
HidDecoded* parseDescriptor(const std::vector<unsigned char>& descriptor);
HidDescriptor* parseDescriptor(const std::vector<unsigned char>& descriptor);


/**
* @brief Print out decoded information to stdout
* @brief Print out decoded descriptor information to stdout
*
* @param decoded an @a HidDecoded struct
* @param describer an @a HidDescriptor struct
*/
static void printDecodedInfo(const HidDecoded decoded);
static void printDecodedInfo(const HidDescriptor describer);


/**
Expand Down Expand Up @@ -169,9 +174,6 @@ private:
int units_exp;
};

int vendorId;
int productId;

std::string device_type = "Unknown";
std::vector<HidReport> reports;
std::vector<HidInput> inputs;
Expand Down
33 changes: 28 additions & 5 deletions include/idf/HidDevice.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public:
/**
* @brief Find the specified device, read and decode its HID Report
* Descriptor, then instantiate an HidDevice based on the decoded
* input information
* descriptor information
*
* @param vendor HID Vendor ID to find the connected device
* @param product HID product ID to find the connected device
Expand All @@ -36,7 +36,16 @@ public:
*/
HidDevice(const int vendor, const int product, const int interface);

HidDevice(const HidDecoded* decoded_in);
/**
* @brief Open device at @path, read and decode its HID Report
* Descriptor, then instantiate an HidDevice based on the decoded
* descriptor information
*
* @param devPath path to device
*/
HidDevice(const std::string& devPath);

HidDevice(const HidDescriptor* descriptor);

virtual ~HidDevice() {};

Expand All @@ -58,20 +67,34 @@ public:
*
* @param vendor USB Vendor ID
* @param product USB Product ID
* @return HIDDecodedDevice struct enumerating the available reports
* @param interface HID interface # (use HidScanner to help find this info)
* @return HidDescriptor struct enumerating the available reports
*/
static HidDecoded* decodeDevice(const int vendor, const int product);
static HidDescriptor* decodeDevice(const int vendor, const int product, const int interface);

/**
* @brief open device at @a path, and parse the HID
* report descriptor. This method exists mainly to ease instantiation
*
* @param path path to device
* @return HidDescriptor struct enumerating the available reports
*/
static HidDescriptor* decodeDevice(const std::string& targetPath);

protected:

HidDecoder decoder;

HidDecoded decoded;
HidDescriptor descriptor;

std::vector<unsigned char> hidReportDescriptor;

virtual std::vector<unsigned char> getHidReportDescriptor();

private:

static std::string resolvePath(const std::string& path);

};

} // namespace idf
Expand Down
16 changes: 14 additions & 2 deletions include/idf/HidGenericJoystick.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
PURPOSE:
LIBRARY DEPENDENCIES: (
(idf/HidGenericJoystick.cpp)

)
*/

Expand Down Expand Up @@ -44,9 +43,18 @@ class HidGenericJoystick : public HidDevice, public virtual GenericJoystick {
*/
HidGenericJoystick(const int vendor, const int product, const int interface);

/**
* @brief Construct a Generic Joystick derived from HID Report Descriptor
* of the given device
*
* @param path path to the device
*/
HidGenericJoystick(const std::string& path);


void decode(const std::vector<unsigned char>& data);

protected:
protected:

/**
* @brief Flag indicating whether the report descriptor contained a Z axis. If so
Expand All @@ -57,6 +65,10 @@ class HidGenericJoystick : public HidDevice, public virtual GenericJoystick {
*/
bool useZForTwist;

private:

void init();

};

} // namespace idf
Expand Down
18 changes: 9 additions & 9 deletions include/idf/UsbDevice.hh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ class UsbDevice : public InputDevice {

virtual std::vector<std::vector<unsigned char> > read();

/**
* returns an absolute path to @a path, resolving '.', '..', and symbolic links
*
* @return the resolved path
*/
std::string resolvePath(const std::string& path) const;

std::string getDeviceName(const Identification& info);

private:

/** number of instances in existance */
Expand Down Expand Up @@ -184,15 +193,6 @@ class UsbDevice : public InputDevice {
*/
UsbDevice* getInstanceAtPath(const std::string& path) const;

/**
* returns an absolute path to @a path, resolving '.', '..', and symbolic links
*
* @return the resolved path
*/
std::string resolvePath(const std::string& path) const;

std::string getDeviceName(const Identification& info);

void operator=(const UsbDevice&);

};
Expand Down
3 changes: 3 additions & 0 deletions source/idf/GenericJoystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ namespace idf {
GenericJoystick::GenericJoystick() :
forwardBackwardPivot(0, 1023, 512),
leftRightPivot(0, 1023, 512),
forwardBackwardTranslation(0, 1023, 512),
leftRightTranslation(0, 1024, 512),
twist(0, 1023, 512),
trigger(0,1),
slider(0, 1023, 512),
wheel(0, 127, 64),
HatNorth(0,1),
HatNorthEast(0,1),
HatEast(0,1),
Expand Down
20 changes: 10 additions & 10 deletions source/idf/HidDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void HidDecoder::init()
}


HidDecoded* HidDecoder::parseDescriptor(const std::vector<unsigned char> &descriptor)
HidDescriptor* HidDecoder::parseDescriptor(const std::vector<unsigned char> &descriptor)
{
init();
uint i = 0;
Expand Down Expand Up @@ -93,7 +93,7 @@ HidDecoded* HidDecoder::parseDescriptor(const std::vector<unsigned char> &descri
}
}

HidDecoded* decoded = new HidDecoded();
HidDescriptor* decoded = new HidDescriptor();

decoded->type = device_type;
decoded->reports = reports;
Expand Down Expand Up @@ -344,21 +344,21 @@ int HidDecoder::convertDataToInt(const std::vector<unsigned char> &data, const b
}


void HidDecoder::printDecodedInfo(const HidDecoded decoded)
void HidDecoder::printDecodedInfo(const HidDescriptor decoded)
{
std::ostringstream ss;
ss << "Device Type: " << decoded.type << "\n";
ss << "Device Type: " << decoded.type << std::endl;
for (HidReport report : decoded.reports) {
ss << "Report: " << report.id << " (" << report.bytes_count << " bytes)\n";
ss << "Report: " << report.id << " (" << report.bytes_count << " bytes)" << std::endl;
if (report.id != 0) {
ss << " Report ID bits 0:7 value: " << report.id << "\n";
ss << " Report ID bits 0:7 value: " << report.id << std::endl;
}
for(HidInput input : report.inputs) {
ss << " " << std::setfill(' ') << std::setw(15) << std::left << input.name;
if (input.start_bit == input.end_bit) {
ss << " bit " << std::setw(5) << std::right << input.start_bit << " range: ";
ss << std::setw(5) << std::right << input.logical_min << ":";
ss << std::left << input.logical_max << "\n";
ss << std::left << input.logical_max << std::endl;
}
else {
ss << " bits " << std::setw(5) << std::right << input.start_bit << ":";
Expand All @@ -367,12 +367,12 @@ void HidDecoder::printDecodedInfo(const HidDecoded decoded)
ss << std::setw(5) << std::right << input.logical_min << ":";
ss << std::setw(5) << std::left << input.logical_max << " ";
ss << std::setw(5) << std::right << input.physical_min << ":";
ss << std::setw(5) << std::left << input.physical_max << "\n";
ss << std::setw(5) << std::left << input.physical_max << std::endl;
}
}
ss << "\n";
ss << std::endl;
}
printf(ss.str().c_str());
std::cout << ss.str();
}


Expand Down
Loading
Loading