我正在编写一个C程序,该程序控制Raspberry PI上的GPIO状态。我正在使用libgpiod
并调用此函数:
gpiod_ctxless_set_value(GPIO_CHIP_NAME, RESET_PIN, 1, false, "some consumer", NULL, NULL);
但是,函数执行后,引脚立即变为低。如何永久更改?还是至少等到程序退出?
答案 0 :(得分:0)
正如@ 0andriy所提到的,出于我的目的,我需要更多的底层函数,而不是无上下文的函数。这是我的带有通用#include <stdio.h>
#include <stdlib.h>
#include <gpiod.h>
#define LED_PIN 28
int main()
{
struct gpiod_chip *gpiochip;
struct gpiod_line *gpioline;
int ret;
gpiochip = gpiod_chip_open("/dev/gpiochip0");
if (gpiochip == NULL)
goto error1;
printf("gpiochip open is ok\r\n");
gpioline = gpiod_chip_get_line(gpiochip, TEST_PIN);
if (gpioline == NULL)
goto error2;
printf("gpioline open is ok\r\n");
ret = gpiod_line_request_output(gpioline, "gpio", 0);
if (ret != 0)
goto error2;
printf("request output is ok\r\n");
for (int i = 0; i < 5; i++)
{
ret = gpiod_line_set_value(gpioline, 1);
printf("LED on\r\n");
sleep(1);
ret = gpiod_line_set_value(gpioline, 0);
printf("LED off\r\n");
sleep(1);
}
gpiod_line_release(gpioline);
error2:
gpiod_chip_close(gpiochip);
error1:
return 0;
}
函数的测试示例。
as1 <- read.csv(header = T, text = "
da, cat
2016-06-04 04:05:45,A
2016-06-04 04:05:46,B
2016-06-04 04:05:45,C
2016-06-04 04:05:46,D", stringsAsFactors = FALSE)