-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathI2CInterface.h
43 lines (36 loc) · 963 Bytes
/
I2CInterface.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
/*
* File: I2CInterface.h
* Author: Matthew
*
* Created on 21 October 2012, 10:38
*/
#ifndef I2CINTERFACE_H
#define I2CINTERFACE_H
#include <iostream>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
//#include <linux/i2c.h>
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
class I2CInterfaceClass
{
public:
I2CInterfaceClass();
virtual ~I2CInterfaceClass();
bool writeRegister(unsigned char slaveAddress, unsigned char registerAddress, unsigned char* buf, unsigned char len);
bool readRegister(unsigned char slaveAddress, unsigned char registerAddress, unsigned char* buf, unsigned char len);
void openInterface();
private:
void setSlaveAddress_(unsigned char address);
int file_;
char filename_[20];
pthread_mutex_t I2Cmutex_;
};
extern I2CInterfaceClass I2CInterface;
#endif /* I2CINTERFACE_H */