-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcp342x.h
executable file
·81 lines (66 loc) · 1.61 KB
/
mcp342x.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef TSAR_MCP342X
#define TSAR_MCP342X
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <string.h>
#include <bitset>
//Raw Config Bit Definitions
#define CFG_RDY 1<<7
#define CFG_C1 1<<6
#define CFG_C0 1<<5
#define CFG_OC 1<<4
#define CFG_S1 1<<3
#define CFG_S0 1<<2
#define CFG_G1 1<<1
#define CFG_G0 1<<0
#define CFG_RDY 1<<7
#define CFG_C1 1<<6
#define CFG_C0 1<<5
#define CFG_OC 1<<4
#define CFG_S1 1<<3
#define CFG_S0 1<<2
#define CFG_G1 1<<1
#define CFG_G0 1<<0
#define CFG_CHAN1 0
#define CFG_CHAN2 CFG_C0
#define CFG_CHAN3 CFG_C1
#define CFG_CHAN4 (CFG_C0 |CFG_C1)
#define CFG_240SPS 0
#define CFG_60SPS CFG_S0
#define CFG_15SPS CFG_S1
#define CFG_3SPS (CFG_S0 | CFG_S1)
#define CFG_X1 0
#define CFG_X2 CFG_G0
#define CFG_X4 CFG_G1
#define CFG_X8 (CFG_G0 | CFG_G1)
#define CFG_DEFAULT (CFG_CHAN1 | CFG_240SPS | CFG_X1)
class mcp342x{
private:
int address;
int file_descriptor;
char* device;
__u8 configuration;
// Helper function for adding the sign bit into the converted data
const int convert(const int, const int);
public:
// Constructor / destructor stuff
mcp342x();
mcp342x(const mcp342x&);
mcp342x(const int, const char*);
~mcp342x();
// Function stuff
const int set_settings(const bool, const int, const int);
const int set_channel(const int);
void start_read();
const bool is_ready();
const int read_register();
// Other
friend std::ostream& operator <<(std::ostream&, const mcp342x&);
};
#endif