Ejemplo n.º 1
0
int main(int argc, const char * argv[])
{

    float freezeInC = 0;
    float freezeInF = fahrenheitToCelsius(freezeInC);
    printf("Water freezes at %f degrees Fahrenheit\n", freezeInF);
    printf("The last temperature converted was %f\n", lastTemperature);
    
    return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
int main (void) {
	static int MIN_FAHRENHEIT = -40;
	static int MAX_FAHRENHEIT = 212;
	int counter;
	
	/* Print the header */
	printf("%10s%12s\n\n", "Fahrenheit", "Celsius");
	
	for(counter = MIN_FAHRENHEIT; counter <= MAX_FAHRENHEIT; counter++) {
		printf("%10+i%12.3+f\n", counter, fahrenheitToCelsius(counter));
	}
	
	waitOnInput();
    return 0;
}
Ejemplo n.º 3
0
void getTemp() {
	uint16_t last_sample = 0;
	double this_temp;
	double temp_avg;
	uint16_t i;
	temp_avg = 0.0;

	for (i=0; i<500; i++) {
		last_sample = adc_read();
		this_temp = sampleToFahrenheit(last_sample);
		temp_avg = temp_avg + this_temp/500.0;
	}

	double c = fahrenheitToCelsius(temp_avg);
	double k = celsiusToKelvin(c);

	// write message to LCD
	lcd_init();
	FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
	lcd_home();
	lcd_write_string(PSTR("ADC: "));
	lcd_write_int16(last_sample);
	lcd_write_string(PSTR(" of 1024 "));
	lcd_line_two();

	fprintf_P(&lcd_stream, PSTR("%.2f"), temp_avg);
	lcd_write_data(0xdf);
	lcd_write_string(PSTR("F"));

	lcd_line_three();
	fprintf_P(&lcd_stream, PSTR("%.2f"), c);
	lcd_write_data(0xdf);
	lcd_write_string(PSTR("C"));

	lcd_line_four();
	fprintf_P(&lcd_stream, PSTR("%.2f"), k);
	lcd_write_data(0xdf);
	lcd_write_string(PSTR("K"));
}
Ejemplo n.º 4
0
void thermocouplePort::receivedMsg( QByteArray msg )
{
    if( msg.isNull() )
    {
        return;
    }
    msg.replace( 0x0A, "" ).replace( 0x0B, "" ).replace( 0x0D, "" )
            .replace( 0x11, "" ).replace( 0x13, "" )
            .replace( 0x3C, "" ).replace( 0x3E, "" ); // < and > - dont know why this is sent ...
    if( msg.isEmpty() )
    {
        return;
    }

    if( _expectedAnswer.size() == 0 )
    {
        if( _sendCounter != 0 )
        {
            return;
        }
        emit portError( "Unexpected answer!" );
        return;
    }
    _answerPending = 0;

    if( _expectedAnswer[0] == CMD_ID )
    {
        if( _idStringSet )
        {
            bool conversionSuccessful = false;
            int version = msg.toInt( &conversionSuccessful );
            if( conversionSuccessful && version > 90615 )
            {
                _probeTemperatureOnly = false;
            }
            _initValueCounter++;
            emit initSuccessful( _idString );
        }
        else
        {
            _idStringSet = true;
            _idString = msg;
            _initValueCounter++;
        }
    }
    else if( _expectedAnswer[0] == CMD_PROBE_TEMPERATURE )
    {
        bool conversionSuccessful = false;

        double probeTemperatureCelsius = msg.toDouble( &conversionSuccessful );

        if( conversionSuccessful )
        {
            if( _emitProbeTemperature )
            {
                if( probeTemperatureCelsius > MAX_TEMPERATURE
                        || probeTemperatureCelsius < -MAX_TEMPERATURE )
                {
                    emit portError( "Out of range!" );
                }
                else
                {
                    emit newProbeTemperature( probeTemperatureCelsius );
                }
            }
        }
        else
        {
            emit portError( "Could not get temperature from answer!" );
        }
    }
    else if( _expectedAnswer[0] == CMD_BOTH_TEMPERATURES )
    {
        bool conversion1Successful = false;
        bool conversion2Successful = false;

        double probeTemperatureFahrenheit = msg.left( msg.indexOf( "," ) )
                .toDouble( &conversion1Successful );
        double ambientTemperatureFahrenheit = msg.mid( msg.indexOf( "," ) + 1 )
                .toDouble( &conversion2Successful );

        if( conversion1Successful && conversion2Successful )
        {
            int tProbeCelsius = fahrenheitToCelsius(
                        probeTemperatureFahrenheit );
            int tAmbientCelsius = fahrenheitToCelsius(
                        ambientTemperatureFahrenheit );
            if( _emitProbeTemperature )
            {
                if( tProbeCelsius > MAX_TEMPERATURE
                        || tProbeCelsius < -MAX_TEMPERATURE )
                {
                    emit portError( "Out of range!" );
                }
                else
                {
                    emit newProbeTemperature( tProbeCelsius );
                }
            }
            if( _emitAmbientTemperature )
            {
                if( tAmbientCelsius > MAX_TEMPERATURE
                        || tAmbientCelsius < -MAX_TEMPERATURE )
                {
                    emit portError( "Out of range!" );
                }
                else
                {
                    emit newAmbientTemperature( tAmbientCelsius );
                }
            }
        }
        else
        {
            emit portError( "Could not get temperatures from answer!" );
        }
    }
    else if( _expectedAnswer[0] == CMD_OTHER )
    {
    }
    else
    {
        emit portError( "Undefined answer!" );
    }

    _expectedAnswer.erase( _expectedAnswer.begin() );
}