Skip to content
Open
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
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Arduino Joystick With Force Feedback Library


Fix DinamicHID for compile with Arduino DUE.

## Statement

### This is a joy library for Atmega32UX chip with force feedback, which can be used to make game handle with vibration, game steering wheel with force feedback, etc.Multi-axis-force-feedback feature is added.
Expand Down
12 changes: 10 additions & 2 deletions src/DynamicHID/DynamicHID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
*/

#include "DynamicHID.h"
#include "Arduino.h"

#if defined(USBCON)

#ifdef _VARIANT_ARDUINO_DUE_X_
#define USB_SendControl USBD_SendControl
#define USB_Send USBD_Send
#define USB_Recv USBD_Recv
#define USB_RecvControl USBD_RecvControl
#define USB_Available USBD_Available
#endif

DynamicHID_& DynamicHID()
Expand Down Expand Up @@ -111,7 +115,7 @@ int DynamicHID_::RecvData(byte* data)
{
int count = 0;
while (usb_Available()) {
data[count++] = (byte)USB_Recv(PID_ENDPOINT_OUT);
data[count++] = USB_Recv(PID_ENDPOINT_OUT);
}
return count;
}
Expand Down Expand Up @@ -141,7 +145,8 @@ bool DynamicHID_::GetReport(USBSetup& setup) {
if (report_type == DYNAMIC_HID_REPORT_TYPE_FEATURE) {
if ((report_id == 6))// && (gNewEffectBlockLoad.reportId==6))
{
_delay_us(500);
//_delay_us(500);
delayMicroseconds(500);
USB_SendControl(TRANSFER_RELEASE, pidReportHandler.getPIDBlockLoad(), sizeof(USB_FFBReport_PIDBlockLoad_Feature_Data_t));
pidReportHandler.pidBlockLoad.reportId = 0;
return (true);
Expand Down Expand Up @@ -189,6 +194,7 @@ bool DynamicHID_::SetReport(USBSetup& setup) {
return true;
}*/
}
return (false);
}

bool DynamicHID_::setup(USBSetup& setup)
Expand Down Expand Up @@ -237,6 +243,7 @@ bool DynamicHID_::setup(USBSetup& setup)
return false;
}


DynamicHID_::DynamicHID_(void) : PluggableUSBModule(PID_ENPOINT_COUNT, 1, epType),
rootNode(NULL), descriptorSize(0),
protocol(DYNAMIC_HID_REPORT_PROTOCOL), idle(1)
Expand All @@ -246,6 +253,7 @@ DynamicHID_::DynamicHID_(void) : PluggableUSBModule(PID_ENPOINT_COUNT, 1, epType
PluggableUSB().plug(this);
}


int DynamicHID_::begin(void)
{
return 0;
Expand Down
8 changes: 6 additions & 2 deletions src/DynamicHID/DynamicHID.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class DynamicHIDSubDescriptor {
DynamicHIDSubDescriptor(const void *d, const uint16_t l, const void* pid_d, const uint16_t pid_l, const bool ipm = true) : data(d), length(l),pid_data(pid_d), pid_length(pid_l), inProgMem(ipm) { }

const void* data;
const void* pid_data;
const uint16_t length;
const void* pid_data;
const uint16_t pid_length;
const bool inProgMem;
};
Expand All @@ -135,7 +135,11 @@ class DynamicHID_ : public PluggableUSBModule
uint8_t getShortName(char* name);

private:
uint8_t epType[2];
#ifdef _VARIANT_ARDUINO_DUE_X_
uint32_t epType[2];
#else
uint8_t epType[2];
#endif

DynamicHIDSubDescriptor* rootNode;
uint16_t descriptorSize;
Expand Down
2 changes: 1 addition & 1 deletion src/Joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ int32_t Joystick_::getEffectForce(volatile TEffectState& effect,Gains _gains,Eff
void Joystick_::forceCalculator(int32_t* forces) {
forces[0] = 0;
forces[1] = 0;
int32_t force = 0;
//int32_t force = 0;
for (int id = 0; id < MAX_EFFECTS; id++) {
volatile TEffectState& effect = DynamicHID().pidReportHandler.g_EffectStates[id];
if ((effect.state == MEFFECTSTATE_PLAYING) &&
Expand Down
6 changes: 6 additions & 0 deletions src/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@
#define DIRECTION_ENABLE 0x04
#define X_AXIS_ENABLE 0x01
#define Y_AXIS_ENABLE 0x02

#ifndef FFB_AXIS_COUNT
#define FFB_AXIS_COUNT 0x02
#endif

#define FORCE_FEEDBACK_MAXGAIN 100
#ifndef DEG_TO_RAD
#define DEG_TO_RAD ((float)((float)3.14159265359 / 180.0))
#endif

struct Gains{
uint8_t totalGain = FORCE_FEEDBACK_MAXGAIN;
Expand Down