Esempio n. 1
0
int main()
{
	rcp_device *devs;
	int num;

	tlog_init(TLOG_MODE_STDERR, TLOG_DEBUG, NULL);

	autodetect(&devs, &num);

	TL_INFO("%d device%s detected", num, num>1?"s":"");
	for (int i=0; i<num; i++)
	{
		log_device(TLOG_INFO, &devs[i]);
		TL_INFO("------------------------");
	}

	free(devs);


	return 0;
}
Esempio n. 2
0
int pinsys_init(void)
{
	signal_length = (hw.code_length + (hw.code_length / BITS_COUNT) * 2) * 1000000 / 1200;

	if (!tty_create_lock(hw.device)) {
		logprintf(LOG_ERR, "could not create lock files");
		return (0);
	}
	if ((hw.fd = open(hw.device, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0) {
		int detected;
		/* last character gets overwritten */
		char auto_lirc_device[] = "/dev/ttyS_";

		tty_delete_lock();
		logprintf(LOG_WARNING, "could not open %s, autodetecting on /dev/ttyS[0-3]", hw.device);
		logperror(LOG_WARNING, "pinsys_init()");
		/* it can also mean you compiled serial support as a
		   module and it isn't inserted, but that's unlikely
		   unless you're me. */

		detected = autodetect();

		if (detected == -1) {
			logprintf(LOG_ERR, "no device found on /dev/ttyS[0-3]");
			tty_delete_lock();
			return (0);
		} else {	/* detected */

			auto_lirc_device[9] = '0' + detected;
			hw.device = auto_lirc_device;
			if ((hw.fd = open(hw.device, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0) {
				/* unlikely, but hey. */
				logprintf(LOG_ERR, "couldn't open autodetected device \"%s\"", hw.device);
				logperror(LOG_ERR, "pinsys_init()");
				tty_delete_lock();
				return (0);
			}
		}
	}
	if (!tty_reset(hw.fd)) {
		logprintf(LOG_ERR, "could not reset tty");
		pinsys_deinit();
		return (0);
	}
	if (!tty_setbaud(hw.fd, 1200)) {
		logprintf(LOG_ERR, "could not set baud rate");
		pinsys_deinit();
		return (0);
	}
	/* set RTS, clear DTR */
	if (!tty_set(hw.fd, 1, 0) || !tty_clear(hw.fd, 0, 1)) {
		logprintf(LOG_ERR, "could not set modem lines (DTR/RTS)");
		pinsys_deinit();
		return (0);
	}

	/* I dunno, but when lircd starts may log `reading of byte 1
	   failed' I know that happened when testing, it's a zero
	   byte. Problem is, flushing doesn't fix it. It's not fatal,
	   it's an indication that it gets fixed.  still... */

	if (tcflush(hw.fd, TCIFLUSH) < 0) {
		logprintf(LOG_ERR, "could not flush input buffer");
		pinsys_deinit();
		return (0);
	}
	return (1);
}
Esempio n. 3
0
/* BaseResourceArchivesPanel::onBtnDetect
 * Called when the 'Detect Archives' button is clicked
 *******************************************************************/
void BaseResourceArchivesPanel::onBtnDetect(wxCommandEvent& e)
{
	autodetect();
}
Esempio n. 4
0
File: lold.c Progetto: apirogov/lold
int main(int argc, char *argv[]) {
  if (eval_flag(argc,argv,"-h\0")) {
    printf("Usage: lold [-p PORT] [-D DELAY] [-d DEVICE]\n\n");
    return EXIT_FAILURE;
  }

  delay = int_arg(eval_arg(argc, argv, "-D\0", NULL), DEF_DELAY);
  port = int_arg(eval_arg(argc, argv, "-p\0", NULL), DEF_LOLD_PORT);
  device = eval_arg(argc, argv, "-d\0", NULL);
  to_stdout = eval_flag(argc, argv, "--stdout\0");

  if (!to_stdout && device==NULL) //no device provided?
    device = autodetect();
  if (!device && !to_stdout) //no device found by autodetect?
    fprintf(stderr, "No serial USB device found! (Try -d flag?) Output to stdout.\n");

  pthread_mutex_init(&imutex, NULL); //init mutex for interrupted flag
  pthread_mutex_init(&qmutex, NULL); //init mutex for queue

  //Start web server thread listening for clients sending stuff
  pthread_t serverThread;
  pthread_create(&serverThread, NULL, server_thread, NULL);
  pthread_detach(serverThread);

  //trap INT
  signal(SIGINT, sig_handler);

  LolTask *currtask = NULL; //task currently being executed

  //clean lolshield
  render_frame(device, EMPTY_FRAME);

  //loop outputting animation frames to device
  while (!shutting_down) {
    //do nothing if some client is streaming
    if (streaming) {
      sleep_ms(100);
      continue;
    }

    //New task arrived -> check stuff
    pthread_mutex_lock(&imutex);
    if (interrupted) {
      interrupted = 0;

      if (DEBUG) fprintf(stderr, "New task inserted!\n");

      if (queue==NULL)
        exit(EXIT_FAILURE); //can not happen!

      pthread_mutex_lock(&qmutex);
      LolTask *first = (LolTask*)(queue->value);
      pthread_mutex_unlock(&qmutex);

      //new arrived has higher priority? cancel current ani
      if (currtask != NULL && first->pri > currtask->pri) {
        loltask_free(currtask);
        currtask = NULL;

        if (DEBUG) fprintf(stderr, "Ani cancelled\n");
      }
    }
    pthread_mutex_unlock(&imutex);

    //load new task if neccessary
    if (currtask == NULL) {
      pthread_mutex_lock(&qmutex);
      currtask = lollist_shift(&queue);
      pthread_mutex_unlock(&qmutex);

      if (DEBUG) if (currtask != NULL) fprintf(stderr, "Ani start\n");
    }

    //nothing in queue -> just wait
    if (currtask == NULL) {
      sleep_ms(delay);
      continue;
    }

    //animation delay
    sleep_ms(currtask->delay);

    //get next frame
    char *frame = lollist_shift(&(currtask->frames));

    //current animation done?
    if (frame == NULL) {
      currtask = NULL;
      clean_tasks(); //remove aged tasks

      //render empty frame to clean lolshield -> breaks hardware text message
      //render_frame(device, EMPTY_FRAME);

      sleep_ms(delay);

      if (DEBUG) fprintf(stderr, "Ani done\n");
      continue;
    }

    //render next frame
    render_frame(device, frame);
    free(frame);
  }
  if (DEBUG) fprintf(stderr, "Shutting down\n");

  //shutting down
  render_frame(device, EMPTY_FRAME); //clean lolshield
  serialport_close(port); //close port
  pthread_cancel(serverThread); //kill server
  pthread_mutex_destroy(&qmutex); //uninit mutex
  pthread_mutex_destroy(&imutex); //uninit mutex

  close(svr_sock); //close server listening socket
  pthread_exit(NULL);
  return EXIT_SUCCESS;
}
Esempio n. 5
0
Config::Config(QWidget *parent,int index) : QDialog(parent)
{
    programPath = qApp->applicationDirPath() + "/";
    ui.setupUi(this);
    ui.tabConfiguration->setCurrentIndex(index);
    ui.radioManualProxy->setChecked(true);
    QRegExpValidator *proxyValidator = new QRegExpValidator(this);
    QRegExp validate("[0-9]*");
    proxyValidator->setRegExp(validate);
    ui.proxyPort->setValidator(proxyValidator);

    // build language list and sort alphabetically
    QStringList langs = findLanguageFiles();
    for(int i = 0; i < langs.size(); ++i)
        lang.insert(languageName(langs.at(i))
            + QString(" (%1)").arg(langs.at(i)), langs.at(i));
    lang.insert(DEFAULT_LANG, DEFAULT_LANG_CODE);
    QMap<QString, QString>::const_iterator i = lang.constBegin();
    while (i != lang.constEnd()) {
        ui.listLanguages->addItem(i.key());
        i++;
    }

    ComboBoxViewDelegate *delegate = new ComboBoxViewDelegate(this);
    ui.mountPoint->setItemDelegate(delegate);
#if !defined(DBG)
    ui.mountPoint->setEditable(false);
#endif

    ui.listLanguages->setSelectionMode(QAbstractItemView::SingleSelection);
    ui.proxyPass->setEchoMode(QLineEdit::Password);
    ui.treeDevices->setAlternatingRowColors(true);
    ui.listLanguages->setAlternatingRowColors(true);

    /* Explicitly set some widgets to have left-to-right layout */
    ui.treeDevices->setLayoutDirection(Qt::LeftToRight);
    ui.mountPoint->setLayoutDirection(Qt::LeftToRight);
    ui.proxyHost->setLayoutDirection(Qt::LeftToRight);
    ui.proxyPort->setLayoutDirection(Qt::LeftToRight);
    ui.proxyUser->setLayoutDirection(Qt::LeftToRight);
    ui.proxyPass->setLayoutDirection(Qt::LeftToRight);
    ui.listLanguages->setLayoutDirection(Qt::LeftToRight);
    ui.cachePath->setLayoutDirection(Qt::LeftToRight);
    ui.comboTts->setLayoutDirection(Qt::LeftToRight);

    this->setModal(true);

    connect(ui.buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
    connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(abort()));
    connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool)));
    connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool)));
    connect(ui.refreshMountPoint, SIGNAL(clicked()), this, SLOT(refreshMountpoint()));
    connect(ui.buttonAutodetect,SIGNAL(clicked()),this,SLOT(autodetect()));
    connect(ui.buttonCacheBrowse, SIGNAL(clicked()), this, SLOT(browseCache()));
    connect(ui.buttonCacheClear, SIGNAL(clicked()), this, SLOT(cacheClear()));
    connect(ui.configTts, SIGNAL(clicked()), this, SLOT(configTts()));
    connect(ui.configEncoder, SIGNAL(clicked()), this, SLOT(configEnc()));
    connect(ui.comboTts, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTtsState(int)));
    connect(ui.treeDevices, SIGNAL(itemSelectionChanged()), this, SLOT(updateEncState()));
    connect(ui.testTTS,SIGNAL(clicked()),this,SLOT(testTts()));
    connect(ui.showDisabled, SIGNAL(toggled(bool)), this, SLOT(showDisabled(bool)));
    connect(ui.mountPoint, SIGNAL(editTextChanged(QString)), this, SLOT(updateMountpoint(QString)));
    connect(ui.mountPoint, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMountpoint(int)));
    // delete this dialog after it finished automatically.
    connect(this, SIGNAL(finished(int)), this, SLOT(deleteLater()));

    setUserSettings();
    setDevices();
}