Monitor for central heating system (e.g. 2zones+hw) Supports up to 15 temp probes (DS18B20/DS18S20) 3 valve monitors Gas pulse meter recording Use stand-alone or with nodeEnergyServer See http://robdobson.com/2015/09/central-heating-monitor
Dependencies: EthernetInterfacePlusHostname NTPClient Onewire RdWebServer SDFileSystem-RTOS mbed-rtos mbed-src
Diff: GasUseCounter.cpp
- Revision:
- 20:7933076df5af
- Parent:
- 19:0367cb46d003
--- a/GasUseCounter.cpp Mon Oct 05 14:05:33 2015 +0000 +++ b/GasUseCounter.cpp Tue Oct 13 18:35:20 2015 +0000 @@ -31,7 +31,7 @@ } // Show count - _pc.printf("Count %d Rate(ms) %d\r\n", _pulseDetector->GetPulseCount(), _pulseDetector->GetPulseRateMs()); + _logger.LogDebug("GasCount %d Rate(ms) %d", _pulseDetector->GetPulseCount(), _pulseDetector->GetPulseRateMs()); } return edgeDetected; } @@ -46,20 +46,32 @@ const char* fname = _gasUseFilename1; if (i == 1) fname = _gasUseFilename2; + + // Obtain lock to access sd card + _sdCardMutex.lock(); + FILE* fp = fopen(fname, "r"); if (fp == NULL) { - _pc.printf ("Read Gas ... Filename %s not found\r\n", fname); + // Release lock on sd card + _sdCardMutex.unlock(); + + _logger.LogDebug("GasCount Read Filename %s not found", fname); } else { int curCount = 0; int retVal = fscanf(fp, "%d", &curCount); fclose(fp); + + // Release lock on sd card + _sdCardMutex.unlock(); + + // Handle result if (retVal == 1) - _pc.printf ("Read from file %s last gas count = %d\r\n", fname, curCount); + _logger.LogDebug("GasCount read from file %s gas count = %d", fname, curCount); else - _pc.printf ("Failed to read gas count from file %s\r\n", fname); + _logger.LogDebug("GasCount Failed to read gas count from file %s", fname); if (i == 0) count0 = curCount; else @@ -72,7 +84,7 @@ maxCount = count1; _lastWrittenGasCount = maxCount; _pulseDetector->SetPulseCount(maxCount); - _pc.printf ("Pulse count set to %d\r\n", maxCount); + _logger.LogDebug("GasCount set to %d", maxCount); } void GasUseCounter::WriteGasCountToSD() @@ -82,16 +94,24 @@ const char* fname = _gasUseFilename1; if (i == 1) fname = _gasUseFilename2; + + // Obtain lock to access sd card + _sdCardMutex.lock(); + FILE* fp = fopen(fname, "w"); if (fp == NULL) { - _pc.printf ("WriteGas ... Filename %s not found\r\n", fname); + _logger.LogDebug("GasCount write failed filename %s not found", fname); } else { fprintf(fp, "%d", GetCount()); - _pc.printf ("Written to %s last gas count = %d\r\n", fname, GetCount()); + _logger.LogDebug("GasCount written to %s gas count = %d", fname, GetCount()); fclose(fp); } + + // Release lock on sd card + _sdCardMutex.unlock(); + } }