-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Fix a number of issues with the gpio.pulse family of functions #2260
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are quite complex changes which call for corner-case testing rather than code review. Therefore I restrict myself to nitpicking 😉
app/modules/gpio_pulse.c
Outdated
// stack now contains: -1 => value; -2 => key; -3 => table | ||
if (lua_type(L, -2) == LUA_TNUMBER) { | ||
int pin = lua_tonumber(L, -2); | ||
int value = lua_tonumber(L, -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if value at -1 isn't LUA_TNUMBER or a convertible string?
app/modules/gpio_pulse.c
Outdated
|
||
if (strcmp(str, "delay") == 0) { | ||
entry->delay = lua_tonumber(L, -1); | ||
if (entry->delay < 0 || entry->delay > DELAY_LIMIT) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect that this won't throw an error if value at index -1
is not convertible to a number. lua_tonumber()
returns 0 in this case and the range check is happy.
luaL_checknumber()
or an explicit test for lua_isnumber()
if delay == 0 would detect nonsense.
Applies to further instances of lua_tonumber()
below.
The changes aren't as big as they look as I moved the guts of one function into its own function so that I could use it elsewhere. I did fix all the unchecked calls so that there is more error detection (and it actually found an error in my current application!) |
This also includes a fix to the issue in https://stackoverflow.com/q/48790455/131929 -- I changed gpio.mode(, gpio.OUTPUT) to actually enable the driver. |
I also addressed the comments in #2265 |
…cu#2260) * Fix some subtle timing issues with gpio.pulse * Add the pulse:update method * Allow getstate to work on stopped pulsers * Make gpio.mode(, gpio.OUTPUT) actually set the output mode * Added some more documentation
Fixes #2254.
dev
branch rather than formaster
.docs/en/*
.I'm now trying to make progress on my clock project and discovering some bugs in the existing code, and missing functionality. This PR adds the missing features and resolves the bugs.