Ejemplo n.º 1
0
double parseTemperature(const char *string)
{
	if (string == NULL || string[0] == '\0')
		return -1;

	/* Copy so we can modify characters */
	char *str = calloc(strlen(string) + 1, sizeof(*str));
	if (str == NULL)
		return -1;
	strcpy(str, string);

	int i = 1;
	while (str[i] != '\0') i++;
	i--;
	char unit = str[i];
	str[i] = '\0';
	double value = atof(str);
	free(str);

	double temperature;
	switch (unit) {
		case 'K':
			temperature = value;
			break;
		case 'C':
			temperature = CELSIUS(value);
			break;
		default:
			return -1;
	}
	return temperature;
}
Ejemplo n.º 2
0
extern
const struct measure_config __flash meastemp_config;
const struct measure_config __flash meastemp_config = {
	.name			= "mt",

	.mux			= MEAS_MUX_ADC1,
	.did			= MEAS_DID_ADC1,
	.ps			= MEAS_PS_64,
	.ref			= MEAS_REF_AREF,

	.averaging_timeout_ms	= 50,

#ifdef HW_LEGACY
	.scale_raw_lo		= 209,
	.scale_raw_hi		= 410,
	.scale_phys_lo		= FLOAT_TO_FIXPT(CELSIUS(150)),
	.scale_phys_hi		= FLOAT_TO_FIXPT(CELSIUS(480)),
#endif
#ifdef HW_SMD
	.scale_raw_lo		= 210,
	.scale_raw_hi		= 411,
	.scale_phys_lo		= FLOAT_TO_FIXPT(CELSIUS(150)),
	.scale_phys_hi		= FLOAT_TO_FIXPT(CELSIUS(480)),
#endif

	.plaus_neglim		= FLOAT_TO_FIXPT(CELSIUS(-20)),
	.plaus_poslim		= FLOAT_TO_FIXPT(CELSIUS(500)),
	.plaus_timeout_ms	= 3000,
};

void meastemp_init(void)