LTR-507 Light And Proximity Sensor Arduino Library 1.0.0
Library used to easily operate with the LTR-507 Light And Proximity Sensor
Loading...
Searching...
No Matches
easyC.hpp
Go to the documentation of this file.
1
12#ifndef __EASYC__
13#define __EASYC__
14
15#include "Arduino.h"
16#include "Wire.h"
17
18#define ANALOG_READ_REG 0
19#define DIGITAL_READ_REG 1
20
21class EasyC
22{
23public:
29 {
30 native = 0;
31 }
32
36 void begin()
37 {
38 if (native)
40 else
42
43 beginDone = 1;
44 }
45
51 void begin(uint8_t _address)
52 {
53 address = _address;
54
55 Wire.begin();
56
57 beginDone = 1;
58 }
59
60 int native = 0;
61 bool beginDone = 0;
62
63 virtual void initializeNative() = 0;
64
65 int err;
66
67 char address;
68 const char defaultAddress = 0x30;
69
77 int sendAddress(char regAddr)
78 {
79 Wire.beginTransmission(address);
80 Wire.write(regAddr);
81
82 return err = Wire.endTransmission();
83 }
84
93 int readData(char a[], int n)
94 {
95 Wire.requestFrom(address, n);
96 Wire.readBytes(a, n);
97
98 return 0;
99 }
100
110 int readRegister(char regAddr, char a[], size_t n)
111 {
112 if (sendAddress(regAddr))
113 return err;
114
115 if (readData(a, n))
116 return err;
117
118 return 0;
119 }
120
129 int sendData(const uint8_t *a, int n)
130 {
131 Wire.beginTransmission(address);
132 Wire.write(a, n);
133
134 return err = Wire.endTransmission();
135 }
136};
137
138#endif
Definition easyC.hpp:22
int sendAddress(char regAddr)
Private function to send a single byte to sensor.
Definition easyC.hpp:77
void begin()
Initializes sensors on native or easyC on default address.
Definition easyC.hpp:36
EasyC()
Main constructor for easyC version.
Definition easyC.hpp:28
bool beginDone
Definition easyC.hpp:61
int readRegister(char regAddr, char a[], size_t n)
Private function to send over i2c and then read n bytes.
Definition easyC.hpp:110
virtual void initializeNative()=0
char address
Definition easyC.hpp:67
int err
Definition easyC.hpp:65
const char defaultAddress
Definition easyC.hpp:68
int readData(char a[], int n)
Private function to read n bytes over i2c.
Definition easyC.hpp:93
void begin(uint8_t _address)
Initializes sensors on supplied i2c address.
Definition easyC.hpp:51
int native
Definition easyC.hpp:60
int sendData(const uint8_t *a, int n)
Private function to write n bytes over i2c.
Definition easyC.hpp:129