aio.hpp: Add C++ wrapper around Aio
* maa_aio_context becomes an opaque pointer * C++ wrapper class Aio created * examples/c++ with a sample for Aio created * swig now uses C++ wrapper Aio to generate an API * python generated code is now C++ Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -10,6 +10,7 @@ set (maa_LIB_HEADERS
|
||||
${PROJECT_SOURCE_DIR}/api/pwm.h
|
||||
${PROJECT_SOURCE_DIR}/api/spi.h
|
||||
${PROJECT_SOURCE_DIR}/api/aio.h
|
||||
${PROJECT_SOURCE_DIR}/api/aio.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/smbus.h
|
||||
${PROJECT_SOURCE_DIR}/include/version.h
|
||||
${PROJECT_SOURCE_DIR}/include/intel_galileo_rev_d.h
|
||||
|
||||
@@ -28,7 +28,12 @@
|
||||
|
||||
#include "aio.h"
|
||||
|
||||
static maa_result_t aio_get_valid_fp(maa_aio_context* dev)
|
||||
struct _aio {
|
||||
unsigned int channel;
|
||||
int adc_in_fp;
|
||||
};
|
||||
|
||||
static maa_result_t aio_get_valid_fp(maa_aio_context dev)
|
||||
{
|
||||
char file_path[64]= "";
|
||||
|
||||
@@ -52,10 +57,8 @@ static maa_result_t aio_get_valid_fp(maa_aio_context* dev)
|
||||
* @returns pointer to maa_aio_context structure after initialisation of
|
||||
* Analog input pin connected to the device successfully, else returns NULL.
|
||||
*/
|
||||
maa_aio_context* maa_aio_init(unsigned int aio_channel)
|
||||
maa_aio_context maa_aio_init(unsigned int aio_channel)
|
||||
{
|
||||
maa_aio_context* dev;
|
||||
|
||||
int checked_pin = maa_check_aio(aio_channel);
|
||||
if (checked_pin < 0) {
|
||||
switch(checked_pin) {
|
||||
@@ -75,7 +78,7 @@ maa_aio_context* maa_aio_init(unsigned int aio_channel)
|
||||
}
|
||||
|
||||
//Create ADC device connected to specified channel
|
||||
dev = (maa_aio_context*) malloc(sizeof(maa_aio_context));
|
||||
maa_aio_context dev = malloc(sizeof(struct _aio));
|
||||
if (dev == NULL) {
|
||||
fprintf(stderr, "Insufficient memory for specified Analog input channel "
|
||||
"%d\n", aio_channel);
|
||||
@@ -102,7 +105,7 @@ maa_aio_context* maa_aio_init(unsigned int aio_channel)
|
||||
* unsigned 16 bit int representing the current input voltage, normalised to
|
||||
* a 16-bit value
|
||||
*/
|
||||
uint16_t maa_aio_read(maa_aio_context* dev)
|
||||
uint16_t maa_aio_read(maa_aio_context dev)
|
||||
{
|
||||
char buffer[16];
|
||||
unsigned int analog_value = 0;
|
||||
@@ -152,7 +155,7 @@ uint16_t maa_aio_read(maa_aio_context* dev)
|
||||
*
|
||||
* @return maa result type.
|
||||
*/
|
||||
maa_result_t maa_aio_close(maa_aio_context* dev)
|
||||
maa_result_t maa_aio_close(maa_aio_context dev)
|
||||
{
|
||||
if (NULL != dev)
|
||||
free(dev);
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "maa.h"
|
||||
#include "intel_galileo_rev_d.h"
|
||||
|
||||
27
src/maa.i
27
src/maa.i
@@ -4,7 +4,7 @@
|
||||
#include "pwm.h"
|
||||
#include "i2c.h"
|
||||
#include "spi.h"
|
||||
#include "aio.h"
|
||||
#include "aio.hpp"
|
||||
%}
|
||||
|
||||
%init %{
|
||||
@@ -112,7 +112,7 @@ typedef struct {
|
||||
{
|
||||
Py_INCREF(pyfunc);
|
||||
// do a nasty cast to get away from the warnings
|
||||
maa_gpio_isr(self, MAA_GPIO_EDGE_BOTH, pyfunc);
|
||||
maa_gpio_isr(self, MAA_GPIO_EDGE_BOTH, (void (*) ()) pyfunc);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
@@ -270,25 +270,4 @@ typedef struct {
|
||||
|
||||
#### AIO ####
|
||||
|
||||
%rename(Aio) maa_aio_context;
|
||||
|
||||
%ignore adc_in_fp;
|
||||
typedef struct {
|
||||
unsigned int channel;
|
||||
FILE *adc_in_fp;
|
||||
} maa_aio_context;
|
||||
|
||||
%nodefault maa_aio_context;
|
||||
%extend maa_aio_context {
|
||||
maa_aio_context(unsigned int aio_channel)
|
||||
{
|
||||
return maa_aio_init(aio_channel);
|
||||
}
|
||||
~maa_aio_context()
|
||||
{
|
||||
}
|
||||
unsigned int read()
|
||||
{
|
||||
return maa_aio_read($self);
|
||||
}
|
||||
}
|
||||
%include "aio.hpp"
|
||||
|
||||
@@ -6,6 +6,7 @@ include_directories(
|
||||
${PYTHON_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set_source_files_properties (pymaa.i PROPERTIES CPLUSPLUS ON)
|
||||
swig_add_module (pymaa python pymaa.i ${maa_LIB_SRCS})
|
||||
swig_link_libraries (pymaa ${PYTHON_LIBRARIES})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user