Library for basic air data calculations  0.5b
SSC.h
Go to the documentation of this file.
1 #ifndef HONEYWELL_SSC_H
2 #define HONEYWELL_SSC_H
3 // Modification by Basic Air Data 2017
4 // Author: Tomas Van Verrewegen <tomasvanverrewegen@telenet.be>
5 // Version: 0.2
6 
7 //#include <Arduino.h>
8 #include <i2c_t3.h>
9 
10 class SSC
11 {
12 public:
13 
14  enum Error
15  {
16  NoError = 0,
22  ErrorMask = 15
23  };
24 
25  enum Flag
26  {
27  RunningFlag = 128,
29  };
30 
31  SSC(uint8_t address, uint8_t busno = 10);
32 
33  uint8_t address() const
34  {
35  return a;
36  }
37  uint8_t busno() const
38  {
39  return q;
40  }
41 
42  uint8_t error() const
43  {
44  return f & ErrorMask;
45  }
46  uint8_t flags() const
47  {
48  return f & FlagsMask;
49  }
50 
51  bool isRunning() const
52  {
53  return f & RunningFlag;
54  }
55 
56  // minimum pressure of the sensor (in bar, Pascal, ...)
57  float minPressure() const
58  {
59  return pmin;
60  }
61  void setMinPressure(float p)
62  {
63  pmin = p;
64  }
65 
66  // maximum pressure of the sensor (in bar, Pascal, ...)
67  float maxPressure() const
68  {
69  return pmax;
70  }
71  void setMaxPressure(float p)
72  {
73  pmax = p;
74  }
75 
76  // minimum reading of the sensor (see datasheet)
77  uint16_t minRaw() const
78  {
79  return rmin;
80  }
81  void setMinRaw(uint16_t raw)
82  {
83  rmin = raw;
84  }
85 
86  // maximum reading of the sensor (see datasheet)
87  uint16_t maxRaw() const
88  {
89  return rmax;
90  }
91  void setMaxRaw(uint16_t raw)
92  {
93  rmax = raw;
94  }
95 
96  // return pressure and temperature
97  uint16_t pressure_Raw() const
98  {
99  return p;
100  }
101  uint16_t temperature_Raw() const
102  {
103  return t;
104  }
105  float pressure() const
106  {
107  return rawToPressure(pressure_Raw());
108  }
109  float temperature() const
110  {
112  }
113 
114  // update pressure and temperature
115  uint8_t update();
116 
117  // convert pressure and temperature
118  float rawToPressure(uint16_t raw) const
119  {
120  return rawToPressure(raw, rmin, rmax, pmin, pmax);
121  }
122  static float rawToPressure(uint16_t raw, uint16_t rawMin, uint16_t rawMax, float pMin, float pMax)
123  {
124  return float(raw - rawMin) * (pMax - pMin) / (rawMax - rawMin) + pMin;
125  }
126  static float rawToTemperature(uint16_t raw)
127  {
128  return (float(raw) * 0.097703957 - 50.0)+273.15;
129  }
130 
131  // control the sensor from a stream
132  uint8_t commandRequest(Stream& stream);
133 
134 private:
135 
136  uint8_t setError(uint8_t error)
137  {
138  f = (f & FlagsMask) | error;
139  return error;
140  }
141  uint8_t commandReply(Stream& stream, uint8_t result)
142  {
143  stream.println(result);
144  return result;
145  }
146  template<typename T> uint8_t commandReply(Stream& stream, uint8_t result, const T& data)
147  {
148  stream.println(data);
149  return result;
150  }
151 
152  uint8_t a;
153  uint8_t q;
154  uint8_t f;
155  uint16_t p;
156  uint16_t t;
157  uint16_t rmin;
158  uint16_t rmax;
159  float pmin;
160  float pmax;
161 };
162 
163 #endif
Definition: SSC.h:19
bool isRunning() const
Definition: SSC.h:51
void setMinPressure(float p)
Definition: SSC.h:61
static float rawToTemperature(uint16_t raw)
Definition: SSC.h:126
uint16_t pressure_Raw() const
Definition: SSC.h:97
Flag
Definition: SSC.h:25
Definition: SSC.h:28
void setMaxRaw(uint16_t raw)
Definition: SSC.h:91
static float rawToPressure(uint16_t raw, uint16_t rawMin, uint16_t rawMax, float pMin, float pMax)
Definition: SSC.h:122
Definition: SSC.h:16
uint8_t error() const
Definition: SSC.h:42
Definition: SSC.h:27
Definition: SSC.h:17
float temperature() const
Definition: SSC.h:109
uint8_t address() const
Definition: SSC.h:33
uint8_t flags() const
Definition: SSC.h:46
Definition: SSC.h:18
float maxPressure() const
Definition: SSC.h:67
void setMaxPressure(float p)
Definition: SSC.h:71
float rawToPressure(uint16_t raw) const
Definition: SSC.h:118
uint8_t busno() const
Definition: SSC.h:37
uint16_t maxRaw() const
Definition: SSC.h:87
void setMinRaw(uint16_t raw)
Definition: SSC.h:81
uint8_t commandRequest(Stream &stream)
Definition: SSC.cpp:103
SSC(uint8_t address, uint8_t busno=10)
Definition: SSC.cpp:4
Error
Definition: SSC.h:14
Definition: SSC.h:10
float pressure() const
Definition: SSC.h:105
Definition: SSC.h:20
uint8_t update()
Definition: SSC.cpp:22
Definition: SSC.h:22
Definition: SSC.h:21
float minPressure() const
Definition: SSC.h:57
uint16_t temperature_Raw() const
Definition: SSC.h:101
uint16_t minRaw() const
Definition: SSC.h:77