From: Ahmed R. <eng...@gm...> - 2011-03-07 15:36:24
|
You are right , this is much better one On Mon, Mar 7, 2011 at 4:27 PM, Patrick Maheral <pma...@dr...>wrote: > That seems like overkill to write a C-application that just spawns off > another process. If you plan to use that approach, I'd suggest sticking > with a shell script. If you want to be a little more efficient, try > something like this: > > #include <stdio.h> > const char dirInString[] = "in\n"; > > int main(int argc, char *argv[]) > { > int gpio13Fd; > gpio13DFd = open("/proc/gpio/GPIO13"); > if (gpio13Fd < 0) { > perror("Could not open GPIO13"); > exit (-1); > } > > write (gpio13Fd, dirInString, strlen(dirInString); > > close(gpio13Fd); > } > > It's a little longer than your example, but you can do other operations on > that file (GPIO13) before closing and exiting. I haven't looked at the > "/proc/gpio" interface, so I'm not sure what else you can do to that file, > but I have used the "/sys/..." interface which has multiple files for each > GPIO (eg. direction, value). If you want to take one step further, you > could open "/dev/mem" and mmap GPIO registers (see devmem2), but requires > root privileges, and may be dangerous if you are not carefull. > > Patrick > > > ------------------------------ > *From:* Ahmed Ramadan [mailto:eng...@gm...] > *Sent:* March 6, 2011 06:20 > *To:* General mailing list for gumstix users. > *Subject:* Re: [Gumstix-users] C-Application to read and write GPIO > [snip] > > thanks, i found it, very simple :) > this is my application to control the GPIOs > > #include <stdio.h> > > int main(){ > > system("echo in > /proc/gpio/GPIO13"); > } > thanks again :) > -- > *A.Ramadan > > Cellular: +20-12-9961294 > Tel: +202-22392779 > > * > > > > ------------------------------------------------------------------------------ > What You Don't Know About Data Connectivity CAN Hurt You > This paper provides an overview of data connectivity, details > its effect on application quality, and explores various alternative > solutions. http://p.sf.net/sfu/progress-d2d > _______________________________________________ > gumstix-users mailing list > gum...@li... > https://lists.sourceforge.net/lists/listinfo/gumstix-users > > -- *A.Ramadan Cellular: +20-12-9961294 Tel: +202-22392779 * |