diff --git a/.DS_Store b/.DS_Store index 193e50a..9f1340f 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/USB_Joystick/Arduino/USBHIDJoystick_calibrated/USBHIDJoystick_calibrated.ino b/USB_Joystick/Arduino/USBHIDJoystick_calibrated/USBHIDJoystick_calibrated.ino index 95d231d..33510d2 100644 --- a/USB_Joystick/Arduino/USBHIDJoystick_calibrated/USBHIDJoystick_calibrated.ino +++ b/USB_Joystick/Arduino/USBHIDJoystick_calibrated/USBHIDJoystick_calibrated.ino @@ -2,11 +2,9 @@ #include -// set pin 4 as the slave select for the digital pot: -const int slaveSelectPin = A0; //4; -//const float foo = .21; +// set pin A0 as the slave select for the digital pot: +const int slaveSelectPin = A0; const int TrimPin = A3; - const int Butt0Pin = A4; const int Butt1Pin = A5; @@ -41,17 +39,12 @@ void setup() { // set the slaveSelectPin as an output: pinMode (slaveSelectPin, OUTPUT); - - pinMode (Butt0Pin, OUTPUT); pinMode (Butt1Pin, OUTPUT); - // initialize SPI: SPI.begin(); - - Serial.begin( 115200 ); Serial.println("Start"); @@ -63,41 +56,36 @@ void setup() if (!Hid.SetReportParser(0, &Joy)) ErrorMessage(PSTR("SetReportParser"), 1 ); - - - } void loop() { Usb.Task(); + int channelX = 5; + int channelY = 3; - float foo = float(analogRead(TrimPin))/1023.000; + float calibrate = float(analogRead(TrimPin))/1023.000; - + // need to determine if x or x2 is giving values int joyX = JoyEvents.X; - int channel = 5; - - digitalPotWrite(channel, joyX * foo); - digitalPotWrite(channel - 1, joyX * foo); - + + // need to determine if y or y2 is giving values int joyY = JoyEvents.Y; - channel = 3; - - digitalPotWrite(channel, joyY * foo); - digitalPotWrite(channel - 1, joyY * foo); + + + // write the values to the POTs + digitalPotWrite(channelX, joyX * calibrate); + digitalPotWrite(channelX - 1, joyX * calibrate); + digitalPotWrite(channelY, joyY * calibrate); + digitalPotWrite(channelY - 1, joyY * calibrate); + // write the buttons digitalWrite(Butt0Pin,JoyEvents.Butt0); digitalWrite(Butt1Pin,JoyEvents.Butt1); - - - } - - void digitalPotWrite(int address, int value) { // take the SS pin low to select the chip: digitalWrite(slaveSelectPin,LOW); diff --git a/USB_Joystick/Arduino/USBHIDJoystick_calibrated/hidjoystickrptparser.cpp b/USB_Joystick/Arduino/USBHIDJoystick_calibrated/hidjoystickrptparser.cpp index c8aeef9..c856935 100644 --- a/USB_Joystick/Arduino/USBHIDJoystick_calibrated/hidjoystickrptparser.cpp +++ b/USB_Joystick/Arduino/USBHIDJoystick_calibrated/hidjoystickrptparser.cpp @@ -1,12 +1,7 @@ - - - - #include "hidjoystickrptparser.h" JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : joyEvents(evt), - oldHat(0xDE), oldButtons(0) { for (uint8_t i=0; iaxis0; + axes[1] = evt->axis1; + axes[2] = evt->axis2; + axes[3] = evt->axis3; + axes[4] = evt->axis4; -X = evt->X; -Y = evt->Y; - Serial.print("X: "); - Serial.print(X); - //PrintHex(evt->X, 0x80); - Serial.print("\tY: "); - Serial.print(Y); -// PrintHex(evt->Y, 0x80); - Serial.println(""); + + if(initialized) { + + + for(int i =0; i<5 ; i++ ){ + + if (axes[i] < axesMin[i] ) { + axesMin[i] = axes[i]; + } + + if (axes[i] > axesMax[i]) { + axesMax[i] = axes[i]; + } + + axesDelta[i] = axesMax[i] - axesMin[i]; + + } + + + for(int j =0; j<5 ; j++ ){ + + if(axesDelta[j] > 0) { + X = axes[j]; + Y = axes[j+1]; + break; + } + + } + + + } else { + + for(int i =0; i<5 ; i++ ){ + axesMin[i] = axes[i]; + axesMax[i] = axes[i]; + } + + initialized = true; + // don't bother with the first set of data, as joystick initializes. + + } + +Serial.print(X); +Serial.print(" "); +Serial.println(Y); + + +/* + +keep track of axes 0 - 4 (5 axes) + +min and max values. max-min = range + +first axis with range, and first +1 are X and Y + +*/ } @@ -76,11 +125,11 @@ void JoystickEvents::OnButtonUp(uint8_t but_id) { Serial.print("Up: "); Serial.println(but_id); - if(but_id == 1) { + if(but_id % 2 == 0) { // all even numbered buttons = button 0 Butt0 = false; } - if(but_id == 2) { + if(but_id % 2 == 1) { // all odd buttons = button 1 Butt1 = false; } @@ -92,11 +141,11 @@ void JoystickEvents::OnButtonDn(uint8_t but_id) Serial.println(but_id); - if(but_id == 1) { + if(but_id % 2 == 0) { // all even numbered buttons = button 0 Butt0 = true; } - if(but_id == 2) { + if(but_id % 2 == 1) { // all odd buttons = button 1 Butt1 = true; } } diff --git a/USB_Joystick/Arduino/USBHIDJoystick_calibrated/hidjoystickrptparser.h b/USB_Joystick/Arduino/USBHIDJoystick_calibrated/hidjoystickrptparser.h index 45f41e9..cfb1d64 100644 --- a/USB_Joystick/Arduino/USBHIDJoystick_calibrated/hidjoystickrptparser.h +++ b/USB_Joystick/Arduino/USBHIDJoystick_calibrated/hidjoystickrptparser.h @@ -23,7 +23,7 @@ struct GamePadEventData { - uint8_t X, Y; + uint8_t axis0, axis1, axis2, axis3, axis4; // read first 5 axes }; class JoystickEvents @@ -36,6 +36,18 @@ public: uint8_t X; uint8_t Y; +int axes[5]; +int axesMin[5]; +int axesMax[5]; +int axesDelta[5]; + +int activeX; +int activeY; +//arrays of min and max values +// var with which axis is X/Y + +boolean initialized; + boolean Butt0; boolean Butt1; @@ -48,7 +60,6 @@ class JoystickReportParser : public HIDReportParser JoystickEvents *joyEvents; uint8_t oldPad[RPT_GEMEPAD_LEN]; - uint8_t oldHat; uint16_t oldButtons; public: