]> pilppa.org Git - lib1wire.git/blob - src/W1Device.hh
api changes
[lib1wire.git] / src / W1Device.hh
1 /*
2  * W1Device.hh
3  *
4  *  Created on: Oct 20, 2010
5  *      Author: lamikr
6  */
7
8 #ifndef W1DEVICE_HH_
9 #define W1DEVICE_HH_
10
11 #include <string>
12 #include <list>
13
14 #include <dirent.h>
15 #include <stdbool.h>
16 #include <pthread.h>
17
18 #include <plp/Data.hh>
19 #include <plp/DataReader.hh>
20 #include <plp/SensorDevice.hh>
21 #include <plp/Device.hh>
22
23 #ifndef W1_SCAN_ROOTDIR
24 #define W1_SCAN_ROOTDIR         "/sys/bus/w1/devices"
25 #endif
26
27 #ifndef W1_SLAVE_FILE
28 #define W1_SLAVE_FILE           "w1_slave";
29 #endif
30
31 namespace w1 {
32         class W1Device : public plp::SensorDevice {
33                 public:
34                         W1Device(std::string device_id_param,
35                                 std::string device_type_param,
36                                 dirent *direntry_param);
37                         ~W1Device();
38                         void printout();
39                         plp::Data *get_data();
40                         const plp::DataReader *get_datareader();
41                 protected:
42                         std::string dir_path;
43                         std::string slave_file;
44                         std::list<plp::Data *> memory_cache;
45                         plp::DataReader *reader;
46                         void save_and_clean_cache();
47                         virtual std::vector<double> *get_raw_data() = 0;
48                         virtual unsigned int get_data_decimal_precision() { return 1; }
49                         void cache(plp::Data *new_data);
50                         std::string to_string(double val, int digit_count);
51                         pthread_mutex_t plock;
52         };
53 }
54
55 #endif /* W1DEVICE_HH_ */