Soldered L86 M33 GNSS Library 1.0.0
Arduino library for communication with Soldered L86-M33 GNSS module
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 bool begin()
37 {
38 if (native)
39 {
41 return true;
42 }
43 else
44 return begin(defaultAddress);
45 }
46
52 bool begin(uint8_t _address)
53 {
54 address = _address;
55
56 Wire.begin();
57
58 // Make sure we can communicate to GNSS
59 char buf [1];
60 this->sendAddress(30);
61 this->readData(buf, 1);
62 beginDone = 1;
63 if(buf[0] == '1') return true;
64 else return false;
65 }
66
67 int native = 0;
68 bool beginDone = 0;
69
70 virtual void initializeNative() = 0;
71
72 int err;
73
74 char address;
75 const char defaultAddress = 0x30;
76
84 int sendAddress(char regAddr)
85 {
86 Wire.beginTransmission(address);
87 Wire.write(regAddr);
88
89 return err = Wire.endTransmission();
90 }
91
100 int readData(char a[], int n)
101 {
102 Wire.requestFrom(address, n);
103 Wire.readBytes(a, n);
104
105 return 0;
106 }
107
117 int readRegister(char regAddr, char a[], size_t n)
118 {
119 if (sendAddress(regAddr))
120 return err;
121
122 if (readData(a, n))
123 return err;
124
125 return 0;
126 }
127
136 int sendData(const uint8_t *a, int n)
137 {
138 Wire.beginTransmission(address);
139 Wire.write(a, n);
140
141 return err = Wire.endTransmission();
142 }
143};
144
145#endif
Definition: easyC.hpp:22
int sendAddress(char regAddr)
Private function to send a single byte to sensor.
Definition: easyC.hpp:84
EasyC()
Main constructor for easyC version.
Definition: easyC.hpp:28
bool beginDone
Definition: easyC.hpp:68
int readRegister(char regAddr, char a[], size_t n)
Private function to send over i2c and then read n bytes.
Definition: easyC.hpp:117
virtual void initializeNative()=0
char address
Definition: easyC.hpp:74
int err
Definition: easyC.hpp:72
const char defaultAddress
Definition: easyC.hpp:75
int readData(char a[], int n)
Private function to read n bytes over i2c.
Definition: easyC.hpp:100
int native
Definition: easyC.hpp:67
bool begin()
Initializes sensors on native or easyC on default address.
Definition: easyC.hpp:36
bool begin(uint8_t _address)
Initializes sensors on supplied i2c address.
Definition: easyC.hpp:52
int sendData(const uint8_t *a, int n)
Private function to write n bytes over i2c.
Definition: easyC.hpp:136