Simple Sensors Arduino library 1.0.0
A library for all the Simple Sensors by Soldered Electronics, regular and easyC versions.
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 beginDone = 1;
43 }
44
50 void begin(uint8_t _address)
51 {
52 address = _address;
53
54 Wire.begin();
55
56
57
58 beginDone = 1;
59 }
60
61 int native = 0;
62 bool beginDone = 0;
63
64 virtual void initializeNative() = 0;
65
66 int err;
67
68 char address;
69 const char defaultAddress = 0x30;
70
78 int sendAddress(char regAddr)
79 {
80 Wire.beginTransmission(address);
81 Wire.write(regAddr);
82
83 return err = Wire.endTransmission();
84 }
85
94 int readData(char a[], int n)
95 {
96 Wire.requestFrom(address, n);
97 delay(5);
98 Wire.readBytes(a, n);
99
100 return 0;
101 }
102
112 int readRegister(char regAddr, char a[], size_t n)
113 {
114 if (sendAddress(regAddr))
115 return err;
116
117 if (readData(a, n))
118 return err;
119
120 return 0;
121 }
122
131 int sendData(const uint8_t *a, int n)
132 {
133 Wire.beginTransmission(address);
134 Wire.write(a, n);
135
136 return err = Wire.endTransmission();
137 }
138};
139
140#endif
Definition easyC.hpp:22
int sendAddress(char regAddr)
Private function to send a single byte to sensor.
Definition easyC.hpp:78
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:62
int readRegister(char regAddr, char a[], size_t n)
Private function to send over i2c and then read n bytes.
Definition easyC.hpp:112
virtual void initializeNative()=0
char address
Definition easyC.hpp:68
int err
Definition easyC.hpp:66
const char defaultAddress
Definition easyC.hpp:69
int readData(char a[], int n)
Private function to read n bytes over i2c.
Definition easyC.hpp:94
void begin(uint8_t _address)
Initializes sensors on supplied i2c address.
Definition easyC.hpp:50
int native
Definition easyC.hpp:61
int sendData(const uint8_t *a, int n)
Private function to write n bytes over i2c.
Definition easyC.hpp:131