Merge remote-tracking branch 'upstream/master'
This commit is contained in:
10
api/gpio.h
10
api/gpio.h
@@ -101,7 +101,7 @@ maa_result_t maa_gpio_mode(maa_gpio_context *dev, gpio_mode_t mode);
|
||||
maa_result_t maa_gpio_dir(maa_gpio_context *dev, gpio_dir_t dir);
|
||||
|
||||
/** Close the GPIO context
|
||||
* - Will free the memory for the context.
|
||||
* - Will free the memory for the context and unexport the GPIO
|
||||
*
|
||||
* @param dev the GPIO context
|
||||
*
|
||||
@@ -109,6 +109,14 @@ maa_result_t maa_gpio_dir(maa_gpio_context *dev, gpio_dir_t dir);
|
||||
*/
|
||||
maa_result_t maa_gpio_close(maa_gpio_context *dev);
|
||||
|
||||
/** Unexport the GPIO context (maa_gpio_close() will call this function)
|
||||
*
|
||||
* @param dev The GPIO context.
|
||||
*
|
||||
* @return maa result type.
|
||||
*/
|
||||
maa_result_t maa_gpio_unexport(maa_gpio_context *dev);
|
||||
|
||||
/** Read the GPIO value.
|
||||
*
|
||||
* @param dev The GPIO context.
|
||||
|
||||
@@ -151,6 +151,14 @@ maa_result_t maa_pwm_pulsewidth_us(maa_pwm_context* pwm, int us);
|
||||
*/
|
||||
maa_result_t maa_pwm_enable(maa_pwm_context* pwm, int enable);
|
||||
|
||||
/** Unexport the PWM context (maa_pwm_close() will call this function)
|
||||
*
|
||||
* @param dev The PWM context/
|
||||
*
|
||||
* @return maa result type.
|
||||
*/
|
||||
maa_result_t maa_pwm_unexport(maa_pwm_context* pwm);
|
||||
|
||||
/** Close and unexport the PWM pin.
|
||||
*
|
||||
* @param pwm The PWM context to use.
|
||||
|
||||
@@ -149,7 +149,9 @@ maa_gpio_read(maa_gpio_context *dev)
|
||||
char buffer[2];
|
||||
fread(buffer, 2, 1, dev->value_fp);
|
||||
fseek(dev->value_fp, SEEK_SET, 0);
|
||||
return atoi(buffer);
|
||||
int ret = strtol(buffer, NULL, 10);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
@@ -158,16 +160,20 @@ maa_gpio_write(maa_gpio_context *dev, int value)
|
||||
if (dev->value_fp == NULL) {
|
||||
maa_gpio_get_valfp(dev);
|
||||
}
|
||||
fseek(dev->value_fp, SEEK_SET, 0);
|
||||
if (fseek(dev->value_fp, SEEK_SET, 0) != 0) {
|
||||
return MAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
fprintf(dev->value_fp, "%d", value);
|
||||
fseek(dev->value_fp, SEEK_SET, 0);
|
||||
if (fseek(dev->value_fp, SEEK_SET, 0) != 0) {
|
||||
return MAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
if (ferror(dev->value_fp) != 0)
|
||||
return MAA_ERROR_INVALID_RESOURCE;
|
||||
return MAA_SUCCESS;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
maa_gpio_close(maa_gpio_context *dev)
|
||||
maa_gpio_unexport(maa_gpio_context *dev)
|
||||
{
|
||||
FILE *unexport_f;
|
||||
|
||||
@@ -179,6 +185,12 @@ maa_gpio_close(maa_gpio_context *dev)
|
||||
fclose(unexport_f);
|
||||
if (ferror(dev->value_fp) != 0)
|
||||
return MAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
maa_gpio_close(maa_gpio_context *dev)
|
||||
{
|
||||
maa_gpio_unexport(dev);
|
||||
free(dev);
|
||||
return MAA_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ typedef struct {
|
||||
}
|
||||
~maa_gpio_context()
|
||||
{
|
||||
maa_gpio_close($self);
|
||||
maa_gpio_unexport($self);
|
||||
}
|
||||
%feature("autodoc") write "
|
||||
Write a value to a GPIO pin
|
||||
@@ -117,7 +117,6 @@ typedef struct {
|
||||
}
|
||||
~maa_i2c_context()
|
||||
{
|
||||
maa_i2c_stop($self);
|
||||
}
|
||||
int frequency(int hz)
|
||||
{
|
||||
@@ -166,7 +165,7 @@ typedef struct {
|
||||
}
|
||||
~maa_pwm_context()
|
||||
{
|
||||
maa_pwm_close($self);
|
||||
maa_pwm_unexport($self);
|
||||
}
|
||||
int write(float percentage)
|
||||
{
|
||||
@@ -225,7 +224,6 @@ typedef struct {
|
||||
}
|
||||
~maa_spi_context()
|
||||
{
|
||||
maa_spi_stop($self);
|
||||
}
|
||||
int mode(unsigned short mode)
|
||||
{
|
||||
@@ -259,7 +257,6 @@ typedef struct {
|
||||
}
|
||||
~maa_aio_context()
|
||||
{
|
||||
maa_aio_close($self);
|
||||
}
|
||||
unsigned int read()
|
||||
{
|
||||
|
||||
@@ -205,8 +205,9 @@ maa_pwm_enable(maa_pwm_context* dev, int enable)
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
maa_pwm_close(maa_pwm_context* dev)
|
||||
maa_pwm_unexport(maa_pwm_context* dev)
|
||||
{
|
||||
// disable pwm before unexporting
|
||||
maa_pwm_enable(dev, 0);
|
||||
FILE *unexport_f;
|
||||
char buffer[64];
|
||||
@@ -218,8 +219,14 @@ maa_pwm_close(maa_pwm_context* dev)
|
||||
}
|
||||
fprintf(unexport_f, "%d", dev->pin);
|
||||
fclose(unexport_f);
|
||||
free(dev);
|
||||
if (ferror(unexport_f) != 0)
|
||||
return MAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
maa_pwm_close(maa_pwm_context* dev)
|
||||
{
|
||||
maa_pwm_unexport(dev);
|
||||
free(dev);
|
||||
return MAA_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user