kulbhushanchand / MCP4251

Arduino library for MCP4251 Digital Potentiometer
https://kulbhushanchand.github.io/MCP4251/
GNU General Public License v3.0
11 stars 1 forks source link

error: prototype for '...' does not match any in class '...' #2

Open ste2425 opened 2 years ago

ste2425 commented 2 years ago

After making the changes defined in #1 and trying to recompile i get the following error:

Arduino\libraries\MCP4251\src\MCP4251.cpp:64:6: error: prototype for 'void MCP4251::DigitalPotSetWiperPosition(bool, unsigned int)' does not match any in class 'MCP4251'
 void MCP4251::DigitalPotSetWiperPosition(bool potNum, unsigned int value)
      ^~~~~~~
In file included from Arduino\libraries\MCP4251\src\MCP4251.cpp:1:0:
Arduino\libraries\MCP4251\src\MCP4251.h:43:8: error: candidate is: void MCP4251::DigitalPotSetWiperPosition(bool, uint16_t)
   void DigitalPotSetWiperPosition(bool potNum, uint16_t value); // Need confirmation if it is working
        ^~~~~~~~~~~~~~~~~~~~~~~~~~
exit status 1
Error compiling for board Arduino NANO 33 IoT.

To fix it i modified line 43 in MCP4251.h from:

void DigitalPotSetWiperPosition(bool potNum, uint16_t value); // Need confirmation if it is working

to

void DigitalPotSetWiperPosition(bool potNum, unsigned int value); // Need confirmation if it is working

With that change it now compiles. I'm unable to test if it actually works just yet but figured i would report this.

This is using Arduino IDE version: 1.8.16 and targeting an Arduino Nano 33 IOT.

I will report back about it physically working or not once ive got everything hooked up.

ste2425 commented 2 years ago

Just want to add this is a super cool Lib that will save me a ton of time. I'll be using in my PSP project here: https://github.com/ste2425/PSP-Bluetooth-Controller

Thanks for making it 👍

kulbhushanchand commented 2 years ago

Thank you for reporting the issue and suggesting appropriate changes. and also for your kind appreciation to my work. I'm glad you are finding it useful...

Regarding the error, I think the issue arises because I have used unsigned int at https://github.com/kulbhushanchand/MCP4251/blob/30573564483181dffe4dd87d77d44fde87c72fc2/src/MCP4251.cpp#L64

Using unsigned int makes code machine/compiler dependent, because of the bits allocated to int varies as per the micro controller (e.g. arduino uno vs due). Therefore, uint16_t is preferred, which always allocate same number of bits irrespective of the machine.

Your solution is also correct 👍

However, can you also test another future-proof solution by not making any change in MCP4251.h and instead replacing unsigned int by uint16_t in the MCP4251.cpp at https://github.com/kulbhushanchand/MCP4251/blob/30573564483181dffe4dd87d77d44fde87c72fc2/src/MCP4251.cpp#L64