Hello,
I have looked at the wiki for the HID lib from nicohood but it was last updated in april and the only text is “TODO”
So I looked in src folder for the gamepad.h file but I am too new to C to really understand what I should look for.
What I need to know is how to get the code compiled. I have included HID.h but that does not help.
The code:
#include <HID.h>
// Teensy pin definitions
#define LED_PIN 11
#define DATA_IN_PIN 14 // 2 Button Data
#define MODE_PIN 16 // 3 Button !CS & !PL
#define CLOCK_PIN 15 // 7 Button Clock
#define X_AXIS_PIN A0 // 4 Shifter X axis
#define Y_AXIS_PIN A1 // 8 Shifter Y axis
// H-shifter mode analog axis thresholds
#define HS_XAXIS_LEFT 400
#define HS_XAXIS_RIGHT 600
#define HS_YAXIS_UP 800
#define HS_YAXIS_DOWN 300
// Sequential shifter mode analog axis thresholds
#define SS_UPSHIFT_BEGIN 670
#define SS_UPSHIFT_END 600
#define SS_DOWNSHIFT_BEGIN 430
#define SS_DOWNSHIFT_END 500
// Handbrake mode analog axis limits
#define HB_MAXIMUM 530
#define HB_MINIMUM 400
#define HB_RANGE (HB_MAXIMUM-HB_MINIMUM)
// Digital inputs definitions
#define DI_REVERSE 1
#define DI_MODE 3
#define DI_RED_CENTERRIGHT 4
#define DI_RED_CENTERLEFT 5
#define DI_RED_RIGHT 6
#define DI_RED_LEFT 7
#define DI_BLACK_TOP 8
#define DI_BLACK_RIGHT 9
#define DI_BLACK_LEFT 10
#define DI_BLACK_BOTTOM 11
#define DI_DPAD_RIGHT 12
#define DI_DPAD_LEFT 13
#define DI_DPAD_BOTTOM 14
#define DI_DPAD_TOP 15
// Shifter state
#define DOWN_SHIFT -1
#define NO_SHIFT 0
#define UP_SHIFT 1
// Shifter mode
#define SHIFTER_MODE 0
#define HANDBRAKE_MODE 1
// Dpad mode
#define DPAD_DISABLED 0
#define DPAD_ENABLED 1
// LED blink counter
int led=0;
// Shifter state
int shift=NO_SHIFT;
// Handbrake mode
int mode=SHIFTER_MODE;
//Dpad mode
int dpad_mode=DPAD_ENABLED;
// Called at startup
// Must initialize hardware and software modules
void setup()
{
// G25 shifter analog inputs configuration
pinMode(X_AXIS_PIN, INPUT_PULLUP); // X axis
pinMode(Y_AXIS_PIN, INPUT_PULLUP); // Y axis
// G25 shift register interface configuration
pinMode(DATA_IN_PIN, INPUT); // Data in
pinMode(MODE_PIN, OUTPUT); // Parallel/serial mode
pinMode(CLOCK_PIN, OUTPUT); // Clock
// LED output mode configuration
pinMode(LED_PIN, OUTPUT); // LED
// Virtual joystick configuration
Gamepad.begin();
// Virtual serial interface configuration
Serial.begin(38400);
// Digital outputs initialization
digitalWrite(LED_PIN, LOW);
digitalWrite(MODE_PIN, HIGH);
digitalWrite(CLOCK_PIN, HIGH);
}
// Called in a loop after initialization
void loop()
{
// Reading of button states from G25 shift register
int b[16];
digitalWrite(MODE_PIN, LOW); // Parallel mode: inputs are read into shift register
delayMicroseconds(10); // Wait for signal to settle
digitalWrite(MODE_PIN, HIGH); // Serial mode: data bits are output on clock falling edge
for(int i=0; i<16; i++) // Iteration over both 8 bit registers
{
digitalWrite(CLOCK_PIN, LOW); // Generate clock falling edge
delayMicroseconds(10); // Wait for signal to settle
b[i]=digitalRead(DATA_IN_PIN); // Read data bit and store it into bit array
digitalWrite(CLOCK_PIN, HIGH); // Generate clock rising edge
delayMicroseconds(10); // Wait for signal to settle
}
// Reading of shifter position
int x=analogRead(X_AXIS_PIN); // X axis
int y=analogRead(Y_AXIS_PIN); // Y axis
// Handbrake mode logic
if(b[DI_RED_CENTERLEFT]!=0) // Is left center red button depressed?
{
if(b[DI_RED_CENTERRIGHT]!=0) // Is right center red button also depressed?
{
if(b[DI_RED_RIGHT]!=0) // Is rightmost red button also depressed?
{
mode=HANDBRAKE_MODE; // Handbrake mode is activated if the 3 rightmost
} // red buttons are depressed
if(b[DI_RED_LEFT]!=0) // Is leftmost red button also depressed?
{
mode=SHIFTER_MODE; // Handbrake mode is deactivated if the 3 leftmost
} // red buttons are depressed
}
}
// Current gear calculation
int gear=0; // Default value is neutral
if(gear!=6) b[DI_REVERSE]=0; // Reverse gear is allowed only on 6th gear position
if(b[DI_REVERSE]==1) gear=0; // 6th gear is deactivated if reverse gear is engaged
// Release virtual buttons for all gears
Gamepad.release(1);
Gamepad.release(2);
Gamepad.release(3);
Gamepad.release(4);
Gamepad.release(5);
Gamepad.release(6);
// Depress virtual button for current gear
if(gear>0) Gamepad.press(gear);
// Dpad positions
// 812
// 703
// 654
int number_of_buttons = 16;
if (dpad_mode)
{
number_of_buttons = 12;
int dpad = 0;
if(b[DI_DPAD_TOP])
{
if (b[DI_DPAD_LEFT]) dpad = 8;
else if (b[DI_DPAD_RIGHT]) dpad = 2;
else dpad = 1;
}
else if (b[DI_DPAD_BOTTOM])
{
if (b[DI_DPAD_LEFT]) dpad = 6;
else if (b[DI_DPAD_RIGHT]) dpad = 4;
else dpad = 5;
}
else
{
if (b[DI_DPAD_LEFT]) dpad = 7;
if (b[DI_DPAD_RIGHT]) dpad = 3;
}
Gamepad.dPad1(dpad);
}
// Set state of virtual buttons for all the physical buttons (including reverse)
for(int i=0; i<number_of_buttons; i++)
{
if (b[i])
{
Gamepad.press(7+i);
}
else
{
Gamepad.release(7+i);
}
}
// Write new virtual joystick state
Gamepad.write();
// Blink the on-board LED
if(++led==100) led=0; // Period is 100 cycles * 10ms = 1s
if(led==0) digitalWrite(LED_PIN, LOW); // LED is off for 50 cycles
if(led==50) digitalWrite(LED_PIN, HIGH); // LED is on for 50 cycles
// Wait
delay(10); // Wait for 10ms
}
The log:
Arduino: 1.6.7 Hourly Build 2015/12/01 05:44 (Windows 10), Board: "SparkFun Pro Micro 5V/16MHz"
C:\Users\<USER>\Documents\Projekter\G25 Shifter Only HIDbox\G25_shifter_en\G25_shifter_en.ino: In function 'void setup()':
G25_shifter_en:119: error: 'Gamepad' was not declared in this scope
Gamepad.begin();
^
C:\Users\<USER>\Documents\Projekter\G25 Shifter Only HIDbox\G25_shifter_en\G25_shifter_en.ino: In function 'void loop()':
G25_shifter_en:196: error: 'Gamepad' was not declared in this scope
Gamepad.zAxis(0);
^
G25_shifter_en:229: error: 'Gamepad' was not declared in this scope
Gamepad.zAxis(y/4+0x80); // Set handbrake analog output
^
G25_shifter_en:238: error: 'Gamepad' was not declared in this scope
Gamepad.release(1);
^
exit status 1
'Gamepad' was not declared in this scope