Compilation errors in this sketch

cfii241

New member
I know practically nothing about coding and am having problems compiling this sketch that I downloaded from a project on YouTube. I'm trying to compile and load it to a Teensy 4.1 but get compilation errors that I can't find a solution too. I have no problem compiling all of the example sketches in the Arduino IDE 2.0 so I'm not sure what my problem is. The sketch is a couple of years old so maybe something has changed somewhere since it was written? Anyone willing to try compiling it to see what might be causing the problem?
 

Attachments

  • sketch_panel_2.0.ino
    11.6 KB · Views: 21
Assuming you used this Rotary encoder library, I got it to compile with 2 errors:
C:\Users\Paul\AppData\Local\Temp\.arduinoIDE-unsaved202429-8632-1z0yy9o.nmtm\sketch_mar9a\sketch_mar9a.ino: In function 'void loop()':
C:\Users\Paul\AppData\Local\Temp\.arduinoIDE-unsaved202429-8632-1z0yy9o.nmtm\sketch_mar9a\sketch_mar9a.ino:116:12: error: 'class usb_joystick_class' has no member named 'Xrotate'; did you mean 'Zrotate'?
116 | Joystick.Xrotate(analogRead(25));
| ^~~~~~~
| Zrotate
C:\Users\Paul\AppData\Local\Temp\.arduinoIDE-unsaved202429-8632-1z0yy9o.nmtm\sketch_mar9a\sketch_mar9a.ino:117:12: error: 'class usb_joystick_class' has no member named 'Yrotate'; did you mean 'Zrotate'?
117 | Joystick.Yrotate(analogRead(26));
| ^~~~~~~
| Zrotate

Using library Bounce in folder: C:\Users\Paul\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.59.0\libraries\Bounce (legacy)
Using library Rotary-master in folder: C:\Users\Paul\Documents\Arduino\Libraries\Rotary-master (legacy)
exit status 1

Compilation error: 'class usb_joystick_class' has no member named 'Xrotate'; did you mean 'Zrotate'?
Then I looked into the Teensy Joystick example [File > Examples > Teensy > USB_Joystick > Complete.ino] and there I noticed this piece of code:
C++:
void loop() {
  // read 6 analog inputs and use them for the joystick axis
  Joystick.X(analogRead(0));
  Joystick.Y(analogRead(1));
  Joystick.Z(analogRead(2));
  Joystick.Zrotate(analogRead(3));
  Joystick.sliderLeft(analogRead(4));
  Joystick.sliderRight(analogRead(5));
So I changed lines #116 & #117 in your code from:
C++:
  Joystick.Xrotate(analogRead(25));
  Joystick.Yrotate(analogRead(26));
to:
C++:
  Joystick.X(analogRead(25));
  Joystick.Y(analogRead(26));
Now your code compiles without error.
By the way, don't forget to set Teensy's USB type to Flight Sim Controls + Joystick.

Disclaimer: no guarantees that the code works properly with the hardware, but it compiles without error...

Paul
 
I believe that you need to update the USB descriptor to have JOYSTICK_SIZE=64, which then gives you things like:

Code:
#elif JOYSTICK_SIZE == 64
    void button(unsigned int num, bool val) {
        if (--num >= 128) return;
        uint32_t *p = usb_joystick_data + (num >> 5);
        num &= 0x1F;
        if (val) *p |= (1 << num);
        else *p &= ~(1 << num);
        if (!manual_mode) usb_joystick_send();
    }
    void X(unsigned int position) { analog16(0, position); }
    void Y(unsigned int position) { analog16(1, position); }
    void Z(unsigned int position) { analog16(2, position); }
    void Xrotate(unsigned int position) { analog16(3, position); }
    void Yrotate(unsigned int position) { analog16(4, position); }
    void Zrotate(unsigned int position) { analog16(5, position); }
    void slider(unsigned int num, unsigned int position) {

From the website:
This is discussed in the forum thread:

I believe to get this you need to go into the Teensy sources and look at the file:
<where your install is>/cores/teensy4/usb_desc.h

And depending on which USB Type you choose, change the define:
#define JOYSTICK_SIZE 64 // 12 = normal, 64 = extreme joystick

to 64 as I show it now... Was 12

maybe in this section:
Code:
#elif defined(USB_FLIGHTSIM_JOYSTICK)
  #define VENDOR_ID        0x16C0
  #define PRODUCT_ID        0x0488
  #define BCD_DEVICE        0x0211
  #define MANUFACTURER_NAME    {'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN    11
  #define PRODUCT_NAME        {'T','e','e','n','s','y',' ','F','l','i','g','h','t',' ','S','i','m',' ','C','o','n','t','r','o','l','s'}
  #define PRODUCT_NAME_LEN    26
  #define EP0_SIZE        64
  #define NUM_ENDPOINTS         4
  #define NUM_INTERFACE        3
  #define FLIGHTSIM_INTERFACE    0    // Flight Sim Control
  #define FLIGHTSIM_TX_ENDPOINT    3
  #define FLIGHTSIM_TX_SIZE    64
  #define FLIGHTSIM_TX_INTERVAL    1
  #define FLIGHTSIM_RX_ENDPOINT    3
  #define FLIGHTSIM_RX_SIZE    64
  #define FLIGHTSIM_RX_INTERVAL    1
  #define SEREMU_INTERFACE      1    // Serial emulation
  #define SEREMU_TX_ENDPOINT    2
  #define SEREMU_TX_SIZE        64
  #define SEREMU_TX_INTERVAL    1
  #define SEREMU_RX_ENDPOINT    2
  #define SEREMU_RX_SIZE        32
  #define SEREMU_RX_INTERVAL    2
  #define JOYSTICK_INTERFACE    2    // Joystick
  #define JOYSTICK_ENDPOINT     4
  #define JOYSTICK_SIZE         64    //  12 = normal, 64 = extreme joystick
  #define JOYSTICK_INTERVAL     1
  #define ENDPOINT2_CONFIG    ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_INTERRUPT
  #define ENDPOINT3_CONFIG    ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK
  #define ENDPOINT4_CONFIG    ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
 
Back
Top