SparkFun Spectral UV Sensor - AS7331
v2.1.2-21-g3e22fb4
Library for the SparkFun Spectral UV Sensor - AS7331
Loading...
Searching...
No Matches
SparkFun_AS7331.h
Go to the documentation of this file.
1
/*
41
#pragma once
42
43
// clang-format off
44
#include <SparkFun_Toolkit.h>
45
#include "sfTk/sfDevAS7331.h"
46
#include <Arduino.h>
47
// clang-format on
48
72
class SfeAS7331ArdI2C : public sfDevAS7331
73
{
74
public:
75
SfeAS7331ArdI2C()
76
{
77
}
78
105
bool begin(const uint8_t &address = kDefaultAS7331Addr, TwoWire &wirePort = Wire)
106
{
107
if (_theI2CBus.init(wirePort, address) != ksfTkErrOk)
108
return false;
109
110
// Device supports repeat starts, enable it.
111
_theI2CBus.setStop(false);
112
113
setCommunicationBus(&_theI2CBus);
114
115
if (!isConnected())
116
return false;
117
118
return sfDevAS7331::begin();
119
}
120
141
bool isConnected(void)
142
{
143
if (_theI2CBus.ping() != ksfTkErrOk)
144
return false;
145
146
return (kDefaultAS7331DeviceID == getDeviceID());
147
}
148
173
bool setDeviceAddress(const uint8_t &deviceAddress)
174
{
175
switch (deviceAddress)
176
{
177
// If it's any of the allowed addresses, set it.
178
case kDefaultAS7331Addr:
179
case kSecondaryAS7331Addr:
180
case kTertiaryAS7331Addr:
181
case kQuaternaryAS7331Addr:
182
_theI2CBus.setAddress(deviceAddress);
183
break;
184
default: // If it's invalid, return false.
185
return false;
186
break;
187
}
188
return true;
189
}
190
212
uint8_t getDeviceAddress(void)
213
{
214
return _theI2CBus.address();
215
}
216
217
private:
229
sfTkArdI2C _theI2CBus;
230
};
src
SparkFun_AS7331.h
Generated by
1.9.5