Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
483dbebe
Commit
483dbebe
authored
Aug 22, 2015
by
aeprox
Browse files
Return error when calling functions before init
TSL2561_ERROR_NOINIT
parent
335ea879
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/modules/tsl2561.c
View file @
483dbebe
...
...
@@ -71,6 +71,7 @@ const LUA_REG_TYPE tsl2561_map[] =
{
LSTRKEY
(
"TSL2561_OK"
),
LNUMVAL
(
TSL2561_ERROR_OK
)
},
{
LSTRKEY
(
"TSL2561_ERROR_I2CINIT"
),
LNUMVAL
(
TSL2561_ERROR_I2CINIT
)
},
{
LSTRKEY
(
"TSL2561_ERROR_I2CBUSY"
),
LNUMVAL
(
TSL2561_ERROR_I2CBUSY
)
},
{
LSTRKEY
(
"TSL2561_ERROR_NOINIT"
),
LNUMVAL
(
TSL2561_ERROR_NOINIT
)
},
{
LSTRKEY
(
"TSL2561_ERROR_LAST"
),
LNUMVAL
(
TSL2561_ERROR_LAST
)
},
{
LSTRKEY
(
"TSL2561_INTEGRATIONTIME_13MS"
),
LNUMVAL
(
TSL2561_INTEGRATIONTIME_13MS
)
},
...
...
app/tsl2561/tsl2561.c
View file @
483dbebe
...
...
@@ -65,6 +65,8 @@
*/
/**************************************************************************/
#include "tsl2561.h"
#include "platform.h"
#include "user_interface.h"
static
const
uint32_t
tsl2561_i2c_id
=
0
;
static
bool
_tsl2561Initialised
=
0
;
...
...
@@ -125,7 +127,7 @@ tsl2561Error_t tsl2561Read16(uint8_t reg, uint16_t *value)
/**************************************************************************/
tsl2561Error_t
tsl2561Enable
(
void
)
{
if
(
!
_tsl2561Initialised
)
tsl2561Init
()
;
if
(
!
_tsl2561Initialised
)
return
TSL2561_ERROR_NOINIT
;
// Enable the device by setting the control bit to 0x03
return
tsl2561Write8
(
TSL2561_COMMAND_BIT
|
TSL2561_REGISTER_CONTROL
,
TSL2561_CONTROL_POWERON
);
...
...
@@ -138,7 +140,7 @@ tsl2561Error_t tsl2561Enable(void)
/**************************************************************************/
tsl2561Error_t
tsl2561Disable
(
void
)
{
if
(
!
_tsl2561Initialised
)
tsl2561Init
()
;
if
(
!
_tsl2561Initialised
)
return
TSL2561_ERROR_NOINIT
;
// Turn the device off to save power
return
tsl2561Write8
(
TSL2561_COMMAND_BIT
|
TSL2561_REGISTER_CONTROL
,
TSL2561_CONTROL_POWEROFF
);
...
...
@@ -171,7 +173,7 @@ tsl2561Error_t tsl2561Init(uint8_t sda, uint8_t scl)
/**************************************************************************/
tsl2561Error_t
tsl2561SetTiming
(
tsl2561IntegrationTime_t
integration
,
tsl2561Gain_t
gain
)
{
if
(
!
_tsl2561Initialised
)
tsl2561Init
()
;
if
(
!
_tsl2561Initialised
)
return
TSL2561_ERROR_NOINIT
;
tsl2561Error_t
error
=
TSL2561_ERROR_OK
;
...
...
@@ -201,7 +203,7 @@ tsl2561Error_t tsl2561SetTiming(tsl2561IntegrationTime_t integration, tsl2561Gai
/**************************************************************************/
tsl2561Error_t
tsl2561GetLuminosity
(
uint16_t
*
broadband
,
uint16_t
*
ir
)
{
if
(
!
_tsl2561Initialised
)
tsl2561Init
()
;
if
(
!
_tsl2561Initialised
)
return
TSL2561_ERROR_NOINIT
;
tsl2561Error_t
error
=
TSL2561_ERROR_OK
;
...
...
app/tsl2561/tsl2561.h
View file @
483dbebe
...
...
@@ -33,6 +33,7 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************/
#include "c_types.h"
#ifndef _TSL2561_H_
#define _TSL2561_H_
...
...
@@ -146,6 +147,7 @@ typedef enum
TSL2561_ERROR_OK
=
0
,
// Everything executed normally
TSL2561_ERROR_I2CINIT
,
// Unable to initialise I2C
TSL2561_ERROR_I2CBUSY
,
// I2C already in use
TSL2561_ERROR_NOINIT
,
// call init first
TSL2561_ERROR_LAST
}
tsl2561Error_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