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
57903585
Commit
57903585
authored
3 years ago
by
thiebolt
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
9a5891e1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
neosensor/libraries/neocampus_drivers/SCD4x.cpp
+24
-26
24 additions, 26 deletions
neosensor/libraries/neocampus_drivers/SCD4x.cpp
neosensor/libraries/neocampus_drivers/SCD4x.h
+32
-66
32 additions, 66 deletions
neosensor/libraries/neocampus_drivers/SCD4x.h
with
56 additions
and
92 deletions
neosensor/libraries/neocampus_drivers/SCD4x.cpp
+
24
−
26
View file @
57903585
...
...
@@ -42,22 +42,18 @@
const
uint8_t
SCD4x
::
i2c_addrs
[]
=
{
0x69
};
#if 0
TO BE CONTINUED
/**************************************************************************/
/*!
@brief Test if device at 'adr' is really what we think of
*/
/**************************************************************************/
boolean S
HT3
x::is_device( uint8_t a ) {
boolean
S
CD4
x
::
is_device
(
uint8_t
a
)
{
// First step, parse all addresses
boolean
found
=
false
;
for( uint8_t i=0; i < sizeof(S
HT3
x::i2c_addrs); i++ ) {
if( S
HT3
x::i2c_addrs[i] == a) {
for
(
uint8_t
i
=
0
;
i
<
sizeof
(
S
CD4
x
::
i2c_addrs
);
i
++
)
{
if
(
S
CD4
x
::
i2c_addrs
[
i
]
==
a
)
{
found
=
true
;
break
;
}
...
...
@@ -77,21 +73,22 @@ boolean SHT3x::is_device( uint8_t a ) {
@brief Instantiates a new class
*/
/**************************************************************************/
S
HT3
x::S
HT3
x( s
ht3
xMeasureType_t kindness ) : generic_driver() {
S
CD4
x
::
S
CD4
x
(
s
cd4
xMeasureType_t
kindness
)
:
generic_driver
()
{
_i2caddr
=
-
1
;
_measureType
=
kindness
;
_resolution = SHT3X_DEFL_RESOLUTION;
}
/* declare kind of units */
const char *SHT3x::_t_units = "celsius";
const char *SHT3x::_rh_units = "%r.H.";
const
char
*
SCD4x
::
units_co2
=
"ppm"
;
const
char
*
SCD4x
::
units_temp
=
"celsius"
;
const
char
*
SCD4x
::
units_rh
=
"%r.H."
;
/* declare others static vars */
unsigned long SHT3x::_lastMsRead = 0;
uint16_t SHT3x::_t_sensor = (uint16_t)(-1);
uint16_t SHT3x::_rh_sensor = (uint16_t)(-1);
unsigned
long
SCD4x
::
_lastMsRead
=
0
;
uint16_t
SCD4x
::
_co2_sensor
=
(
uint16_t
)(
-
1
);
uint16_t
SCD4x
::
_t_sensor
=
(
uint16_t
)(
-
1
);
uint16_t
SCD4x
::
_rh_sensor
=
(
uint16_t
)(
-
1
);
/**************************************************************************/
...
...
@@ -99,17 +96,20 @@ uint16_t SHT3x::_rh_sensor = (uint16_t)(-1);
@brief send back units
*/
/**************************************************************************/
const char * S
HT3
x::sensorUnits( uint8_t idx ) {
const
char
*
S
CD4
x
::
sensorUnits
(
uint8_t
idx
)
{
switch
(
_measureType
)
{
case s
ht3
xMeasureType_t::
temperature
:
return
_t_
units;
case
s
cd4
xMeasureType_t
::
co2
:
return
units
_co2
;
break
;
case sht3xMeasureType_t::humidity:
return _rh_units;
case
scd4xMeasureType_t
::
temperature
:
return
units_temp
;
break
;
case
scd4xMeasureType_t
::
humidity
:
return
units_rh
;
break
;
default:
log_error(F("\n[S
HT3
x] unknown kind of measureType ?!?")); log_flush();
log_error
(
F
(
"
\n
[S
CD4
x] unknown kind of measureType ?!?"
));
log_flush
();
return
nullptr
;
}
}
...
...
@@ -120,7 +120,7 @@ const char * SHT3x::sensorUnits( uint8_t idx ) {
@brief Setups the HW
*/
/**************************************************************************/
boolean S
HT3
x::begin( uint8_t addr=-1) {
boolean
S
CD4
x
::
begin
(
uint8_t
addr
=-
1
)
{
// get i2caddr
if
(
(
addr
<
(
uint8_t
)(
I2C_ADDR_START
))
or
(
addr
>
(
uint8_t
)(
I2C_ADDR_STOP
))
)
return
false
;
_i2caddr
=
addr
;
...
...
@@ -134,7 +134,6 @@ boolean SHT3x::begin( uint8_t addr=-1) {
*/
// define defaults parameters
setResolution( _resolution );
/* start lastmsg time measurement.
* This way, we get sure to have at least a first acquisition! */
...
...
@@ -147,16 +146,17 @@ boolean SHT3x::begin( uint8_t addr=-1) {
/*
* Power modes: ON or powerOFF
*/
void S
HT3
x::powerOFF( void )
void
S
CD4
x
::
powerOFF
(
void
)
{
// device does not feature continuous integration so nothing to start or stop
}
void S
HT3
x::powerON( void )
void
S
CD4
x
::
powerON
(
void
)
{
// device does not feature continuous integration so nothing to start or stop
}
TO
BE
CONTINUED
/**************************************************************************/
/*!
...
...
@@ -505,5 +505,3 @@ bool SHT3x::_check_identity( uint8_t a ) {
return
true
;
}
#endif
/* 0 */
This diff is collapsed.
Click to expand it.
neosensor/libraries/neocampus_drivers/SCD4x.h
+
32
−
66
View file @
57903585
...
...
@@ -50,7 +50,7 @@
* - CO2, temp and humidity are measured and sent in a single 9bytes frame
* 16bits C02 + CRC + 16bits T + CRC + 16bits RH + CRC
* - every 16bits frames are CRC protected
* - CRC8 0x31, initial=0xFF for 16bits data (first is )
* - CRC8 0x31, initial=0xFF
, final xor=0x00
for 16bits data (first is )
*/
enum
class
sht3xCmd_t
:
uint16_t
{
...
...
@@ -74,73 +74,37 @@ enum class sht3xCmd_t : uint16_t {
// low-power operations
start_low_power_periodoc_measurement
=
0x21ac
,
// 30s measurement delay
get_data_ready_status
=
0xe4b8
,
// execution time: 1ms
TO
BE
CONTINUED
//Advanced features
#define SCD4x_COMMAND_PERSIST_SETTINGS 0x3615 // execution time: 800ms
#define SCD4x_COMMAND_GET_SERIAL_NUMBER 0x3682 // execution time: 1ms
#define SCD4x_COMMAND_PERFORM_SELF_TEST 0x3639 // execution time: 10000ms
#define SCD4x_COMMAND_PERFORM_FACTORY_RESET 0x3632 // execution time: 1200ms
#define SCD4x_COMMAND_REINIT 0x3646 // execution time: 20ms
//Low power single shot - SCD41 only
#define SCD4x_COMMAND_MEASURE_SINGLE_SHOT 0x219d // execution time: 5000ms
#define SCD4x_COMMAND_MEASURE_SINGLE_SHOT_RHT_ONLY 0x2196 // execution time: 50ms
soft_reset
=
0X30A2
,
// software reset
heater_enable
=
0x306D
,
// on-chip heater enable
heater_disable
=
0x3066
,
// on-chip heater disable
get_status
=
0xF32D
,
// read Status Register
clear_status
=
0x3041
,
// clear Status Register
meas_highRes_stretch
=
0x2C06
,
// Measurement High Repeatability (resolution) with Clock Stretch Enabled
meas_medRes_stretch
=
0x2C0D
,
// Measurement Medium Repeatability (resolution) with Clock Stretch Enabled
meas_lowRes_stretch
=
0x2C10
,
// Measurement Low Repeatability (resolution) with Clock Stretch Enabled
meas_highRes
=
0x2400
,
// Measurement High Repeatability (resolution) WITHOUT clock stretching
meas_medRes
=
0x240B
,
// Measurement Medium Repeatability (resolution) WITHOUT clock stretching
meas_lowRes
=
0x2416
,
// Measurement Low Repeatability (resolution) WITHOUT clock stretching
// stop_periodic_measurement to stop low_power periodic measurement
// advanced features
persist_settings
=
0x3615
,
// execution time: 800ms
get_serial_number
=
0x3682
,
// execution time: 1ms
perform_self_test
=
0x3639
,
// execution time: 10000ms
perform_factory_reset
=
0x3632
,
// execution time: 1200ms
reinit
=
0x3646
,
// execution time: 20ms
// low-power single shot - SCD41 only
measure_single_shot
=
0x219d
,
// execution time: 5000ms
measure_single_shot_rht_only
=
0x2196
,
// execution time: 50ms
};
// status
#define SHT3X_STATUS_REG_MASK 0xFC1F // removed bit 9:5 because of their unspecified value
#define SHT3X_STATUS_REG_DEFL 0x8010 // expected default value (apply MASK for value checking)
// type of measure
enum
class
sht3xMeasureType_t
:
uint8_t
{
enum
class
scd4xMeasureType_t
:
uint8_t
{
co2
=
0x00
,
humidity
=
0x10
,
temperature
=
0x20
};
// resolution
enum
class
sht3xResolution_t
:
uint8_t
{
high_res
,
medium_res
,
low_res
};
#define SHT3X_DEFL_RESOLUTION sht3xResolution_t::high_res
// integration time (ms)
enum
class
sht3xIntegration_t
:
uint8_t
{
ms_integrate_high
=
16
,
// integraion time (ms) for high resolution measure
ms_integrate_medium
=
7
,
// integraion time (ms) for medium resolution measure
ms_integrate_low
=
5
// integraion time (ms) for low resolution measure
};
#define SHT3X_INTEGRATION_TIME_CTE 5 // additionnal ms delay to all timings (total <= 255 ---uint8_t)
/*
* Class
*/
class
S
HT3
x
:
public
generic_driver
{
class
S
CD4
x
:
public
generic_driver
{
public:
S
HT3
x
(
s
ht3
xMeasureType_t
);
S
CD4
x
(
s
cd4
xMeasureType_t
);
boolean
begin
(
uint8_t
);
// start with an i2c address
bool
setResolution
(
sht3xResolution_t
);
boolean
begin
(
uint8_t
);
// start with an i2c address
void
powerON
(
void
);
// switch ON
void
powerOFF
(
void
);
// switch OFF
...
...
@@ -150,17 +114,18 @@ class SHT3x : public generic_driver {
String
subID
(
uint8_t
=
0
)
{
return
String
(
_i2caddr
);
};
// read sensor's values
boolean
getCO2
(
float
*
);
// retroieve co2
boolean
getRH
(
float
*
);
// retrieve humidity
boolean
getTemp
(
float
*
);
// retrieve temperature
// --- static methods / constants -----------------------
// list of possibles I2C addrs
static
const
uint8_t
i2c_addrs
[];
// device detection
static
boolean
is_device
(
uint8_t
);
private
:
// -- private methods
bool
_readSensor
(
uint16_t
*
);
// low-level function to read value registers
...
...
@@ -171,22 +136,23 @@ class SHT3x : public generic_driver {
// --- private attributes
uint8_t
_i2caddr
;
s
ht3xResolution_t
_resolution
;
s
ht3xMeasureType_t
_measureType
;
static
const
char
*
_t_
units
;
static
const
char
*
_rh_
units
;
uint
8
_t
_integrationTime
;
// ms time to integrate a measure
(for non continuous mode)
/*
both
TEMP and RH are read at the same time ==> hence we store them
s
cd4xMeasureType_t
_measureType
;
s
tatic
const
char
*
units_co2
;
static
const
char
*
units
_temp
;
static
const
char
*
units
_rh
;
uint
16
_t
_integrationTime
;
// ms time to integrate a measure
/*
CO2,
TEMP and RH are read at the same time ==> hence we store them
as shared attributes across all instances */
static
unsigned
long
_lastMsRead
;
// last time data have been read (elapsed ms from beginning)
static
uint16_t
_t_sensor
;
// shared across all instances (for both humidity and temperature modules)
static
uint16_t
_rh_sensor
;
// shared across all instances (for both humidity and temperature modules)
static
uint16_t
_co2_sensor
;
// shared across all instances
static
uint16_t
_t_sensor
;
// shared across all instances
static
uint16_t
_rh_sensor
;
// shared across all instances
// CRC computation
static
const
uint8_t
_crc8_polynom
;
// crc P(x)=x^8+x^5+x^4+1 (0x31) 1.00110001, init=0xFF
#ifdef S
HT3
X_CRC_LOOKUP_TABLE
#ifdef S
CD4
X_CRC_LOOKUP_TABLE
static
const
uint8_t
_crc8_table
[
256
];
#endif
/* S
HT3
X_CRC_LOOKUP_TABLE */
#endif
/* S
CD4
X_CRC_LOOKUP_TABLE */
};
#endif
/* _SCD4X_H_ */
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