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
af56aea1
Commit
af56aea1
authored
Jun 18, 2015
by
vowstar
Browse files
Update dhtlib api, support both integer and float version.
parent
899935e6
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/dhtlib/dht.c
View file @
af56aea1
...
@@ -110,8 +110,8 @@ int dht_read(uint8_t pin)
...
@@ -110,8 +110,8 @@ int dht_read(uint8_t pin)
}
}
// CONVERT AND STORE
// CONVERT AND STORE
dht_humidity
=
COMBINE_HIGH_AND_LOW_BYTE
(
dht_bits
[
0
],
dht_bits
[
1
])
*
0
.
1
;
dht_humidity
=
(
double
)
COMBINE_HIGH_AND_LOW_BYTE
(
dht_bits
[
0
],
dht_bits
[
1
])
*
0
.
1
;
dht_temperature
=
COMBINE_HIGH_AND_LOW_BYTE
(
dht_bits
[
2
]
&
0x7F
,
dht_bits
[
3
])
*
0
.
1
;
dht_temperature
=
(
double
)
COMBINE_HIGH_AND_LOW_BYTE
(
dht_bits
[
2
]
&
0x7F
,
dht_bits
[
3
])
*
0
.
1
;
if
(
dht_bits
[
2
]
&
0x80
)
// negative dht_temperature
if
(
dht_bits
[
2
]
&
0x80
)
// negative dht_temperature
{
{
dht_temperature
=
-
dht_temperature
;
dht_temperature
=
-
dht_temperature
;
...
...
app/include/user_version.h
View file @
af56aea1
...
@@ -7,6 +7,6 @@
...
@@ -7,6 +7,6 @@
#define NODE_VERSION_INTERNAL 0U
#define NODE_VERSION_INTERNAL 0U
#define NODE_VERSION "NodeMCU 0.9.6"
#define NODE_VERSION "NodeMCU 0.9.6"
#define BUILD_DATE "build 2015061
7
"
#define BUILD_DATE "build 2015061
8
"
#endif
/* __USER_VERSION_H__ */
#endif
/* __USER_VERSION_H__ */
app/modules/dht.c
View file @
af56aea1
...
@@ -22,7 +22,9 @@ static int dht_lapi_read( lua_State *L )
...
@@ -22,7 +22,9 @@ static int dht_lapi_read( lua_State *L )
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
MOD_CHECK_ID
(
dht
,
id
);
MOD_CHECK_ID
(
dht
,
id
);
lua_pushinteger
(
L
,
dht_read
(
id
)
);
lua_pushinteger
(
L
,
dht_read
(
id
)
);
return
1
;
lua_pushnumber
(
L
,
dht_getTemperature
()
);
lua_pushnumber
(
L
,
dht_getHumidity
()
);
return
3
;
}
}
// Lua: result = dht.read11( id )
// Lua: result = dht.read11( id )
...
@@ -31,23 +33,42 @@ static int dht_lapi_read11( lua_State *L )
...
@@ -31,23 +33,42 @@ static int dht_lapi_read11( lua_State *L )
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
unsigned
id
=
luaL_checkinteger
(
L
,
1
);
MOD_CHECK_ID
(
dht
,
id
);
MOD_CHECK_ID
(
dht
,
id
);
lua_pushinteger
(
L
,
dht_read11
(
id
)
);
lua_pushinteger
(
L
,
dht_read11
(
id
)
);
return
1
;
lua_pushnumber
(
L
,
dht_getTemperature
()
);
lua_pushnumber
(
L
,
dht_getHumidity
()
);
return
3
;
}
}
// Lua: result = dht.humidity()
// Lua: result = dht.humidity()
static
int
dht_lapi_humidity
(
lua_State
*
L
)
static
int
dht_lapi_humidity
(
lua_State
*
L
)
{
{
lua_pushinteger
(
L
,
dht_getHumidity
()
);
lua_pushnumber
(
L
,
dht_getHumidity
()
);
return
1
;
}
// Lua: result = dht.humiditydecimal()
static
int
dht_lapi_humiditydecimal
(
lua_State
*
L
)
{
double
value
=
dht_getHumidity
();
int
result
=
(
int
)((
value
-
(
int
)
value
)
*
1000
);
lua_pushnumber
(
L
,
result
);
return
1
;
return
1
;
}
}
// Lua: result = dht.temperature()
// Lua: result = dht.temperature()
static
int
dht_lapi_temperature
(
lua_State
*
L
)
static
int
dht_lapi_temperature
(
lua_State
*
L
)
{
{
lua_push
integ
er
(
L
,
dht_getTemperature
()
);
lua_push
numb
er
(
L
,
dht_getTemperature
()
);
return
1
;
return
1
;
}
}
// Lua: result = dht.temperaturedecimal()
static
int
dht_lapi_temperaturedecimal
(
lua_State
*
L
)
{
double
value
=
dht_getTemperature
();
int
result
=
(
int
)((
value
-
(
int
)
value
)
*
1000
);
lua_pushnumber
(
L
,
result
);
return
1
;
}
// Module function map
// Module function map
#define MIN_OPT_LEVEL 2
#define MIN_OPT_LEVEL 2
...
@@ -58,6 +79,8 @@ const LUA_REG_TYPE dht_map[] =
...
@@ -58,6 +79,8 @@ const LUA_REG_TYPE dht_map[] =
{
LSTRKEY
(
"read11"
),
LFUNCVAL
(
dht_lapi_read11
)
},
{
LSTRKEY
(
"read11"
),
LFUNCVAL
(
dht_lapi_read11
)
},
{
LSTRKEY
(
"humidity"
),
LFUNCVAL
(
dht_lapi_humidity
)
},
{
LSTRKEY
(
"humidity"
),
LFUNCVAL
(
dht_lapi_humidity
)
},
{
LSTRKEY
(
"temperature"
),
LFUNCVAL
(
dht_lapi_temperature
)
},
{
LSTRKEY
(
"temperature"
),
LFUNCVAL
(
dht_lapi_temperature
)
},
{
LSTRKEY
(
"humiditydecimal"
),
LFUNCVAL
(
dht_lapi_humiditydecimal
)
},
{
LSTRKEY
(
"temperaturedecimal"
),
LFUNCVAL
(
dht_lapi_temperaturedecimal
)
},
#if LUA_OPTIMIZE_MEMORY > 0
#if LUA_OPTIMIZE_MEMORY > 0
{
LSTRKEY
(
"OK"
),
LNUMVAL
(
DHTLIB_OK
)
},
{
LSTRKEY
(
"OK"
),
LNUMVAL
(
DHTLIB_OK
)
},
{
LSTRKEY
(
"ERROR_CHECKSUM"
),
LNUMVAL
(
DHTLIB_ERROR_CHECKSUM
)
},
{
LSTRKEY
(
"ERROR_CHECKSUM"
),
LNUMVAL
(
DHTLIB_ERROR_CHECKSUM
)
},
...
...
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