Exemplo n.º 1
0
static int
standard_session(const char* device, const char* fsName, bool interactive)
{
	// mount FS
	fssh_dev_t fsDev = _kern_mount(kMountPoint, device, fsName, 0, NULL, 0);
	if (fsDev < 0) {
		fprintf(stderr, "Error: Mounting FS failed: %s\n",
			fssh_strerror(fsDev));
		return 1;
	}

	// register commands
	register_commands();

	// process commands
	input_loop(interactive);

	// unmount FS
	_kern_setcwd(-1, "/");	// avoid a "busy" vnode
	fssh_status_t error = _kern_unmount(kMountPoint, 0);
	if (error != FSSH_B_OK) {
		fprintf(stderr, "Error: Unmounting FS failed: %s\n",
			fssh_strerror(error));
		return 1;
	}

	return 0;
}
void Visualize(int *argc, char** argv) {
	
	glutInit(argc, argv);											// --- Initializes the GLUT library
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);		// --- Sets the initial display mode
    //glutInitWindowSize(1024, 768);									// --- Sets the initial window size
    glutInitWindowSize(2048, 1024);									// --- Sets the initial window size
    glutInitWindowPosition (100, 100);								// --- Sets the initial window position
    glutCreateWindow(argv[0]);										// --- Creates a top level window

	// --- Black background
	//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);							// --- Clears the color buffer
	// --- White background
	glClearColor(1.0f, 1.0f, 1.0f, 1.0f);							// --- Clears the color buffer
    glClearDepth(1.0f);												// --- Specifies the depth value used when the depth buffer is cleared
    glDepthFunc(GL_LESS);											// --- Specifies the value used for depth buffer comparisons
    glEnable(GL_DEPTH_TEST);										// --- Specifies a symbolic constant indicating a GL capability
    glShadeModel(GL_SMOOTH);										// --- Specifies a symbolic value representing a shading technique

	srand((unsigned int)time(NULL));

	cam.pos = make_vec3(0, 3, 15);
    cam.elevation = 0;
    cam.azimut = 0;

	input_loop();
	//pthread_t thread1;

 //   int  iret1 = pthread_create(&thread1, NULL, input_loop, NULL);
 //   if(iret1) {
 //       fprintf(stderr,"Error - pthread_create() return code: %d\n",iret1);
 //       exit(EXIT_FAILURE);
 //   }

    mesh_colors.push_back(make_vec3(0.5,0,0));
    mesh_colors.push_back(make_vec3(0,0.5,0));
    mesh_colors.push_back(make_vec3(0,0,0.5));
    mesh_colors.push_back(make_vec3(1,1,0));
    mesh_colors.push_back(make_vec3(0,1,1));
    mesh_colors.push_back(make_vec3(1,0,1));
    mesh_colors.push_back(make_vec3(1,0.5,0.5));
    mesh_colors.push_back(make_vec3(0.2,0.5,1));
    mesh_colors.push_back(make_vec3(0.2,0.2,0.2));

    ray_colors.push_back(make_vec3(0.2f, 0.8f, 1.0f));
    ray_colors.push_back(make_vec3(0.2f, 1.0f, 1.0f));
    ray_colors.push_back(make_vec3(0.2f, 1.0f, 1.0f));
    ray_colors.push_back(make_vec3(1.0f, 0.2f, 0.2f));
    ray_colors.push_back(make_vec3(0.0f, 0.2f, 1.0f));

    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutKeyboardFunc(keyboardDown);
    glutKeyboardUpFunc(keyboardUp);
    glutTimerFunc(50, loop, 0);
    glutMainLoop();
}
Exemplo n.º 3
0
int					main(int argc, char **argv)
{
	t_environment	*env;

	if (argc < 2)
		ft_putendl_fd_exit("Usage: ft_select [parameters]", 2, 1);
	env = malloc(sizeof(t_environment));
	setup_environment(env, argc, argv);
	get_set_environment(env);
	set_signals(&restart);
	refresh_screen(0);
	input_loop();
	return (0);
}
Exemplo n.º 4
0
int
main(int argc, char** argv)
{
  const char* portname = "/dev/ttyS0";
  int         c;

  while ((c = getopt(argc, argv, "p:?")) != -1)
    switch (c)
    {
      case 'p': portname = optarg; break;
      case '?': exit_usage();
      default:  abort();
    }

  if (optind < argc)
    exit_usage();

  setlocale(LC_ALL, "");
  init_screen();

  int portfd = open(portname, O_RDWR | O_NOCTTY | O_NONBLOCK);
  if (portfd < 0)
    exit_error(portname, errno);

  init_serial_port(portfd, portname);

  int flags = fcntl(portfd, F_GETFL, 0);
  if (flags < 0 || fcntl(portfd, F_SETFL, flags & ~O_NONBLOCK) < 0)
    exit_error(portname, errno);

  wprintw(win_header, "Using serial port %s.\nPress CTRL-D to quit.", portname);
  waddch(win_prompt, '>');
  wnoutrefresh(win_header);
  wnoutrefresh(win_prompt);
  wnoutrefresh(win_input);
  doupdate();

  input_loop(portfd);

  while (close(portfd) < 0)
    if (errno != EINTR)
      exit_error(portname, errno);

  destroy_screen();
  return 0;
}
Exemplo n.º 5
0
/* prompt = NULL --> from gprc. Return 1 if new input, and 0 if EOF */
int
get_line_from_file(const char *prompt, filtre_t *F, FILE *file)
{
  char *s;
  input_method IM;

  IM.file = file;
  IM.fgets= (file==stdin && cb_pari_fgets_interactive)? cb_pari_fgets_interactive: &fgets;
  IM.getline = &file_input;
  IM.free = 0;
  if (! input_loop(F,&IM))
  {
    if (file==stdin && cb_pari_start_output) cb_pari_start_output();
    return 0;
  }
  s = F->buf->buf;
  /* don't log if from gprc or empty input */
  if (*s && prompt) gp_echo_and_log(prompt, s);
  return 1;
}
Exemplo n.º 6
0
int main(int argc, char **argv)
{


	if (argc <= 1) 
		cmdline_help();

	init_windows();
	init_buffers();

	for (argv++; *argv != NULL ; argv++) 
		current_buf = load_buffer(*argv);
		

	paint_buffer(current_buf);
	statusprintf("%s", current_buf->name);

	refresh();
	input_loop();

}
Exemplo n.º 7
0
void loop(){ //one frame
    static uint8_t escape_state = 0;
    uint16_t receive_state = 1;
    //primitive somewhat messy state machine of the uart interface
    do{ //Always empty the receive buffer since there are _delay_xxs in the following code and thus this might not run all that often.
        receive_state = uart_getc();
        char c = receive_state&0xFF;
        receive_state &= 0xFF00;
        //escape code format:
        // \\   - backslash
        // \n   - newline
        // \[x] - x
        //eats [n] commands:   's' (0x73) led value                         sets led number [led] to [value]
        //                     'b' (0x62) buffer buffer buffer buffer       sets the whole frame buffer
        //                     'a' (0x61) meter value                       sets analog meter number [meter] to [value]
        //                     'r' (0x72)                                   read the frame buffer
        //                     'd' (0x64) display digit digit digit digit   sets the 7-segment display (CAUTION: "display" currently is ignored)
        //this device will utter a "'c' (0x63) num state" when switch [num] changes state to [state]
        //commands are terminated by \n
        if(!receive_state){
            if(!escape_state){
                if(c == '\\'){
                    receive_state |= 0x02;
                    escape_state = 1;
                }else if(c == '\n'){
                    receive_state |= 0x02;
                    state = 0;
                }
            }else{
                receive_state = 0;
                escape_state = 0;
                switch(c){
                    case '\\':
                        break;
                    case 'n':
                        c = '\n';
                        break;
                }
            }
        }
        if(!receive_state){
            switch(state){
                case 0: //Do not assume anything about the variables used
                    //command char
                    switch(c){
#ifdef HAS_LED_SUPPORT
                        case 's':
                            state = 2;
                            break;
                        case 'b':
                            nbuf = 0;
                            state = 4;
                            break;
#endif//HAS_LED_SUPPORT
#ifdef HAS_PWM_SUPPORT
                        case 'a':
                            state = 5;
                            nbuf = 0;
                            break;
#endif//HAS_PWM_SUPPORT
#ifdef HAS_NOISE_MAKER_SUPPORT
                        case 'x':
                            //DDRF |= 0x01;
                            //PORTF |= 0x01;
                            break;
                        case 'X':
                            //DDRF &= 0xFE;
                            //PORTF &= 0xFE;
                            break;
#endif//HAS_NOISE_MAKER_SUPPORT
#ifdef HAS_LED_SUPPORT
                        case 'r':
                            uart_putc('r');
                            for(uint8_t i=0; i<sizeof(frameBuffer); i++){
                                uart_puthex(frameBuffer[i]);
                            }
                            uart_putc('\n');
                            break;
#endif//HAS_LED_SUPPORT
#ifdef HAS_7SEG_SUPPORT
                        case 'd':
                            nbuf = 0;
                            bpos = 0;
                            state = 7;
#endif//HAS_7SEG_SUPPORT
                    }
                    break;
#ifdef HAS_LED_SUPPORT
                case 2:
                    nbuf=c;
                    state = 3;
                    break;
                case 3:
                    setLED(nbuf, c);
                    state = 0;
                    break;
                case 4:
                    secondFrameBuffer[(uint8_t) nbuf] = c;
                    nbuf++;
                    if(nbuf == 7){
                        swapBuffers();
                        state = 0;
                    }
                    break;
#endif//HAS_LED_SUPPORT
#ifdef HAS_PWM_SUPPORT
                case 5:
                    if(c > PWM_COUNT)
                        c = 0;
                    nbuf = c;
                    if(nbuf >= PWM_COUNT)
                        nbuf = 0;
                    state = 6;
                    break;
                case 6:
                    pwm_val[(uint8_t) nbuf] = c;
                    uart_puts_p(PSTR("ACK\n"));
                    state = 0;
                    break;
#endif//HAS_PWM_SUPPORT
#ifdef HAS_7SEG_SUPPORT
                case 7:
                    nbuf = c;
                    state = 8;
                    break;
                case 8:
                    l7seg_buf[(uint8_t)bpos] = c;
                    bpos++;
                    if(bpos == 4){
                        state = 0;
                    }
                    break;
#endif//HAS_7SEG_SUPPORT
            }
        }
    }while(!receive_state);
    led_loop();
    r0ketbeam_loop();
    l7seg_loop();
    input_loop();
    pwm_loop();
    config_loop();
    _delay_ms(1);
}
Exemplo n.º 8
0
int main(int argc, char **argv)
{
    char logpath[FILENAME_MAX];
    int log;

    if (argc != 2) 
    {
        fprintf(stderr, PACKAGE_STRING "\n"
                "  (c) Copyright 2001-2004 The IceS Development Team <*****@*****.**>\n"
                "        Michael Smith <*****@*****.**>\n"
                "        Karl Heyes    <*****@*****.**>\n"
                "        and others\n"
                "\n"
                "Usage: \"ices config.xml\"\n");
        return 1;
    }

    config_initialize();

    if (config_read(argv[1]) <= 0) 
    {
        fprintf(stderr, "Failed to read config file \"%s\"\n", argv[1]);
        goto fail;
    }
	
    if (ices_config->background)
    {
#ifndef _WIN32		
        int ret = 0;
        /* Start up new session, to lose old session and process group */
        switch (fork())
        {
        case 0: break; /* child continues */
        case -1: perror ("fork"); ret = -1;
        default:
            exit (ret);
        }

        /* Disassociate process group and controlling terminal */ 
        setsid();

        /* Become a NON-session leader so that a */
        /* control terminal can't be reacquired */
        switch (fork())
        {
        case 0: break; /* child continues */
        case -1: perror ("fork"); ret = -1;
        default:
            exit (ret);
        }
#else
        FreeConsole();
#endif    		
    }

    log_initialize();
    thread_initialize();
    shout_init();
    encode_init();
#ifndef _WIN32	
    signals_setup();
#endif

    snprintf(logpath, FILENAME_MAX, "%s/%s", ices_config->logpath, 
            ices_config->logfile);
    if(ices_config->log_stderr)
        log = log_open_file(stderr);
    else
    {
        log = log_open(logpath);
        if (log < 0)
            fprintf (stderr, "unable to open log %s\n", logpath);
        log_set_trigger (log, ices_config->logsize);
    }
    /* Set the log level, if requested - defaults to 2 (WARN) otherwise */
    if (ices_config->loglevel)
        log_set_level(log, ices_config->loglevel);

    ices_config->log_id = log;

    LOG_INFO0(PACKAGE_STRING " started...");
    if (ices_config->pidfile != NULL)
    {
        FILE *f = fopen (ices_config->pidfile, "w");
        if (f)
        {
            fprintf (f, "%i", getpid());
            fclose (f);
        }
        else
        {
            LOG_WARN1("pidfile \"%s\" cannot be written to", ices_config->pidfile);
            xmlFree (ices_config->pidfile);
            ices_config->pidfile = NULL;
        }
    }

    /* Start the core streaming loop */
    input_loop();

    if (ices_config->pidfile)
        remove (ices_config->pidfile);

    LOG_INFO0("Shutdown complete");

    log_close(log);

 fail:
    encode_close();
    shout_shutdown();
    config_shutdown();
    thread_shutdown();
    log_shutdown();

    return 0;
}
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
    int status = 0;
    struct rc_config rc;
    struct cli_state *state;
    bool exit_immediately = false;
    struct str_queue exec_list;

    /* If no actions are specified, just show the usage text and exit */
    if (argc == 1) {
        usage(argv[0]);
        return 0;
    }

    str_queue_init(&exec_list);
    init_rc_config(&rc);

    if (get_rc_config(argc, argv, &rc, &exec_list)) {
        return 1;
    }

    state = cli_state_create();

    if (!state) {
        fprintf(stderr, "Failed to create state object\n");
        return 1;
    }

    state->exec_list = &exec_list;
    bladerf_log_set_verbosity(rc.verbosity);

    if (rc.show_help) {
        usage(argv[0]);
        exit_immediately = true;
    } else if (rc.show_help_interactive) {
        printf("Interactive Commands:\n\n");
        cmd_show_help_all();
        exit_immediately = true;
    } else if (rc.show_version) {
        printf(BLADERF_CLI_VERSION "\n");
        exit_immediately = true;
    } else if (rc.show_lib_version) {
        struct bladerf_version version;
        bladerf_version(&version);
        printf("%s\n", version.describe);
        exit_immediately = true;
    } else if (rc.probe) {
        status = cmd_handle(state, "probe strict");
        exit_immediately = true;
    }

    if (!exit_immediately) {
        check_for_bootloader_devs();

        /* Conditionally performed items, depending on runtime config */
        status = open_device(&rc, state, status);
        if (status) {
            goto main_issues;
        }

        status = flash_fw(&rc, state, status);
        if (status) {
            goto main_issues;
        }

        status = flash_fpga(&rc, state, status);
        if (status) {
            goto main_issues;
        }

        status = load_fpga(&rc, state, status);
        if (status) {
            goto main_issues;
        }

        if (rc.script_file) {
            status = cli_open_script(&state->scripts, rc.script_file);
            if (status != 0) {
                fprintf(stderr, "Failed to open script file \"%s\": %s\n",
                        rc.script_file, strerror(-status));
                goto main_issues;
            }
        }

        /* Drop into interactive mode or begin executing commands from a a
         * command-line list or a script. If we're not requested to do either,
         * exit cleanly */
        if (!str_queue_empty(&exec_list) || rc.interactive_mode ||
            cli_script_loaded(state->scripts)) {

            status = cli_start_tasks(state);
            if (status == 0) {
                status = input_loop(state, rc.interactive_mode);
            }
        }
    }

main_issues:
    cli_state_destroy(state);
    str_queue_deinit(&exec_list);
    deinit_rc_config(&rc);
    return status;
}