syslog: remove all fprintf calls and use syslog instead
Syslog is now used for all error messages, return values in the code should be used by programmers to see the status of the library/board and syslog can be used to see quickly from a debugging perspective what has gone wrong. A few cosmetics where improved as well as a mraa_set_log_level() call where the syslog log mask can be set directly from libmraa. Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -207,7 +207,8 @@ mraa_result_t mraa_init() __attribute__((constructor));
|
|||||||
* De-Initilise MRAA
|
* De-Initilise MRAA
|
||||||
*
|
*
|
||||||
* This is not a strict requirement but useful to test memory leaks and for
|
* This is not a strict requirement but useful to test memory leaks and for
|
||||||
* people who like super clean code.
|
* people who like super clean code. If dynamically loading & unloading
|
||||||
|
* libmraa you need to call this before unloading the library.
|
||||||
*/
|
*/
|
||||||
void mraa_deinit();
|
void mraa_deinit();
|
||||||
|
|
||||||
@@ -234,6 +235,15 @@ unsigned int mraa_adc_raw_bits();
|
|||||||
*/
|
*/
|
||||||
unsigned int mraa_adc_supported_bits();
|
unsigned int mraa_adc_supported_bits();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the log level to use from 0-7 where 7 is very verbose. These are the
|
||||||
|
* syslog log levels, see syslog(3) for more information on the levels.
|
||||||
|
*
|
||||||
|
* @return Result of operation
|
||||||
|
*/
|
||||||
|
mraa_result_t mraa_set_log_level(int level);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -116,4 +116,15 @@ unsigned int adcSupportedBits()
|
|||||||
return mraa_adc_supported_bits();
|
return mraa_adc_supported_bits();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the log level to use from 0-7 where 7 is very verbose. These are the
|
||||||
|
* syslog log levels, see syslog(3) for more information on the levels.
|
||||||
|
*
|
||||||
|
* @return Result of operation
|
||||||
|
*/
|
||||||
|
mraa_result_t setLogLevel(int level)
|
||||||
|
{
|
||||||
|
return mraa_set_log_level(level);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,15 +22,22 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "stdio.h"
|
#include <stdio.h>
|
||||||
|
#include <syslog.h>
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
#include "mraa.h"
|
#include "mraa.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
mraa_result_t ret;
|
||||||
|
|
||||||
|
ret = mraa_set_log_level(LOG_DEBUG);
|
||||||
|
|
||||||
fprintf(stdout, "hello mraa\n Version: %s\n", mraa_get_version());
|
fprintf(stdout, "hello mraa\n Version: %s\n", mraa_get_version());
|
||||||
|
|
||||||
mraa_deinit();
|
mraa_deinit();
|
||||||
return 0;
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|||||||
@@ -27,6 +27,11 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
// general status failures for internal functions
|
||||||
|
#define MRAA_PLATFORM_NO_INIT -3
|
||||||
|
#define MRAA_IO_SETUP_FAILURE -2
|
||||||
|
#define MRAA_NO_SUCH_IO -1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A structure representing a gpio pin.
|
* A structure representing a gpio pin.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ aio_get_valid_fp(mraa_aio_context dev)
|
|||||||
|
|
||||||
dev->adc_in_fp = open(file_path, O_RDONLY);
|
dev->adc_in_fp = open(file_path, O_RDONLY);
|
||||||
if (dev->adc_in_fp == -1) {
|
if (dev->adc_in_fp == -1) {
|
||||||
fprintf(stderr, "Failed to open Analog input raw file %s for "
|
syslog(LOG_ERR, "Failed to open Analog input raw file %s for "
|
||||||
"reading!\n", file_path);
|
"reading!", file_path);
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,16 +67,16 @@ mraa_aio_init(unsigned int aio_channel)
|
|||||||
int checked_pin = mraa_setup_aio(aio_channel);
|
int checked_pin = mraa_setup_aio(aio_channel);
|
||||||
if (checked_pin < 0) {
|
if (checked_pin < 0) {
|
||||||
switch (checked_pin) {
|
switch (checked_pin) {
|
||||||
case -1:
|
case MRAA_NO_SUCH_IO:
|
||||||
fprintf(stderr, "Invalid analog input channel %d specified\n",
|
syslog(LOG_ERR, "Invalid analog input channel %d specified",
|
||||||
aio_channel);
|
aio_channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
case -2:
|
case MRAA_IO_SETUP_FAILURE:
|
||||||
fprintf(stderr, "Failed to set-up analog input channel %d "
|
syslog(LOG_ERR, "Failed to set-up analog input channel %d "
|
||||||
"multiplexer\n", aio_channel);
|
"multiplexer", aio_channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
case -3:
|
case MRAA_PLATFORM_NO_INIT:
|
||||||
fprintf(stderr, "Platform not initialised");
|
syslog(LOG_ERR, "Platform not initialised");
|
||||||
return NULL;
|
return NULL;
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -86,7 +86,7 @@ mraa_aio_init(unsigned int aio_channel)
|
|||||||
//Create ADC device connected to specified channel
|
//Create ADC device connected to specified channel
|
||||||
mraa_aio_context dev = malloc(sizeof(struct _aio));
|
mraa_aio_context dev = malloc(sizeof(struct _aio));
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
fprintf(stderr, "Insufficient memory for specified Analog input channel "
|
syslog(LOG_ERR, "Insufficient memory for specified Analog input channel "
|
||||||
"%d\n", aio_channel);
|
"%d\n", aio_channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ mraa_aio_read(mraa_aio_context dev)
|
|||||||
|
|
||||||
lseek(dev->adc_in_fp, 0, SEEK_SET);
|
lseek(dev->adc_in_fp, 0, SEEK_SET);
|
||||||
if (read(dev->adc_in_fp, buffer, sizeof(buffer)) < 1) {
|
if (read(dev->adc_in_fp, buffer, sizeof(buffer)) < 1) {
|
||||||
fprintf(stderr, "Failed to read a sensible value\n");
|
syslog(LOG_ERR, "Failed to read a sensible value");
|
||||||
}
|
}
|
||||||
lseek(dev->adc_in_fp, 0, SEEK_SET);
|
lseek(dev->adc_in_fp, 0, SEEK_SET);
|
||||||
|
|
||||||
@@ -131,10 +131,10 @@ mraa_aio_read(mraa_aio_context dev)
|
|||||||
char *end;
|
char *end;
|
||||||
unsigned int analog_value = (unsigned int) strtoul(buffer, &end, 10);
|
unsigned int analog_value = (unsigned int) strtoul(buffer, &end, 10);
|
||||||
if (end == &buffer[0]) {
|
if (end == &buffer[0]) {
|
||||||
fprintf(stderr, "%s is not a decimal number\n", buffer);
|
syslog(LOG_ERR, "%s is not a decimal number", buffer);
|
||||||
}
|
}
|
||||||
else if (errno != 0) {
|
else if (errno != 0) {
|
||||||
fprintf(stderr, "errno was set\n");
|
syslog(LOG_ERR, "errno was set");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev->value_bit != raw_bits) {
|
if (dev->value_bit != raw_bits) {
|
||||||
@@ -164,11 +164,11 @@ mraa_result_t
|
|||||||
mraa_aio_set_bit(mraa_aio_context dev, int bits)
|
mraa_aio_set_bit(mraa_aio_context dev, int bits)
|
||||||
{
|
{
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
fprintf(stderr, "AIO Device not valid\n");
|
syslog(LOG_ERR, "AIO Device not valid");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
if (bits < 1) {
|
if (bits < 1) {
|
||||||
fprintf(stderr, "AIO Device not valid\n");
|
syslog(LOG_ERR, "AIO Device not valid");
|
||||||
return MRAA_ERROR_INVALID_PARAMETER;
|
return MRAA_ERROR_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
dev->value_bit = bits;
|
dev->value_bit = bits;
|
||||||
@@ -179,7 +179,7 @@ int
|
|||||||
mraa_aio_get_bit(mraa_aio_context dev)
|
mraa_aio_get_bit(mraa_aio_context dev)
|
||||||
{
|
{
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
fprintf(stderr, "AIO Device not valid\n");
|
syslog(LOG_ERR, "AIO Device not valid");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return dev->value_bit;
|
return dev->value_bit;
|
||||||
|
|||||||
@@ -101,12 +101,12 @@ mraa_gpio_init_raw(int pin)
|
|||||||
} else {
|
} else {
|
||||||
int export = open(SYSFS_CLASS_GPIO "/export", O_WRONLY);
|
int export = open(SYSFS_CLASS_GPIO "/export", O_WRONLY);
|
||||||
if (export == -1) {
|
if (export == -1) {
|
||||||
fprintf(stderr, "Failed to open export for writing!\n");
|
syslog(LOG_ERR, "Failed to open export for writing");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
length = snprintf(bu, sizeof(bu), "%d", dev->pin);
|
length = snprintf(bu, sizeof(bu), "%d", dev->pin);
|
||||||
if (write(export, bu, length*sizeof(char)) == -1) {
|
if (write(export, bu, length*sizeof(char)) == -1) {
|
||||||
fprintf(stderr, "Failed to write to export\n");
|
syslog(LOG_ERR, "Failed to write to export");
|
||||||
close(export);
|
close(export);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -190,11 +190,11 @@ mraa_gpio_interrupt_handler(void* arg)
|
|||||||
PyObject *ret;
|
PyObject *ret;
|
||||||
arglist = Py_BuildValue("(i)", dev->isr_args);
|
arglist = Py_BuildValue("(i)", dev->isr_args);
|
||||||
if (arglist == NULL) {
|
if (arglist == NULL) {
|
||||||
fprintf(stdout, "Py_BuildValue NULL\n");
|
syslog(LOG_ERR, "Py_BuildValue NULL");
|
||||||
} else {
|
} else {
|
||||||
ret = PyEval_CallObject((PyObject*)dev->isr, arglist);
|
ret = PyEval_CallObject((PyObject*)dev->isr, arglist);
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
fprintf(stdout, "PyEval_CallObject failed\n");
|
syslog(LOG_ERR, "PyEval_CallObject failed");
|
||||||
} else {
|
} else {
|
||||||
Py_DECREF(ret);
|
Py_DECREF(ret);
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, gpio_edge_t mode)
|
|||||||
|
|
||||||
int edge = open(filepath, O_RDWR);
|
int edge = open(filepath, O_RDWR);
|
||||||
if (edge == -1) {
|
if (edge == -1) {
|
||||||
fprintf(stderr, "Failed to open edge for writing!\n");
|
syslog(LOG_ERR, "Failed to open edge for writing");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +253,7 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, gpio_edge_t mode)
|
|||||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
if (write(edge, bu, length*sizeof(char)) == -1) {
|
if (write(edge, bu, length*sizeof(char)) == -1) {
|
||||||
fprintf(stderr, "Failed to write to edge\n");
|
syslog(LOG_ERR, "Failed to write to edge");
|
||||||
close(edge);
|
close(edge);
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
@@ -339,7 +339,7 @@ mraa_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode)
|
|||||||
|
|
||||||
int drive = open(filepath, O_WRONLY);
|
int drive = open(filepath, O_WRONLY);
|
||||||
if (drive == -1) {
|
if (drive == -1) {
|
||||||
fprintf(stderr, "Failed to open drive for writing!\n");
|
syslog(LOG_ERR, "Failed to open drive for writing");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,7 +363,7 @@ mraa_gpio_mode(mraa_gpio_context dev, gpio_mode_t mode)
|
|||||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
if (write(drive, bu, length*sizeof(char)) == -1) {
|
if (write(drive, bu, length*sizeof(char)) == -1) {
|
||||||
fprintf(stderr, "Failed to write to drive mode!\n");
|
syslog(LOG_ERR, "Failed to write to drive mode");
|
||||||
close(drive);
|
close(drive);
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
|
|
||||||
@@ -432,7 +432,7 @@ mraa_gpio_read(mraa_gpio_context dev)
|
|||||||
{
|
{
|
||||||
if (dev->value_fp == -1) {
|
if (dev->value_fp == -1) {
|
||||||
if (mraa_gpio_get_valfp(dev) != MRAA_SUCCESS) {
|
if (mraa_gpio_get_valfp(dev) != MRAA_SUCCESS) {
|
||||||
fprintf(stderr, "Failed to get value file pointer\n");
|
syslog(LOG_ERR, "Failed to get value file pointer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -441,7 +441,7 @@ mraa_gpio_read(mraa_gpio_context dev)
|
|||||||
}
|
}
|
||||||
char bu[2];
|
char bu[2];
|
||||||
if (read(dev->value_fp, bu, 2*sizeof(char)) != 2) {
|
if (read(dev->value_fp, bu, 2*sizeof(char)) != 2) {
|
||||||
fprintf(stderr, "Failed to read a sensible value from sysfs");
|
syslog(LOG_ERR, "Failed to read a sensible value from sysfs");
|
||||||
}
|
}
|
||||||
lseek(dev->value_fp, 0, SEEK_SET);
|
lseek(dev->value_fp, 0, SEEK_SET);
|
||||||
int ret = strtol(bu, NULL, 10);
|
int ret = strtol(bu, NULL, 10);
|
||||||
@@ -485,14 +485,14 @@ mraa_gpio_unexport_force(mraa_gpio_context dev)
|
|||||||
{
|
{
|
||||||
int unexport = open(SYSFS_CLASS_GPIO "/unexport", O_WRONLY);
|
int unexport = open(SYSFS_CLASS_GPIO "/unexport", O_WRONLY);
|
||||||
if (unexport == -1) {
|
if (unexport == -1) {
|
||||||
fprintf(stderr, "Failed to open unexport for writing!\n");
|
syslog(LOG_ERR, "Failed to open unexport for writing");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char bu[MAX_SIZE];
|
char bu[MAX_SIZE];
|
||||||
int length = snprintf(bu, sizeof(bu), "%d", dev->pin);
|
int length = snprintf(bu, sizeof(bu), "%d", dev->pin);
|
||||||
if (write(unexport, bu, length*sizeof(char)) == -1) {
|
if (write(unexport, bu, length*sizeof(char)) == -1) {
|
||||||
fprintf(stderr, "Failed to write to unexport\n");
|
syslog(LOG_ERR, "Failed to write to unexport");
|
||||||
close(unexport);
|
close(unexport);
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
@@ -550,7 +550,7 @@ mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_boolean_t mmap_en)
|
|||||||
int fd;
|
int fd;
|
||||||
fd = open(mmp->mem_dev, O_RDWR);
|
fd = open(mmp->mem_dev, O_RDWR);
|
||||||
if (fd < 1) {
|
if (fd < 1) {
|
||||||
fprintf(stderr, "Unable to open memory device\n");
|
syslog(LOG_ERR, "Unable to open memory device");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
dev->reg_sz = mmp->mem_sz;
|
dev->reg_sz = mmp->mem_sz;
|
||||||
|
|||||||
@@ -32,14 +32,14 @@ mraa_i2c_init(int bus)
|
|||||||
int checked_pin = mraa_setup_i2c(bus);
|
int checked_pin = mraa_setup_i2c(bus);
|
||||||
if (checked_pin < 0) {
|
if (checked_pin < 0) {
|
||||||
switch(checked_pin) {
|
switch(checked_pin) {
|
||||||
case -1:
|
case MRAA_NO_SUCH_IO:
|
||||||
fprintf(stderr, "No i2c on board\n");
|
syslog(LOG_ERR, "No i2c on board");
|
||||||
return NULL;
|
return NULL;
|
||||||
case -2:
|
case MRAA_IO_SETUP_FAILURE:
|
||||||
fprintf(stderr, "Failed to set-up i2c multiplexer!\n");
|
syslog(LOG_ERR, "Failed to set-up i2c multiplexer");
|
||||||
return NULL;
|
return NULL;
|
||||||
case -3:
|
case MRAA_PLATFORM_NO_INIT:
|
||||||
fprintf(stderr, "Platform Not Initialised\n");
|
syslog(LOG_ERR, "Platform Not Initialised");
|
||||||
return NULL;
|
return NULL;
|
||||||
default: return NULL;
|
default: return NULL;
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ mraa_i2c_init_raw(unsigned int bus)
|
|||||||
char filepath[32];
|
char filepath[32];
|
||||||
snprintf(filepath, 32, "/dev/i2c-%u", bus);
|
snprintf(filepath, 32, "/dev/i2c-%u", bus);
|
||||||
if ((dev->fh = open(filepath, O_RDWR)) < 1) {
|
if ((dev->fh = open(filepath, O_RDWR)) < 1) {
|
||||||
fprintf(stderr, "Failed to open requested i2c port %s\n", filepath);
|
syslog(LOG_ERR, "Failed to open requested i2c port %s", filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (advance_func->i2c_init_post != NULL) {
|
if (advance_func->i2c_init_post != NULL) {
|
||||||
@@ -106,7 +106,7 @@ mraa_result_t
|
|||||||
mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
|
mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
|
||||||
{
|
{
|
||||||
if (i2c_smbus_write_i2c_block_data(dev->fh, data[0], length-1, (uint8_t*) data+1) < 0) {
|
if (i2c_smbus_write_i2c_block_data(dev->fh, data[0], length-1, (uint8_t*) data+1) < 0) {
|
||||||
fprintf(stderr, "Failed to write to i2c\n");
|
syslog(LOG_ERR, "Failed to write to i2c");
|
||||||
return MRAA_ERROR_INVALID_HANDLE;
|
return MRAA_ERROR_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
return MRAA_SUCCESS;
|
return MRAA_SUCCESS;
|
||||||
@@ -116,7 +116,7 @@ mraa_result_t
|
|||||||
mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data)
|
mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data)
|
||||||
{
|
{
|
||||||
if (i2c_smbus_write_byte(dev->fh, data) < 0) {
|
if (i2c_smbus_write_byte(dev->fh, data) < 0) {
|
||||||
fprintf(stderr, "Failed to write to i2c\n");
|
syslog(LOG_ERR, "Failed to write to i2c");
|
||||||
return MRAA_ERROR_INVALID_HANDLE;
|
return MRAA_ERROR_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
return MRAA_SUCCESS;
|
return MRAA_SUCCESS;
|
||||||
@@ -127,7 +127,7 @@ mraa_i2c_address(mraa_i2c_context dev, int addr)
|
|||||||
{
|
{
|
||||||
dev->addr = addr;
|
dev->addr = addr;
|
||||||
if (ioctl(dev->fh, I2C_SLAVE_FORCE, addr) < 0) {
|
if (ioctl(dev->fh, I2C_SLAVE_FORCE, addr) < 0) {
|
||||||
fprintf(stderr, "Failed to set slave address %d\n", addr);
|
syslog(LOG_ERR, "Failed to set slave address %d", addr);
|
||||||
return MRAA_ERROR_INVALID_HANDLE;
|
return MRAA_ERROR_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
return MRAA_SUCCESS;
|
return MRAA_SUCCESS;
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ mraa_intel_edison_pinmode_change(int sysfs, int mode)
|
|||||||
snprintf(buffer, MAX_SIZE, SYSFS_PINMODE_PATH "%i/current_pinmux",sysfs);
|
snprintf(buffer, MAX_SIZE, SYSFS_PINMODE_PATH "%i/current_pinmux",sysfs);
|
||||||
int modef = open(buffer, O_WRONLY);
|
int modef = open(buffer, O_WRONLY);
|
||||||
if (modef == -1) {
|
if (modef == -1) {
|
||||||
fprintf(stderr, "Failed to open SoC pinmode for opening\n");
|
syslog(LOG_ERR, "Failed to open SoC pinmode for opening");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ mraa_result_t
|
|||||||
mraa_intel_edison_i2c_init_pre(unsigned int bus)
|
mraa_intel_edison_i2c_init_pre(unsigned int bus)
|
||||||
{
|
{
|
||||||
if(bus != 6) {
|
if(bus != 6) {
|
||||||
fprintf(stderr, "Edison: You can use that bus, ERR\n");
|
syslog(LOG_ERR, "Edison: You can't use that bus :/");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
mraa_gpio_write(tristate, 0);
|
mraa_gpio_write(tristate, 0);
|
||||||
@@ -205,8 +205,9 @@ mraa_intel_edison_aio_get_fp(mraa_aio_context dev)
|
|||||||
|
|
||||||
dev->adc_in_fp = open(file_path, O_RDONLY);
|
dev->adc_in_fp = open(file_path, O_RDONLY);
|
||||||
if (dev->adc_in_fp == -1) {
|
if (dev->adc_in_fp == -1) {
|
||||||
fprintf(stderr, "Failed to open Analog input raw file %s for "
|
syslog(LOG_ERR, "Failed to open Analog input raw file %s for "
|
||||||
"reading!\n", file_path); return( MRAA_ERROR_INVALID_RESOURCE);
|
"reading!", file_path);
|
||||||
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return MRAA_SUCCESS;
|
return MRAA_SUCCESS;
|
||||||
@@ -216,7 +217,7 @@ mraa_result_t
|
|||||||
mraa_intel_edison_aio_init_pre(unsigned int aio)
|
mraa_intel_edison_aio_init_pre(unsigned int aio)
|
||||||
{
|
{
|
||||||
if (aio > plat->aio_count) {
|
if (aio > plat->aio_count) {
|
||||||
fprintf(stderr, "Invalid analog input channel\n");
|
syslog(LOG_ERR, "Invalid analog input channel");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,7 +341,7 @@ mraa_intel_edison_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mode)
|
|||||||
pullup_e = mraa_gpio_init_raw(pullup_map[dev->phy_pin]);
|
pullup_e = mraa_gpio_init_raw(pullup_map[dev->phy_pin]);
|
||||||
mraa_result_t sta = mraa_gpio_dir(pullup_e, MRAA_GPIO_IN);
|
mraa_result_t sta = mraa_gpio_dir(pullup_e, MRAA_GPIO_IN);
|
||||||
if(sta != MRAA_SUCCESS) {
|
if(sta != MRAA_SUCCESS) {
|
||||||
fprintf(stderr, "MRAA: Edison: Failed to set gpio mode-pullup\n");
|
syslog(LOG_ERR, "Edison: Failed to set gpio mode-pullup");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +365,7 @@ mraa_intel_edison_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mode)
|
|||||||
sta = mraa_gpio_dir(pullup_e, MRAA_GPIO_OUT);
|
sta = mraa_gpio_dir(pullup_e, MRAA_GPIO_OUT);
|
||||||
sta = mraa_gpio_write(pullup_e, value);
|
sta = mraa_gpio_write(pullup_e, value);
|
||||||
if (sta != MRAA_SUCCESS) {
|
if (sta != MRAA_SUCCESS) {
|
||||||
fprintf(stderr, "MRAA: Edison: Error Setting pullup");
|
syslog(LOG_ERR, "Edison: Error Setting pullup");
|
||||||
return sta;
|
return sta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -401,7 +402,7 @@ mraa_intel_edison_fab_c()
|
|||||||
|
|
||||||
tristate = mraa_gpio_init_raw(214);
|
tristate = mraa_gpio_init_raw(214);
|
||||||
if (tristate == NULL) {
|
if (tristate == NULL) {
|
||||||
fprintf(stderr, "Intel Edison Failed to initialise Arduino board TriState,\
|
syslog(LOG_CRIT, "Intel Edison Failed to initialise Arduino board TriState,\
|
||||||
check i2c devices! FATAL\n");
|
check i2c devices! FATAL\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -634,8 +635,7 @@ mraa_intel_edison_fab_c()
|
|||||||
b->spi_bus[0].sclk = 13;
|
b->spi_bus[0].sclk = 13;
|
||||||
|
|
||||||
int il;
|
int il;
|
||||||
|
for (il =0; il < MRAA_INTEL_EDISON_PINCOUNT; il++) {
|
||||||
for(il =0; il < MRAA_INTEL_EDISON_PINCOUNT; il++) {
|
|
||||||
pinmodes[il].gpio.sysfs = -1;
|
pinmodes[il].gpio.sysfs = -1;
|
||||||
pinmodes[il].gpio.mode = -1;
|
pinmodes[il].gpio.mode = -1;
|
||||||
pinmodes[il].pwm.sysfs = -1;
|
pinmodes[il].pwm.sysfs = -1;
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ mraa_intel_galileo_gen2_pwm_period_replace(mraa_pwm_context dev, int period)
|
|||||||
|
|
||||||
int period_f = open(bu, O_RDWR);
|
int period_f = open(bu, O_RDWR);
|
||||||
if (period_f == -1) {
|
if (period_f == -1) {
|
||||||
fprintf(stderr, "Failed to open period for writing!\n");
|
syslog(LOG_ERR, "Failed to open period for writing!");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
char out[MAX_SIZE];
|
char out[MAX_SIZE];
|
||||||
@@ -109,8 +109,8 @@ mraa_intel_galileo_gen2_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mod
|
|||||||
mraa_gpio_context pullup_e;
|
mraa_gpio_context pullup_e;
|
||||||
pullup_e = mraa_gpio_init_raw(pullup_map[dev->phy_pin]);
|
pullup_e = mraa_gpio_init_raw(pullup_map[dev->phy_pin]);
|
||||||
mraa_result_t sta = mraa_gpio_dir(pullup_e, MRAA_GPIO_IN);
|
mraa_result_t sta = mraa_gpio_dir(pullup_e, MRAA_GPIO_IN);
|
||||||
if(sta != MRAA_SUCCESS) {
|
if (sta != MRAA_SUCCESS) {
|
||||||
fprintf(stderr, "MRAA: Galileo Gen 2: Failed to set gpio pullup\n");
|
syslog(LOG_ERR, "Galileo Gen 2: Failed to set gpio pullup");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ mraa_intel_galileo_gen2_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mod
|
|||||||
|
|
||||||
int drive = open(filepath, O_WRONLY);
|
int drive = open(filepath, O_WRONLY);
|
||||||
if (drive == -1) {
|
if (drive == -1) {
|
||||||
fprintf(stderr, "Failed to open drive for writing!\n");
|
syslog(LOG_ERR, "Failed to open drive for writing");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ mraa_intel_galileo_gen2_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mod
|
|||||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
if (write(drive, bu, length*sizeof(char)) == -1) {
|
if (write(drive, bu, length*sizeof(char)) == -1) {
|
||||||
fprintf(stderr, "Failed to write to drive mode!\n");
|
syslog(LOG_ERR, "Failed to write to drive mode");
|
||||||
close(drive);
|
close(drive);
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ mraa_intel_galileo_gen2_gpio_mode_replace(mraa_gpio_context dev, gpio_mode_t mod
|
|||||||
sta = mraa_gpio_dir(pullup_e, MRAA_GPIO_OUT);
|
sta = mraa_gpio_dir(pullup_e, MRAA_GPIO_OUT);
|
||||||
sta = mraa_gpio_write(pullup_e, value);
|
sta = mraa_gpio_write(pullup_e, value);
|
||||||
if (sta != MRAA_SUCCESS) {
|
if (sta != MRAA_SUCCESS) {
|
||||||
fprintf(stderr, "MRAA: Galileo Gen 2: Error Setting pullup");
|
syslog(LOG_ERR, "Galileo Gen 2: Error Setting pullup");
|
||||||
return sta;
|
return sta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
96
src/mraa.c
96
src/mraa.c
@@ -45,12 +45,28 @@ mraa_get_version()
|
|||||||
return gVERSION;
|
return gVERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mraa_result_t
|
||||||
|
mraa_set_log_level(int level)
|
||||||
|
{
|
||||||
|
if (level <= 7 && level >= 0) {
|
||||||
|
setlogmask(LOG_UPTO(level));
|
||||||
|
return MRAA_SUCCESS;
|
||||||
|
}
|
||||||
|
return MRAA_ERROR_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
mraa_result_t __attribute__((constructor))
|
mraa_result_t __attribute__((constructor))
|
||||||
mraa_init()
|
mraa_init()
|
||||||
{
|
{
|
||||||
/** Once more board definitions have been added,
|
#ifdef DEBUG
|
||||||
* A method for detecting them will need to be devised.
|
setlogmask(LOG_UPTO(LOG_DEBUG));
|
||||||
*/
|
#else
|
||||||
|
setlogmask(LOG_UPTO(LOG_NOTICE));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
openlog("libmraa", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
|
||||||
|
syslog(LOG_DEBUG, "libmraa initialised by user %d", getuid());
|
||||||
|
|
||||||
if (plat != NULL) {
|
if (plat != NULL) {
|
||||||
return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
|
return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
|
||||||
}
|
}
|
||||||
@@ -96,9 +112,10 @@ mraa_init()
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
plat = mraa_intel_galileo_rev_d();
|
plat = mraa_intel_galileo_rev_d();
|
||||||
fprintf(stderr, "Platform not found, initialising MRAA_INTEL_GALILEO_GEN1\n");
|
syslog(LOG_ERR, "Platform not found, initialising MRAA_INTEL_GALILEO_GEN1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
syslog(LOG_NOTICE, "libmraa initialised for platform %d", platform_type);
|
||||||
return MRAA_SUCCESS;
|
return MRAA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +124,7 @@ mraa_deinit()
|
|||||||
{
|
{
|
||||||
free(plat->pins);
|
free(plat->pins);
|
||||||
free(plat);
|
free(plat);
|
||||||
|
closelog();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -145,17 +163,17 @@ unsigned int
|
|||||||
mraa_setup_gpio(int pin)
|
mraa_setup_gpio(int pin)
|
||||||
{
|
{
|
||||||
if (plat == NULL)
|
if (plat == NULL)
|
||||||
return -1;
|
return MRAA_PLATFORM_NO_INIT;
|
||||||
|
|
||||||
if (pin < 0 || pin > plat->phy_pin_count)
|
if (pin < 0 || pin > plat->phy_pin_count)
|
||||||
return -1;
|
return MRAA_NO_SUCH_IO;
|
||||||
|
|
||||||
if(plat->pins[pin].capabilites.gpio != 1)
|
if(plat->pins[pin].capabilites.gpio != 1)
|
||||||
return -1;
|
return MRAA_NO_SUCH_IO;
|
||||||
|
|
||||||
if (plat->pins[pin].gpio.mux_total > 0)
|
if (plat->pins[pin].gpio.mux_total > 0)
|
||||||
if (mraa_setup_mux_mapped(plat->pins[pin].gpio) != MRAA_SUCCESS)
|
if (mraa_setup_mux_mapped(plat->pins[pin].gpio) != MRAA_SUCCESS)
|
||||||
return -1;
|
return MRAA_NO_SUCH_IO;
|
||||||
return plat->pins[pin].gpio.pinmap;
|
return plat->pins[pin].gpio.pinmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,19 +181,19 @@ unsigned int
|
|||||||
mraa_setup_aio(int aio)
|
mraa_setup_aio(int aio)
|
||||||
{
|
{
|
||||||
if (plat == NULL)
|
if (plat == NULL)
|
||||||
return -3;
|
return MRAA_PLATFORM_NO_INIT;
|
||||||
|
|
||||||
if (aio < 0 || aio > plat->aio_count)
|
if (aio < 0 || aio > plat->aio_count)
|
||||||
return -1;
|
return MRAA_NO_SUCH_IO;
|
||||||
|
|
||||||
int pin = aio + plat->gpio_count;
|
int pin = aio + plat->gpio_count;
|
||||||
|
|
||||||
if (plat->pins[pin].capabilites.aio != 1)
|
if (plat->pins[pin].capabilites.aio != 1)
|
||||||
return -1;
|
return MRAA_NO_SUCH_IO;
|
||||||
|
|
||||||
if (plat->pins[pin].aio.mux_total > 0)
|
if (plat->pins[pin].aio.mux_total > 0)
|
||||||
if (mraa_setup_mux_mapped(plat->pins[pin].aio) != MRAA_SUCCESS)
|
if (mraa_setup_mux_mapped(plat->pins[pin].aio) != MRAA_SUCCESS)
|
||||||
return -1;
|
return MRAA_NO_SUCH_IO;
|
||||||
return plat->pins[pin].aio.pinmap;
|
return plat->pins[pin].aio.pinmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,31 +201,31 @@ unsigned int
|
|||||||
mraa_setup_i2c(int bus)
|
mraa_setup_i2c(int bus)
|
||||||
{
|
{
|
||||||
if (plat == NULL)
|
if (plat == NULL)
|
||||||
return -3;
|
return MRAA_PLATFORM_NO_INIT;
|
||||||
|
|
||||||
if (plat->i2c_bus_count == 0) {
|
if (plat->i2c_bus_count == 0) {
|
||||||
fprintf(stderr, "No i2c buses defined in platform");
|
syslog(LOG_ERR, "No i2c buses defined in platform");
|
||||||
return -1;
|
return MRAA_NO_SUCH_IO;
|
||||||
}
|
}
|
||||||
if (bus >= plat->i2c_bus_count) {
|
if (bus >= plat->i2c_bus_count) {
|
||||||
fprintf(stderr, "Above i2c bus count");
|
syslog(LOG_ERR, "Above i2c bus count");
|
||||||
return -1;
|
return MRAA_NO_SUCH_IO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plat->i2c_bus[bus].bus_id == -1) {
|
if (plat->i2c_bus[bus].bus_id == -1) {
|
||||||
fprintf(stderr, "Platform not currently allowed for mraa use\n");
|
syslog(LOG_ERR, "Platform not currently allowed for mraa use");
|
||||||
return -1;
|
return MRAA_NO_SUCH_IO;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pos = plat->i2c_bus[bus].sda;
|
int pos = plat->i2c_bus[bus].sda;
|
||||||
if (plat->pins[pos].i2c.mux_total > 0)
|
if (plat->pins[pos].i2c.mux_total > 0)
|
||||||
if (mraa_setup_mux_mapped(plat->pins[pos].i2c) != MRAA_SUCCESS)
|
if (mraa_setup_mux_mapped(plat->pins[pos].i2c) != MRAA_SUCCESS)
|
||||||
return -2;
|
return MRAA_IO_SETUP_FAILURE;
|
||||||
|
|
||||||
pos = plat->i2c_bus[bus].scl;
|
pos = plat->i2c_bus[bus].scl;
|
||||||
if (plat->pins[pos].i2c.mux_total > 0)
|
if (plat->pins[pos].i2c.mux_total > 0)
|
||||||
if (mraa_setup_mux_mapped(plat->pins[pos].i2c) != MRAA_SUCCESS)
|
if (mraa_setup_mux_mapped(plat->pins[pos].i2c) != MRAA_SUCCESS)
|
||||||
return -2;
|
return MRAA_IO_SETUP_FAILURE;
|
||||||
|
|
||||||
return plat->i2c_bus[bus].bus_id;
|
return plat->i2c_bus[bus].bus_id;
|
||||||
}
|
}
|
||||||
@@ -219,14 +237,14 @@ mraa_setup_spi(int bus)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (plat->spi_bus_count >! 0) {
|
if (plat->spi_bus_count >! 0) {
|
||||||
fprintf(stderr, "No spi buses defined in platform");
|
syslog(LOG_ERR, "No spi buses defined in platform");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (plat->spi_bus_count == 1) {
|
if (plat->spi_bus_count == 1) {
|
||||||
bus = plat->def_spi_bus;
|
bus = plat->def_spi_bus;
|
||||||
}
|
}
|
||||||
if (bus >= plat->spi_bus_count) {
|
if (bus >= plat->spi_bus_count) {
|
||||||
fprintf(stderr, "Above spi bus count");
|
syslog(LOG_ERR, "Above spi bus count");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,48 +305,50 @@ void
|
|||||||
mraa_result_print(mraa_result_t result)
|
mraa_result_print(mraa_result_t result)
|
||||||
{
|
{
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case MRAA_SUCCESS: fprintf(stderr, "MRAA: SUCCESS\n");
|
case MRAA_SUCCESS:
|
||||||
|
fprintf(stdout, "MRAA: SUCCESS\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_FEATURE_NOT_IMPLEMENTED:
|
case MRAA_ERROR_FEATURE_NOT_IMPLEMENTED:
|
||||||
fprintf(stderr, "MRAA: Feature not implemented.\n");
|
fprintf(stdout, "MRAA: Feature not implemented.\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_FEATURE_NOT_SUPPORTED:
|
case MRAA_ERROR_FEATURE_NOT_SUPPORTED:
|
||||||
fprintf(stderr, "MRAA: Feature not supported by Hardware.\n");
|
fprintf(stdout, "MRAA: Feature not supported by Hardware.\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_INVALID_VERBOSITY_LEVEL:
|
case MRAA_ERROR_INVALID_VERBOSITY_LEVEL:
|
||||||
fprintf(stderr, "MRAA: Invalid verbosity level.\n");
|
fprintf(stdout, "MRAA: Invalid verbosity level.\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_INVALID_PARAMETER:
|
case MRAA_ERROR_INVALID_PARAMETER:
|
||||||
fprintf(stderr, "MRAA: Invalid parameter.\n");
|
fprintf(stdout, "MRAA: Invalid parameter.\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_INVALID_HANDLE:
|
case MRAA_ERROR_INVALID_HANDLE:
|
||||||
fprintf(stderr, "MRAA: Invalid Handle.\n");
|
fprintf(stdout, "MRAA: Invalid Handle.\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_NO_RESOURCES:
|
case MRAA_ERROR_NO_RESOURCES:
|
||||||
fprintf(stderr, "MRAA: No resources.\n");
|
fprintf(stdout, "MRAA: No resources.\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_INVALID_RESOURCE:
|
case MRAA_ERROR_INVALID_RESOURCE:
|
||||||
fprintf(stderr, "MRAA: Invalid resource.\n");
|
fprintf(stdout, "MRAA: Invalid resource.\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_INVALID_QUEUE_TYPE:
|
case MRAA_ERROR_INVALID_QUEUE_TYPE:
|
||||||
fprintf(stderr, "MRAA: Invalid Queue Type.\n");
|
fprintf(stdout, "MRAA: Invalid Queue Type.\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_NO_DATA_AVAILABLE:
|
case MRAA_ERROR_NO_DATA_AVAILABLE:
|
||||||
fprintf(stderr, "MRAA: No Data available.\n");
|
fprintf(stdout, "MRAA: No Data available.\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_INVALID_PLATFORM:
|
case MRAA_ERROR_INVALID_PLATFORM:
|
||||||
fprintf(stderr, "MRAA: Platform not recognised.\n");
|
fprintf(stdout, "MRAA: Platform not recognised.\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_PLATFORM_NOT_INITIALISED:
|
case MRAA_ERROR_PLATFORM_NOT_INITIALISED:
|
||||||
fprintf(stderr, "MRAA: Platform not initialised.\n");
|
fprintf(stdout, "MRAA: Platform not initialised.\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_PLATFORM_ALREADY_INITIALISED:
|
case MRAA_ERROR_PLATFORM_ALREADY_INITIALISED:
|
||||||
fprintf(stderr, "MRAA: Platform already initialised.\n");
|
fprintf(stdout, "MRAA: Platform already initialised.\n");
|
||||||
break;
|
break;
|
||||||
case MRAA_ERROR_UNSPECIFIED:
|
case MRAA_ERROR_UNSPECIFIED:
|
||||||
fprintf(stderr, "MRAA: Unspecified Error.\n");
|
fprintf(stdout, "MRAA: Unspecified Error.\n");
|
||||||
break;
|
break;
|
||||||
default: fprintf(stderr, "MRAA: Unrecognised error.\n");
|
default:
|
||||||
|
fprintf(stdout, "MRAA: Unrecognised error.\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ mraa_pwm_write_period(mraa_pwm_context dev, int period)
|
|||||||
|
|
||||||
int period_f = open(bu, O_RDWR);
|
int period_f = open(bu, O_RDWR);
|
||||||
if (period_f == -1) {
|
if (period_f == -1) {
|
||||||
fprintf(stderr, "Failed to open period for writing!\n");
|
syslog(LOG_ERR, "Failed to open period for writing");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
char out[MAX_SIZE];
|
char out[MAX_SIZE];
|
||||||
@@ -92,7 +92,7 @@ mraa_pwm_read_period(mraa_pwm_context dev)
|
|||||||
|
|
||||||
int period_f = open(bu, O_RDWR);
|
int period_f = open(bu, O_RDWR);
|
||||||
if (period_f == -1) {
|
if (period_f == -1) {
|
||||||
fprintf(stderr, "Failed to open period for reading!\n");
|
syslog(LOG_ERR, "Failed to open period for reading");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
off_t size = lseek(period_f, 0, SEEK_END);
|
off_t size = lseek(period_f, 0, SEEK_END);
|
||||||
@@ -161,14 +161,14 @@ mraa_pwm_init_raw(int chipin, int pin)
|
|||||||
snprintf(directory, MAX_SIZE, SYSFS_PWM "/pwmchip%d/pwm%d", dev->chipid, dev->pin);
|
snprintf(directory, MAX_SIZE, SYSFS_PWM "/pwmchip%d/pwm%d", dev->chipid, dev->pin);
|
||||||
struct stat dir;
|
struct stat dir;
|
||||||
if (stat(directory, &dir) == 0 && S_ISDIR(dir.st_mode)) {
|
if (stat(directory, &dir) == 0 && S_ISDIR(dir.st_mode)) {
|
||||||
fprintf(stderr, "PWM Pin already exporting, continuing.\n");
|
syslog(LOG_NOTICE, "PWM Pin already exporting, continuing");
|
||||||
dev->owner = 0; // Not Owner
|
dev->owner = 0; // Not Owner
|
||||||
} else {
|
} else {
|
||||||
char buffer[MAX_SIZE];
|
char buffer[MAX_SIZE];
|
||||||
snprintf(buffer, MAX_SIZE, "/sys/class/pwm/pwmchip%d/export", dev->chipid);
|
snprintf(buffer, MAX_SIZE, "/sys/class/pwm/pwmchip%d/export", dev->chipid);
|
||||||
int export_f = open(buffer, O_WRONLY);
|
int export_f = open(buffer, O_WRONLY);
|
||||||
if (export_f == -1) {
|
if (export_f == -1) {
|
||||||
fprintf(stderr, "Failed to open export for writing!\n");
|
syslog(LOG_ERR, "Failed to open export for writing");
|
||||||
free(dev);
|
free(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ mraa_pwm_init_raw(int chipin, int pin)
|
|||||||
char out[MAX_SIZE];
|
char out[MAX_SIZE];
|
||||||
int size = snprintf(out, MAX_SIZE, "%d", dev->pin);
|
int size = snprintf(out, MAX_SIZE, "%d", dev->pin);
|
||||||
if (write(export_f, out, size*sizeof(char)) == -1) {
|
if (write(export_f, out, size*sizeof(char)) == -1) {
|
||||||
fprintf(stderr, "Failed to write to export! Potentially already enabled\n");
|
syslog(LOG_WARNING, "Failed to write to export! Potentially already enabled");
|
||||||
close(export_f);
|
close(export_f);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -251,13 +251,13 @@ mraa_pwm_enable(mraa_pwm_context dev, int enable)
|
|||||||
int enable_f = open(bu, O_RDWR);
|
int enable_f = open(bu, O_RDWR);
|
||||||
|
|
||||||
if (enable_f == -1) {
|
if (enable_f == -1) {
|
||||||
fprintf(stderr, "Failed to open enable for writing!\n");
|
syslog(LOG_ERR, "Failed to open enable for writing");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
char out[2];
|
char out[2];
|
||||||
int size = snprintf(out, sizeof(out), "%d", enable);
|
int size = snprintf(out, sizeof(out), "%d", enable);
|
||||||
if (write(enable_f, out, size * sizeof(char)) == -1) {
|
if (write(enable_f, out, size * sizeof(char)) == -1) {
|
||||||
fprintf(stderr, "Failed to write to enable!\n");
|
syslog(LOG_ERR, "Failed to write to enable");
|
||||||
close(enable_f);
|
close(enable_f);
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
@@ -273,14 +273,14 @@ mraa_pwm_unexport_force(mraa_pwm_context dev)
|
|||||||
|
|
||||||
int unexport_f = open(filepath, O_WRONLY);
|
int unexport_f = open(filepath, O_WRONLY);
|
||||||
if (unexport_f == -1) {
|
if (unexport_f == -1) {
|
||||||
fprintf(stderr, "Failed to open unexport for writing!\n");
|
syslog(LOG_ERR, "Failed to open unexport for writing");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char out[MAX_SIZE];
|
char out[MAX_SIZE];
|
||||||
int size = snprintf(out, MAX_SIZE, "%d", dev->pin);
|
int size = snprintf(out, MAX_SIZE, "%d", dev->pin);
|
||||||
if (write(unexport_f, out, size*sizeof(char)) == -1) {
|
if (write(unexport_f, out, size*sizeof(char)) == -1) {
|
||||||
fprintf(stderr, "Failed to write to unexport!\n");
|
syslog(LOG_ERR, "Failed to write to unexport");
|
||||||
close(unexport_f);
|
close(unexport_f);
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ mraa_spi_init(int bus)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mraa_spi_bus_t *spi = mraa_setup_spi(bus);
|
mraa_spi_bus_t *spi = mraa_setup_spi(bus);
|
||||||
if(bus < 0) {
|
if (bus < 0) {
|
||||||
fprintf(stderr, "Failed. SPI platform Error\n");
|
syslog(LOG_ERR, "Failed. SPI platform Error");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mraa_spi_context dev = (mraa_spi_context) malloc(sizeof(struct _spi));
|
mraa_spi_context dev = (mraa_spi_context) malloc(sizeof(struct _spi));
|
||||||
@@ -70,7 +70,7 @@ mraa_spi_init(int bus)
|
|||||||
|
|
||||||
dev->devfd = open(path, O_RDWR);
|
dev->devfd = open(path, O_RDWR);
|
||||||
if (dev->devfd < 0) {
|
if (dev->devfd < 0) {
|
||||||
fprintf(stderr, "Failed opening SPI Device. bus:%s\n", path);
|
syslog(LOG_ERR, "Failed opening SPI Device. bus:%s", path);
|
||||||
free(dev);
|
free(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ mraa_spi_mode(mraa_spi_context dev, mraa_spi_mode_t mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl (dev->devfd, SPI_IOC_WR_MODE, &spi_mode) < 0) {
|
if (ioctl (dev->devfd, SPI_IOC_WR_MODE, &spi_mode) < 0) {
|
||||||
fprintf(stderr, "Failed to set spi mode\n");
|
syslog(LOG_ERR, "Failed to set spi mode");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ mraa_spi_lsbmode(mraa_spi_context dev, mraa_boolean_t lsb)
|
|||||||
lsb_mode = 1;
|
lsb_mode = 1;
|
||||||
}
|
}
|
||||||
if (ioctl (dev->devfd, SPI_IOC_WR_LSB_FIRST, &lsb_mode) < 0) {
|
if (ioctl (dev->devfd, SPI_IOC_WR_LSB_FIRST, &lsb_mode) < 0) {
|
||||||
fprintf(stderr, "Failed to set bit order\n");
|
syslog(LOG_ERR, "Failed to set bit order");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
dev->lsb = lsb;
|
dev->lsb = lsb;
|
||||||
@@ -166,7 +166,7 @@ mraa_spi_write(mraa_spi_context dev, uint8_t data)
|
|||||||
msg.delay_usecs = 0;
|
msg.delay_usecs = 0;
|
||||||
msg.len = length;
|
msg.len = length;
|
||||||
if (ioctl(dev->devfd, SPI_IOC_MESSAGE(1), &msg) < 0) {
|
if (ioctl(dev->devfd, SPI_IOC_MESSAGE(1), &msg) < 0) {
|
||||||
fprintf(stderr, "Failed to perform dev transfer\n");
|
syslog(LOG_ERR, "Failed to perform dev transfer");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return recv;
|
return recv;
|
||||||
@@ -187,7 +187,7 @@ mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length)
|
|||||||
msg.delay_usecs = 0;
|
msg.delay_usecs = 0;
|
||||||
msg.len = length;
|
msg.len = length;
|
||||||
if (ioctl(dev->devfd, SPI_IOC_MESSAGE(1), &msg) < 0) {
|
if (ioctl(dev->devfd, SPI_IOC_MESSAGE(1), &msg) < 0) {
|
||||||
fprintf(stderr, "Failed to perform dev transfer\n");
|
syslog(LOG_ERR, "Failed to perform dev transfer");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return recv;
|
return recv;
|
||||||
|
|||||||
Reference in New Issue
Block a user