[Armadeus-commitlog] armadeus branch, master, updated. release-3.2-263-g2043bcd
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2010-03-23 17:03:29
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via 2043bcd322d66bda218d4d5680bb48d27f52de5e (commit)
via 171ab54e7daef05f67d233fb15181b94d5301640 (commit)
via c9c1377c7b7f9c7a035aa278ed72d41acecd9bc4 (commit)
via a5030c18dc1c7211c5d7c44bfc1770ef5f0b8744 (commit)
from 64b9be3b70e37014e7529bb4f1eca33971591dff (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 2043bcd322d66bda218d4d5680bb48d27f52de5e
Author: Fabien Marteau <fab...@ar...>
Date: Tue Mar 23 18:02:54 2010 +0100
[buildroot] adding python wrapper in menu
commit 171ab54e7daef05f67d233fb15181b94d5301640
Author: Fabien Marteau <fab...@ar...>
Date: Tue Mar 23 18:02:26 2010 +0100
[as_devices] python class asgpio in progress
commit c9c1377c7b7f9c7a035aa278ed72d41acecd9bc4
Author: Fabien Marteau <fab...@ar...>
Date: Tue Mar 23 16:30:37 2010 +0100
[as_devices] Adding python gpio multiton class
commit a5030c18dc1c7211c5d7c44bfc1770ef5f0b8744
Author: Fabien Marteau <fab...@ar...>
Date: Tue Mar 23 15:23:59 2010 +0100
[as_devices] Compiling gpio python wrapper low level api
-----------------------------------------------------------------------
Summary of changes:
buildroot/package/armadeus/as_devices/Config.in | 14 +-
.../packages/as_devices/python/AsDevices/AsGpio.py | 107 +++++++++++++
.../as_devices/python/AsDevices/__init__.py | 2 +-
.../python/AsDevices/wrappers/__init__.py | 2 +-
.../packages/as_devices/python/src/AsGpio_wrap.c | 165 +++++++++++++++++++-
.../packages/as_devices/python/src/AsGpio_wrap.h | 10 +-
6 files changed, 275 insertions(+), 25 deletions(-)
create mode 100644 target/packages/as_devices/python/AsDevices/AsGpio.py
diff --git a/buildroot/package/armadeus/as_devices/Config.in b/buildroot/package/armadeus/as_devices/Config.in
index 086825c..2bf8b2f 100644
--- a/buildroot/package/armadeus/as_devices/Config.in
+++ b/buildroot/package/armadeus/as_devices/Config.in
@@ -12,10 +12,10 @@ config BR2_PACKAGE_AS_DEVICES
# help
# C++ wrapper for as_devices library
#
-#config BR2_PACKAGE_AS_DEVICES_PYTHON
-# depends on BR2_PACKAGE_AS_DEVICES
-# depends on BR2_PACKAGE_PYTHON
-# bool "wrapper Python"
-# default n
-# help
-# Python wrapper for as_devices library. need python
+config BR2_PACKAGE_AS_DEVICES_PYTHON
+ depends on BR2_PACKAGE_AS_DEVICES
+ depends on BR2_PACKAGE_PYTHON
+ bool "wrapper Python"
+ default n
+ help
+ Python wrapper for as_devices library. need python
diff --git a/target/packages/as_devices/python/AsDevices/AsGpio.py b/target/packages/as_devices/python/AsDevices/AsGpio.py
new file mode 100644
index 0000000..2e09403
--- /dev/null
+++ b/target/packages/as_devices/python/AsDevices/AsGpio.py
@@ -0,0 +1,107 @@
+#! /usr/bin/python
+# -*- coding: utf-8 -*-
+#-----------------------------------------------------------------------------
+# Name: AsGpio.py
+# Purpose:
+# Author: Fabien Marteau <fab...@ar...>
+# Created: 23/03/2010
+#-----------------------------------------------------------------------------
+# Copyright (2008) Armadeus Systems
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+#-----------------------------------------------------------------------------
+
+__doc__ = "This class drive ARMadeus board GPIO"
+__version__ = "1.0.0"
+__versionTime__ = "23/03/2010"
+__author__ = "Fabien Marteau <fab...@ar...>"
+
+import wrappers.AsGpio_wrap as wrapper
+
+class AsGpioError(Exception):
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)
+
+class AsGpio:
+ """ Drive GPIO
+ """
+
+ # Dictionary of gpio multiton classes
+ __gpio = {}
+
+ ################################################################$
+ class __impl:
+ """ implementation
+ """
+ def __init__(self, port_letter):
+ self.__port_letter = port_letter
+ try:
+ self.__device = wrapper.gpio_open(self.__port_letter)
+ except Exception, e:
+ raise AsGpioError("Can't open GPIO "+str(self.__port_letter)+\
+ ": "+str(e))
+
+ def __del__(self):
+ try:
+ wrapper.gpio_close(self.__device)
+ except Exception, e:
+ raise AsGpioError(str(e))
+
+ def setPinDirection(self, aPinNum, aDirection):
+ """ Set period in us
+ \param aPinNum pin number
+ \param aDirection pin direction 0:input 1:output
+ """
+ try:
+ wrapper.setPinDirection(self.__device, aPinNum, aDirection)
+ except Exception, e:
+ raise AsGpioError(str(e))
+
+
+ ################################################################
+
+ @classmethod
+ def getInstance(cls, aPort_letter):
+ if type(aPort_letter)!=str:
+ raise Exception("port letter must be a character")
+ if ((aPort_letter[0] <= 'A') or (aPort_letter[0] >= 'Z')):
+ raise Exception("Port letter must be an UPPER case letter")
+
+ try:
+ return AsGpio.__gpio[aPort_letter[0]]
+ except KeyError:
+ AsGpio.__gpio[aPort_letter[0]] = cls.__impl(aPort_letter[0])
+
+ return AsGpio.__gpio[aPort_letter[0]]
+
+ def __init__(self):
+ """ Initialize pwm
+ """
+ raise Exception("This constructor is private")
+
+if __name__ == "__main__":
+ import os
+ def pressEnterToContinue():
+ print "Press enter to continue"
+ raw_input()
+ print "AsGpio class test\n"
+ print AsGpio.__doc__
+
+ portf = AsGpio.getInstance('F')
+ print str(portf)
+
diff --git a/target/packages/as_devices/python/AsDevices/__init__.py b/target/packages/as_devices/python/AsDevices/__init__.py
index 23d479a..72395c2 100644
--- a/target/packages/as_devices/python/AsDevices/__init__.py
+++ b/target/packages/as_devices/python/AsDevices/__init__.py
@@ -35,4 +35,4 @@ __versionTime__ = "08/10/2009"
__author__ = "Fabien Marteau <fab...@ar...>"
import wrappers
-from Apf27Pwm import *
+from AsGpio import *
diff --git a/target/packages/as_devices/python/AsDevices/wrappers/__init__.py b/target/packages/as_devices/python/AsDevices/wrappers/__init__.py
index 63fc282..a699242 100644
--- a/target/packages/as_devices/python/AsDevices/wrappers/__init__.py
+++ b/target/packages/as_devices/python/AsDevices/wrappers/__init__.py
@@ -34,5 +34,5 @@ __version__ = "1.0.0"
__versionTime__ = "08/10/2009"
__author__ = "Fabien Marteau <fab...@ar...>"
-import Apf27Pwm_wrap
+import AsGpio_wrap
diff --git a/target/packages/as_devices/python/src/AsGpio_wrap.c b/target/packages/as_devices/python/src/AsGpio_wrap.c
index 19821ec..482977c 100644
--- a/target/packages/as_devices/python/src/AsGpio_wrap.c
+++ b/target/packages/as_devices/python/src/AsGpio_wrap.c
@@ -21,8 +21,21 @@
#include "AsGpio_wrap.h"
#include "as_gpio.h"
+/* Methods definitions */
+static PyMethodDef AsGpio_wrap_methods[] = {
+ {"gpio_open", gpio_open, METH_VARARGS, "Initialize gpio"},
+ {"setPinDirection", setPinDirection, METH_VARARGS, "Set pin direction"},
+ {"setPinValue", setPinValue, METH_VARARGS, "Set pin value"},
+ {"getPinValue", getPinValue, METH_VARARGS, "Get pin value"},
+ {"gpio_close", gpio_close, METH_VARARGS, "Close gpio"},
+ {NULL, NULL, 0, NULL} /* Sentinel */
+};
+
/* Init module */
-//void initAsGpio();
+void initAsGpio_wrap() /* called on first import */
+{ /* name matter if called dynamically */
+ (void) Py_InitModule("AsGpio_wrap", AsGpio_wrap_methods); /* mod name, table ptr */
+}
/** @brief Initialize port access
* @param aPortChar character port in UPPER case
@@ -50,7 +63,7 @@ static PyObject * gpio_open(PyObject *self, PyObject *args)
"Initialization error. Is kernel module loaded ?");
return NULL;
}
- ret = Py_BuildValue("(c,i)",
+ ret = Py_BuildValue("((ci))",
dev->port_letter,
dev->fdev);
free(dev);
@@ -59,7 +72,7 @@ static PyObject * gpio_open(PyObject *self, PyObject *args)
/** @brief Set pin direction
*
- * @param (c,i) -> (aPort_letter, aFdev) as_gpio_device structure_list
+ * @param ((ci)) -> (aPort_letter, aFdev) as_gpio_device structure_list
* @param aPinNum pin number
* @param aDirection direction 0:input 1:output
*
@@ -78,7 +91,7 @@ static PyObject * setPinDirection(PyObject *self, PyObject *args)
int ret;
/* Get arguments */
- if (!PyArg_ParseTuple(args, "(c,i)ii",
+ if (!PyArg_ParseTuple(args, "((ci))ii",
&aPort_letter,
&aFdev,
&aPinNum,
@@ -111,18 +124,156 @@ static PyObject * setPinDirection(PyObject *self, PyObject *args)
return Py_BuildValue("i", ret);
}
+/** @brief Set pin value
+ *
+ * @param ((ci)) -> (aPort_letter, aFdev) as_gpio_device structure_list
+ * @param aPinNum pin number
+ * @param aValue value of pin (1 or 0)
+ *
+ * @return error if negative
+ */
static PyObject * setPinValue(PyObject *self, PyObject *args)
{
- return NULL;
+ /* parameters */
+ char aPort_letter;
+ int aFdev;
+
+ int aPinNum;
+ int aValue;
+
+ struct as_gpio_device *dev;
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "((ci))ii",
+ &aPort_letter,
+ &aFdev,
+ &aPinNum,
+ &aValue))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ dev = (struct as_gpio_device *)malloc(sizeof(struct as_gpio_device));
+ if (dev == NULL)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "memory allocation:Â can't malloc fdev structure");
+ return NULL;
+ }
+ dev->port_letter = aPort_letter;
+ dev->fdev = aFdev;
+
+ ret = as_gpio_set_pin_value(dev, aPinNum, aValue);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't set pin value");
+ return NULL;
+ }
+
+ free(dev);
+ return Py_BuildValue("i", ret);
+
}
+
+/** @brief Get pin value
+ *
+ * @param ((ci)) -> (aPort_letter, aFdev) as_gpio_device structure_list
+ * @param aPinNum pin number
+ *
+ * @return pin value if positive or null, error if negative
+ */
static PyObject * getPinValue(PyObject *self, PyObject *args)
{
- return NULL;
+ /* parameters */
+ char aPort_letter;
+ int aFdev;
+
+ int aPinNum;
+
+ struct as_gpio_device *dev;
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "((ci))i",
+ &aPort_letter,
+ &aFdev,
+ &aPinNum))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ dev = (struct as_gpio_device *)malloc(sizeof(struct as_gpio_device));
+ if (dev == NULL)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "memory allocation:Â can't malloc fdev structure");
+ return NULL;
+ }
+ dev->port_letter = aPort_letter;
+ dev->fdev = aFdev;
+
+ ret = as_gpio_get_pin_value(dev, aPinNum);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't get pin value");
+ return NULL;
+ }
+
+ free(dev);
+ return Py_BuildValue("i", ret);
}
+/** @brief Close port access
+ *
+ * @param ((ci)) -> (aPort_letter, aFdev) as_gpio_device structure_list
+ *
+ * @return pin value if positive or null, error if negative
+ */
static PyObject * gpio_close(PyObject *self, PyObject *args)
{
- return NULL;
+ /* parameters */
+ char aPort_letter;
+ int aFdev;
+
+ struct as_gpio_device *dev;
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "((ci))",
+ &aPort_letter,
+ &aFdev))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ dev = (struct as_gpio_device *)malloc(sizeof(struct as_gpio_device));
+ if (dev == NULL)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "memory allocation:Â can't malloc fdev structure");
+ return NULL;
+ }
+ dev->port_letter = aPort_letter;
+ dev->fdev = aFdev;
+
+ ret = as_gpio_close(dev);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't close port");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
}
diff --git a/target/packages/as_devices/python/src/AsGpio_wrap.h b/target/packages/as_devices/python/src/AsGpio_wrap.h
index 952062b..bf52ba6 100644
--- a/target/packages/as_devices/python/src/AsGpio_wrap.h
+++ b/target/packages/as_devices/python/src/AsGpio_wrap.h
@@ -22,7 +22,7 @@
#include <Python.h>
/* Init module */
-//void initAsGpio();
+void initAsGpio_wrap();
/*********************/
/* Functions wrapped */
@@ -35,11 +35,3 @@ static PyObject * getPinValue(PyObject *self, PyObject *args);
static PyObject * gpio_close(PyObject *self, PyObject *args);
-/* Methods definitions */
-static PyMethodDef AsGpio_wrap_Methods[] = {
- {"init", gpio_open, METH_VARARGS, "Initialize gpio"},
- {"setPinDirection", setPinDirection, METH_VARARGS, "Set pin direction"},
- {"setPinValue", setPinValue, METH_VARARGS, "Set pin value"},
- {"getPinValue", getPinValue, METH_VARARGS, "Get pin value"},
- {NULL, NULL, 0, NULL} /* Sentinel */
-};
hooks/post-receive
--
armadeus
|