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
0caf745d
Commit
0caf745d
authored
Aug 23, 2015
by
aeprox
Browse files
Improve lua API interface
parent
29ee02f6
Changes
3
Show whitespace changes
Inline
Side-by-side
app/modules/tsl2561.c
View file @
0caf745d
...
@@ -13,7 +13,9 @@
...
@@ -13,7 +13,9 @@
static
uint16_t
ch0
;
static
uint16_t
ch0
;
static
uint16_t
ch1
;
static
uint16_t
ch1
;
/*
* Lua: error = tsl2561.init(sdapin, sclpin)
*/
static
int
ICACHE_FLASH_ATTR
tsl2561_init
(
lua_State
*
L
)
{
static
int
ICACHE_FLASH_ATTR
tsl2561_init
(
lua_State
*
L
)
{
uint32_t
sda
;
uint32_t
sda
;
uint32_t
scl
;
uint32_t
scl
;
...
@@ -33,23 +35,44 @@ static int ICACHE_FLASH_ATTR tsl2561_init(lua_State* L) {
...
@@ -33,23 +35,44 @@ static int ICACHE_FLASH_ATTR tsl2561_init(lua_State* L) {
lua_pushnumber
(
L
,
error
);
lua_pushnumber
(
L
,
error
);
return
1
;
return
1
;
}
}
/*
* Lua: error = tsl2561.settiming(integration, gain)
*/
static
int
ICACHE_FLASH_ATTR
tsl2561_lua_settiming
(
lua_State
*
L
)
{
static
int
ICACHE_FLASH_ATTR
tsl2561_lua_settiming
(
lua_State
*
L
)
{
// check variables
// check variables
if
(
!
lua_isnumber
(
L
,
1
)
||
!
lua_isnumber
(
L
,
2
))
{
if
(
!
lua_isnumber
(
L
,
1
)
||
!
lua_isnumber
(
L
,
2
))
{
return
luaL_error
(
L
,
"wrong arg range"
);
return
luaL_error
(
L
,
"wrong arg range"
);
}
}
uint8_t
integration
=
luaL_checkinteger
(
L
,
1
);
uint8_t
integration
=
luaL_checkinteger
(
L
,
1
);
if
(
!
((
integration
==
TSL2561_INTEGRATIONTIME_13MS
)
||
(
integration
==
TSL2561_INTEGRATIONTIME_101MS
)
||
(
integration
==
TSL2561_INTEGRATIONTIME_402MS
))){
return
luaL_error
(
L
,
"wrong range for arg integration"
);
}
uint8_t
gain
=
luaL_checkinteger
(
L
,
2
);
uint8_t
gain
=
luaL_checkinteger
(
L
,
2
);
if
(
!
((
gain
==
TSL2561_GAIN_16X
)
||
(
gain
==
TSL2561_GAIN_1X
))){
return
luaL_error
(
L
,
"wrong range for arg gain"
);
}
lua_pushnumber
(
L
,
tsl2561SetTiming
(
integration
,
gain
)
);
lua_pushnumber
(
L
,
tsl2561SetTiming
(
integration
,
gain
)
);
return
1
;
return
1
;
}
}
/*
* Lua: lux, error = tsl2561.getlux()
*/
static
int
ICACHE_FLASH_ATTR
tsl2561_lua_calclux
(
lua_State
*
L
)
{
static
int
ICACHE_FLASH_ATTR
tsl2561_lua_calclux
(
lua_State
*
L
)
{
lua_pushnumber
(
L
,
tsl2561CalculateLux
(
ch0
,
ch1
)
);
uint8_t
error
=
tsl2561GetLuminosity
(
&
ch0
,
&
ch1
);
return
1
;
if
(
error
){
lua_pushnumber
(
L
,
0
);
lua_pushnumber
(
L
,
error
);
}
else
{
lua_pushnumber
(
L
,
tsl2561CalculateLux
(
ch0
,
ch1
));
lua_pushnumber
(
L
,
error
);
}
return
2
;
}
}
/*
* Lua: tsl2561.getrawchannels()
*/
static
int
ICACHE_FLASH_ATTR
tsl2561_lua_getchannels
(
lua_State
*
L
)
{
static
int
ICACHE_FLASH_ATTR
tsl2561_lua_getchannels
(
lua_State
*
L
)
{
uint8_t
error
=
tsl2561GetLuminosity
(
&
ch0
,
&
ch1
);
uint8_t
error
=
tsl2561GetLuminosity
(
&
ch0
,
&
ch1
);
lua_pushnumber
(
L
,
ch0
);
lua_pushnumber
(
L
,
ch0
);
...
@@ -64,8 +87,8 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) {
...
@@ -64,8 +87,8 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) {
const
LUA_REG_TYPE
tsl2561_map
[]
=
const
LUA_REG_TYPE
tsl2561_map
[]
=
{
{
{
LSTRKEY
(
"settiming"
),
LFUNCVAL
(
tsl2561_lua_settiming
)},
{
LSTRKEY
(
"settiming"
),
LFUNCVAL
(
tsl2561_lua_settiming
)},
{
LSTRKEY
(
"
calc
lux"
),
LFUNCVAL
(
tsl2561_lua_calclux
)},
{
LSTRKEY
(
"
get
lux"
),
LFUNCVAL
(
tsl2561_lua_calclux
)},
{
LSTRKEY
(
"channels
_raw
"
),
LFUNCVAL
(
tsl2561_lua_getchannels
)},
{
LSTRKEY
(
"
getraw
channels"
),
LFUNCVAL
(
tsl2561_lua_getchannels
)},
{
LSTRKEY
(
"init"
),
LFUNCVAL
(
tsl2561_init
)},
{
LSTRKEY
(
"init"
),
LFUNCVAL
(
tsl2561_init
)},
{
LSTRKEY
(
"TSL2561_OK"
),
LNUMVAL
(
TSL2561_ERROR_OK
)
},
{
LSTRKEY
(
"TSL2561_OK"
),
LNUMVAL
(
TSL2561_ERROR_OK
)
},
...
@@ -74,11 +97,11 @@ const LUA_REG_TYPE tsl2561_map[] =
...
@@ -74,11 +97,11 @@ const LUA_REG_TYPE tsl2561_map[] =
{
LSTRKEY
(
"TSL2561_ERROR_NOINIT"
),
LNUMVAL
(
TSL2561_ERROR_NOINIT
)
},
{
LSTRKEY
(
"TSL2561_ERROR_NOINIT"
),
LNUMVAL
(
TSL2561_ERROR_NOINIT
)
},
{
LSTRKEY
(
"TSL2561_ERROR_LAST"
),
LNUMVAL
(
TSL2561_ERROR_LAST
)
},
{
LSTRKEY
(
"TSL2561_ERROR_LAST"
),
LNUMVAL
(
TSL2561_ERROR_LAST
)
},
{
LSTRKEY
(
"
TSL2561_
INTEGRATIONTIME_13MS"
),
LNUMVAL
(
TSL2561_INTEGRATIONTIME_13MS
)
},
{
LSTRKEY
(
"INTEGRATIONTIME_13MS"
),
LNUMVAL
(
TSL2561_INTEGRATIONTIME_13MS
)
},
{
LSTRKEY
(
"
TSL2561_
INTEGRATIONTIME_101MS"
),
LNUMVAL
(
TSL2561_INTEGRATIONTIME_101MS
)
},
{
LSTRKEY
(
"INTEGRATIONTIME_101MS"
),
LNUMVAL
(
TSL2561_INTEGRATIONTIME_101MS
)
},
{
LSTRKEY
(
"
TSL2561_
INTEGRATIONTIME_402MS"
),
LNUMVAL
(
TSL2561_INTEGRATIONTIME_402MS
)
},
{
LSTRKEY
(
"INTEGRATIONTIME_402MS"
),
LNUMVAL
(
TSL2561_INTEGRATIONTIME_402MS
)
},
{
LSTRKEY
(
"
TSL2561_
GAIN_
0
X"
),
LNUMVAL
(
TSL2561_GAIN_
0
X
)
},
{
LSTRKEY
(
"GAIN_
1
X"
),
LNUMVAL
(
TSL2561_GAIN_
1
X
)
},
{
LSTRKEY
(
"
TSL2561_
GAIN_16X"
),
LNUMVAL
(
TSL2561_GAIN_16X
)
},
{
LSTRKEY
(
"GAIN_16X"
),
LNUMVAL
(
TSL2561_GAIN_16X
)
},
{
LNILKEY
,
LNILVAL
}
{
LNILKEY
,
LNILVAL
}
};
};
...
...
app/tsl2561/tsl2561.c
View file @
0caf745d
...
@@ -71,7 +71,7 @@
...
@@ -71,7 +71,7 @@
static
const
uint32_t
tsl2561_i2c_id
=
0
;
static
const
uint32_t
tsl2561_i2c_id
=
0
;
static
bool
_tsl2561Initialised
=
0
;
static
bool
_tsl2561Initialised
=
0
;
static
tsl2561IntegrationTime_t
_tsl2561IntegrationTime
=
TSL2561_INTEGRATIONTIME_402MS
;
static
tsl2561IntegrationTime_t
_tsl2561IntegrationTime
=
TSL2561_INTEGRATIONTIME_402MS
;
static
tsl2561Gain_t
_tsl2561Gain
=
TSL2561_GAIN_
0
X
;
static
tsl2561Gain_t
_tsl2561Gain
=
TSL2561_GAIN_
1
X
;
/**************************************************************************/
/**************************************************************************/
...
...
app/tsl2561/tsl2561.h
View file @
0caf745d
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
Software License Agreement (BSD License)
Software License Agreement (BSD License)
Copyright (c) 2010, microBuilder SARL
/ Adapted for nodeMCU by Michael Lucas (Aeprox @github)
Copyright (c) 2010, microBuilder SARL
All rights reserved.
All rights reserved.
Redistribution and use in source and binary forms, with or without
Redistribution and use in source and binary forms, with or without
...
@@ -137,7 +137,7 @@ tsl2561IntegrationTime_t;
...
@@ -137,7 +137,7 @@ tsl2561IntegrationTime_t;
typedef
enum
typedef
enum
{
{
TSL2561_GAIN_
0
X
=
0x00
,
// No gain
TSL2561_GAIN_
1
X
=
0x00
,
// No gain
TSL2561_GAIN_16X
=
0x10
,
// 16x gain
TSL2561_GAIN_16X
=
0x10
,
// 16x gain
}
}
tsl2561Gain_t
;
tsl2561Gain_t
;
...
...
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