Fix for 1Wire sensor reading. Only 1value per loop step
This commit is contained in:
		
							parent
							
								
									6a608aba5c
								
							
						
					
					
						commit
						2b885ec915
					
				| 
						 | 
					@ -328,6 +328,7 @@ void sensorTask(void *param){
 | 
				
			||||||
    double voffset = (api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asString()).toFloat();
 | 
					    double voffset = (api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asString()).toFloat();
 | 
				
			||||||
    double vslope = (api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asString()).toFloat();
 | 
					    double vslope = (api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asString()).toFloat();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    static long loopCounter = 0;    // Loop counter for 1Wire data transmission
 | 
				
			||||||
    long starttime0 = millis();     // GPS update all 100ms
 | 
					    long starttime0 = millis();     // GPS update all 100ms
 | 
				
			||||||
    long starttime5 = millis();     // Voltage update all 1s
 | 
					    long starttime5 = millis();     // Voltage update all 1s
 | 
				
			||||||
    long starttime6 = millis();     // Environment sensor update all 1s
 | 
					    long starttime6 = millis();     // Environment sensor update all 1s
 | 
				
			||||||
| 
						 | 
					@ -390,18 +391,22 @@ void sensorTask(void *param){
 | 
				
			||||||
            float tempC;
 | 
					            float tempC;
 | 
				
			||||||
            ds18b20.requestTemperatures();  // Collect all temperature values (max.8)
 | 
					            ds18b20.requestTemperatures();  // Collect all temperature values (max.8)
 | 
				
			||||||
            for(int i=0;i<numberOfDevices; i++){
 | 
					            for(int i=0;i<numberOfDevices; i++){
 | 
				
			||||||
                if(ds18b20.getAddress(tempDeviceAddress, i)){
 | 
					                // Send only one 1Wire data per loop step (time reduction)
 | 
				
			||||||
                    // Read temperature value in Celsius
 | 
					                if(i == loopCounter % numberOfDevices){
 | 
				
			||||||
                    tempC = ds18b20.getTempC(tempDeviceAddress); 
 | 
					                    if(ds18b20.getAddress(tempDeviceAddress, i)){
 | 
				
			||||||
                }
 | 
					                        // Read temperature value in Celsius
 | 
				
			||||||
                // Send to NMEA200 bus for each sensor with instance number
 | 
					                        tempC = ds18b20.getTempC(tempDeviceAddress); 
 | 
				
			||||||
                if(!isnan(tempC)){
 | 
					                    }
 | 
				
			||||||
                    sensors.onewireTemp[i] = tempC; // Save values in SensorData
 | 
					                    // Send to NMEA200 bus for each sensor with instance number
 | 
				
			||||||
                    SetN2kPGN130316(N2kMsg, 0, i, N2kts_OutsideTemperature, CToKelvin(tempC), N2kDoubleNA);
 | 
					                    if(!isnan(tempC)){
 | 
				
			||||||
                    api->sendN2kMessage(N2kMsg);
 | 
					                        sensors.onewireTemp[i] = tempC; // Save values in SensorData
 | 
				
			||||||
                    api->getLogger()->logDebug(GwLog::LOG,"DS18B20-%1d Temp: %.1f",i,tempC);
 | 
					                        SetN2kPGN130316(N2kMsg, 0, i, N2kts_OutsideTemperature, CToKelvin(tempC), N2kDoubleNA);
 | 
				
			||||||
                }
 | 
					                        api->sendN2kMessage(N2kMsg);
 | 
				
			||||||
 | 
					                        api->getLogger()->logDebug(GwLog::LOG,"DS18B20-%1d Temp: %.1f",i,tempC);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }    
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            loopCounter++;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // If GPS not ready or installed then send RTC time on bus all 500ms
 | 
					        // If GPS not ready or installed then send RTC time on bus all 500ms
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue