Separate temp scan results from runtime sensors
This commit is contained in:
@@ -15,6 +15,9 @@ DeviceAddress sensorAddresses[MAX_TEMP_SENSORS];
|
||||
String sensorAddressStrings[MAX_TEMP_SENSORS];
|
||||
int sensorCount = 0;
|
||||
|
||||
int tempScanResultIndexes[MAX_TEMP_SENSORS];
|
||||
int tempScanResultCount = 0;
|
||||
|
||||
float cToF(float c) {
|
||||
return (c * 9.0 / 5.0) + 32.0;
|
||||
}
|
||||
@@ -88,45 +91,48 @@ int scanTempSensors() {
|
||||
sensorCount = MAX_TEMP_SENSORS;
|
||||
}
|
||||
|
||||
tempScanResultCount = 0;
|
||||
|
||||
for (int i = 0; i < MAX_TEMP_SENSORS; i++) {
|
||||
sensorAddressStrings[i] = "";
|
||||
tempScanResultIndexes[i] = -1;
|
||||
}
|
||||
|
||||
int availableCount = 0;
|
||||
|
||||
for (int i = 0; i < sensorCount; i++) {
|
||||
DeviceAddress address;
|
||||
|
||||
if (!ds18b20.getAddress(address, i)) {
|
||||
if (!ds18b20.getAddress(sensorAddresses[i], i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String addressString = addressToString(address);
|
||||
String addressString = addressToString(sensorAddresses[i]);
|
||||
sensorAddressStrings[i] = addressString;
|
||||
|
||||
if (isTempAddressAssigned(addressString)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
memcpy(sensorAddresses[availableCount], address, 8);
|
||||
sensorAddressStrings[availableCount] = addressString;
|
||||
availableCount++;
|
||||
tempScanResultIndexes[tempScanResultCount] = i;
|
||||
tempScanResultCount++;
|
||||
}
|
||||
|
||||
sensorCount = availableCount;
|
||||
|
||||
return sensorCount;
|
||||
return tempScanResultCount;
|
||||
}
|
||||
|
||||
int getTempScanResultCount() {
|
||||
return sensorCount;
|
||||
return tempScanResultCount;
|
||||
}
|
||||
|
||||
String getTempScanResultAddress(int index) {
|
||||
if (index < 0 || index >= sensorCount) {
|
||||
if (index < 0 || index >= tempScanResultCount) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return sensorAddressStrings[index];
|
||||
int physicalIndex = tempScanResultIndexes[index];
|
||||
|
||||
if (physicalIndex < 0 || physicalIndex >= sensorCount) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return sensorAddressStrings[physicalIndex];
|
||||
}
|
||||
|
||||
void printSensorAddresses() {
|
||||
@@ -191,11 +197,17 @@ bool assignTempSensorByIndex(int configIndex, int scanIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (scanIndex < 0 || scanIndex >= sensorCount) {
|
||||
if (scanIndex < 0 || scanIndex >= tempScanResultCount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String selectedAddress = sensorAddressStrings[scanIndex];
|
||||
int physicalIndex = tempScanResultIndexes[scanIndex];
|
||||
|
||||
if (physicalIndex < 0 || physicalIndex >= sensorCount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String selectedAddress = sensorAddressStrings[physicalIndex];
|
||||
|
||||
for (int i = 0; i < MAX_TEMP_SENSORS; i++) {
|
||||
if (i == configIndex) {
|
||||
|
||||
Reference in New Issue
Block a user