Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
45fea23d
Unverified
Commit
45fea23d
authored
Apr 27, 2018
by
Terry Ellison
Committed by
GitHub
Apr 27, 2018
Browse files
Merge pull request #2322 from peturdainn/peturdainn-patch-1
fix for ds18b20 negative decimals
parents
53e44d5e
a1e02fc6
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/ds18b20.c
View file @
45fea23d
...
@@ -197,6 +197,7 @@ static int ds18b20_lua_read(lua_State *L) {
...
@@ -197,6 +197,7 @@ static int ds18b20_lua_read(lua_State *L) {
static
int
ds18b20_read_device
(
uint8_t
*
ds18b20_device_rom
)
{
static
int
ds18b20_read_device
(
uint8_t
*
ds18b20_device_rom
)
{
lua_State
*
L
=
lua_getstate
();
lua_State
*
L
=
lua_getstate
();
int16_t
ds18b20_raw_temp
;
if
(
onewire_crc8
(
ds18b20_device_rom
,
7
)
==
ds18b20_device_rom
[
7
])
{
if
(
onewire_crc8
(
ds18b20_device_rom
,
7
)
==
ds18b20_device_rom
[
7
])
{
...
@@ -221,8 +222,9 @@ static int ds18b20_read_device(uint8_t *ds18b20_device_rom) {
...
@@ -221,8 +222,9 @@ static int ds18b20_read_device(uint8_t *ds18b20_device_rom) {
lua_pushfstring
(
L
,
"%d:%d:%d:%d:%d:%d:%d:%d"
,
ds18b20_device_rom
[
0
],
ds18b20_device_rom
[
1
],
ds18b20_device_rom
[
2
],
ds18b20_device_rom
[
3
],
ds18b20_device_rom
[
4
],
ds18b20_device_rom
[
5
],
ds18b20_device_rom
[
6
],
ds18b20_device_rom
[
7
]);
lua_pushfstring
(
L
,
"%d:%d:%d:%d:%d:%d:%d:%d"
,
ds18b20_device_rom
[
0
],
ds18b20_device_rom
[
1
],
ds18b20_device_rom
[
2
],
ds18b20_device_rom
[
3
],
ds18b20_device_rom
[
4
],
ds18b20_device_rom
[
5
],
ds18b20_device_rom
[
6
],
ds18b20_device_rom
[
7
]);
ds18b20_device_scratchpad_conf
=
(
ds18b20_device_scratchpad
[
4
]
>>
5
)
+
9
;
ds18b20_device_scratchpad_conf
=
(
ds18b20_device_scratchpad
[
4
]
>>
5
)
+
9
;
ds18b20_device_scratchpad_temp
=
((
int8_t
)(
ds18b20_device_scratchpad
[
1
]
<<
4
)
+
(
ds18b20_device_scratchpad
[
0
]
>>
4
)
+
((
double
)(
ds18b20_device_scratchpad
[
0
]
&
0x0F
)
/
16
));
ds18b20_raw_temp
=
((
ds18b20_device_scratchpad
[
1
]
<<
8
)
|
ds18b20_device_scratchpad
[
0
]);
ds18b20_device_scratchpad_temp_dec
=
((
double
)(
ds18b20_device_scratchpad
[
0
]
&
0x0F
)
/
16
*
1000
);
ds18b20_device_scratchpad_temp
=
(
double
)
ds18b20_raw_temp
/
16
;
ds18b20_device_scratchpad_temp_dec
=
(
ds18b20_raw_temp
-
(
ds18b20_raw_temp
/
16
*
16
))
*
1000
/
16
;
if
(
ds18b20_device_scratchpad_conf
>=
ds18b20_device_res
)
{
if
(
ds18b20_device_scratchpad_conf
>=
ds18b20_device_res
)
{
ds18b20_device_res
=
ds18b20_device_scratchpad_conf
;
ds18b20_device_res
=
ds18b20_device_scratchpad_conf
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment