gpio  1.4.2
General Purpose I/O Package
gpiodirection

Macros

#define APP_EC_OK   0
 success exit code
 
#define APP_EC_ARGS   2
 command-line options/arguments error exit code
 
#define APP_EC_EXEC   4
 execution exit code
 

Functions

static int strToInt (const string &str, int &val)
 
static void mainInit (int argc, char *argv[])
 Main initialization. More...
 
static int sysfsSetDirection ()
 Set GPIO directiion. More...
 
int main (int argc, char *argv[])
 Main. More...
 

Variables

static char * Argv0
 the command
 
static char * OptsMethod = (char *)"sysfs"
 system file system
 
static int ArgsGpio
 gpio number
 
static int ArgsDirection
 gpio direction
 
static OptsPgmInfo_T PgmInfo
 Program information. More...
 
static OptsInfo_T OptsInfo []
 Command line options information. More...
 

Detailed Description

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Main.

Parameters
argcCommand-line argument count.
argvCommand-line argument list.
Returns
Returns 0 on succes, non-zero on failure.

Definition at line 237 of file gpiodirection.cxx.

References APP_EC_ARGS, mainInit(), OptsMethod, and sysfsSetDirection().

238 {
239  int ec;
240 
241  mainInit(argc, argv);
242 
243  if( !strcmp(OptsMethod, "sysfs") )
244  {
245  ec = sysfsSetDirection();
246  }
247 #ifdef MMAP_GPIO
248  else if( !strcmp(OptsMethod, "mmap") )
249  {
250  ec = mmapSetDirection();
251  }
252 #endif // MMAP_GPIO
253  else
254  {
255  fprintf(stderr,"%s: Unknown GPIO access method.", OptsMethod);
256  ec = APP_EC_ARGS;
257  }
258 
259  return ec;
260 }
#define APP_EC_ARGS
command-line options/arguments error exit code
static char * OptsMethod
system file system
static void mainInit(int argc, char *argv[])
Main initialization.
static int sysfsSetDirection()
Set GPIO directiion.
static void mainInit ( int  argc,
char *  argv[] 
)
static

Main initialization.

Parameters
argcCommand-line argument count.
argvCommand-line argument list.
Exits:
Program terminates on conversion error.

Definition at line 130 of file gpiodirection.cxx.

References APP_EC_ARGS, ArgsDirection, ArgsGpio, Argv0, GPIO_DIR_IN, GPIO_DIR_IN_STR, GPIO_DIR_OUT, GPIO_DIR_OUT_STR, OptsInfo, PgmInfo, and PkgInfo.

Referenced by main().

131 {
132  // name of this process
133  Argv0 = basename(argv[0]);
134 
135  // parse input options
136  argv = OptsGet(Argv0, &PkgInfo, &PgmInfo, OptsInfo, true, &argc, argv);
137 
138  if( argc == 0 )
139  {
140  fprintf(stderr, "%s: No GPIO pin number <gpio> specified.\n", Argv0);
141  fprintf(stderr, "Try '%s --help' for more information.\n", Argv0);
142  exit(APP_EC_ARGS);
143  }
144 
145  else if( strToInt(argv[0], ArgsGpio) < 0 )
146  {
147  fprintf(stderr, "%s: '%s': Bad GPIO number.\n", Argv0, argv[0]);
148  fprintf(stderr, "Try '%s --help' for more information.\n", Argv0);
149  exit(APP_EC_ARGS);
150  }
151 
152  if( argc == 1 )
153  {
154  fprintf(stderr, "%s: No GPIO direction specified.\n", Argv0);
155  fprintf(stderr, "Try '%s --help' for more information.\n", Argv0);
156  exit(APP_EC_ARGS);
157  }
158  else if( !strcmp(argv[1], GPIO_DIR_IN_STR) )
159  {
161  }
162  else if( !strcmp(argv[1], GPIO_DIR_OUT_STR) )
163  {
165  }
166  else
167  {
168  fprintf(stderr, "%s: '%s': Bad direction.\n", Argv0, argv[1]);
169  fprintf(stderr, "Try '%s --help' for more information.\n", Argv0);
170  exit(APP_EC_ARGS);
171  }
172 }
static int ArgsDirection
gpio direction
#define APP_EC_ARGS
command-line options/arguments error exit code
#define GPIO_DIR_IN
input
Definition: gpio.h:68
#define GPIO_DIR_OUT_STR
output string
Definition: gpio.h:71
static OptsPgmInfo_T PgmInfo
Program information.
static char * Argv0
the command
#define GPIO_DIR_OUT
output
Definition: gpio.h:69
static const PkgInfo_T PkgInfo
Definition: version.h:45
#define GPIO_DIR_IN_STR
input string
Definition: gpio.h:70
static OptsInfo_T OptsInfo[]
Command line options information.
static int ArgsGpio
gpio number
static int sysfsSetDirection ( )
static

Set GPIO directiion.

Method: sysfs

Returns
Application exit code.

Definition at line 181 of file gpiodirection.cxx.

References APP_EC_EXEC, APP_EC_OK, ArgsDirection, ArgsGpio, and gpioSetDirection().

Referenced by main().

182 {
183  int ec;
184 
186  {
187  ec = APP_EC_EXEC;
188  }
189  else
190  {
191  ec = APP_EC_EXEC;
192  }
193 
194  return ec;
195 }
static int ArgsDirection
gpio direction
#define APP_EC_EXEC
execution exit code
static int ArgsGpio
gpio number
int gpioSetDirection(int gpio, int dir)
Set GPIO signal direction.
Definition: gpio.c:250

Variable Documentation

OptsInfo_T OptsInfo[]
static
Initial value:
=
{
{NULL, }
}

Command line options information.

Definition at line 86 of file gpiodirection.cxx.

Referenced by mainInit().

OptsPgmInfo_T PgmInfo
static
Initial value:
=
{
"<gpio> {in | out}",
"Set GPIO pin direction.",
"The %P command sets the direction for the GPIO associated with the given "
"<gpio> exported number."
"An input (in) direction allows for the value of the GPIO to be read. "
"An output (out) direction allows for writing of values to the GPIO.",
NULL
}

Program information.

Definition at line 65 of file gpiodirection.cxx.

Referenced by mainInit().