Example #1
0
void main()
{
    InitModules();

    while(1)
    {
        ReadSensor();
        CalculatePPM();
        DisplayAirQValue( ppm );
        Delay_ms(500);
    }
}
Example #2
0
void RRCSSensor::Run() {
    auto thread_lambda = [this]() -> void {
    	std::cout << "Starting " << name_ << std::endl;
        time_ = std::chrono::high_resolution_clock::now();
        time_ += std::chrono::milliseconds(10000);
        bool queue_status = true;
        RRCSSensorMeasurement d;
        while(!abort_() && queue_status) {
            std::this_thread::sleep_until(time_);
            ReadSensor(d, time_);
            time_ += rate_;
            queue_status = update_(d);
        }
    };

    thread_ = std::thread(thread_lambda);
}
Example #3
0
//==========================================================================
// Class:			DS18B20
// Function:		ReadSensor
//
// Description:		Reads current temperature from DS18B20 sensor.
//
// Input Arguments:
//		recursion	= unsigned int, number of attempts to make in the event of repeated errors
//
// Output Arguments:
//		temperature	= double& [deg C]
//
// Return Value:
//		bool, true for success, false otherwise
//
//==========================================================================
bool DS18B20::ReadSensor(double &temperature, unsigned int recursion) const
{
	if (recursion == 0)
		return false;
		
	std::ifstream file(device.c_str(), std::ios::in);
	if (!file.is_open() || !file.good())
	{
		outStream << "Could not open file '" << device << "' for input" << std::endl;
		return ReadSensor(temperature, recursion - 1);
	}

	std::string data;
	if (!std::getline(file, data))
	{
		outStream << "Failed to read CRC from file '" << device << "'" << std::endl;
		return ReadSensor(temperature, recursion - 1);
	}

	// Line must contain at least "YES" at the end...
	if (data.length() < 3)
	{
		outStream << "File contents too short (" << deviceID << ")" << std::endl;
		return ReadSensor(temperature, recursion - 1);
	}

	if (data.substr(data.length() - 3).compare("YES") != 0)
	{
		// This happens quite often - might want to disable this statement
		// after testing is complete, to avoid spamming?
		outStream << "Bad checksum (" << deviceID << ")" << std::endl;
		return ReadSensor(temperature, recursion - 1);
	}

	if (!std::getline(file, data))
	{
		outStream << "Failed to read temperature from file '" << device << "'" << std::endl;
		return ReadSensor(temperature, recursion - 1);
	}

	size_t start(data.find("t="));
	if (start == std::string::npos)
	{
		outStream << "Temperature reading does not contain 't='"
			<< " (" << deviceID << ")" << std::endl;
		return ReadSensor(temperature, recursion - 1);
	}

	temperature = atof(data.substr(start + 2).c_str()) / 1000.0;

	return true;
}
Example #4
0
//==========================================================================
// Class:			DS18B20
// Function:		GetTemperature
//
// Description:		Reads current temperature from DS18B20 sensor.
//
// Input Arguments:
//		None
//
// Output Arguments:
//		temperature	= double& [deg C]
//
// Return Value:
//		bool, true for success, false otherwise
//
//==========================================================================
bool DS18B20::GetTemperature(double &temperature) const
{
	return ReadSensor(temperature, allowedRecursions);
}