29 #include <sys/types.h> 38 #include "rnr/rnrconfig.h" 75 "<gpio> [{in|out} [{none|rising|falling|both}]]",
78 "Create GPIO exported interface.",
81 "The %P command creates a GPIO exported interface for the specified GPIO " 82 "number. Optionally, the direction and edge of the GPIO can also be " 85 " <gpio> Exported GPIO number.\n" 86 " <direction> GPIO direction. One of: in out.\n" 87 " Default: System defined.\n" 88 " <edge> Input GPIO trigger. One of: none rising falling both.\n" 89 " Default: System defined. N/A for output GPIO." 91 "NOTE: This command requires root privileges.",
113 "Change GPIO exported interface permissions. " 114 "Format: 0[0-7]+ for user,group,other." 125 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
136 if( sscanf(str.c_str(),
"%lli", &val1) != 1 )
168 mode = (mode_t)((val << 6) & S_IRWXU);
171 else if( val <= 077 )
173 mode = (mode_t)((val << 3) & (S_IRWXU|S_IRWXG));
176 else if( val <= 0777 )
178 mode = (mode_t)(val & (S_IRWXU|S_IRWXG|S_IRWXO));
204 Argv0 = basename(argv[0]);
213 fprintf(stderr,
"%s: '%s': Bad permissions mode.\n",
Argv0,
OptsMode);
220 fprintf(stderr,
"%s: No GPIO pin number <gpio> specified.\n",
Argv0);
226 fprintf(stderr,
"%s: '%s': Bad GPIO number.\n",
Argv0, argv[0]);
242 fprintf(stderr,
"%s: '%s': Bad GPIO direction.\n",
Argv0, argv[1]);
271 fprintf(stderr,
"%s: '%s': Bad GPIO edge.\n",
Argv0, argv[2]);
282 fprintf(stderr,
"%s: '%s...': What is this?.\n",
Argv0, argv[3]);
295 int main(
int argc,
char* argv[])
322 char gpioPath[MAX_PATH];
327 sprintf(path,
"%s/%s", gpioPath,
"value");
static void badCmdExit()
Exit program on bad command-line values.
#define GPIO_EDGE_FALLING
falling edge
static int strToMode(const string &str, mode_t &mode)
Convert string to file permissions.
#define NO_ARG
no argument
GPIO interface declarations and defines.
static int ArgsGpioDir
gpio direction
#define GPIO_EDGE_BOTH
both edges
#define GPIO_EDGE_FALLING_STR
falling edge string
static char * Argv0
the command
static int ArgsGpioNum
gpio number
#define GPIO_DIR_OUT_STR
output string
int gpioSetEdge(int gpio, int edge)
Set GPIO edge trigger type.
static OptsInfo_T OptsInfo[]
Command line options information.
static int ArgsGpioEdge
gpio edge trigger type
static OptsPgmInfo_T PgmInfo
Program information.
#define GPIO_EDGE_BOTH_STR
both edges string
#define GPIO_EDGE_NONE_STR
no edge string
#define GPIO_DIR_OUT
output
static const PkgInfo_T PkgInfo
#define GPIO_DIR_IN_STR
input string
#define GPIO_EDGE_NONE
no edge
int main(int argc, char *argv[])
Main.
#define APP_EC_EXEC
execution exit code
Package version information.
static mode_t Permissions
gpio permissions
#define GPIO_EDGE_RISING_STR
rising edge string
static void mainInit(int argc, char *argv[])
Main initialization.
int gpioSetDirection(int gpio, int dir)
Set GPIO signal direction.
void gpioMakeDirname(int gpio, char buf[], size_t size)
Make GPIO directory name.
#define GPIO_EDGE_RISING
rising edge
#define APP_EC_ARGS
command-line options/arguments error exit code
static char * OptsMode
permissions
static int strToInt(const string &str, int &val)
Convert string to integer.
#define APP_EC_OK
success exit code
int gpioExport(int gpio)
Export (create) a GPIO interface.