Hall Effect sensor Library 1.0.0
Hall Effect Sensor library (Analog and Digital, regular and EasyC)
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 beginDone = 1;
57 }
58
59 int native = 0;
60 bool beginDone = 0;
61
62 virtual void initializeNative() = 0;
63
64 int err;
65
66 char address;
67 const char defaultAddress = 0x30;
68
76 int sendAddress(char regAddr)
77 {
78 Wire.beginTransmission(address);
79 Wire.write(regAddr);
80
81 return err = Wire.endTransmission();
82 }
83
92 int readData(char a[], int n)
93 {
94 Wire.requestFrom(address, n);
95 Wire.readBytes(a, n);
96
97 return 0;
98 }
99
109 int readRegister(char regAddr, char a[], size_t n)
110 {
111 if (sendAddress(regAddr))
112 return err;
113
114 if (readData(a, n))
115 return err;
116
117 return 0;
118 }
119
128 int sendData(const uint8_t *a, int n)
129 {
130 Wire.beginTransmission(address);
131 Wire.write(a, n);
132
133 return err = Wire.endTransmission();
134 }
135};
136
137#endif
Definition easyC.hpp:22
int sendAddress(char regAddr)
Private function to send a single byte to sensor.
Definition easyC.hpp:76
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:60
int readRegister(char regAddr, char a[], size_t n)
Private function to send over i2c and then read n bytes.
Definition easyC.hpp:109
virtual void initializeNative()=0
char address
Definition easyC.hpp:66
int err
Definition easyC.hpp:64
const char defaultAddress
Definition easyC.hpp:67
int readData(char a[], int n)
Private function to read n bytes over i2c.
Definition easyC.hpp:92
void begin(uint8_t _address)
Initializes sensors on supplied i2c address.
Definition easyC.hpp:50
int native
Definition easyC.hpp:59
int sendData(const uint8_t *a, int n)
Private function to write n bytes over i2c.
Definition easyC.hpp:128