diff --git a/examples/python/gas/mq2.py b/examples/python/gas/mq2.py new file mode 100644 index 00000000..3073fda1 --- /dev/null +++ b/examples/python/gas/mq2.py @@ -0,0 +1,62 @@ +#!/usr/bin/python +# Author: Zion Orent +# Copyright (c) 2015 Intel Corporation. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +import time, sys, signal, atexit +import pyupm_gas as upmGas + +# Attach gas sensor to AIO0 +myMQ2 = upmGas.MQ2(0); + + +## Exit handlers ## +# This function stops python from printing a stacktrace when you hit control-C +def SIGINTHandler(signum, frame): + raise SystemExit + +# This function lets you run code on exit, including functions from myMQ2 +def exitHandler(): + print "Exiting" + sys.exit(0) + +# Register exit handlers +atexit.register(exitHandler) +signal.signal(signal.SIGINT, SIGINTHandler) + + +threshContext = upmGas.thresholdContext() +threshContext.averageReading = 0 +threshContext.runningAverage = 0 +threshContext.averagedOver = 2 + +# Infinite loop, ends when script is cancelled +# Repeatedly, take a sample every 2 microseconds; +# find the average of 128 samples; and +# print a running graph of dots as averages +mybuffer = upmGas.uint16Array(128) +while(1): + samplelen = myMQ2.getSampledWindow(2, 128, mybuffer) + if samplelen: + thresh = myMQ2.findThreshold(threshContext, 30, mybuffer, samplelen) + myMQ2.printGraph(threshContext, 5) + if(thresh): + print "Threshold is ", thresh diff --git a/examples/python/gas/mq3.py b/examples/python/gas/mq3.py new file mode 100644 index 00000000..c464cfc3 --- /dev/null +++ b/examples/python/gas/mq3.py @@ -0,0 +1,62 @@ +#!/usr/bin/python +# Author: Zion Orent +# Copyright (c) 2015 Intel Corporation. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +import time, sys, signal, atexit +import pyupm_gas as upmGas + +# Attach gas sensor to AIO0 +myMQ3 = upmGas.MQ3(0) + + +## Exit handlers ## +# This function stops python from printing a stacktrace when you hit control-C +def SIGINTHandler(signum, frame): + raise SystemExit + +# This function lets you run code on exit, including functions from myMQ3 +def exitHandler(): + print "Exiting" + sys.exit(0) + +# Register exit handlers +atexit.register(exitHandler) +signal.signal(signal.SIGINT, SIGINTHandler) + + +threshContext = upmGas.thresholdContext() +threshContext.averageReading = 0 +threshContext.runningAverage = 0 +threshContext.averagedOver = 2 + +# Infinite loop, ends when script is cancelled +# Repeatedly, take a sample every 2 microseconds; +# find the average of 128 samples; and +# print a running graph of dots as averages +mybuffer = upmGas.uint16Array(128) +while(1): + samplelen = myMQ3.getSampledWindow(2, 128, mybuffer) + if samplelen: + thresh = myMQ3.findThreshold(threshContext, 30, mybuffer, samplelen) + myMQ3.printGraph(threshContext, 5) + if(thresh): + print "Threshold is ", thresh diff --git a/examples/python/gas/mq5.py b/examples/python/gas/mq5.py new file mode 100644 index 00000000..5e7deb84 --- /dev/null +++ b/examples/python/gas/mq5.py @@ -0,0 +1,62 @@ +#!/usr/bin/python +# Author: Zion Orent +# Copyright (c) 2015 Intel Corporation. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +import time, sys, signal, atexit +import pyupm_gas as upmGas + +# Attach gas sensor to AIO0 +myMQ5 = upmGas.MQ5(0) + + +## Exit handlers ## +# This function stops python from printing a stacktrace when you hit control-C +def SIGINTHandler(signum, frame): + raise SystemExit + +# This function lets you run code on exit, including functions from myMQ5 +def exitHandler(): + print "Exiting" + sys.exit(0) + +# Register exit handlers +atexit.register(exitHandler) +signal.signal(signal.SIGINT, SIGINTHandler) + + +threshContext = upmGas.thresholdContext() +threshContext.averageReading = 0 +threshContext.runningAverage = 0 +threshContext.averagedOver = 2 + +# Infinite loop, ends when script is cancelled +# Repeatedly, take a sample every 2 microseconds; +# find the average of 128 samples; and +# print a running graph of dots as averages +mybuffer = upmGas.uint16Array(128) +while(1): + samplelen = myMQ5.getSampledWindow(2, 128, mybuffer) + if samplelen: + thresh = myMQ5.findThreshold(threshContext, 30, mybuffer, samplelen) + myMQ5.printGraph(threshContext, 5) + if(thresh): + print "Threshold is ", thresh diff --git a/examples/python/gas/mq9.py b/examples/python/gas/mq9.py new file mode 100644 index 00000000..f39cf396 --- /dev/null +++ b/examples/python/gas/mq9.py @@ -0,0 +1,62 @@ +#!/usr/bin/python +# Author: Zion Orent +# Copyright (c) 2015 Intel Corporation. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +import time, sys, signal, atexit +import pyupm_gas as upmGas + +# Attach gas sensor to AIO0 +myMQ9 = upmGas.MQ9(0) + + +## Exit handlers ## +# This function stops python from printing a stacktrace when you hit control-C +def SIGINTHandler(signum, frame): + raise SystemExit + +# This function lets you run code on exit, including functions from myMQ9 +def exitHandler(): + print "Exiting" + sys.exit(0) + +# Register exit handlers +atexit.register(exitHandler) +signal.signal(signal.SIGINT, SIGINTHandler) + + +threshContext = upmGas.thresholdContext() +threshContext.averageReading = 0 +threshContext.runningAverage = 0 +threshContext.averagedOver = 2 + +# Infinite loop, ends when script is cancelled +# Repeatedly, take a sample every 2 microseconds; +# find the average of 128 samples; and +# print a running graph of dots as averages +mybuffer = upmGas.uint16Array(128) +while(1): + samplelen = myMQ9.getSampledWindow(2, 128, mybuffer) + if samplelen: + thresh = myMQ9.findThreshold(threshContext, 30, mybuffer, samplelen) + myMQ9.printGraph(threshContext, 5) + if(thresh): + print "Threshold is ", thresh diff --git a/src/gas/pyupm_gas.i b/src/gas/pyupm_gas.i index 5b419962..41826c67 100644 --- a/src/gas/pyupm_gas.i +++ b/src/gas/pyupm_gas.i @@ -2,7 +2,11 @@ %include "../upm.i" %include "../carrays_uint16_t.i" -%include "stdint.i" +%typemap(in) uint16_t * { + void *argp = 0 ; + int res = SWIG_ConvertPtr($input, &argp,SWIGTYPE_p_uint16Array, 0 | 0 ); + $1 = reinterpret_cast< uint16_t * >(argp); +} %feature("autodoc", "3");