dimircea / REncoder

Rotary Encoder with and without builtin Switch implementation for Arduino UNO/MEGA/DUE and many others, inclusive Seeeduino XIAO.
Other
3 stars 1 forks source link

Example shows error #1

Open adynis opened 3 years ago

adynis commented 3 years ago

Hi, I'm testing this right now on a ESP32 (Espressif32). I had one issue with this: https://github.com/dimircea/REncoder/blob/01bd4b5e9460963a47b5bcde5bcdd99a196e661f/examples/EncoderWithSwitch_WithIRQ/EncoderWithSwitch_WithIRQ.ino#L33 I think it needs to be "int" not "int16_t", since here https://github.com/dimircea/REncoder/blob/01bd4b5e9460963a47b5bcde5bcdd99a196e661f/REncoderWithoutSwitch.cpp#L49 RENCODER_ROTATION_VALUE_TYPE is int. At least I don't have errors anymore after changing to int and I can continue testing :)

PS. Actually I did a separated function, not an inline lambda. I like more with a named function.

dimircea commented 3 years ago

Hi,

Thanks for testing and reporting.

Normally, for AVR MCUs, the int16_t is actually mapped to int, with a typedef or other C/C++ compiler / pre-compiler mechanisms. However, as you have discovered already in your tests, this may be different for other platforms, e.g., for ESPs (8266/32) and possibly for others too.

The "RENCODER_ROTATION_VALUE_TYPE " is defined in REncoderWithoutSwitch.h header file. You can adjust it for your needs / platforms. I will try for the future to make this customizable, so that it can be a parameter.

Have fun! Mircea

adynis commented 3 years ago

Thanks, Then, depending on your plans, you can close this ticket (or keep it open if you want to link it anywhere).

PS. The REncoder module worked great during my tests !! 👍 Thank you

Msprg commented 3 years ago

Hello, @dimircea , Sorry to bother you, but I'm seeing similar error in EncoderWithSwitch_WithIRQ example. I'm getting

class "REncoderWithSwitch" has no member "attachEncoderHandler"

and as a C++ noob, I have no idea how to fix this.

How to reproduce:

  1. VSCode v 1.53.2 + PlatformIO core 5.1.0, Home 3.3.3 extension:
  2. Create a new project, board for example Arduino UNO.
  3. Go to library manager, and search for REncoder. Click "Add to project" and choose newly created project.
  4. Go to projects, and open our newly created project.
  5. In the file explorer open .pio/libdeps/uno/REncoder/examples/EncoderWithSwitch_WithIRQ/EncoderWithSwitch_WithIRQ.ino
  6. Copy the code, and open src/main.cpp paste the code here, replacing all lines except the very first one #include <Arduino.h> one.
  7. The described error should be showing up on the line 34 now...

So, maybe you would have a little time to look into it, and perhaps help me out? Maybe I have misconfigured something here, but if I do, I have no idea what could it be anyways... Thanks!

dimircea commented 3 years ago

Hi,

The problem is that the "attachEncoderHandler" is only available when "RENCODER_ENABLE_ENCODER_IRQ" is defined. This parameter is available in the REncoderConfig.h file, and by default it is commented (therefore disabled). In that file one can also find comments about these parameters and what they are supposed to do. Practically, in your case you have to uncomment the line 58 of the REncoderConfig.h and to comment out the line 71 from the same file. Commenting out the line 71 (this defines the RENCODER_ENABLE_ENCODER_SOFTWARE_DEBOUNCING) parameter, will practically disable the software debouncing.

I hope this helps to solve your problem.

Have fun! Mircea

Msprg commented 3 years ago

Okay I just tried it, and yes, i'm just dumb or something... I actually have been trying to play around with defines in the config file, but I somehow just broke it even more...

So yes, what you have proposed has worked for me. I then got the same int16_t issue as the OP of this issue, and also resolved it by using int instead. Now I'm only getting a warning:

enumeration value 'REncoder_Event_None' not handled in switch [-Wswitch] (35, 12, in the example code)

But I think I'll manage to cope with it somehow... I may add this to the readme.md (or make it stand out a bit clearer if it's already there as i've must missed it all 4 times I've read through it), to save others like me from annoying you with stupid noob questions...

Thanks a bunch nonetheless! Have a nice day!

dimircea commented 3 years ago

It is normal to miss some things. It happens to all of us. No worries! That warning you mention is normal and it is also inoffensive, it will not affect the code or your program.

Have fun and a great day for you too! Mircea