Ver código fonte

Java: Adding example for Grove MQ9 Gas Sensor

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
Abhishek Malik 9 anos atrás
pai
commit
0586775ffc
1 arquivos alterados com 58 adições e 0 exclusões
  1. 58
    0
      examples/java/GroveMQ9.java

+ 58
- 0
examples/java/GroveMQ9.java Ver arquivo

@@ -0,0 +1,58 @@
1
+import upm_gas.Gas;
2
+import upm_gas.MQ2;
3
+import upm_gas.MQ3;
4
+import upm_gas.MQ4;
5
+import upm_gas.MQ5;
6
+import upm_gas.MQ6;
7
+import upm_gas.MQ7;
8
+import upm_gas.MQ8;
9
+import upm_gas.MQ9;
10
+import upm_gas.TP401;
11
+import upm_gas.thresholdContext;
12
+
13
+public class GroveMQ9 {
14
+
15
+	static {
16
+		try {
17
+			System.loadLibrary("javaupm_gas");
18
+			System.loadLibrary("mraajava");
19
+		} catch (UnsatisfiedLinkError e) {
20
+			System.err.println(
21
+					"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
22
+							e);
23
+			System.exit(1);
24
+		}
25
+	}
26
+
27
+	public static void main(String[] args) {
28
+		// TODO Auto-generated method stub
29
+		//! [Interesting]
30
+		// initialize the sensor on A0
31
+		MQ9 mq9 = new MQ9(0);
32
+
33
+		short[] buffer = new short[128];
34
+
35
+		thresholdContext context = new thresholdContext();
36
+
37
+		context.setAverageReading(0);
38
+		context.setRunningAverage(0);
39
+		context.setAveragedOver(2);
40
+
41
+		int len;
42
+		int thres;
43
+		while(true){
44
+			len = mq9.getSampledWindow((long)2, buffer);
45
+
46
+			if(len != 0){
47
+				thres = mq9.findThreshold(context, 30, buffer);
48
+				mq9.printGraph(context, (short)5);
49
+				if(thres != 0){
50
+					// do something
51
+					System.out.println("threshold is crossed");
52
+				}
53
+			}
54
+		}
55
+		//! [Interesting]
56
+	}
57
+
58
+}