From addad212bbf05f6599fea747ebae945cb16e5d96 Mon Sep 17 00:00:00 2001 From: kutayboz Date: Mon, 5 Jun 2023 05:30:20 +0300 Subject: Added device power status pin functionality --- src/gpio.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/gpio.c') diff --git a/src/gpio.c b/src/gpio.c index 0ccfd6b..9c00805 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -42,3 +42,39 @@ int modemPowerToggle(int pinNum) { gpiod_chip_close(chip); return 0; } + +int checkPinVal(int pinNum) { + int pinVal = -1; + struct gpiod_chip *chip; + struct gpiod_line *line; + + chip = gpiod_chip_open("/dev/gpiochip0"); + if (!chip) { + perror("Error opening GPIO chip"); + return -1; + } + + line = gpiod_chip_get_line( + chip, pinNum); // Replace with the desired GPIO pin number + if (!line) { + perror("Error getting GPIO line"); + gpiod_chip_close(chip); + return -1; + } + + if (gpiod_line_request_input(line, "cellular modem power status") < 0) { + perror("Error setting GPIO line as input"); + gpiod_chip_close(chip); + return -1; + } + + pinVal = gpiod_line_get_value(line); + if (pinVal < 0) { + perror("Error getting GPIO line value"); + gpiod_chip_close(chip); + return -1; + } + + gpiod_chip_close(chip); + return pinVal; +} -- cgit v1.3