Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
neOCampus-arduino
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GIS-neOCampus
neOSensor
neOCampus-arduino
Commits
b68279bc
Commit
b68279bc
authored
3 years ago
by
thiebolt
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
bab6cd9f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
neosensor/libraries/neocampus_drivers/SCD4x.cpp
+31
-20
31 additions, 20 deletions
neosensor/libraries/neocampus_drivers/SCD4x.cpp
neosensor/libraries/neocampus_drivers/SCD4x.h
+1
-1
1 addition, 1 deletion
neosensor/libraries/neocampus_drivers/SCD4x.h
with
32 additions
and
21 deletions
neosensor/libraries/neocampus_drivers/SCD4x.cpp
+
31
−
20
View file @
b68279bc
...
...
@@ -265,23 +265,27 @@ boolean SHT3x::getTemp( float *pval )
/*
* Software reset through I2C command
*/
void
S
HT3
x
::
sw_reset
(
uint8_t
adr
)
{
log_debug
(
F
(
"
\n
[S
HT3
x] SOFT RESET action started ..."
));
log_flush
();
_writeCmd
(
adr
,
static_cast
<
uint16_t
>
(
s
ht3
xCmd_t
::
soft_rese
t
)
);
delay
(
5
0
);
void
S
CD4
x
::
sw_reset
(
uint8_t
adr
)
{
log_debug
(
F
(
"
\n
[S
CD4
x] SOFT RESET action started ..."
));
log_flush
();
_writeCmd
(
adr
,
static_cast
<
uint16_t
>
(
s
cd4
xCmd_t
::
reini
t
)
);
delay
(
2
0
);
}
/*
* Read 16bits sensor values
registers
and check CRCs
* Note: S
HT3
x sensors read
both
T and RH
with both
CRC
s
* Read 16bits sensor
s
values and check CRCs
* Note: S
CD4
x sensors read
CO2,
T and RH
, all feature
CRC
* hence we store static values with a timestamp to avoid
* multiple (useless) access for same things.
*/
bool
S
HT3
x
::
_readSensor
(
uint16_t
*
pval
)
{
bool
S
CD4
x
::
_readSensor
(
uint16_t
*
pval
)
{
// do we need to acquire fresh sensors values ?
if
(
(
millis
()
-
_lastMsRead
)
>=
(
unsigned
long
)(
SHT3X_SENSOR_CACHE_MS
)
)
{
if
(
(
millis
()
-
_lastMsRead
)
>=
(
unsigned
long
)(
SCD4X_SENSOR_CACHE_MS
)
)
{
TO
BE
CONTINUED
// select proper command
uint16_t
_cmd
;
...
...
@@ -364,11 +368,11 @@ bool SHT3x::_readSensor( uint16_t *pval ) {
/*
* CRC related attributes
*/
const
uint8_t
S
HT3
x
::
_crc8_polynom
=
0x31
;
const
uint8_t
S
CD4
x
::
_crc8_polynom
=
0x31
;
#ifdef S
HT3
X_CRC_LOOKUP_TABLE
#ifdef S
CD4
X_CRC_LOOKUP_TABLE
// CRC8 lookup table
const
uint8_t
S
HT3
x
::
_crc8_table
[
256
]
PROGMEM
=
{
const
uint8_t
S
CD4
x
::
_crc8_table
[
256
]
PROGMEM
=
{
0x00
,
0x31
,
0x62
,
0x53
,
0xC4
,
0xF5
,
0xA6
,
0x97
,
0xB9
,
0x88
,
0xDB
,
0xEA
,
0x7D
,
0x4C
,
0x1F
,
0x2E
,
0x43
,
0x72
,
0x21
,
0x10
,
0x87
,
0xB6
,
0xE5
,
0xD4
,
0xFA
,
0xCB
,
0x98
,
0xA9
,
0x3E
,
0x0F
,
0x5C
,
0x6D
,
0x86
,
0xB7
,
0xE4
,
0xD5
,
0x42
,
0x73
,
0x20
,
0x11
,
0x3F
,
0x0E
,
0x5D
,
0x6C
,
0xFB
,
0xCA
,
0x99
,
0xA8
,
...
...
@@ -388,7 +392,7 @@ const uint8_t SHT3x::_crc8_table[256] PROGMEM = {
};
// crc checksum verification
bool
S
HT3
x
::
crc_check
(
uint8_t
data
[],
uint8_t
nb_bytes
,
uint8_t
checksum
)
{
bool
S
CD4
x
::
crc_check
(
uint8_t
data
[],
uint8_t
nb_bytes
,
uint8_t
checksum
)
{
uint8_t
crc
=
0xff
;
while
(
nb_bytes
)
{
crc
=
pgm_read_byte_near
(
_crc8_table
+
(
*
data
^
crc
));
...
...
@@ -401,7 +405,7 @@ bool SHT3x::crc_check( uint8_t data[], uint8_t nb_bytes, uint8_t checksum ) {
}
#else
// crc checksum verification
bool
S
HT3
x
::
crc_check
(
uint8_t
data
[],
uint8_t
nb_bytes
,
uint8_t
checksum
)
{
bool
S
CD4
x
::
crc_check
(
uint8_t
data
[],
uint8_t
nb_bytes
,
uint8_t
checksum
)
{
uint8_t
crc
=
0xff
;
uint8_t
byteCtr
;
...
...
@@ -416,13 +420,13 @@ bool SHT3x::crc_check( uint8_t data[], uint8_t nb_bytes, uint8_t checksum ) {
if
(
crc
!=
checksum
)
return
false
;
else
return
true
;
}
#endif
/* S
HT3
X_CRC_LOOKUP_TABLE */
#endif
/* S
CD4
X_CRC_LOOKUP_TABLE */
/*
* Check that device identity is what we expect!
*/
void
S
HT3
x
::
_writeCmd
(
uint8_t
a
,
uint16_t
cmd
)
{
void
S
CD4
x
::
_writeCmd
(
uint8_t
a
,
uint16_t
cmd
)
{
write8
(
a
,
(
uint8_t
)(
cmd
>>
8
)
,
(
uint8_t
)(
cmd
&
0xFF
)
);
delay
(
1
);
// 1ms min between i2c transactions
}
...
...
@@ -431,37 +435,44 @@ void SHT3x::_writeCmd( uint8_t a, uint16_t cmd ) {
/*
* Check that device identity is what we expect!
*/
bool
S
HT3
x
::
_check_identity
(
uint8_t
a
)
{
bool
S
CD4
x
::
_check_identity
(
uint8_t
a
)
{
uint8_t
_retry
=
3
;
bool
status
=
false
;
while
(
not
status
and
_retry
--
)
{
// cmd for read out status register
_writeCmd
(
a
,
static_cast
<
uint16_t
>
(
s
ht3
xCmd_t
::
get_s
tatus
)
);
_writeCmd
(
a
,
static_cast
<
uint16_t
>
(
s
cd4
xCmd_t
::
get_s
erial_number
)
);
// read answer (MSB + LSB + CRC)
uint8_t
buf
[
3
];
uint8_t
buf
[
9
];
if
(
readList_ll
(
a
,
buf
,
sizeof
(
buf
))
<
sizeof
(
buf
)
)
{
log_error
(
F
(
"
\n
[S
HT3
x] not enough bytes read !"
));
log_flush
();
log_error
(
F
(
"
\n
[S
CD4
x] not enough bytes read !"
));
log_flush
();
delay
(
1
);
// min time between commands
sw_reset
(
a
);
continue
;
}
// DEBUG
hex_dump
(
buf
,
sizeof
(
buf
)
);
break
;
// check answer's CRC
if
(
not
crc_check
(
buf
,
2
,
buf
[
2
])
)
{
log_error
(
F
(
"
\n
[S
HT3
x] CRC check failed !"
));
log_flush
();
log_error
(
F
(
"
\n
[S
CD4
x] CRC check failed !"
));
log_flush
();
delay
(
1
);
// min time between commands
continue
;
}
// TODO: check subsequents word+CRC
/*
// finally does status match our expectations
uint16_t status_reg = buf[0] << 8;
status_reg |= buf[1];
if( (status_reg & SHT3X_STATUS_REG_MASK) != SHT3X_STATUS_REG_DEFL ) return false;
status = true;
*/
}
// check result
if
(
not
status
)
return
false
;
...
...
This diff is collapsed.
Click to expand it.
neosensor/libraries/neocampus_drivers/SCD4x.h
+
1
−
1
View file @
b68279bc
...
...
@@ -52,7 +52,7 @@
* - every 16bits frames are CRC protected
* - CRC8 0x31, initial=0xFF, final xor=0x00 for 16bits data (first is )
*/
enum
class
s
ht3
xCmd_t
:
uint16_t
{
enum
class
s
cd4
xCmd_t
:
uint16_t
{
// basic commands
start_periodic_measurement
=
0x21b1
,
// 5000ms measurement delay
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment