blob: 0ccfd6b2b0e6315ecc727f612c38561608d39624 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
}
|