29 #include <sys/types.h> 36 #include "rnr/rnrconfig.h" 71 "Write a value to a GPIO pin.",
74 "The %P command writes the specified value to the GPIO at the given " 75 "<gpio> exported number." 76 "A value of 0 sets the pin low. " 77 "A value of 1 set the pin high.",
100 "GPIO access method. One of: sysfs mmap." 107 static int strToInt(
const string &str,
int &val)
111 if( sscanf(str.c_str(),
"%lli", &val1) != 1 )
133 Argv0 = basename(argv[0]);
140 fprintf(stderr,
"%s: No GPIO pin number <gpio> specified.\n",
Argv0);
141 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
145 else if( strToInt(argv[0],
ArgsGpio) < 0 )
147 fprintf(stderr,
"%s: '%s': Bad GPIO number.\n",
Argv0, argv[0]);
148 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
154 fprintf(stderr,
"%s: No value specified.\n",
Argv0);
155 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
159 else if( (strToInt(argv[1],
ArgsValue) < 0) ||
162 fprintf(stderr,
"%s: '%s': Bad value.\n",
Argv0, argv[1]);
163 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
199 static int mmapWrite()
203 if( mmapGpioMap() < 0 )
231 int main(
int argc,
char* argv[])
252 fprintf(stderr,
"%s: Unknown GPIO access method.",
OptsMethod);
#define APP_EC_OK
success exit code
static int ArgsGpio
gpio number
static char * OptsMethod
system file system
static OptsPgmInfo_T PgmInfo
Program information.
GPIO interface declarations and defines.
static char * Argv0
the command
int gpioWrite(int gpio, int value)
Write GPIO value.
static int sysfsWrite()
Write value to GPIO.
static int ArgsValue
value to write
static const PkgInfo_T PkgInfo
#define APP_EC_ARGS
command-line options/arguments error exit code
int main(int argc, char *argv[])
Main.
Package version information.
static OptsInfo_T OptsInfo[]
Command line options information.
static void mainInit(int argc, char *argv[])
Main initialization.
#define APP_EC_EXEC
execution exit code