void wifi_init(FILE *output, FILE *input, int (*available)()) { pin_set_direction(Pin_Wifi_Enable, Direction_Output); serial_output = output; serial_input = input; serial_available = available; }
int main(int argc, char **argv) { struct pollfd *fdlist; int numfds = 0; int ch; int i; while (-1 != (ch = getopt(argc, argv, OPTSTRING))) { switch (ch) { case OPT_LOGFILE: logfile = strdup(optarg); break; case OPT_DETACH: detach = 1; break; case OPT_SCRIPT_DIR: script_dir = strdup(optarg); break; case OPT_DEFAULT_EDGE: if (-1 == (default_edge = parse_edge(optarg))) { fprintf(stderr, "error: invalid edge value: %s\n", optarg); exit(1); } break; case OPT_VERBOSE: loglevel += 1; break; case '?': usage(stderr); exit(2); } } if (logfile) { int fd; if (-1 == (fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0644))) { LOG_ERROR("failed to open logfile %s", logfile); exit(1); } close(1); close(2); dup(fd); dup(fd); } if (! is_dir(script_dir)) { LOG_ERROR("error: script directory \"%s\" does not exist.", script_dir); exit(1); } for (i=optind; i<argc; i++) { char *pos, *pinspec; struct pin p; pinspec = strdup(argv[i]); pos = strchr(pinspec, ':'); if (pos) { *pos = '\0'; pos++; p.pin = atoi(pinspec); if (-1 == (p.edge = parse_edge(pos))) { fprintf(stderr, "error: unknown edge spec: %s\n", argv[i]); exit(1); } } else { p.pin = atoi(pinspec); p.edge = default_edge; } free(pinspec); num_pins++; pins = realloc(pins, sizeof(struct pin) * num_pins); pins[num_pins-1] = p; } for (i=0; i<num_pins; i++) { pin_export(pins[i].pin); pin_set_edge(pins[i].pin, pins[i].edge); pin_set_direction(pins[i].pin, DIRECTION_IN); } if (detach) daemon(1, logfile ? 1: 0); watch_pins(); return 0; }