Procházet zdrojové kódy

mhz16: fixed JS/Python examples to match driver API

Signed-off-by: Zion Orent <zorent@ics.com>
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Zion Orent před 9 roky
rodič
revize
d04f93ffca
2 změnil soubory, kde provedl 16 přidání a 16 odebrání
  1. 9
    8
      examples/javascript/mhz16.js
  2. 7
    8
      examples/python/mhz16.py

+ 9
- 8
examples/javascript/mhz16.js Zobrazit soubor

@@ -47,16 +47,17 @@ console.log(outputStr);
47 47
 outputStr = "but rather the temperature of the sensor elements.";
48 48
 console.log(outputStr);
49 49
 
50
-var gas = CO2_lib.new_intp();
51
-var temp = CO2_lib.new_intp();
52
-
53 50
 function writeCO2data()
54 51
 {
55
-	myCO2_obj.getData(gas, temp);
56
-	outputStr = "CO2 concentration: " + CO2_lib.intp_value(gas) +
57
-	" PPM, " +
58
-	"Temperature (in C): " + CO2_lib.intp_value(temp);
59
-	console.log(outputStr);	
52
+	if (!myCO2_obj.getData())
53
+		console.log("Failed to retrieve data");
54
+	else
55
+	{
56
+		outputStr = "CO2 concentration: " + myCO2_obj.getGas() +
57
+		" PPM, " +
58
+		"Temperature (in C): " + myCO2_obj.getTemperature();
59
+		console.log(outputStr);
60
+	}
60 61
 }
61 62
 var myInterval;
62 63
 setTimeout(function()

+ 7
- 8
examples/python/mhz16.py Zobrazit soubor

@@ -56,16 +56,15 @@ print ("Make sure that the sensor has had "
56 56
 "The temperature reported is not the ambient temperature,\n"
57 57
 "but rather the temperature of the sensor elements.")
58 58
 
59
-gas = upmMhz16.new_intp()
60
-temp = upmMhz16.new_intp()
61
-
62 59
 time.sleep(1)
63 60
 
64 61
 while(1):
65
-	myCO2.getData(gas, temp)
66
-	outputStr = ("CO2 concentration: {0} PPM, "
67
-	"Temperature (in C): {1}".format(
68
-	upmMhz16.intp_value(gas), upmMhz16.intp_value(temp)))
69
-	print outputStr
62
+	if (not myCO2.getData()):
63
+		print "Failed to retrieve data"
64
+	else:
65
+		outputStr = ("CO2 concentration: {0} PPM, "
66
+		"Temperature (in C): {1}".format(
67
+		myCO2.getGas(), myCO2.getTemperature()))
68
+		print outputStr
70 69
 
71 70
 	time.sleep(2)