@@ -59,7 +59,7 @@ bool SCD4x::begin(TwoWire &wirePort, bool measBegin, bool autoCalibrate, bool sk
59
59
if (pollAndSetDeviceType == true )
60
60
{
61
61
scd4x_sensor_type_e sensorType;
62
- success &= determineSensorType (&sensorType, serialNumber );
62
+ success &= getFeatureSetVersion (&sensorType);
63
63
64
64
setSensorType (sensorType);
65
65
@@ -870,27 +870,6 @@ char SCD4x::convertHexToASCII(uint8_t digit)
870
870
return (char (digit + 0x41 - 10 )); // Use upper case for A-F
871
871
}
872
872
873
- void SCD4x::convertASCIIToHex (const char *hexstr, uint16_t *integers)
874
- {
875
- for (int i = 0 ; i < 3 ; i++ ) {
876
- uint16_t val = 0 ;
877
- for (int j = 0 ; j < 4 ; j++ ) {
878
- char c = hexstr[i * 4 + j];
879
- val <<= 4 ;
880
- if (c >= ' 0' && c <= ' 9' ) {
881
- val += c - ' 0' ;
882
- }
883
- else if (c >= ' A' && c <= ' F' ) {
884
- val += c - ' A' + 10 ;
885
- }
886
- else if (c >= ' a' && c <= ' f' ) {
887
- val += c - ' a' + 10 ;
888
- }
889
- }
890
- integers[i] = val;
891
- }
892
- }
893
-
894
873
// Perform self test. Takes 10 seconds to complete. See 3.9.3
895
874
// The perform_self_test feature can be used as an end-of-line test to check sensor functionality
896
875
// and the customer power supply to the sensor.
@@ -1061,59 +1040,7 @@ bool SCD4x::measureSingleShotRHTOnly(void)
1061
1040
return (success);
1062
1041
}
1063
1042
1064
- // Determine Sensor type from the serial number
1065
- bool SCD4x::determineSensorType (scd4x_sensor_type_e *sensorType, char *serialNumber)
1066
- {
1067
- bool success = true ;
1068
-
1069
- if (strlen (serialNumber) != 12 )
1070
- {
1071
- #if SCD4x_ENABLE_DEBUGLOG
1072
- if (_printDebug == true )
1073
- {
1074
- _debugPort->println (F (" SCD40::getSensorType: S/N is not 13 bytes." ));
1075
- _debugPort->print (F (" SCD40::getSensorType: Num Bytes: " ));
1076
- _debugPort->println (strlen (serialNumber));
1077
- }
1078
- #endif // if SCD4x_ENABLE_DEBUGLOG
1079
- success = false ;
1080
- return (success);
1081
- }
1082
-
1083
- uint16_t serNumInt[3 ];
1084
- convertASCIIToHex (serialNumber, serNumInt);
1085
-
1086
- #if SCD4x_ENABLE_DEBUGLOG
1087
- if (_printDebug == true )
1088
- {
1089
- _debugPort->print (" SCD40::getSensorType: Word 1: " );
1090
- _debugPort->println (serNumInt[0 ], HEX);
1091
- _debugPort->print (" SCD40::getSensorType: Word 2: " );
1092
- _debugPort->println (serNumInt[1 ], HEX);
1093
- _debugPort->print (" SCD40::getSensorType: Word 3: " );
1094
- _debugPort->println (serNumInt[2 ], HEX);
1095
- }
1096
- #endif // if SCD4x_ENABLE_DEBUGLOG
1097
-
1098
- *sensorType = extractMaskedSensorType (serNumInt);
1099
-
1100
- if (*sensorType == SCD4x_SENSOR_INVALID)
1101
- {
1102
- #if SCD4x_ENABLE_DEBUGLOG
1103
- if (_printDebug == true )
1104
- {
1105
- _debugPort->println (" SCD40::getSensorType: Invalid Sensor Type Determined." );
1106
- }
1107
- #endif // if SCD4x_ENABLE_DEBUGLOG
1108
- *sensorType = SCD4x_SENSOR_SCD40; // Pick a default so we don't break things.
1109
- success = false ;
1110
- return (success);
1111
- }
1112
-
1113
- return (success);
1114
- }
1115
-
1116
- scd4x_sensor_type_e SCD4x::getSensorType ()
1043
+ scd4x_sensor_type_e SCD4x::getSensorType (void )
1117
1044
{
1118
1045
return _sensorType;
1119
1046
}
@@ -1123,71 +1050,80 @@ void SCD4x::setSensorType(scd4x_sensor_type_e sensorType)
1123
1050
_sensorType = sensorType;
1124
1051
}
1125
1052
1126
- // Extract the Sensor type (SCD40 vs SCD41) from the Serial Number of the connected device.
1127
- scd4x_sensor_type_e SCD4x::extractMaskedSensorType (uint16_t *serialNumberArray)
1053
+ bool SCD4x::getFeatureSetVersion (scd4x_sensor_type_e* sensorType)
1128
1054
{
1129
- // Of the 48-bit serial number, the Type is identified by bits 24-37
1130
- // 0bxxxx'xxxx'xx11'1111'1111'1111'xxxx'xxxx'xxxx'xxxx'xxxx'xxxx
1131
- uint16_t masks[] = {0x003F , 0xFF00 };
1132
-
1133
- uint16_t maskedValues[2 ];
1134
- uint16_t combinedValue = 0 ;
1135
-
1136
- for (int i = 0 ; i < 2 ; i++) {
1137
- maskedValues[i] = serialNumberArray[i] & masks[i];
1055
+ if (periodicMeasurementsAreRunning)
1056
+ {
1138
1057
#if SCD4x_ENABLE_DEBUGLOG
1139
- if (_printDebug == true ) {
1140
- _debugPort->print (" SCD40::extractMaskedSensorType: i: " );
1141
- _debugPort->println (i);
1142
- _debugPort->print (" SCD40::extractMaskedSensorType: serialNumberArray[i]: " );
1143
- _debugPort->println (serialNumberArray[i], HEX);
1144
- _debugPort->print (" SCD40::extractMaskedSensorType: masks[i]: " );
1145
- _debugPort->println (masks[i], HEX);
1146
- _debugPort->print (" SCD40::extractMaskedSensorType: maskedValues[i]: " );
1147
- _debugPort->println (maskedValues[i], HEX);
1058
+ if (_printDebug == true )
1059
+ {
1060
+ _debugPort->println (F (" SCD4x::getFeatureSetVersion: periodic measurements are running. Aborting..." ));
1148
1061
}
1149
- #endif // if SCD4x_ENABLE_DEBUGLOG
1062
+ #endif // SCD4x_ENABLE_DEBUGLOG
1063
+ return (false );
1150
1064
}
1151
1065
1152
- combinedValue = (maskedValues[0 ] << 8 ) | (maskedValues[1 ] >> 8 );
1066
+ uint16_t featureSet;
1067
+
1068
+ bool success = readRegister (SCD4x_COMMAND_GET_FEATURE_SET_VERSION, &featureSet, 1 );
1153
1069
1154
1070
#if SCD4x_ENABLE_DEBUGLOG
1155
- if (_printDebug == true )
1071
+ if (_printDebug == true )
1156
1072
{
1157
- _debugPort->print (" SCD40::extractMaskedSensorType: Combined Value: " );
1158
- _debugPort->println (combinedValue , HEX);
1073
+ _debugPort->print (F ( " SCD4x::getFeatureSetVersion: Read value: 0x " ) );
1074
+ _debugPort->println (featureSet , HEX);
1159
1075
}
1160
- #endif // if SCD4x_ENABLE_DEBUGLOG
1076
+ #endif // SCD4x_ENABLE_DEBUGLOG
1077
+
1078
+ uint8_t typeOfSensor = ((featureSet & 0x1000 ) >> 12 );
1079
+
1080
+ #if SCD4x_ENABLE_DEBUGLOG
1081
+ if (_printDebug == true )
1082
+ {
1083
+ _debugPort->print (F (" SCD4x::getFeatureSetVersion: Type read: 0x" ));
1084
+ _debugPort->println (typeOfSensor, HEX);
1085
+ }
1086
+ #endif // SCD4x_ENABLE_DEBUGLOG
1161
1087
1162
- if (combinedValue == 0x376F )
1088
+ if (typeOfSensor == 0 )
1163
1089
{
1164
1090
#if SCD4x_ENABLE_DEBUGLOG
1165
1091
if (_printDebug == true )
1166
1092
{
1167
- _debugPort->println (" SCD40::extractMaskedSensorType : Picked SCD41 " );
1093
+ _debugPort->println (F ( " SCD4x::getFeatureSetVersion : Picked SCD40 " ) );
1168
1094
}
1169
1095
#endif // if SCD4x_ENABLE_DEBUGLOG
1170
- return SCD4x_SENSOR_SCD41 ;
1096
+ *sensorType = SCD4x_SENSOR_SCD40 ;
1171
1097
}
1172
- else if (combinedValue == 0x2397 )
1098
+ else if (typeOfSensor == 1 )
1173
1099
{
1174
1100
#if SCD4x_ENABLE_DEBUGLOG
1175
1101
if (_printDebug == true )
1176
1102
{
1177
- _debugPort->println (" SCD40::extractMaskedSensorType : Picked SCD40 " );
1103
+ _debugPort->println (F ( " SCD4x::getFeatureSetVersion : Picked SCD41 " ) );
1178
1104
}
1179
1105
#endif // if SCD4x_ENABLE_DEBUGLOG
1180
- return SCD4x_SENSOR_SCD40 ;
1106
+ *sensorType = SCD4x_SENSOR_SCD41 ;
1181
1107
}
1182
1108
else
1183
1109
{
1184
1110
#if SCD4x_ENABLE_DEBUGLOG
1185
1111
if (_printDebug == true ) {
1186
- _debugPort->println (" SCD40::extractMaskedSensorType: Something's seriously wrong here..." );
1112
+ if (typeOfSensor == 2 )
1113
+ {
1114
+ _debugPort->println (F (" SCD4x::getFeatureSetVersion: SCD42 is not supported by this library." ));
1115
+ }
1116
+ else
1117
+ {
1118
+ _debugPort->println (F (" SCD4x::getFeatureSetVersion: Unknown device type." ));
1119
+ }
1187
1120
}
1188
1121
#endif // if SCD4x_ENABLE_DEBUGLOG
1189
- return SCD4x_SENSOR_INVALID;
1122
+ *sensorType = SCD4x_SENSOR_INVALID;
1123
+ success = false ;
1190
1124
}
1125
+
1126
+ return (success);
1191
1127
}
1192
1128
1193
1129
// Sends a command along with arguments and CRC
0 commit comments