X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=src%2FW1TemperatureSensor.cc;h=b02bb29dd01518738b2fd59136d3b94f8a7d37d4;hb=8c97cbb9b5f8997fe9ab3917fcbea66d74b45837;hp=b5445c3e58ed309a96065e1b3eb0e92574d7a9af;hpb=c7979a0225a21182f68d40374723a649d032908d;p=lib1wire.git diff --git a/src/W1TemperatureSensor.cc b/src/W1TemperatureSensor.cc index b5445c3..b02bb29 100644 --- a/src/W1TemperatureSensor.cc +++ b/src/W1TemperatureSensor.cc @@ -9,13 +9,16 @@ #include #include +#include "W1Util.hh" #include "W1TemperatureSensor.hh" +#include + using namespace std; using namespace w1; -template -bool string_to_number(T& result, +template +bool string_to_number(NumberDataType& result, const std::string& string_param, std::ios_base& (*format)(std::ios_base&)) { @@ -23,14 +26,13 @@ bool string_to_number(T& result, return !(iss >> format >> result).fail(); } -string convert_for_3_digits_value(string raw_value) { +string convert_celcius_value_to_three_digits(string raw_value) { string ret_val; - int int_val; - bool sucFlg; + bool suc_flg; double dbl_val; - sucFlg = string_to_number(dbl_val, raw_value, dec); - if (sucFlg == true) { + suc_flg = string_to_number(dbl_val, raw_value, dec); + if (suc_flg == true) { dbl_val = dbl_val / 1000; std::ostringstream out; out << fixed << setprecision(3) << dbl_val; @@ -42,16 +44,17 @@ string convert_for_3_digits_value(string raw_value) { return ret_val; } -W1TemperatureSensor::W1TemperatureSensor(dirent *direntry, int family_code_param, string id_param): W1Device(direntry, family_code_param, id_param) { +W1TemperatureSensor::W1TemperatureSensor(int family_code_param, + string device_id_param, + dirent *direntry_param): W1Device(family_code_param, device_id_param, direntry_param) { + string text; + + log_debug("trying to open file: %s\n", slave_file.c_str()); ifstream ifs(slave_file.c_str()); if (ifs.is_open() == false) { - string text; - - text = get_time() + ": device type = " + get_devicetype_name() + ", id = " + id + ", could not read file: " + slave_file; - cout << text << endl; - cout << "verify that you have w1_therm kernel module loaded." << endl; - } - else { + text = get_time() + ": device type = " + get_device_type() + ", id = " + id + ", could not read file: " + slave_file + "\n"; + log_debug(text.c_str()); + log_debug("verify that you have w1_therm kernel module loaded.\n"); ifs.close(); } } @@ -72,14 +75,13 @@ bool W1TemperatureSensor::is_supported_family_code(int family_code) { return ret_val; } -string W1TemperatureSensor::get_value() { +string W1TemperatureSensor::get_raw_value() { string temp; string ret_val; string last_line; int pos; int length; - string formatted_data; - int int_value; + string format; ret_val = ""; ifstream ifs(slave_file.c_str()); @@ -87,20 +89,19 @@ string W1TemperatureSensor::get_value() { while(getline(ifs, temp)) { if (temp.length() > 0) { last_line = temp; - //cout << ret_val << endl; } } ifs.close(); length = last_line.length(); if (length > 0) { - pos = last_line.find("t="); + pos = last_line.find("t="); if ((pos >= 0) && (pos + 2 < length)) { ret_val = last_line.substr(pos + 2); } } } - ret_val = convert_for_3_digits_value(ret_val); + ret_val = convert_celcius_value_to_three_digits(ret_val); return ret_val; } @@ -108,21 +109,6 @@ string W1TemperatureSensor::get_unit() { return "C"; } -string W1TemperatureSensor::get_devicetype_name() { +string W1TemperatureSensor::get_device_type() { return "Temperature Sensor"; } -/* -void W1TemperatureSensor::printout() { - string text; - - text = get_formatted_data(); - cout << text << endl; -} - -string W1TemperatureSensor::get_formatted_data() { - string ret_val; - - ret_val = get_time() + ": device type = temperature sensor, id = " + id + ", value = " + get_value() + " " + get_unit(); - return ret_val; -} -*/