Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_PWM_range returns real range and not just 0 or an error #453

Open
berndporr opened this issue Apr 9, 2021 · 3 comments
Open

set_PWM_range returns real range and not just 0 or an error #453

berndporr opened this issue Apr 9, 2021 · 3 comments

Comments

@berndporr
Copy link

set_PWM_range doc states:

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE,
or PI_NOT_PERMITTED.

https://github.com/joan2937/pigpio/blob/master/pigpiod_if2.h#L595
However the underlying function in pigpio.c returns the real range:
https://github.com/joan2937/pigpio/blob/master/pigpio.c#L9080

return pwmRealRange[gpioInfo[gpio].freqIdx];

The doc on the web page states the same. It obv makes sense to return the actual range which might be different to the one requested. I do a workaround for now in my code:
https://github.com/berndporr/alphabot/blob/main/alphabot.cpp#L9
where I just set the pwm range and then read it back. Either way the real range is really good to have as with that I can avoid rounding errors and get always the best resolution.

@guymcswain
Copy link
Collaborator

I agree with you but if we change the API from the documentation then it could disrupt current users of the library. It looks like you have a satisfactory working method so can this issue be closed?

@berndporr
Copy link
Author

The API is great as it is. I'd suggest to just fix the documentation and state that the function actually returns the real range not just zero on success. If you have no plans of changing it then I can actually use the return value. :)

@guymcswain
Copy link
Collaborator

Thank you for clarifying for me. In that case it makes sense to change the doc to match the behavior.

berndporr added a commit to berndporr/pigpio that referenced this issue Apr 10, 2021
Fixed the documentation that the command set_PWM_range() actually
returns the actual range. This resolves joan2937#453.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants