]> pilppa.org Git - lib1wire.git/blobdiff - src/W1Device.cc
Bug fix for counter device data saving.
[lib1wire.git] / src / W1Device.cc
index 7bb44183c489287c846d95487dbafa44abe25773..a765cd36a6091432b4d2577ae6828efc3f36694b 100644 (file)
@@ -36,6 +36,14 @@ W1Device::W1Device(int family_code_param,
 }
 
 W1Device::~W1Device() {
+       list<Data *>::iterator  iter;
+       Data                    *data;
+
+       for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
+               data    = (Data *)*iter;
+               delete(data);
+       }
+       memory_cache.clear();
 }
 
 int W1Device::get_w1_family_code() {
@@ -54,19 +62,6 @@ void W1Device::set_name(string name_param) {
        name    = name_param;
 }
 
-string W1Device::get_time() {
-       time_t          wtime;
-       struct tm       *ltime;
-       char            buffer[80];
-       string          ret_val;
-
-       time(&wtime);
-       ltime   = localtime(&wtime);
-       strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", ltime);
-       ret_val = buffer;
-       return ret_val;
-}
-
 void W1Device::printout() {
        Data    *data;
        string  text;
@@ -105,16 +100,6 @@ Data *W1Device::get_and_collect_data() {
        return ret_val;
 }
 
-/*
-Data *W1Device::get_formatted_data(Data *data) {
-       Data    *ret_val;
-
-       ret_val = get_time() + "|" + raw_data + " " + get_unit();
-       add_to_save_fifo(ret_val);
-       return ret_val;
-}
-*/
-
 void W1Device::collect_data(Data *data) {
        // TODO: add mutex for memory_cache
        memory_cache.push_back(data);
@@ -123,8 +108,10 @@ void W1Device::collect_data(Data *data) {
 void W1Device::save_data() {
        list<Data *>::iterator  iter;
        Data                    *data;
+       int                     dec_precision;
 
-       W1Store::save(id, &memory_cache);
+       dec_precision   = get_data_decimal_precision();
+       W1Store::save(id, &memory_cache, dec_precision);
        for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
                data    = (Data *)*iter;
                delete(data);