static void metar_tok_temp (gchar *tokp, WeatherInfo *info) { gchar *ptemp, *pdew, *psep; psep = strchr (tokp, '/'); *psep = 0; ptemp = tokp; pdew = psep + 1; info->temp = (*ptemp == 'M') ? TEMP_C_TO_F (-atoi (ptemp + 1)) : TEMP_C_TO_F (atoi (ptemp)); if (*pdew) { info->dew = (*pdew == 'M') ? TEMP_C_TO_F (-atoi (pdew + 1)) : TEMP_C_TO_F (atoi (pdew)); } else { info->dew = -1000.0; } }
/***************************************************************************** * Method: oneWireTask * Description: This method runs the oneWire task ****************************************************************************/ void oneWire::oneWireTask (void) { static uint8_t runs = 0; uint8_t low_byte, high_byte; int16_t temp; int32_t temp_f; //if ((runs % 5) == 0) //{ //DBG(this->p_serial, "\r\noneWire Task Running on device: %d\r\n", dev_id); // perform temperature conversion reset(); write_byte(0xCC); // skip ROM write_byte(0x44); // single temp conversion // read in scratch pad reset(); write_byte(0xCC); // skip ROM write_byte(0xBE); // read scratchpad // read temperature low_byte = read_byte(); high_byte = read_byte(); temp = (high_byte << BYTE_SHIFT) | low_byte; temp = convert_temp(temp); temp_f = TEMP_C_TO_F((int32_t)temp); // update global value if (dev_id == ID_SURFACE_TEMP) { surf_temp = temp_f; } else if (dev_id == ID_UNDERWATER_TEMP) { sub_temp = temp_f; } //DBG(this->p_serial, "Temp sensor %d: %d.%02dC or %ld.%02ldF\r\n", // dev_id, // (temp / 100), (temp % 100), // (temp_f / 100), (temp_f % 100)); //} runs++; }
static inline void read_temperature (GWeatherInfo *info, xmlNodePtr node) { xmlChar *unit; xmlChar *val; double celsius; unit = xmlGetProp (node, XC("unit")); if (unit == NULL || strcmp ((char*)unit, "celsius")) return; val = xmlGetProp (node, XC("value")); if (val == NULL) return; celsius = g_ascii_strtod ((char*) val, NULL); info->priv->temp = TEMP_C_TO_F (celsius); }