]> pilppa.org Git - lib1wire.git/blob - src_test/test_w1.cc
add support for storing data to text file periodically
[lib1wire.git] / src_test / test_w1.cc
1 /*
2  * test_w1.cc
3  *
4  *  Created on: Oct 20, 2010
5  *      Author: lamikr
6  */
7 #include <list>
8 #include <string>
9 #include <iostream>
10
11 #include <unistd.h>
12
13 #include "W1Scanner.hh"
14
15 using namespace w1;
16 using namespace std;
17
18 int main(int argc, char** argv)
19 {
20         W1Scanner                       *scanner;
21         list<W1Device *>        device_list;
22         int                                     round;
23         int                                     interval_seconds;
24         int                                     store_interval;
25
26         interval_seconds        = 60;
27         store_interval          = 10;
28         scanner                         = new W1Scanner();
29         device_list                     = scanner->get_device_list();
30         round                           = 0;
31         while(1) {
32                 round++;
33                 for(list<W1Device *>::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++)
34                 {
35                         W1Device *device = (W1Device *)*list_iter;
36 /*
37                         string name     = device->get_name();
38                         string value    = device->get_value();
39                         string unit             = device->get_unit();
40                         cout << name << ": " << value << " " << unit << endl;
41 */
42                         device->printout();
43                         if (round >= store_interval) {
44                                 device->store();
45                         }
46                 }
47                 sleep(interval_seconds);
48                 if (round >= store_interval) {
49                         round = 0;
50                 }
51         }
52         return 0;
53 }