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
7df610a6
Commit
7df610a6
authored
Jan 30, 2015
by
Martin Han
Browse files
Merge pull request #1 from vowstar/master
Followed Vladimir Dronnikov's advices.
parents
ad1ec8fb
f45e6fec
Changes
1
Hide whitespace changes
Inline
Side-by-side
lua_modules/bh1750/bh1750.lua
View file @
7df610a6
...
@@ -7,48 +7,51 @@
...
@@ -7,48 +7,51 @@
-- MIT license, http://opensource.org/licenses/MIT
-- MIT license, http://opensource.org/licenses/MIT
-- ***************************************************************************
-- ***************************************************************************
local
moduleName
=
...
local
moduleName
=
...
local
M
=
{}
local
M
=
{}
_G
[
moduleName
]
=
M
_G
[
moduleName
]
=
M
--I2C slave address of GY-30
--I2C slave address of GY-30
local
GY_30_address
=
0X23
local
GY_30_address
=
0x23
-- i2c interface ID
-- i2c interface ID
local
id
=
0
local
id
=
0
--LUX
--LUX
local
l
local
l
--CMD
--CMD
local
CMD
=
0x10
local
CMD
=
0x10
local
init
=
false
local
init
=
false
function
M
.
init
(
sda
,
scl
)
--Make it more faster
i2c
.
setup
(
id
,
sda
,
scl
,
i2c
.
SLOW
)
local
i2c
=
i2c
--print("i2c ok..")
function
M
.
init
(
sda
,
scl
)
init
=
true
i2c
.
setup
(
id
,
sda
,
scl
,
i2c
.
SLOW
)
end
--print("i2c ok..")
local
function
read_data
(
ADDR
,
commands
,
length
)
init
=
true
i2c
.
start
(
id
)
end
i2c
.
address
(
id
,
ADDR
,
i2c
.
TRANSMITTER
)
local
function
read_data
(
ADDR
,
commands
,
length
)
i2c
.
write
(
id
,
commands
)
i2c
.
start
(
id
)
i2c
.
stop
(
id
)
i2c
.
address
(
id
,
ADDR
,
i2c
.
TRANSMITTER
)
i2c
.
start
(
id
)
i2c
.
write
(
id
,
commands
)
i2c
.
address
(
id
,
ADDR
,
i2c
.
RECEIVER
)
i2c
.
stop
(
id
)
tmr
.
delay
(
200000
)
i2c
.
start
(
id
)
c
=
i2c
.
read
(
id
,
length
)
i2c
.
address
(
id
,
ADDR
,
i2c
.
RECEIVER
)
i2c
.
stop
(
id
)
tmr
.
delay
(
200000
)
return
c
c
=
i2c
.
read
(
id
,
length
)
end
i2c
.
stop
(
id
)
local
function
read_lux
()
return
c
dataT
=
read_data
(
GY_30_address
,
CMD
,
2
)
end
UT
=
string.byte
(
dataT
,
1
)
*
256
+
string.byte
(
dataT
,
2
)
local
function
read_lux
()
l
=
(
UT
*
1000
/
12
)
dataT
=
read_data
(
GY_30_address
,
CMD
,
2
)
return
(
l
)
--Make it more faster
end
UT
=
dataT
:
byte
(
1
)
*
256
+
dataT
:
byte
(
2
)
function
M
.
read
()
l
=
(
UT
*
1000
/
12
)
if
(
not
init
)
then
return
(
l
)
print
(
"init() must be called before read."
)
end
else
function
M
.
read
()
read_lux
()
if
(
not
init
)
then
end
print
(
"init() must be called before read."
)
end
else
function
M
.
getlux
()
read_lux
()
return
l
end
end
end
return
M
function
M
.
getlux
()
return
l
end
return
M
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