Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit 33a7acd

Browse files
committed
mikroSDK library for Air Quality 5 click
1 parent 3eff54b commit 33a7acd

File tree

2 files changed

+1
-242
lines changed

2 files changed

+1
-242
lines changed

library/__airq5_driver.c

Lines changed: 1 addition & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ const uint16_t _AIRQ5_CONFIG_COMP_QUE_4CONV = 0x0002;
7272
const uint16_t _AIRQ5_CONFIG_COMP_QUE_0CONV = 0x0003;
7373

7474
/* ---------------------------------------------------------------- VARIABLES */
75-
#define _DBL_MAX_ 3.40282347e+38
76-
#define _FRNDINT(x) ((double)(long)(x))
7775

7876
#ifdef __AIRQ5_DRV_I2C__
7977
static uint8_t _slaveAddress;
@@ -83,214 +81,9 @@ static uint16_t _dataConfig = 0x8583;
8381

8482
/* -------------------------------------------- PRIVATE FUNCTION DECLARATIONS */
8583

86-
static double _floor(double x);
87-
static double _frexp(double value, int * eptr);
88-
static double _ldexp(double value, int newexp);
89-
static double _eval_poly(double x, const double code * d, int n);
90-
static double _exp(double x);
91-
static double _log(double x);
92-
static double _myPow(double x, double y);
9384

94-
/* --------------------------------------------- PRIVATE FUNCTION DEFINITIONS */
95-
96-
#if defined __MIKROC_PRO_FOR_ARM__ || __MIKROC_PRO_FOR_PIC32__ || __MIKROC_PRO_FOR_DSPIC__ || __MIKROC_PRO_FOR_AVR__ || __MIKROC_PRO_FOR_FT90x__
97-
static union both
98-
{
99-
struct flt
100-
{
101-
unsigned char mant[2];
102-
unsigned hmant:7;
103-
unsigned exp:8;
104-
unsigned sign:1;
105-
106-
} flt;
107-
double fl;
108-
};
109-
110-
//--------------
111-
static double _frexp(double value, int * eptr) {
112-
union both uv;
113-
volatile int bb;
114-
115-
uv.fl = value;
116-
bb = uv.flt.exp - 126;
117-
*eptr = bb;
118-
uv.flt.exp = 126;
119-
return uv.fl;
120-
121-
}
122-
123-
//--------------
124-
static double _ldexp(double value, int newexp) {
125-
union both uv;
126-
127-
uv.fl = value;
128-
newexp += uv.flt.exp;
129-
if (newexp < 0)
130-
return 0.0;
131-
else
132-
if (newexp > 255)
133-
if (value < 0.0)
134-
return -_DBL_MAX_;
135-
else
136-
return _DBL_MAX_;
137-
else
138-
uv.flt.exp = newexp;
139-
return uv.fl;
140-
141-
}
142-
#endif
143-
144-
#if defined __MIKROC_PRO_FOR_PIC__
145-
static double _frexp(double value, int * eptr)
146-
{
147-
char * pom;
148-
pom = &value;
149-
*eptr = pom[3] - 126;
150-
pom[3] = 126;
151-
return value;
152-
}
153-
154-
static double _ldexp(double value, int newexp)
155-
{
156-
char * pom;
157-
pom = &value;
158-
newexp += pom[3];
159-
if (newexp < 0)
160-
return 0.0;
161-
else if (newexp > 255)
162-
if (value < 0.0)
163-
return -_DBL_MAX_;
164-
else
165-
return _DBL_MAX_;
166-
else
167-
pom[3] = newexp;
168-
return value;
169-
}
170-
#endif
17185

172-
173-
static double _floor(double x) {
174-
double i;
175-
int expon;
176-
177-
expon = ((*(unsigned long *)&x >> 23) & 255);
178-
expon = expon- 127;
179-
if(expon < 0)
180-
if (x < 0.0)
181-
return -1.0;
182-
else
183-
return 0.0;
184-
if((unsigned)expon > sizeof(double) * 8 - 8)
185-
return x; /* already an integer */
186-
i = _FRNDINT(x);
187-
188-
if(i > x)
189-
return i - 1.0;
190-
return i;
191-
}
192-
193-
194-
static double _eval_poly(double x, const double code * d, int n) {
195-
double res;
196-
197-
res = d[n];
198-
while(n)
199-
res = x * res + d[--n];
200-
201-
return res;
202-
}
203-
204-
static double _exp(double x) {
205-
int exp;
206-
char sign;
207-
208-
const static double coeff[] = {
209-
1.0000000000e+00,
210-
6.9314718056e-01,
211-
2.4022650695e-01,
212-
5.5504108945e-02,
213-
9.6181261779e-03,
214-
1.3333710529e-03,
215-
1.5399104432e-04,
216-
1.5327675257e-05,
217-
1.2485143336e-06,
218-
1.3908092221e-07,
219-
};
220-
221-
if(x == 0.0)
222-
return 1.0;
223-
if (x > 89.416) //too big?
224-
return _DBL_MAX_;
225-
if (x < -87.33655) //too small?
226-
return 0.0;
227-
sign = x < 0.0;
228-
if(sign)
229-
x = -x;
230-
x *= 1.4426950409; // convert to log2 //
231-
exp = (int)_floor(x);
232-
x -= (double)exp;
233-
x = _ldexp(_eval_poly(x, coeff, sizeof coeff/sizeof coeff[0] - 1), exp);
234-
if(sign) {
235-
if (x == _DBL_MAX_)
236-
return 0.0;
237-
return 1.0/x;
238-
}
239-
return x;
240-
}
241-
242-
243-
//-------------- Returns natural logarithm of given argument - ln(x)
244-
static double _log(double x) {
245-
int exp;
246-
static const double coeff[] = {
247-
0.0000000001, // a0 //
248-
0.9999964239, // a1 //
249-
-0.4998741238, // a2 //
250-
0.3317990258, // a3 //
251-
-0.2407338084, // a4 //
252-
0.1676540711, // a5 //
253-
-0.0953293897, // a6 //
254-
0.0360884937, // a7 //
255-
-0.0064535442, // a8 //
256-
};
257-
258-
// zero or -ve arguments are not defined //
259-
260-
if(x <= 0.0)
261-
return 0.0;
262-
x = _frexp(x, &exp) * 2.0 - 1.0;
263-
exp--;
264-
x = _eval_poly(x, coeff, sizeof coeff/sizeof coeff[0] - 1);
265-
return x + 0.69314718055995 * exp;
266-
//return x + 0.68768932874451 * exp;
267-
}
268-
269-
//-------------- Returns argument x raised to power of argument y
270-
static double _myPow(double x, double y) {
271-
unsigned char sign = 0; // Promenjeno unsigned int u
272-
// unsigned char (optimizacija) MZ 11.08.2008.
273-
long yi;
274-
275-
if(y == 0.0)
276-
return 1.0;
277-
if(x == 0.0)
278-
return 0.0;
279-
if(x < 0.0) {
280-
yi = (long)y;
281-
if((double)yi != y)
282-
return 0.0;
283-
sign = yi & 1;
284-
x = -x;
285-
}
286-
x = _log(x);
287-
x = x*y;
288-
x = _exp(x);
289-
290-
if(sign)
291-
return -x;
292-
return x;
293-
}
86+
/* --------------------------------------------- PRIVATE FUNCTION DEFINITIONS */
29487

29588

29689

library/__airq5_driver.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -192,40 +192,6 @@ uint16_t airq5_readSensorData(uint16_t channel_data);
192192
*/
193193
uint8_t airq5_getInterrupt();
194194

195-
/**
196-
* @brief Functions for calculation NO2 sensor data
197-
*
198-
* @param[in] NO2_Data NO2 data which be calculation
199-
* @retval NO2 data in ppm
200-
*/
201-
float airq5_getNO2Data(uint16_t NO2_data);
202-
203-
/**
204-
* @brief Functions for calculation CO sensor data
205-
*
206-
* @param[in] CO_Data CO data which be calculation
207-
* @param[out] dataBuffer Buffer in which data is stored
208-
*
209-
* Data Buffer:
210-
- dataBuffer[0] - CO in ppm
211-
- dataBuffer[1] - CH4 in ppm
212-
- dataBuffer[2] - H2 in ppm
213-
- dataBuffer[3] - C2H5OH in ppm
214-
*/
215-
void airq5_getCOData(uint16_t CO_Data, float *dataBuffer);
216-
217-
/**
218-
* @brief Functions for calculation NH3 sensor data
219-
*
220-
* @param[in] NH3_Data NH3 data which be calculation
221-
* @param[out] dataBuffer Buffer in which data is stored
222-
*
223-
* Data Buffer:
224-
- dataBuffer[0] - NH3 in ppm
225-
- dataBuffer[1] - C3H8 in ppm
226-
- dataBuffer[2] - C4H10 in ppm
227-
*/
228-
void airq5_getNH3Data(uint16_t NH3_Data, float *dataBuffer);
229195

230196

231197

0 commit comments

Comments
 (0)