Esempio n. 1
0
static void usage(const char * progname)
{
    static const char firewire_args[] =
	"[-c CARD-NUMBER | DEVICE]";
    static const char v4l2_args[] = "[DEVICE]";
    static const char other_args[] =
	"[-t] [-h HOST] [-p PORT] [-i ID]";

    switch (program_mode(progname))
    {
    case mode_unknown:
	fprintf(stderr,
		"Usage: %s %s \\\n"
		"           --firewire %s\n"
		"       %s %s \\\n"
		"           --v4l2 %s\n",
		progname, other_args, firewire_args,
		progname, other_args, v4l2_args);
	break;
    case mode_firewire:
	fprintf(stderr,
		"Usage: %s %s \\\n"
		"           %s\n",
		progname, other_args, firewire_args);
	break;
    case mode_v4l2:
	fprintf(stderr,
		"Usage: %s %s \\\n"
		"           %s\n",
		progname, other_args, v4l2_args);
	break;
    }
}
Esempio n. 2
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  my_usb_init();
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_TIM1_Init();
  MX_USB_DEVICE_Init();
  MX_USART3_UART_Init();
  MX_TIM2_Init();

  /* USER CODE BEGIN 2 */
  HAL_TIM_Base_Start(&htim2);
  delay_us_init(&htim2);
  softserial_init(SOFTSERIAL_TX_GPIO_Port, SOFTSERIAL_TX_Pin);
  hmi_lcd_init(&huart3);
  cpu_ctrl_init(&htim1);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  HAL_Delay(100);
  hsc_stop();
  cpu_reset();
  lcd_clear();
  addr_input();
  data_input();
  build_ui();
  HAL_Delay(100);

  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
    if(is_running == 0)
      addr_data_display_update();

    // z80 reset button
    if(is_button_1_pressed)
    {
      hsc_stop();
      cpu_reset();
      lcd_print_width(130, 110, 180, 45, "CYAN", "RESET");
      is_button_1_pressed = 0;
      HAL_Delay(500);
      build_ui();
    }

    // clk step button
    if(is_button_3_pressed)
    {
      hsc_stop();
      cycle_clock(1);
      lcd_print_width(130, 110, 180, 45, "RED", "CLK STEP");
      is_button_3_pressed = 0;
      HAL_Delay(100);
      build_ui();
    }

    // ins step button
    if(is_button_4_pressed)
    {
      hsc_stop();
      lcd_print_width(130, 110, 180, 45, "GREEN", "INS STEP");
      // cycle clock until we're at next M1 cycle
      while(HAL_GPIO_ReadPin(CPU_CTRL_PORT, M1_Pin) == LOW)
        cycle_clock(1);
      while(HAL_GPIO_ReadPin(CPU_CTRL_PORT, M1_Pin) == HIGH)
        cycle_clock(1);
      is_button_4_pressed = 0;
      HAL_Delay(100);
      build_ui();
    }

    // run/stop button
    if(is_button_5_pressed)
    {
      is_running = (is_running + 1) % 2;
      if(is_running)
      {
        lcd_print_width(130, 110, 180, 45, "GREEN", "RUNNING");
        hsc_start();
      }
      else
      {
        hsc_stop();
        build_ui();
      }
      is_button_5_pressed = 0;
    }

    usb_data = my_usb_readline();
    if(usb_data != NULL && strstr(usb_data, "epm") != NULL)
    {
      hsc_stop();
      program_mode();
      build_ui();
    }
  }
  /* USER CODE END 3 */

}
Esempio n. 3
0
int main(int argc, char ** argv)
{
    mode = program_mode(argv[0]);

    /* Initialise settings from configuration files. */
    dvswitch_read_config(handle_config);

    /* Parse arguments. */

    int opt;
    while ((opt = getopt_long(argc, argv, "c:h:p:i:t", options, NULL)) != -1)
    {
	switch (opt)
	{
	case 'c':
	    free(firewire_card);
	    firewire_card = strdup(optarg);
	    break;
	case 'F':
	    mode = mode_firewire;
	    break;
	case 'V':
	    mode = mode_v4l2;
	    break;
	case 'h':
	    free(mixer_host);
	    mixer_host = strdup(optarg);
	    break;
	case 'p':
	    free(mixer_port);
	    mixer_port = strdup(optarg);
	    break;
	case 't':
	    do_tally = 1;
	    break;
	case 'i':
	    {
		long id = strtoul(optarg, NULL, 10);
		mixer_id = (id < 255) ? id-1 : 255;
	    }
	    break;
	case 'H': /* --help */
	    usage(argv[0]);
	    return 0;
	default:
	    usage(argv[0]);
	    return 2;
	}
    }

    if (optind != argc)
    {
	free(device_name);
	device_name = strdup(argv[optind++]);
    }

    if (!mixer_host || !mixer_port)
    {
	fprintf(stderr, "%s: mixer hostname and port not defined\n",
		argv[0]);
	return 2;
    }

    if (optind != argc)
    {
	fprintf(stderr, "%s: excess argument \"%s\"\n",
		argv[0], argv[optind]);
	usage(argv[0]);
	return 2;
    }

    if (mode == mode_firewire)
    {
	if (device_name)
	    printf("INFO: Reading from Firewire device %s\n", device_name);
	else if (firewire_card)
	    printf("INFO: Reading from Firewire card %s\n", firewire_card);
	else
	    printf("INFO: Reading from first Firewire card with camera\n");
    }
    else if (mode == mode_v4l2)
    {
	if (!device_name)
	    device_name = "/dev/video";
	printf("INFO: Reading from V4L2 device %s\n", device_name);
    }
    else
    {
	fprintf(stderr, "%s: mode not defined (Firewire or V4L2)\n", argv[0]);
	return 2;
    }

    /* Connect to the mixer, set that as stdout, and run dvgrab. */

    printf("INFO: Connecting to %s:%s\n", mixer_host, mixer_port);
    int sock = create_connected_socket(mixer_host, mixer_port);
    assert(sock >= 0); /* create_connected_socket() should handle errors */
    if (write(sock, do_tally ? GREETING_ACT_SOURCE : GREETING_SOURCE,
              GREETING_SIZE-1) != GREETING_SIZE-1)
    {
	perror("ERROR: write");
	exit(1);
    }
    if (write(sock, &mixer_id, sizeof(mixer_id)) != sizeof(mixer_id))
    {
	perror("ERROR: write");
	exit(1);
    }
    if (do_tally)
    {
	fflush(NULL);
	int child_pid = fork();

	if (child_pid < 0)
	{
	    perror("ERROR: fork");
	    return 1;
	}
	if (child_pid == 0)
	{
	    tally(sock);
	    _exit(0);
	}
    }
    if (dup2(sock, STDOUT_FILENO) < 0)
    {
	perror("ERROR: dup2");
	return 1;
    }
    close(sock);

    char * dvgrab_argv[7];
    char ** argp = dvgrab_argv;
    *argp++ = "dvgrab";
    if (mode == mode_v4l2)
	*argp++ = "-v4l2";
    if (device_name)
    {
	*argp++ = "-input";
	*argp++ = device_name;
    }
    else if (firewire_card)
    {
	*argp++ = "-card";
	*argp++ = firewire_card;
    }
    *argp++ = "-noavc";
    *argp++ = "-";
    *argp = NULL;
    assert(argp < dvgrab_argv + sizeof(dvgrab_argv) / sizeof(dvgrab_argv[0]));

    execvp("dvgrab", dvgrab_argv);
    perror("ERROR: execvp");
    return 1;
}