-
Notifications
You must be signed in to change notification settings - Fork 8
/
GasBreakout.h
97 lines (86 loc) · 3.31 KB
/
GasBreakout.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef _GASBREAKOUT_h
#define _GASBREAKOUT_h
/***** Includes *****/
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "Wire.h"
#include "IOExpander.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////////////////////////
class GasBreakout
{
//--------------------------------------------------
// Constants
//--------------------------------------------------
public:
static const uint8_t DEFAULT_I2C_ADDRESS = 0x19;
static constexpr float DEFAULT_BRIGHTNESS = 1.0f; //Effectively the maximum fraction of the period that the LED will be on
static const uint32_t DEFAULT_ADC_TIMEOUT = 1;
private:
static const byte PIN_RED = 3;
static const byte PIN_GREEN = 7;
static const byte PIN_BLUE = 2;
static const byte MICS6814_VREF = 14;
static const byte MICS6814_RED = 13;
static const byte MICS6814_NH3 = 11;
static const byte MICS6814_OX = 12;
static const byte PIN_HEATER_EN = 1;
static const bool INVERT_OUTPUT = true; //true for common cathode, false for common anode
//--------------------------------------------------
// Substructures
//--------------------------------------------------
public:
struct Reading {
float ref;
float reducing;
float nh3;
float oxidising;
};
//--------------------------------------------------
// Constructors/Destructor
//--------------------------------------------------
public:
GasBreakout(TwoWire& wire, uint8_t address = DEFAULT_I2C_ADDRESS, float brightness = DEFAULT_BRIGHTNESS,
uint32_t timeout = 1, int8_t interruptPin = -1, bool debug = false);
//--------------------------------------------------
// Methods
//--------------------------------------------------
public:
bool initialise(bool skipChipIdCheck = false);
//--------------------------------------------------
//Calls through to IOExpander class
//--------------------------------------------------
void setAddr(uint8_t i2cAddr);
void setPwmPeriod(uint16_t value, bool load = true);
//--------------------------------------------------
//MIC6814 Gas Breakout specific
//--------------------------------------------------
void setBrightness(float brightness);
void setRGB(uint8_t r, uint8_t g, uint8_t b);
void setR(uint8_t r);
void setG(uint8_t g);
void setB(uint8_t b);
void setHeater(bool value);
Reading readAll(uint32_t adcTimeout = DEFAULT_ADC_TIMEOUT);
float readReducing(uint32_t adcTimeout = DEFAULT_ADC_TIMEOUT);
float readNH3(uint32_t adcTimeout = DEFAULT_ADC_TIMEOUT);
float readOxidising(uint32_t adcTimeout = DEFAULT_ADC_TIMEOUT);
float readRef(uint32_t adcTimeout = DEFAULT_ADC_TIMEOUT);
private:
float readGas(byte channel, uint32_t adcTimeout = DEFAULT_ADC_TIMEOUT);
void setSingle(uint8_t pin, uint8_t v);
//--------------------------------------------------
// Variables
//--------------------------------------------------
private:
IOExpander _ioe;
float _brightness;
unsigned int _pwm_period;
};
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////