Soldered 125kHz RFID board Arduino library 1.0.0
Library for Soldered 125kHz RFID board.
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
18class EasyC
19{
20public:
26 {
27 native = 0;
28 }
29
33 void begin()
34 {
35 if (native)
37 else
39 beginDone = 1;
40 }
41
47 void begin(uint8_t _address)
48 {
49 address = _address;
50
51 Wire.begin();
52
53 beginDone = 1;
54 }
55
56 int native = 0;
57 bool beginDone = 0;
58
59 virtual void initializeNative() = 0;
60
61 int err;
62
63 char address;
64 const char defaultAddress = 0x30;
65
73 int sendAddress(char regAddr)
74 {
75 Wire.beginTransmission(address);
76 Wire.write(regAddr);
77
78 return err = Wire.endTransmission();
79 }
80
89 int readData(char a[], int n)
90 {
91 Wire.requestFrom(address, n);
92 Wire.readBytes(a, n);
93
94 return 0;
95 }
96
106 int readRegister(char regAddr, char a[], size_t n)
107 {
108 if (sendAddress(regAddr))
109 return err;
110
111 if (readData(a, n))
112 return err;
113
114 return 0;
115 }
116
125 int sendData(const uint8_t *a, int n)
126 {
127 Wire.beginTransmission(address);
128 Wire.write(a, n);
129
130 return err = Wire.endTransmission();
131 }
132};
133
134#endif
Definition easyC.hpp:19
int sendAddress(char regAddr)
Private function to send a single byte to sensor.
Definition easyC.hpp:73
void begin()
Initializes sensors on native or easyC on default address.
Definition easyC.hpp:33
EasyC()
Main constructor for easyC version.
Definition easyC.hpp:25
bool beginDone
Definition easyC.hpp:57
int readRegister(char regAddr, char a[], size_t n)
Private function to send over i2c and then read n bytes.
Definition easyC.hpp:106
virtual void initializeNative()=0
char address
Definition easyC.hpp:63
int err
Definition easyC.hpp:61
const char defaultAddress
Definition easyC.hpp:64
int readData(char a[], int n)
Private function to read n bytes over i2c.
Definition easyC.hpp:89
void begin(uint8_t _address)
Initializes sensors on supplied i2c address.
Definition easyC.hpp:47
int native
Definition easyC.hpp:56
int sendData(const uint8_t *a, int n)
Private function to write n bytes over i2c.
Definition easyC.hpp:125