Example #1
0
int main(void) {
  uchar   updateNeeded = 0;
  uchar   idleCounter = 0;

  wdt_enable(WDTO_2S); /* Enable watchdog timer 2s */
  hardwareInit(); /* Initialize hardware (I/O) */
  
  //odDebugInit();

  usbInit(); /* Initialize USB stack processing */
  sei(); /* Enable global interrupts */
  
  for(;;){  /* Main loop */
    wdt_reset(); /* Reset the watchdog */
    usbPoll(); /* Poll the USB stack */

    updateNeeded|=scankeys(); /* Scan the keyboard for changes */
    
    /* Check timer if we need periodic reports */
    if(TIFR0 & (1<<TOV0)){
      TIFR0 = 1<<TOV0; /* Reset flag */
      if(idleRate != 0){ /* Do we need periodic reports? */
        if(idleCounter > 4){ /* Yes, but not yet */
          idleCounter -= 5;   /* 22 ms in units of 4 ms */
        }else{ /* Yes, it is time now */
          updateNeeded = 1;
          idleCounter = idleRate;
        }
      }
    }
    
    /* If an update is needed, send the report */
    if(updateNeeded && usbInterruptIsReady()){
      updateNeeded = 0;
      usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
    }
  }
  return 0;
}
Example #2
0
int
main(int argc, char *argv[])
{
	int ch;
	FILE *f;
	struct quotahandle *qh;

	int dflag = 0;
	const char *volume = NULL;
	const char *dumpfile = NULL;

	while ((ch = getopt(argc, argv, "d")) != -1) {
		switch (ch) {
		    case 'd': dflag = 1; break;
		    default: usage(); break;
		}
	}

	if (optind >= argc) {
		usage();
	}
	volume = argv[optind++];
	if (optind < argc) {
		dumpfile = argv[optind++];
	}
	if (optind < argc) {
		usage();
	}

	qh = quota_open(volume);
	if (qh == NULL) {
		err(EXIT_FAILURE, "quota_open: %s", volume);
	}
	if (dumpfile != NULL) {
		f = fopen(dumpfile, "r");
		if (f == NULL) {
			err(EXIT_FAILURE, "%s", dumpfile);
		}
	} else {
		f = stdin;
		dumpfile = "<stdin>";
	}

	maketables(qh);

	if (dflag) {
		struct qklist *seenkeys, *dropkeys;

		seenkeys = qklist_create();
		dropkeys = qklist_create();

		readdumpfile(qh, f, dumpfile, seenkeys);
		qklist_sort(seenkeys);
		scankeys(qh, seenkeys, dropkeys);
		purge(qh, dropkeys);

		qklist_destroy(dropkeys);
		qklist_destroy(seenkeys);
	} else {
		readdumpfile(qh, f, dumpfile, NULL);
	}

	if (f != stdin) {
		fclose(f);
	}
	quota_close(qh);
	return EXIT_SUCCESS;
}