mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
mhz16: Split the getData(int* gas, int *temp) function into two separate functions and updated the C++ an Java examples
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:

committed by
Mihai Tudor Panu

parent
f8a105adbf
commit
7f7fdb8441
@ -62,14 +62,15 @@ int main (int argc, char **argv)
|
||||
|
||||
sleep(1);
|
||||
|
||||
int gas;
|
||||
int temp;
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
co2->getData(&gas, &temp);
|
||||
cout << "CO2 concentration: " << gas << " PPM, "
|
||||
<< "Temperature (in C): " << temp <<endl;
|
||||
if(!co2->getData()){
|
||||
cerr << "Failed to retrieve data" << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
cout << "CO2 concentration: " << co2->getGas() << " PPM, "
|
||||
<< "Temperature (in C): " << co2->getTemperature() <<endl;
|
||||
|
||||
sleep(2);
|
||||
}
|
||||
|
@ -36,9 +36,6 @@ public class MHZ16Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
int[] gas = new int[1];
|
||||
int[] temp = new int[1];
|
||||
|
||||
// Instantiate a MHZ16 serial CO2 sensor on uart 0.
|
||||
upm_mhz16.MHZ16 co2 = new upm_mhz16.MHZ16(0);
|
||||
|
||||
@ -48,9 +45,12 @@ public class MHZ16Sample {
|
||||
System.out.println("but rather the temperature of the sensor elements.");
|
||||
|
||||
while (true) {
|
||||
co2.getData(gas, temp);
|
||||
System.out.println("CO2 concentration: " + gas[0] + "PPM, Temperature (in C): "
|
||||
+ temp[0]);
|
||||
if (!co2.getData()) {
|
||||
System.out.println("Failed to retrieve data");
|
||||
continue;
|
||||
}
|
||||
System.out.println("CO2 concentration: " + co2.getGas() + "PPM, Temperature (in C): "
|
||||
+ co2.getTemperature());
|
||||
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
|
Reference in New Issue
Block a user