Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (58 loc) · 1.91 KB
/
Copy pathmain.cpp
File metadata and controls
78 lines (58 loc) · 1.91 KB
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
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*/
// ---------------------------- Réponses Communiquer avec le capteur ---------------------------- //
/*
Procédure de lecture de la mesure par le capteur (UART) pour la Zest Sensor Dust
UART donc pas d'adresse de registre
=> Start Particle measurement
- send : 0x68 - 0x01 - 0x01 - data sur 1 octet
- response (ACK) : 0xA5A5
=> Read Particule Measuring
- send : 0x68 - 0x01 - 0x04 - data sur 1 octet
- response (ACK): 0x40 - 0x05 - 0x04 - data sur 5 octets
=> Stop particule measurement
- send : 0x68 - 0x01 - 0x02 - data sur 1 octet
- response (ACK) : 0xA5A5
*/
#include "hpma115/hpma115.h"
#include "mbed.h"
namespace {
#define WAIT 1s
}
using namespace sixtron;
static DigitalOut led(LED1);
static hpma115_data_t data;
int main()
{
uint8_t coef;
HPMA115::ErrorType err;
HPMA115 sensor(P1_UART_TX, P1_UART_RX);
printf("\n\n------------\nHPMA115 Example\n");
err = sensor.stop_measurement();
assert(err == HPMA115::ErrorType::Ok);
err = sensor.stop_autosend();
assert(err == HPMA115::ErrorType::Ok);
err = sensor.set_adjust_coef(200);
assert(err == HPMA115::ErrorType::Ok);
err = sensor.read_adjust_coef(&coef);
assert(err == HPMA115::ErrorType::Ok);
assert(coef == 200);
err = sensor.set_adjust_coef(100);
assert(err == HPMA115::ErrorType::Ok);
err = sensor.start_measurement();
assert(err == HPMA115::ErrorType::Ok);
while (true) {
led = !led;
err = sensor.read_measurement(&data);
if (err == HPMA115::ErrorType::Ok) {
printf("Data: ");
if (data.pm1_pm4_valid) {
printf("PM1.0: %d, PM4.0: %d ", data.pm1_0, data.pm4_0);
}
printf("PM10: %d, PM2.5: %d\n", data.pm10, data.pm2_5);
}
ThisThread::sleep_for(WAIT);
}
}