Hey There…me again. Um, here is some source code to review for the BeagleY-AI. Right now, I cannot configure logic correctly to make myself understand anything in data processing.
For whatever reason, I seem to not know the logic on building I/O statements.
Anyway, here is the primary source I have conjured up:
// From https://github.com/starnight/libgpiod-example
// With the Beagle Family in Mind...
#include <gpiod.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#ifndef CONSUMER
#define CONSUMER "Consumer"
#endif
int main(int argc, char **argv)
{
char *chipname_one = "gpiochip2";
char *chipname_two = "gpiochip3";
unsigned int line_num_one = 38; // GPIO Pin #7 on the BeagleY-AI
unsigned int line_num_two = 14; // GPIO Pin #8 on the BeagleY-AI
struct gpiod_chip *chip_one;
struct gpiod_chip *chip_two;
struct gpiod_line *line_in;
struct gpiod_line *line_out;
int i, val, ret_one, ret_two;
chip_one = gpiod_chip_open_by_name(chipname_one);
if (!chip_one) {
perror("Open chip_one failed\n");
ret_one = -1;
goto end;
}
line_in = gpiod_chip_get_line(chip_one, line_num_one);
if (!line_in) {
perror("Get line_in failed\n");
ret_one = -1;
goto close_chip;
}
ret_one = gpiod_line_request_input(line_in, CONSUMER);
if (ret_one < 0) {
perror("Request for input failed\n");
ret_one = -1;
goto release_line;
}
chip_two = gpiod_chip_open_by_name(chipname_two);
if (!chip_two) {
perror("Open chip_one failed\n");
ret_two = -1;
goto end;
}
line_out = gpiod_chip_get_line(chip_two, line_num_two);
if (!line_out) {
perror("Get line_out failed\n");
ret_two = -1;
goto close_chip;
}
ret_two = gpiod_line_request_output(line_out, CONSUMER, 0);
if (ret_two < 0) {
perror("Request for output failed\n");
ret_two = -1;
goto release_line;
}
while (1) {
ret_two = gpiod_line_set_value(line_out, 0);
if (ret_two < 0) {
perror("Output failed\n");
ret_two = -1;
goto release_line;
}
if (ret_two >= 1) {
printf("Working on Output and Input \n", line_out, 0);
continue;
usleep(100000);
ret_one = gpiod_line_get_value(line_in);
printf("Button Pressed\n %d ", line_num_one);
if (ret_one < 0) {
perror("I/O Failed\n");
ret_one = -1;
goto release_line;
}
if (ret_one == 0) {
ret_two = gpiod_line_set_value(line_out, 0);
usleep(50000);
}
if (ret_one >= 1) {
ret_two = gpiod_line_set_value(line_out, 1);
usleep(50000);
}
usleep(50000);
}
}
release_line:
gpiod_line_release(line_in);
gpiod_line_release(line_out);
close_chip:
gpiod_chip_close(chip_one);
gpiod_chip_close(chip_two);
end:
return ret_one, ret_two;
ret_two = gpiod_line_set_value(line_out, 0);
}
I know you cannot tell off the bat here but…
- The source code is leaning towards getting Input from hardware.
- The hardware is a limit switch (electromechanical).
- The Input once selected tells the processor to handle the Output.
- My Output in this case is a LED which will later be a, you guessed it, motor.
The source code compiles. This is nice. It does nothing actually. It just allows itself to run and then I have to CTRL-C out of my terminal running the source code to make it stop.
Seth
P.S. I will keep trying to progress and learn more while people are making decisions on answering me. Does the logic in the while
loop make it so my Input is even working? Once I can configure Input correctly in a while
loop, I have thoughts on how to incorporate the Output easily…