[Armadeus-commitlog] armadeus branch, master, updated. release-3.3-362-g87a2308
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2011-02-23 14:08:19
|
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 87a23082a7e5186717b1cad0703c400c0520fbab (commit)
via 1084387623200c67ab17612eda301d50a4b35955 (commit)
via 46c17462a400e262f040a499f04cc0a10c5e7b68 (commit)
from 301f5550a43101957e80424f216bb9f77cf07052 (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 87a23082a7e5186717b1cad0703c400c0520fbab
Merge: 1084387623200c67ab17612eda301d50a4b35955 301f5550a43101957e80424f216bb9f77cf07052
Author: Fabien Marteau <fab...@ar...>
Date: Wed Feb 23 15:05:01 2011 +0100
Merge branch 'master' of ssh://armadeus.git.sourceforge.net/gitroot/armadeus/armadeus
commit 1084387623200c67ab17612eda301d50a4b35955
Author: Fabien Marteau <fab...@ar...>
Date: Wed Feb 23 15:04:04 2011 +0100
[as_devices] Adding i2c python class wrapper
commit 46c17462a400e262f040a499f04cc0a10c5e7b68
Author: Fabien Marteau <fab...@ar...>
Date: Wed Feb 23 14:31:08 2011 +0100
[as_devices] Suppress multiton implementation under python classes
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/Makefile | 5 +-
.../as_devices/python/AsDevices/Apf27Pwm.py | 286 ++++++------------
.../packages/as_devices/python/AsDevices/AsAdc.py | 64 +---
.../packages/as_devices/python/AsDevices/AsDac.py | 63 +---
.../packages/as_devices/python/AsDevices/AsGpio.py | 224 ++++++---------
.../packages/as_devices/python/AsDevices/AsI2c.py | 133 +++++++++
target/packages/as_devices/python/Makefile | 1 +
target/packages/as_devices/python/src/AsI2c_wrap.c | 310 ++++++++++++++++++++
.../python/src/{AsAdc_wrap.h => AsI2c_wrap.h} | 20 +-
9 files changed, 679 insertions(+), 427 deletions(-)
create mode 100644 target/packages/as_devices/python/AsDevices/AsI2c.py
create mode 100644 target/packages/as_devices/python/src/AsI2c_wrap.c
copy target/packages/as_devices/python/src/{AsAdc_wrap.h => AsI2c_wrap.h} (59%)
diff --git a/target/packages/as_devices/c/Makefile b/target/packages/as_devices/c/Makefile
index cba285c..1cb0161 100644
--- a/target/packages/as_devices/c/Makefile
+++ b/target/packages/as_devices/c/Makefile
@@ -13,14 +13,15 @@ OBJ += as_gpio_2_6_29.o
else
OBJ += as_gpio.o
endif
+OBJ += as_dac.o
+OBJ += as_adc.o
+
OBJ += as_93lcxx.o
OBJ += as_spi.o
OBJ += as_as1531.o
OBJ += as_max1027.o
OBJ += as_max5821.o
-OBJ += as_dac.o
OBJ += as_helpers.o
-OBJ += as_adc.o
LIBRARY=as_devices
LIB_VERS=1
diff --git a/target/packages/as_devices/python/AsDevices/Apf27Pwm.py b/target/packages/as_devices/python/AsDevices/Apf27Pwm.py
index ee34690..70284a3 100644
--- a/target/packages/as_devices/python/AsDevices/Apf27Pwm.py
+++ b/target/packages/as_devices/python/AsDevices/Apf27Pwm.py
@@ -29,15 +29,13 @@
#
#-----------------------------------------------------------------------------
-__doc__ = "This class drive pwm under apf27. It's implemented as a multiton"
+__doc__ = "This class drive pwm under apf27."
__version__ = "1.0.0"
__versionTime__ = "08/10/2009"
__author__ = "Fabien Marteau <fab...@ar...>"
import wrappers
-NUMBER_OF_PWM = 2
-
class Apf27PwmError(Exception):
def __init__(self, value):
self.value = value
@@ -47,197 +45,99 @@ class Apf27PwmError(Exception):
class Apf27Pwm:
""" Drive pwm on apf27
"""
-
- __pwm = [None for i in range(NUMBER_OF_PWM)]
-
- ################################################################$
- class __impl:
- """ implementation
+ def __init__(self, pwm_num):
+ self.__pwm_num = pwm_num
+ try:
+ self.wrapper = wrappers.Apf27Pwm_wrap
+ self.wrapper.init(self.__pwm_num)
+ except Exception, e:
+ raise Apf27PwmError("Can't init pwm "+str(self.__pwm_num)+\
+ ": "+str(e))
+
+ def __del__(self):
+ try:
+ self.wrapper.pwm_close(self.pwm_num)
+ except Exception, e:
+ raise Apf27PwmError(str(e))
+
+ def setFrequency(self, aFrequency):
+ """ Set frequency of pwm
+ \param aFrequency frequency in Hz
"""
- def __init__(self, pwm_num):
- self.__pwm_num = pwm_num
- try:
- self.wrapper = wrappers.Apf27Pwm_wrap
- self.wrapper.init(self.__pwm_num)
- except Exception, e:
- raise Apf27PwmError("Can't init pwm "+str(self.__pwm_num)+\
- ": "+str(e))
-
- def __del__(self):
- try:
- self.wrapper.pwm_close(self.pwm_num)
- except Exception, e:
- raise Apf27PwmError(str(e))
-
- def setFrequency(self, aFrequency):
- """ Set frequency of pwm
- \param aFrequency frequency in Hz
- """
- try:
- self.wrapper.setFrequency(self.__pwm_num, aFrequency)
- except Exception, e:
- raise Apf27PwmError(str(e))
-
- def getFrequency(self):
- """ Get frequency of pwm
- \return frequency in Hz
- """
- try:
- return self.wrapper.getFrequency(self.__pwm_num)
- except Exception, e:
- raise Apf27PwmError(str(e))
-
- def setPeriod(self, aPeriod):
- """ Set period in us
- \param aPeriod period in us
- """
- try:
- self.wrapper.setPeriod(self.__pwm_num, aPeriod)
- except Exception, e:
- raise Apf27PwmError(str(e))
-
- def getPeriod(self):
- """ Get period in us
- \return period in us
- """
- try:
- return self.wrapper.getPeriod(self.__pwm_num)
- except Exception, e:
- raise Apf27PwmError(str(e))
-
- def setDuty(self, aDuty):
- """ Set duty in 1/1000
- \param aDuty in 1/1000
- """
- try:
- self.wrapper.setDuty(self.__pwm_num, aDuty)
- except Exception, e:
- raise Apf27PwmError(str(e))
-
- def getDuty(self):
- """ Get duty in 1/1000
- \return duty in 1/1000
- """
- try:
- return self.wrapper.getDuty(self.__pwm_num)
- except Exception,e:
- raise Apf27PwmError(str(e))
-
- def activate(self, aEnable):
- """ Activate pwm
- \param aEnable if True enable, else disable
- \return aEnable
- """
- try:
- if aEnable:
- self.wrapper.activate(self.__pwm_num, 1)
- return True
- else:
- self.wrapper.activate(self.__pwm_num, 0)
- return False
- except Exception, e:
- raise Apf27PwmError(str(e))
-
- def getState(self):
- """ Get state of pwm
- \return boolean
- """
- try:
- if self.wrapper.getState(self.__pwm_num) == 1:
- return True
- else:
- return False
- except Exception, e:
- raise Apf27PwmError(str(e))
-
-
- ################################################################
-
- @classmethod
- def getInstance(cls, pwm_num):
- if type(pwm_num)!=int:
- raise Exception("pwm_num argunent must be 'int'")
- if pwm_num < 0:
- raise Exception("pwm_num must be positive")
- if pwm_num >= NUMBER_OF_PWM:
- raise Exception("There is no pwm number "+\
- str(pwm_num)+", max is "+str(NUMBER_OF_PWM-1))
- if Apf27Pwm.__pwm[pwm_num] is None:
- Apf27Pwm.__pwm[pwm_num] = cls.__impl(pwm_num)
-
- return Apf27Pwm.__pwm[pwm_num]
-
- def __init__(self):
- """ Initialize pwm
+ try:
+ self.wrapper.setFrequency(self.__pwm_num, aFrequency)
+ except Exception, e:
+ raise Apf27PwmError(str(e))
+
+ def getFrequency(self):
+ """ Get frequency of pwm
+ \return frequency in Hz
"""
- raise Exception("This constructor is private")
-
-if __name__ == "__main__":
- import os
- def pressEnterToContinue():
- print "Press enter to continue"
- raw_input()
-
- print "Apf27Pwm class test\n"
- print Apf27Pwm.__doc__
-
- pwm0 = Apf27Pwm.getInstance(0)
-
- keyInput = "0"
-
- while keyInput is not "q":
- os.system("clear")
- print "***********************************************"
- print "* Testing pwm python class *"
- print "***********************************************"
- print "Choose ('q' to quit):"
- print " 1) set Frequency"
- print " 2) get Frequency"
- print " 3) set Period"
- print " 4) get Period"
- print " 5) set Duty"
- print " 6) get Duty"
- print " 7) activate/desactivate"
- print " 8) get state"
- print "> ",
-
- keyInput = raw_input()
-
- if keyInput == "1" :
- print "Give frequency :",
- freq = raw_input()
- pwm0.setFrequency(int(freq,10))
- pressEnterToContinue()
- elif keyInput == "2" :
- print "Current pwm frequency is "+str(pwm0.getFrequency())
- pressEnterToContinue()
- elif keyInput == "3" :
- print "Give period :",
- period = raw_input()
- pwm0.setFrequency(int(period,10))
- pressEnterToContinue()
- elif keyInput == "4" :
- print "Current period is "+str(pwm0.getPeriod())
- pressEnterToContinue()
- elif keyInput == "5" :
- print "Give duty :",
- duty = raw_input()
- pwm0.setDuty(int(duty,10))
- pressEnterToContinue()
- elif keyInput == "6" :
- print "Current duty is "+str(pwm0.getDuty())
- pressEnterToContinue()
- elif keyInput == "7" :
- print "activate 'a' or desactivat 'd' ?",
- response = raw_input()
- if response == 'a':
- pwm0.activate(True)
+ try:
+ return self.wrapper.getFrequency(self.__pwm_num)
+ except Exception, e:
+ raise Apf27PwmError(str(e))
+
+ def setPeriod(self, aPeriod):
+ """ Set period in us
+ \param aPeriod period in us
+ """
+ try:
+ self.wrapper.setPeriod(self.__pwm_num, aPeriod)
+ except Exception, e:
+ raise Apf27PwmError(str(e))
+
+ def getPeriod(self):
+ """ Get period in us
+ \return period in us
+ """
+ try:
+ return self.wrapper.getPeriod(self.__pwm_num)
+ except Exception, e:
+ raise Apf27PwmError(str(e))
+
+ def setDuty(self, aDuty):
+ """ Set duty in 1/1000
+ \param aDuty in 1/1000
+ """
+ try:
+ self.wrapper.setDuty(self.__pwm_num, aDuty)
+ except Exception, e:
+ raise Apf27PwmError(str(e))
+
+ def getDuty(self):
+ """ Get duty in 1/1000
+ \return duty in 1/1000
+ """
+ try:
+ return self.wrapper.getDuty(self.__pwm_num)
+ except Exception,e:
+ raise Apf27PwmError(str(e))
+
+ def activate(self, aEnable):
+ """ Activate pwm
+ \param aEnable if True enable, else disable
+ \return aEnable
+ """
+ try:
+ if aEnable:
+ self.wrapper.activate(self.__pwm_num, 1)
+ return True
else:
- pwm0.activate(False)
- pressEnterToContinue()
- elif keyInput == "8" :
- if pwm0.getState():
- print "pwm is active"
+ self.wrapper.activate(self.__pwm_num, 0)
+ return False
+ except Exception, e:
+ raise Apf27PwmError(str(e))
+
+ def getState(self):
+ """ Get state of pwm
+ \return boolean
+ """
+ try:
+ if self.wrapper.getState(self.__pwm_num) == 1:
+ return True
else:
- print "pwm is inactive"
- pressEnterToContinue()
+ return False
+ except Exception, e:
+ raise Apf27PwmError(str(e))
+
diff --git a/target/packages/as_devices/python/AsDevices/AsAdc.py b/target/packages/as_devices/python/AsDevices/AsAdc.py
index 43bbb6c..11d54f5 100644
--- a/target/packages/as_devices/python/AsDevices/AsAdc.py
+++ b/target/packages/as_devices/python/AsDevices/AsAdc.py
@@ -45,56 +45,24 @@ class AsAdcError(Exception):
class AsAdc:
""" Drive adc
"""
-
- # Dictionary of adc multiton classes
- __adc = {}
-
- ################################################################
- class __impl:
- """ implementation
- """
- def __init__(self, aAdcType, aDeviceNum, aVRef):
- try:
- self.__device = wrapper.adc_open(aAdcType, aDeviceNum, aVRef)
- except Exception, e:
- raise AsAdcError("Can't open adc port type "+str(aAdcType)+\
- " num "+str(aDeviceNum))
-
- def __del__(self):
- try:
- wrapper.adc_close(self.__device)
- except Exception, e:
- pass
-
- def getValueInMillivolts(self, aChannel):
- """ Get value in millivolts
- """
- try:
- return wrapper.getValueInMillivolts(self.__device, aChannel)
- except Exception, e:
- raise AsAdcError(str(e))
-
- ################################################################
-
- @classmethod
- def getInstance(cls, aAdcType, aDeviceNum, aVRef):
+ def __init__(self, aAdcType, aDeviceNum, aVRef):
try:
- return AsAdc.__adc["%s:%d"%(aAdcType, aDeviceNum)]
- except KeyError:
- AsAdc.__adc["%s:%d"%(aAdcType, aDeviceNum)] =\
- cls.__impl(aAdcType, aDeviceNum, aVRef)
+ self.__device = wrapper.adc_open(aAdcType, aDeviceNum, aVRef)
+ except Exception, e:
+ raise AsAdcError("Can't open adc port type "+str(aAdcType)+\
+ " num "+str(aDeviceNum))
- return AsAdc.__adc["%s:%d"%(aAdcType, aDeviceNum)]
+ def __del__(self):
+ try:
+ wrapper.adc_close(self.__device)
+ except Exception, e:
+ pass
- def __init__(self):
- """ Initialize adc
+ def getValueInMillivolts(self, aChannel):
+ """ Get value in millivolts
"""
- raise Exception("This constructor is private, to instanciate object do:"+\
- "AsAdc.getInstance(adctype, deviceNum, vref)")
-
-if __name__ == "__main__":
- import os
- def pressEnterToContinue():
- print "Press enter to continue"
- raw_input()
+ try:
+ return wrapper.getValueInMillivolts(self.__device, aChannel)
+ except Exception, e:
+ raise AsAdcError(str(e))
diff --git a/target/packages/as_devices/python/AsDevices/AsDac.py b/target/packages/as_devices/python/AsDevices/AsDac.py
index 983345f..d235663 100644
--- a/target/packages/as_devices/python/AsDevices/AsDac.py
+++ b/target/packages/as_devices/python/AsDevices/AsDac.py
@@ -39,56 +39,25 @@ class AsDacError(Exception):
class AsDac:
""" Drive dac
"""
-
- # Dictionary of dac multiton classes
- __dac = {}
-
- ################################################################
- class __impl:
- """ implementation
- """
- def __init__(self, aDacType, aBusNumber, aAddress, aVRef):
- try:
- self.__device = wrapper.dac_open(aDacType, aBusNumber, aAddress, aVRef)
- except Exception, e:
- raise AsDacError("Can't open dac port type "+str(aDacType)+\
- " num "+str(aBusNumber))
-
- def __del__(self):
- try:
- wrapper.dac_close(self.__device)
- except Exception, e:
- pass
-
- def setValueInMillivolts(self, aChannel, aValue):
- """ Get value in millivolts
- """
- try:
- return wrapper.dac_setValueInMillivolts(self.__device, aChannel, aValue)
- except Exception, e:
- raise AsDacError(str(e))
-
- ################################################################
-
- @classmethod
- def getInstance(cls, aDacType, aBusNumber, aAddress, aVRef):
+ def __init__(self, aDacType, aBusNumber, aAddress, aVRef):
try:
- return AsDac.__dac["%s:%d-0x%02x"%(aDacType, aBusNumber, aAddress)]
- except KeyError:
- AsDac.__dac["%s:%d-0x%02x"%(aDacType, aBusNumber, aAddress)] =\
- cls.__impl(aDacType, aBusNumber, aAddress, aVRef)
+ self.__device = wrapper.dac_open(aDacType, aBusNumber, aAddress, aVRef)
+ except Exception, e:
+ raise AsDacError("Can't open dac port type "+str(aDacType)+\
+ " num "+str(aBusNumber))
- return AsDac.__dac["%s:%d-0x%02x"%(aDacType, aBusNumber, aAddress)]
+ def __del__(self):
+ try:
+ wrapper.dac_close(self.__device)
+ except Exception, e:
+ pass
- def __init__(self):
- """ Initialize dac
+ def setValueInMillivolts(self, aChannel, aValue):
+ """ Get value in millivolts
"""
- raise Exception("This constructor is private, to instanciate object do:"+\
- "AsDac.getInstance(dactype, busnumber, address, vref)")
+ try:
+ return wrapper.dac_setValueInMillivolts(self.__device, aChannel, aValue)
+ except Exception, e:
+ raise AsDacError(str(e))
-if __name__ == "__main__":
- import os
- def pressEnterToContinue():
- print "Press enter to continue"
- raw_input()
diff --git a/target/packages/as_devices/python/AsDevices/AsGpio.py b/target/packages/as_devices/python/AsDevices/AsGpio.py
index 9c9f357..2ea71c1 100644
--- a/target/packages/as_devices/python/AsDevices/AsGpio.py
+++ b/target/packages/as_devices/python/AsDevices/AsGpio.py
@@ -40,145 +40,103 @@ class AsGpioError(Exception):
class AsGpio:
""" Drive GPIO
"""
+ def __init__(self, aPortLetter, aPinNum):
+ try:
+ self.__device = wrapper.gpio_open(aPortLetter, aPinNum)
+ except Exception, e:
+ raise AsGpioError("Can't open GPIO port "+str(aPortLetter)+\
+ " pin "+str(aPinNum)+": "+str(e))
+
+ def __del__(self):
+ try:
+ wrapper.gpio_close(self.__device)
+ except Exception, e:
+ pass
+
+ def setPinDirection(self, aDirection):
+ """ Set period in us
+ \param aDirection pin direction 0:input 1:output
+ """
+ try:
+ wrapper.setPinDirection(self.__device, aDirection)
+ except Exception, e:
+ raise AsGpioError(str(e))
+
+ def getPinDirection(self):
+ """ Set period in us
+ \param aDirection pin direction 0:input 1:output
+ """
+ try:
+ return wrapper.getPinDirection(self.__device)
+ except Exception, e:
+ raise AsGpioError(str(e))
+
+ def setPinValue(self, aValue):
+ """ Set pin value
+ \param aValue value to write
+ """
+ try:
+ wrapper.setPinValue(self.__device, aValue)
+ except Exception, e:
+ raise AsGpioError(str(e))
- # Dictionary of gpio multiton classes
- __gpio = {}
+ def getPinValue(self):
+ """ Get pin value
+ \param return pin value
+ """
+ try:
+ return wrapper.getPinValue(self.__device)
+ except Exception, e:
+ raise AsGpioError(str(e))
- ################################################################
- class __impl:
- """ implementation
+ def blockingGetPinValue(self, aDelay_s, aDelay_us=0):
+ """ Get pin value (blocking mode)
+ \param return pin value
"""
- def __init__(self, aPortLetter, aPinNum):
- try:
- self.__device = wrapper.gpio_open(aPortLetter, aPinNum)
- except Exception, e:
- raise AsGpioError("Can't open GPIO port "+str(aPortLetter)+\
- " pin "+str(aPinNum)+": "+str(e))
-
- def __del__(self):
- try:
- wrapper.gpio_close(self.__device)
- except Exception, e:
- pass
-
- def setPinDirection(self, aDirection):
- """ Set period in us
- \param aDirection pin direction 0:input 1:output
- """
- try:
- wrapper.setPinDirection(self.__device, aDirection)
- except Exception, e:
- raise AsGpioError(str(e))
-
- def getPinDirection(self):
- """ Set period in us
- \param aDirection pin direction 0:input 1:output
- """
- try:
- return wrapper.getPinDirection(self.__device)
- except Exception, e:
- raise AsGpioError(str(e))
-
- def setPinValue(self, aValue):
- """ Set pin value
- \param aValue value to write
- """
- try:
- wrapper.setPinValue(self.__device, aValue)
- except Exception, e:
- raise AsGpioError(str(e))
-
- def getPinValue(self):
- """ Get pin value
- \param return pin value
- """
- try:
- return wrapper.getPinValue(self.__device)
- except Exception, e:
- raise AsGpioError(str(e))
-
- def blockingGetPinValue(self, aDelay_s, aDelay_us=0):
- """ Get pin value (blocking mode)
- \param return pin value
- """
- try:
- return wrapper.blockingGetPinValue(self.__device,
- aDelay_s,
- aDelay_us)
- except Exception, e:
- raise AsGpioError(str(e))
-
- def setIrqMode(self, aMode):
- """ Set irq Mode
- \param aMode.
- 1:MODE_NOINT
- 2:MODE_RISING
- 3:MODE_FALLING
- 4:MODE_BOTH
- """
- try:
- return wrapper.setIrqMode(self.__device, aMode)
- except Exception, e:
- raise AsGpioError(str(e))
-
- def getIrqMode(self):
- """ get irq mode
- """
- try:
- return wrapper.getIrqMode(self.__device)
- except Exception, e:
- raise AsGpioError(str(e))
-
-
- def getPinNumber(self):
- """ Get pin number
- \param return pin number
- """
- try:
- return wrapper.getPinNumber(self.__device)
- except Exception, e:
- raise AsGpioError(str(e))
-
- def getPortLetter(self):
- """ Get pin letter
- \param return pin letter
- """
- try:
- return wrapper.getPortLetter(self.__device)
- except Exception, e:
- raise AsGpioError(str(e))
-
-
- ################################################################
-
- @classmethod
- def getInstance(cls, aPort_letter, aPinNumber):
- 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")
- if type(aPinNumber)!=int:
- raise Exception("Pin number must be a int")
- if aPinNumber < 0 or aPinNumber > 31:
- raise Exception("Pin number must be between 0 and 31")
+ try:
+ return wrapper.blockingGetPinValue(self.__device,
+ aDelay_s,
+ aDelay_us)
+ except Exception, e:
+ raise AsGpioError(str(e))
+
+ def setIrqMode(self, aMode):
+ """ Set irq Mode
+ \param aMode.
+ 1:MODE_NOINT
+ 2:MODE_RISING
+ 3:MODE_FALLING
+ 4:MODE_BOTH
+ """
+ try:
+ return wrapper.setIrqMode(self.__device, aMode)
+ except Exception, e:
+ raise AsGpioError(str(e))
+ def getIrqMode(self):
+ """ get irq mode
+ """
try:
- return AsGpio.__gpio["%s%d"%(aPort_letter[0],aPinNumber)]
- except KeyError:
- AsGpio.__gpio["%s%d"%(aPort_letter[0],aPinNumber)] =\
- cls.__impl(aPort_letter[0], aPinNumber)
+ return wrapper.getIrqMode(self.__device)
+ except Exception, e:
+ raise AsGpioError(str(e))
- return AsGpio.__gpio["%s%d"%(aPort_letter[0],aPinNumber)]
- def __init__(self):
- """ Initialize pwm
+ def getPinNumber(self):
+ """ Get pin number
+ \param return pin number
"""
- raise Exception("This constructor is private, to instanciate object do:"+\
- "AsGpio.getInstance(port_letter, pin_number)")
-
-if __name__ == "__main__":
- import os
- def pressEnterToContinue():
- print "Press enter to continue"
- raw_input()
+ try:
+ return wrapper.getPinNumber(self.__device)
+ except Exception, e:
+ raise AsGpioError(str(e))
+
+ def getPortLetter(self):
+ """ Get pin letter
+ \param return pin letter
+ """
+ try:
+ return wrapper.getPortLetter(self.__device)
+ except Exception, e:
+ raise AsGpioError(str(e))
diff --git a/target/packages/as_devices/python/AsDevices/AsI2c.py b/target/packages/as_devices/python/AsDevices/AsI2c.py
new file mode 100644
index 0000000..2963b2e
--- /dev/null
+++ b/target/packages/as_devices/python/AsDevices/AsI2c.py
@@ -0,0 +1,133 @@
+#! /usr/bin/python
+# -*- coding: utf-8 -*-
+#-----------------------------------------------------------------------------
+# Name: AsI2c.py
+# Purpose:
+# Author: Fabien Marteau <fab...@ar...>
+# Created: 23/02/2011
+#-----------------------------------------------------------------------------
+# Copyright (2011) 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 I²C"
+__version__ = "0.1"
+__author__ = "Fabien Marteau <fab...@ar...>"
+
+import wrappers.AsI2c_wrap as wrapper
+
+class AsI2cError(Exception):
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)
+
+class AsI2c:
+ """
+ """
+
+ def __init__(self, aBusNumber):
+ try:
+ self.__device = wrapper.i2c_open(aBusNumber)
+ except Exception, e:
+ raise AsI2cError("Can't open i2c bus number "+str(aBusNumber)+\
+ ": "+str(e))
+
+ def __def__(self):
+ try:
+ wrappers.i2c_close(self.__device)
+ except Exception, e:
+ pass
+
+ def setSlaveAddr(self, aAddr):
+ """ Set address of slave
+ """
+ try:
+ return wrapper.i2c_set_slave_addr(self.__device, aAddr)
+ except Exception, e:
+ raise AsI2cError(str(e))
+
+ def getSlaveAddr(self):
+ """ Get address of slave
+ """
+ try:
+ return wrapper.i2c_get_slave_addr(self.__device)
+ except Exception, e:
+ raise AsI2cError(str(e))
+
+ def read(self, aNumber):
+ """ read aNumber of bytes on i2c bus
+ """
+ try:
+ rString = wrapper.i2c_read(self.__device, aNumber)
+ except Exception, e:
+ raise AsI2cError(str(e))
+ rList = []
+ for character in rString:
+ rList.append(ord(character))
+ return rList
+
+ def write(self, aList):
+ """ read a list of bytes on i2c bus
+ """
+ aString = ''
+ for character in aList:
+ aString += chr(character)
+ try:
+ return wrapper.i2c_write(self.__device, aString)
+ except Exception, e:
+ raise AsI2cError(str(e))
+
+ def readReg(self, aReg, aNumber):
+ """ read a list of bytes at aReg register address
+ """
+ try:
+ rString = wrapper.i2c_read_reg(self.__device, aReg, aNumber)
+ except Exception, e:
+ raise AsI2cError(str(e))
+ rList = []
+ for character in rString:
+ rList.append(ord(character))
+ return rList
+
+ def writeReg(self, aReg, aList):
+ """ write a list of bytes at aReg register address
+ """
+ aString = ''
+ for character in aList:
+ aString += chr(character)
+ try:
+ return wrapper.i2c_write_reg(self.__device, aReg, aString)
+ except Exception, e:
+ raise AsI2cError(str(e))
+
+ def readRegByte(self, aReg):
+ """ Read one byte at aReg register address
+ """
+ try:
+ return wrapper.i2c_read_reg_byte(self.__device, aReg)
+ except Exception, e:
+ raise AsI2cError(str(e))
+
+ def writeRegByte(self, aReg, aValue):
+ """ write one byte at aReg register address
+ """
+ try:
+ return wrapper.i2c_write_reg_byte(self.__device, aReg, aValue)
+ except Exception, e:
+ raise AsI2cError(str(e))
+
diff --git a/target/packages/as_devices/python/Makefile b/target/packages/as_devices/python/Makefile
index 8368d4e..375b6e2 100644
--- a/target/packages/as_devices/python/Makefile
+++ b/target/packages/as_devices/python/Makefile
@@ -18,6 +18,7 @@ LIBNAME=AsDevices
WRAPPER_LIBS=AsGpio_wrap.so
WRAPPER_LIBS+= AsAdc_wrap.so
WRAPPER_LIBS+= AsDac_wrap.so
+WRAPPER_LIBS+= AsI2c_wrap.so
WRAPPER_DIR=src
PYTHON_VERS=2.4
diff --git a/target/packages/as_devices/python/src/AsI2c_wrap.c b/target/packages/as_devices/python/src/AsI2c_wrap.c
new file mode 100644
index 0000000..b25184f
--- /dev/null
+++ b/target/packages/as_devices/python/src/AsI2c_wrap.c
@@ -0,0 +1,310 @@
+/*
+** The ARMadeus Project
+**
+** Copyright (C) 2011 The armadeus systems team
+** Fabien Marteau <fab...@ar...>
+**
+** This library 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.1 of the License, or (at your option) any later version.
+**
+** This library 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
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+#include "AsI2c_wrap.h"
+#include "as_i2c.h"
+
+#define MAX_DATA_SIZE 20
+
+/* Methods definitions */
+static PyMethodDef AsI2c_wrap_methods[] = {
+ {"i2c_open" , i2c_open , METH_VARARGS, "as_i2c function wrapped"},
+ {"i2c_close" , i2c_close , METH_VARARGS, "as_i2c function wrapped"},
+ {"i2c_set_slave_addr", i2c_set_slave_addr, METH_VARARGS, "as_i2c function wrapped"},
+ {"i2c_get_slave_addr", i2c_get_slave_addr, METH_VARARGS, "as_i2c function wrapped"},
+ {"i2c_read" , i2c_read , METH_VARARGS, "as_i2c function wrapped"},
+ {"i2c_write" , i2c_write , METH_VARARGS, "as_i2c function wrapped"},
+ {"i2c_read_reg" , i2c_read_reg , METH_VARARGS, "as_i2c function wrapped"},
+ {"i2c_write_reg" , i2c_write_reg , METH_VARARGS, "as_i2c function wrapped"},
+ {"i2c_read_reg_byte" , i2c_read_reg_byte , METH_VARARGS, "as_i2c function wrapped"},
+ {"i2c_write_reg_byte", i2c_write_reg_byte, METH_VARARGS, "as_i2c function wrapped"},
+ {NULL, NULL, 0, NULL} /* Sentinel */
+};
+
+
+/* Init module */
+void initAsI2c_wrap() /* called on first import */
+{ /* name matter if called dynamically */
+ (void) Py_InitModule("AsI2c_wrap", AsI2c_wrap_methods); /* mod name, table ptr */
+}
+
+static PyObject * i2c_open(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ int aBusNumber;
+
+ struct as_i2c_device *dev;
+ PyObject *ret;
+ char buff[300];
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "i", &aBusNumber))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+ dev = as_i2c_open(aBusNumber);
+ if (dev == NULL)
+ {
+ snprintf(buff, 300,
+ "Initialization error for i2c bus %d.", aBusNumber);
+ PyErr_SetString(PyExc_IOError,buff);
+ return NULL;
+ }
+ ret = Py_BuildValue("l", (long)dev);
+
+ return ret;
+}
+
+static PyObject * i2c_close(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ struct as_i2c_device *aDev;
+
+ /* return value */
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "l", (long *)&aDev)) {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+ ret = as_i2c_close(aDev);
+ if (ret < 0) {
+ PyErr_SetString(PyExc_IOError, "Can't close i2c");
+ return Py_BuildValue("i", -1);
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * i2c_set_slave_addr(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ struct as_i2c_device *aDev;
+ int aSlaveAddr;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "li", (long *)&aDev, &aSlaveAddr))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_i2c_set_slave_addr(aDev, aSlaveAddr);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't set slave address");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * i2c_get_slave_addr(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ struct as_i2c_device *aDev;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "l", (long *)&aDev))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_i2c_get_slave_addr(aDev);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't get slave address");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * i2c_read(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ struct as_i2c_device *aDev;
+ uint8_t aData[MAX_DATA_SIZE];
+ int aSize;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "li", (long *)&aDev, &aSize))
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_i2c_read(aDev, aData, aSize);
+ if (ret < 0)
+ {
+ PyErr_SetString(PyExc_IOError,
+ "Can't get slave address");
+ return NULL;
+ }
+
+ return Py_BuildValue("s#", (unsigned char *)aData, aSize);
+}
+
+static PyObject * i2c_write(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ struct as_i2c_device *aDev;
+ uint8_t *aData;
+ int aSize;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "ls#", (long *)&aDev, (unsigned char *)&aData, &aSize)) {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_i2c_write(aDev, aData, aSize);
+ if (ret < 0) {
+ PyErr_SetString(PyExc_IOError,
+ "Can't get slave address");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * i2c_read_reg(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ struct as_i2c_device *aDev;
+ uint8_t aReg;
+ uint8_t aData[MAX_DATA_SIZE];
+ int aSize;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "lii", (long *)&aDev, &aReg, &aSize)) {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_i2c_read_reg(aDev, aReg, aData, aSize);
+ if (ret < 0) {
+ PyErr_SetString(PyExc_IOError,
+ "Can't get slave address");
+ return NULL;
+ }
+
+ return Py_BuildValue("s#", (unsigned char *)aData, aSize);
+}
+
+static PyObject * i2c_write_reg(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ struct as_i2c_device *aDev;
+ uint8_t aReg;
+ uint8_t *aData;
+ int aSize;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "lis#", (long *)&aDev, &aReg, (unsigned char *)&aData, &aSize)) {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_i2c_write_reg(aDev, aReg, aData, aSize);
+ if (ret < 0) {
+ PyErr_SetString(PyExc_IOError,
+ "Can't get slave address");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * i2c_read_reg_byte(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ struct as_i2c_device *aDev;
+ uint8_t aReg;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "li", (long *)&aDev, &aReg)) {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_i2c_read_reg_byte(aDev, aReg);
+ if (ret < 0) {
+ PyErr_SetString(PyExc_IOError,
+ "Can't get slave address");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
+static PyObject * i2c_write_reg_byte(PyObject *self, PyObject *args)
+{
+ /* parameters */
+ struct as_i2c_device *aDev;
+ uint8_t aReg;
+ uint8_t aVal;
+
+ int ret;
+
+ /* Get arguments */
+ if (!PyArg_ParseTuple(args, "lii", (long *)&aDev, &aReg, &aVal)) {
+ PyErr_SetString(PyExc_IOError,
+ "Wrong parameters.");
+ return NULL;
+ }
+
+ ret = as_i2c_write_reg_byte(aDev, aReg, aVal);
+ if (ret < 0) {
+ PyErr_SetString(PyExc_IOError,
+ "Can't get slave address");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", ret);
+}
+
diff --git a/target/packages/as_devices/python/src/AsAdc_wrap.h b/target/packages/as_devices/python/src/AsI2c_wrap.h
similarity index 59%
copy from target/packages/as_devices/python/src/AsAdc_wrap.h
copy to target/packages/as_devices/python/src/AsI2c_wrap.h
index 7fa0b8f..b4f0b47 100644
--- a/target/packages/as_devices/python/src/AsAdc_wrap.h
+++ b/target/packages/as_devices/python/src/AsI2c_wrap.h
@@ -19,14 +19,26 @@
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
#include <Python.h>
/* Init module */
-void initAsAdc_wrap();
+void initAsI2c_wrap();
/*********************/
/* Functions wrapped */
/*********************/
-static PyObject * adc_open(PyObject *self, PyObject *args);
-static PyObject * getValueInMillivolts(PyObject *self, PyObject *args);
-static PyObject * adc_close(PyObject *self, PyObject *args);
+static PyObject * i2c_open(PyObject *self, PyObject *args);
+static PyObject * i2c_close(PyObject *self, PyObject *args);
+
+static PyObject * i2c_set_slave_addr(PyObject *self, PyObject *args);
+static PyObject * i2c_get_slave_addr(PyObject *self, PyObject *args);
+
+static PyObject * i2c_read(PyObject *self, PyObject *args);
+static PyObject * i2c_write(PyObject *self, PyObject *args);
+
+static PyObject * i2c_read_reg(PyObject *self, PyObject *args);
+static PyObject * i2c_write_reg(PyObject *self, PyObject *args);
+
+static PyObject * i2c_read_reg_byte(PyObject *self, PyObject *args);
+static PyObject * i2c_write_reg_byte(PyObject *self, PyObject *args);
hooks/post-receive
--
armadeus
|