#include <string>
#include <iostream>
-#include <unistd.h>
+#include <plp/log.h>
+#include "W1Store.hh"
#include "W1Scanner.hh"
using namespace w1;
using namespace std;
-int main(int argc, char** argv)
-{
- W1Scanner *scanner;
+int main(int argc, char** argv) {
+ W1Scanner *scanner;
list<W1Device *> device_list;
- int round;
- int interval_seconds;
- int store_interval;
+ int round;
+ int interval_seconds;
+ int store_interval;
+ string location;
- interval_seconds = 60;
- store_interval = 10;
- scanner = new W1Scanner();
- device_list = scanner->get_device_list();
- round = 0;
- while(1) {
- round++;
- for(list<W1Device *>::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++)
- {
- W1Device *device = (W1Device *)*list_iter;
-/*
- string name = device->get_name();
- string value = device->get_value();
- string unit = device->get_unit();
- cout << name << ": " << value << " " << unit << endl;
-*/
- device->printout();
+ location = "/tmp/";
+ if (argc > 1) {
+ location = argv[1];
+ log_info("storage location: %s\n", location.c_str());
+ }
+ W1Store::set_location(location.c_str());
+ interval_seconds = 3;
+ store_interval = 3;
+ scanner = new W1Scanner();
+ device_list = scanner->get_device_list();
+ round = 0;
+ if (device_list.size() > 0) {
+ while(1) {
+ round++;
+ for(list<W1Device *>::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++)
+ {
+ W1Device *device = (W1Device *)*list_iter;
+
+ device->printout();
+ sleep(1);
+ if (round >= store_interval) {
+ device->store();
+ }
+ }
+ sleep(interval_seconds);
if (round >= store_interval) {
- device->store();
+ round = 0;
}
}
- sleep(interval_seconds);
- if (round >= store_interval) {
- round = 0;
- }
+ }
+ else {
+ log_debug("could not find 1-wire devices.\n");
}
return 0;
}