static struct threadqueue_t *initDev(JsonNode *jdevice) { char *platform = GPIO_PLATFORM; if(config_setting_get_string("gpio-platform", 0, &platform) != 0) { logprintf(LOG_ERR, "no gpio-platform configured"); return NULL; } if(strcmp(platform, "none") == 0) { FREE(platform); logprintf(LOG_ERR, "no gpio-platform configured"); return NULL; } if(wiringXSetup(platform, logprintf1) < 0) { FREE(platform); return NULL; } FREE(platform); loop = 1; char *output = json_stringify(jdevice, NULL); JsonNode *json = json_decode(output); json_free(output); struct protocol_threads_t *node = protocol_thread_init(gpio_switch, json); return threads_register("gpio_switch", &thread, (void *)node, 0); }
static struct threadqueue_t *initDev(JsonNode *jdevice) { loop = 1; char *output = json_stringify(jdevice, NULL); JsonNode *json = json_decode(output); json_free(output); struct protocol_threads_t *node = protocol_thread_init(ds18s20, json); return threads_register("ds18s20", &thread, (void *)node, 0); }
struct threadqueue_t *ds18b20InitDev(JsonNode *jdevice) { ds18b20_loop = 1; char *output = json_stringify(jdevice, NULL); JsonNode *json = json_decode(output); sfree((void *)&output); struct protocol_threads_t *node = protocol_thread_init(ds18b20, json); return threads_register("ds18b20", &ds18b20Parse, (void *)node, 0); }
struct threadqueue_t *programInitDev(JsonNode *jdevice) { program_loop = 1; char *output = json_stringify(jdevice, NULL); JsonNode *json = json_decode(output); sfree((void *)&output); struct protocol_threads_t *node = protocol_thread_init(program, json); return threads_register("program", &programParse, (void *)node, 0); }
struct threadqueue_t *xbmcInitDev(JsonNode *jdevice) { xbmc_loop = 1; char *output = json_stringify(jdevice, NULL); JsonNode *json = json_decode(output); sfree((void *)&output); struct protocol_threads_t *node = protocol_thread_init(xbmc, json); return threads_register("xbmc", &xbmcParse, (void *)node, 0); }
static struct threadqueue_t *dht22InitDev(JsonNode *jdevice) { dht22_loop = 1; wiringXSetup(); char *output = json_stringify(jdevice, NULL); JsonNode *json = json_decode(output); json_free(output); struct protocol_threads_t *node = protocol_thread_init(dht22, json); return threads_register("dht22", &dht22Parse, (void *)node, 0); }
int main(int argc, char **argv) { gc_attach(main_gc); /* Catch all exit signals for gc */ gc_catch(); log_shell_enable(); log_file_disable(); log_level_set(LOG_NOTICE); struct options_t *options = NULL; char *args = NULL; char *hwfile = NULL; pid_t pid = 0; if(!(settingsfile = malloc(strlen(SETTINGS_FILE)+1))) { logprintf(LOG_ERR, "out of memory"); exit(EXIT_FAILURE); } strcpy(settingsfile, SETTINGS_FILE); if(!(progname = malloc(12))) { logprintf(LOG_ERR, "out of memory"); exit(EXIT_FAILURE); } strcpy(progname, "pilight-raw"); options_add(&options, 'H', "help", OPTION_NO_VALUE, 0, JSON_NULL, NULL, NULL); options_add(&options, 'V', "version", OPTION_NO_VALUE, 0, JSON_NULL, NULL, NULL); options_add(&options, 'S', "settings", OPTION_HAS_VALUE, 0, JSON_NULL, NULL, NULL); while (1) { int c; c = options_parse(&options, argc, argv, 1, &args); if(c == -1) break; if(c == -2) c = 'H'; switch (c) { case 'H': printf("Usage: %s [options]\n", progname); printf("\t -H --help\t\tdisplay usage summary\n"); printf("\t -V --version\t\tdisplay version\n"); printf("\t -S --settings\t\tsettings file\n"); return (EXIT_SUCCESS); break; case 'V': printf("%s %s\n", progname, VERSION); return (EXIT_SUCCESS); break; case 'S': if(access(args, F_OK) != -1) { settingsfile = realloc(settingsfile, strlen(args)+1); if(!settingsfile) { logprintf(LOG_ERR, "out of memory"); exit(EXIT_FAILURE); } strcpy(settingsfile, args); settings_set_file(args); } else { fprintf(stderr, "%s: the settings file %s does not exists\n", progname, args); return EXIT_FAILURE; } break; default: printf("Usage: %s [options]\n", progname); return (EXIT_FAILURE); break; } } options_delete(options); char pilight_daemon[] = "pilight-daemon"; char pilight_learn[] = "pilight-learn"; char pilight_debug[] = "pilight-debug"; if((pid = findproc(pilight_daemon, NULL)) > 0) { logprintf(LOG_ERR, "pilight-daemon instance found (%d)", (int)pid); return (EXIT_FAILURE); } if((pid = findproc(pilight_learn, NULL)) > 0) { logprintf(LOG_ERR, "pilight-learn instance found (%d)", (int)pid); return (EXIT_FAILURE); } if((pid = findproc(pilight_debug, NULL)) > 0) { logprintf(LOG_ERR, "pilight-debug instance found (%d)", (int)pid); return (EXIT_FAILURE); } if(access(settingsfile, F_OK) != -1) { if(settings_read() != 0) { return EXIT_FAILURE; } } hardware_init(); if(settings_find_string("hardware-file", &hwfile) == 0) { hardware_set_file(hwfile); if(hardware_read() == EXIT_FAILURE) { goto clear; } } /* Start threads library that keeps track of all threads used */ threads_create(&pth, NULL, &threads_start, (void *)NULL); struct conf_hardware_t *tmp_confhw = conf_hardware; while(tmp_confhw) { if(tmp_confhw->hardware->init() == EXIT_FAILURE) { logprintf(LOG_ERR, "could not initialize %s hardware mode", tmp_confhw->hardware->id); goto clear; } threads_register(tmp_confhw->hardware->id, &receive_code, (void *)tmp_confhw->hardware, 0); tmp_confhw = tmp_confhw->next; } while(main_loop) { sleep(1); } clear: main_gc(); return (EXIT_FAILURE); }
struct threadqueue_t *lircInitDev(JsonNode *jdevice) { lirc_loop = 1; struct protocol_threads_t *node = protocol_thread_init(lirc, NULL); return threads_register("lirc", &lircParse, (void *)node, 0); }