-
Notifications
You must be signed in to change notification settings - Fork 1
/
sen66_i2c.c
680 lines (645 loc) · 26.3 KB
/
sen66_i2c.c
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
/*
* THIS FILE IS AUTOMATICALLY GENERATED
*
* Generator: sensirion-driver-generator 1.0.1
* Product: sen66
* Model-Version: 1.3.0
*/
/*
* Copyright (c) 2024, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Sensirion AG nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "sen66_i2c.h"
#include "sensirion_common.h"
#include "sensirion_i2c.h"
#include "sensirion_i2c_hal.h"
#define sensirion_hal_sleep_us sensirion_i2c_hal_sleep_usec
static uint8_t communication_buffer[48] = {0};
static uint8_t _i2c_address;
void sen66_init(uint8_t i2c_address) {
_i2c_address = i2c_address;
}
uint16_t sen66_signal_co2(uint16_t co2_raw) {
uint16_t co2 = 0;
co2 = co2_raw;
return co2;
}
int16_t sen66_start_continuous_measurement() {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x21);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(50 * 1000);
return local_error;
}
int16_t sen66_stop_measurement() {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x104);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(1000 * 1000);
return local_error;
}
int16_t sen66_get_data_ready(uint8_t* padding, bool* data_ready) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x202);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
if (local_error != NO_ERROR) {
return local_error;
}
*padding = (uint8_t)buffer_ptr[0];
*data_ready = (bool)buffer_ptr[1];
return local_error;
}
int16_t sen66_read_measured_values_as_integers(
uint16_t* mass_concentration_pm1p0, uint16_t* mass_concentration_pm2p5,
uint16_t* mass_concentration_pm4p0, uint16_t* mass_concentration_pm10p0,
int16_t* ambient_humidity, int16_t* ambient_temperature, int16_t* voc_index,
int16_t* nox_index, uint16_t* co2) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x300);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 18);
if (local_error != NO_ERROR) {
return local_error;
}
*mass_concentration_pm1p0 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
*mass_concentration_pm2p5 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[2]);
*mass_concentration_pm4p0 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[4]);
*mass_concentration_pm10p0 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[6]);
*ambient_humidity = sensirion_common_bytes_to_int16_t(&buffer_ptr[8]);
*ambient_temperature = sensirion_common_bytes_to_int16_t(&buffer_ptr[10]);
*voc_index = sensirion_common_bytes_to_int16_t(&buffer_ptr[12]);
*nox_index = sensirion_common_bytes_to_int16_t(&buffer_ptr[14]);
*co2 = sensirion_common_bytes_to_uint16_t(&buffer_ptr[16]);
return local_error;
}
int16_t sen66_read_number_concentration_values_as_integers(
uint16_t* number_concentration_pm0p5, uint16_t* number_concentration_pm1p0,
uint16_t* number_concentration_pm2p5, uint16_t* number_concentration_pm4p0,
uint16_t* number_concentration_pm10p0) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x316);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 10);
if (local_error != NO_ERROR) {
return local_error;
}
*number_concentration_pm0p5 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
*number_concentration_pm1p0 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[2]);
*number_concentration_pm2p5 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[4]);
*number_concentration_pm4p0 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[6]);
*number_concentration_pm10p0 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[8]);
return local_error;
}
int16_t sen66_read_measured_raw_values(int16_t* raw_humidity,
int16_t* raw_temperature,
uint16_t* raw_voc, uint16_t* raw_nox,
uint16_t* raw_co2) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x405);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 10);
if (local_error != NO_ERROR) {
return local_error;
}
*raw_humidity = sensirion_common_bytes_to_int16_t(&buffer_ptr[0]);
*raw_temperature = sensirion_common_bytes_to_int16_t(&buffer_ptr[2]);
*raw_voc = sensirion_common_bytes_to_uint16_t(&buffer_ptr[4]);
*raw_nox = sensirion_common_bytes_to_uint16_t(&buffer_ptr[6]);
*raw_co2 = sensirion_common_bytes_to_uint16_t(&buffer_ptr[8]);
return local_error;
}
int16_t sen66_start_fan_cleaning() {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x5607);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_set_temperature_offset_parameters(int16_t offset, int16_t slope,
uint16_t time_constant,
uint16_t slot) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x60b2);
local_offset =
sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset, offset);
local_offset =
sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset, slope);
local_offset = sensirion_i2c_add_uint16_t_to_buffer(
buffer_ptr, local_offset, time_constant);
local_offset =
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, slot);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_set_voc_algorithm_tuning_parameters(
int16_t index_offset, int16_t learning_time_offset_hours,
int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes,
int16_t std_initial, int16_t gain_factor) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x60d0);
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
index_offset);
local_offset = sensirion_i2c_add_int16_t_to_buffer(
buffer_ptr, local_offset, learning_time_offset_hours);
local_offset = sensirion_i2c_add_int16_t_to_buffer(
buffer_ptr, local_offset, learning_time_gain_hours);
local_offset = sensirion_i2c_add_int16_t_to_buffer(
buffer_ptr, local_offset, gating_max_duration_minutes);
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
std_initial);
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
gain_factor);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_get_voc_algorithm_tuning_parameters(
int16_t* index_offset, int16_t* learning_time_offset_hours,
int16_t* learning_time_gain_hours, int16_t* gating_max_duration_minutes,
int16_t* std_initial, int16_t* gain_factor) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x60d0);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 12);
if (local_error != NO_ERROR) {
return local_error;
}
*index_offset = sensirion_common_bytes_to_int16_t(&buffer_ptr[0]);
*learning_time_offset_hours =
sensirion_common_bytes_to_int16_t(&buffer_ptr[2]);
*learning_time_gain_hours =
sensirion_common_bytes_to_int16_t(&buffer_ptr[4]);
*gating_max_duration_minutes =
sensirion_common_bytes_to_int16_t(&buffer_ptr[6]);
*std_initial = sensirion_common_bytes_to_int16_t(&buffer_ptr[8]);
*gain_factor = sensirion_common_bytes_to_int16_t(&buffer_ptr[10]);
return local_error;
}
int16_t sen66_set_nox_algorithm_tuning_parameters(
int16_t index_offset, int16_t learning_time_offset_hours,
int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes,
int16_t std_initial, int16_t gain_factor) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x60e1);
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
index_offset);
local_offset = sensirion_i2c_add_int16_t_to_buffer(
buffer_ptr, local_offset, learning_time_offset_hours);
local_offset = sensirion_i2c_add_int16_t_to_buffer(
buffer_ptr, local_offset, learning_time_gain_hours);
local_offset = sensirion_i2c_add_int16_t_to_buffer(
buffer_ptr, local_offset, gating_max_duration_minutes);
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
std_initial);
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
gain_factor);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_get_nox_algorithm_tuning_parameters(
int16_t* index_offset, int16_t* learning_time_offset_hours,
int16_t* learning_time_gain_hours, int16_t* gating_max_duration_minutes,
int16_t* std_initial, int16_t* gain_factor) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x60e1);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 12);
if (local_error != NO_ERROR) {
return local_error;
}
*index_offset = sensirion_common_bytes_to_int16_t(&buffer_ptr[0]);
*learning_time_offset_hours =
sensirion_common_bytes_to_int16_t(&buffer_ptr[2]);
*learning_time_gain_hours =
sensirion_common_bytes_to_int16_t(&buffer_ptr[4]);
*gating_max_duration_minutes =
sensirion_common_bytes_to_int16_t(&buffer_ptr[6]);
*std_initial = sensirion_common_bytes_to_int16_t(&buffer_ptr[8]);
*gain_factor = sensirion_common_bytes_to_int16_t(&buffer_ptr[10]);
return local_error;
}
int16_t sen66_set_temperature_acceleration_parameters(uint16_t k, uint16_t p,
uint16_t t1,
uint16_t t2) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6100);
local_offset =
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, k);
local_offset =
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, p);
local_offset =
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, t1);
local_offset =
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, t2);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_set_voc_algorithm_state(const uint8_t* state,
uint16_t state_size) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6181);
sensirion_i2c_add_bytes_to_buffer(buffer_ptr, local_offset, state,
state_size);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
return local_error;
}
int16_t sen66_get_voc_algorithm_state(uint8_t* state, uint16_t state_size) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6181);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 8);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_common_copy_bytes(&buffer_ptr[0], (uint8_t*)state, state_size);
return local_error;
}
int16_t
sen66_perform_forced_co2_recalibration(uint16_t target_co2_concentration,
uint16_t* correction) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6707);
local_offset = sensirion_i2c_add_uint16_t_to_buffer(
buffer_ptr, local_offset, target_co2_concentration);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(500 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
if (local_error != NO_ERROR) {
return local_error;
}
*correction = sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
return local_error;
}
int16_t sen66_set_co2_sensor_automatic_self_calibration(uint16_t status) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6711);
local_offset =
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, status);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_get_co2_sensor_automatic_self_calibration(uint8_t* padding,
bool* status) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6711);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
if (local_error != NO_ERROR) {
return local_error;
}
*padding = (uint8_t)buffer_ptr[0];
*status = (bool)buffer_ptr[1];
return local_error;
}
int16_t sen66_set_ambient_pressure(uint16_t ambient_pressure) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6720);
local_offset = sensirion_i2c_add_uint16_t_to_buffer(
buffer_ptr, local_offset, ambient_pressure);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_get_ambient_pressure(uint16_t* ambient_pressure) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6720);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
if (local_error != NO_ERROR) {
return local_error;
}
*ambient_pressure = sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
return local_error;
}
int16_t sen66_set_sensor_altitude(uint16_t altitude) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6736);
local_offset = sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr,
local_offset, altitude);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_get_sensor_altitude(uint16_t* altitude) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6736);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
if (local_error != NO_ERROR) {
return local_error;
}
*altitude = sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
return local_error;
}
int16_t sen66_activate_sht_heater() {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6765);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(1300 * 1000);
return local_error;
}
int16_t sen66_get_product_name(uint8_t* product_name,
uint16_t product_name_size) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0xd014);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 32);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_common_copy_bytes(&buffer_ptr[0], (uint8_t*)product_name,
product_name_size);
return local_error;
}
int16_t sen66_get_serial_number(uint8_t* serial_number,
uint16_t serial_number_size) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0xd033);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 32);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_common_copy_bytes(&buffer_ptr[0], (uint8_t*)serial_number,
serial_number_size);
return local_error;
}
int16_t sen66_read_device_status(sen66_device_status* device_status) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0xd206);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 4);
if (local_error != NO_ERROR) {
return local_error;
}
(*device_status).value = sensirion_common_bytes_to_uint32_t(&buffer_ptr[0]);
return local_error;
}
int16_t sen66_read_and_clear_device_status(sen66_device_status* device_status) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0xd210);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 4);
if (local_error != NO_ERROR) {
return local_error;
}
(*device_status).value = sensirion_common_bytes_to_uint32_t(&buffer_ptr[0]);
return local_error;
}
int16_t sen66_device_reset() {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0xd304);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(1200 * 1000);
return local_error;
}