-
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
node_modules/bme280.lua broken #3323
Comments
That... yes, that seems like a bug. If it's important to avoid the use of Please do open a PR. |
I vote for correcting the bug via |
It seems to me there are several lines of Lua code that it would be nice to review once Lua 5.1 is abandoned. This formula where the bug was being a nice example: 4*math_floor(self._config[3]:byte(1)/4)+ 1 can be rewritten to simple (self._config[3]:byte(1) & 0xFC) | 1 |
I thought about that too. How about a comment |
I like the The discussed part of the code will look this way: write_reg(self.id, self.addr, BME280_REGISTER_CONTROL, 4*math_floor(self._config[3]:byte(1)/4)+ 1) -- LUA51
-- 4*math_floor(self._config[3]:byte(1)/4)+ 1
-- an awful way to avoid bit operations but calculate (config[3] & 0xFC) | BME280_FORCED_MODE
-- Lua 5.3: write_reg(self.id, self.addr, BME280_REGISTER_CONTROL, (self._config[3]:byte(1) & 0xFC) | 1) I think we can close this issue. |
Closing at request of @vsky279. |
Expected behavior
bme280 LUA module
bme280_startreadout
providing valid readout values in callbackActual behavior
bme280 LUA module
bme280_startreadout
provides zero values in callbackNodeMCU startup banner
Hardware
ESP12F + BME280
Problematic code
In https://github.com/nodemcu/nodemcu-firmware/blob/release/lua_modules/bme280/bme280.lua#L133 there is an attempt to avoid using bit operations. However, this produces invalid data (at least in my setup).
I'm running in 1x oversampling on everything, no IIR, and using forced mode.
That gives the value for
_config[3]= 0b00100101 = 0x25
.Applying
math_floor(self._config[3]:byte(1)/4)+ 1
on that yields(0x25 / 4) + 1 = 9 + 1 = 10 = 0x0a =0b00001010
This means that Temperature sampling is turned of, and when the
bme280_math.read
is trigged, the first thing it does if there is no temperature is to return nil.Changing the line to instead use
bit.band(self._config[3]:byte(1), 0xFC) + 1
resolve the problem and the sensor starts working.I might be missing something but I cannot see how this would work at all :)
The text was updated successfully, but these errors were encountered: