summaryrefslogtreecommitdiff
path: root/src/gpio.c
diff options
context:
space:
mode:
authorkutayboz <kutayboz@gmail.com>2023-06-03 04:18:33 +0300
committerkutayboz <kutayboz@gmail.com>2023-06-03 04:18:33 +0300
commit2374721c6840f56c07c31abcfddd6bd385d97d8b (patch)
tree356e47e92f88c842c145d78181cc645c93c247e1 /src/gpio.c
parent8eec887bad2b821079e15d653fbbe6d6ccaceaf2 (diff)
downloadcelnetmon-2374721c6840f56c07c31abcfddd6bd385d97d8b.tar.gz
Added GPIO control. Seperated functions into libs
Diffstat (limited to 'src/gpio.c')
-rw-r--r--src/gpio.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/gpio.c b/src/gpio.c
new file mode 100644
index 0000000..0ccfd6b
--- /dev/null
+++ b/src/gpio.c
@@ -0,0 +1,44 @@
+#include <gpiod.h>
+#include <stdio.h>
+
+int modemPowerToggle(int pinNum) {
+ 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_output(line, "cellular modem power toggle", 0) < 0) {
+ perror("Error setting GPIO line as output");
+ gpiod_chip_close(chip);
+ return 1;
+ }
+
+ if (gpiod_line_set_value(line, 1) < 0) {
+ perror("Error setting GPIO line high");
+ gpiod_chip_close(chip);
+ return 1;
+ }
+
+ sleep(1);
+
+ if (gpiod_line_set_value(line, 0) < 0) {
+ perror("Error setting GPIO line low");
+ gpiod_chip_close(chip);
+ return 1;
+ }
+
+ gpiod_chip_close(chip);
+ return 0;
+}