int blinkm_main(int argc, char *argv[]) { int i2cdevice = 3; int blinkmadr = 9; int x; for (x = 1; x < argc; x++) { if (strcmp(argv[x], "-b") == 0 || strcmp(argv[x], "--bus") == 0) { if (argc > x + 1) { i2cdevice = atoi(argv[x + 1]); } } if (strcmp(argv[x], "-a") == 0 || strcmp(argv[x], "--blinkmaddr") == 0) { if (argc > x + 1) { blinkmadr = atoi(argv[x + 1]); } } } if (!strcmp(argv[1], "start")) { if (g_blinkm != nullptr) errx(1, "already started"); g_blinkm = new BlinkM(i2cdevice, blinkmadr); if (g_blinkm == nullptr) errx(1, "new failed"); if (OK != g_blinkm->init()) { delete g_blinkm; g_blinkm = nullptr; errx(1, "init failed"); } exit(0); } if (g_blinkm == nullptr) { fprintf(stderr, "not started\n"); blinkm_usage(); exit(0); } if (!strcmp(argv[1], "systemstate")) { g_blinkm->setMode(1); exit(0); } if (!strcmp(argv[1], "ledoff")) { g_blinkm->setMode(0); exit(0); } if (!strcmp(argv[1], "list")) { for (unsigned i = 0; BlinkM::script_names[i] != nullptr; i++) fprintf(stderr, " %s\n", BlinkM::script_names[i]); fprintf(stderr, " <html color number>\n"); exit(0); } /* things that require access to the device */ int fd = open(BLINKM_DEVICE_PATH, 0); if (fd < 0) err(1, "can't open BlinkM device"); g_blinkm->setMode(0); if (ioctl(fd, BLINKM_PLAY_SCRIPT_NAMED, (unsigned long)argv[1]) == OK) exit(0); blinkm_usage(); exit(0); }
int blinkm_main(int argc, char *argv[]) { int i2cdevice = PX4_I2C_BUS_EXPANSION; int blinkmadr = 9; int x; if (argc < 2) { blinkm_usage(); return 1; } for (x = 1; x < argc; x++) { if (strcmp(argv[x], "-b") == 0 || strcmp(argv[x], "--bus") == 0) { if (argc > x + 1) { i2cdevice = atoi(argv[x + 1]); } } if (strcmp(argv[x], "-a") == 0 || strcmp(argv[x], "--blinkmaddr") == 0) { if (argc > x + 1) { blinkmadr = atoi(argv[x + 1]); } } } if (!strcmp(argv[1], "start")) { if (g_blinkm != nullptr) { warnx("already started"); return 1; } g_blinkm = new BlinkM(i2cdevice, blinkmadr); if (g_blinkm == nullptr) { warnx("new failed"); return 1; } if (OK != g_blinkm->init()) { delete g_blinkm; g_blinkm = nullptr; warnx("init failed"); return 1; } return 0; } if (g_blinkm == nullptr) { fprintf(stderr, "not started\n"); blinkm_usage(); return 0; } if (!strcmp(argv[1], "systemstate")) { g_blinkm->setMode(1); return 0; } if (!strcmp(argv[1], "ledoff")) { g_blinkm->setMode(0); return 0; } if (!strcmp(argv[1], "list")) { for (unsigned i = 0; BlinkM::script_names[i] != nullptr; i++) { fprintf(stderr, " %s\n", BlinkM::script_names[i]); } fprintf(stderr, " <html color number>\n"); return 0; } /* things that require access to the device */ int fd = px4_open(BLINKM0_DEVICE_PATH, 0); if (fd < 0) { warn("can't open BlinkM device"); return 1; } g_blinkm->setMode(0); if (px4_ioctl(fd, BLINKM_PLAY_SCRIPT_NAMED, (unsigned long)argv[1]) == OK) { return 0; } px4_close(fd); blinkm_usage(); return 0; }