int main(int argc, char* argv[])
{
	int res;
	int i;

	// Initialize the hidapi library
	printf("Starting to initialize HID library...\n");
	res = hid_init();
	printf("Initialized HID library.\n");

	// Open the device using the VID, PID,
	// and optionally the Serial number.
	printf("Trying to open device...\n");
	handle = hid_open(0x04d8, 0x003f, NULL);
	if(handle != NULL) {
		printf("Opened device successfully.\n");
	} else {
		printf("Could not open device.\n");
		exit(EXIT_FAILURE);
	}
	read_device_info();

	toggle_led1();

	printf("Button is %spressed.\n", get_push1_state() ? "" : "not ");

	printf("The decimal result is %d\n", get_pot1_val());

	// Register signal handler
	if (signal(SIGINT, sig_handler) == SIG_ERR) {
        printf("\nCan't catch SIGINT\n");
        exit(EXIT_FAILURE);
	}

	// Enter ncurses mode
	initialize_display();

	// Main loop
	while(1) {
		int a;
		a = (int)((100 / 1023.0) * get_pot1_val()); 
		print_percent_bar(2, a);
		refresh();
		sleep(0.1);
	}

	// Leave ncurses mode
	end_display();

	// Unregister signal handler
	signal(SIGINT, SIG_DFL);

	// Finalize the hidapi library
	res = hid_exit();

	return 0;
}
Beispiel #2
0
int flash_entry(struct ftm_param *param, void *priv)
{
    char *ptr;
    int chosen;
    bool exit = false;
    struct nand_info *flash = (struct nand_info *)priv;
    //struct textview *tv;
    struct itemview *iv;
    /* for time evaluations */
    struct timeval tv1, tv2;

    /* reset the read/write test result */
    flash->base_rw_test_result = false;
    
    LOGD(TAG "%s\n", __FUNCTION__);

    init_text(&flash->title, param->name, COLOR_YELLOW);
    init_text(&flash->text, &flash->info[0], COLOR_YELLOW);

    /* Check if the data partition is mounted or not */
    if(!check_root_path_mounted(DATA_PARTITION))
    {
        /* Get the manf id and dev id */
        read_device_info(flash, CMD_LINE_PATH);
    
        gettimeofday(&tv1, NULL);
        flash->teststart = tv1.tv_sec * 1000000 + tv1.tv_usec;

        /* Start the basic read/write tests */
        flash->base_rw_test_result = flash_basic_rw(flash, DATA_PARTITION);
        
        gettimeofday(&tv2, NULL);
        flash->testend = tv2.tv_sec * 1000000 + tv2.tv_usec;

        /* Delete the test temp file */
        remove(flash->test_file_path);
    } else
    {
        LOGD(TAG "%s partition is not mounted !", DATA_PARTITION);
    }
    
    flash_update_info(flash, flash->info);
   
    flash->exit_thd = false;  

    /* Create a itemview */
    if (!flash->iv)
    {
        iv = ui_new_itemview();
        if (!iv)
        {
            LOGD(TAG "No memory");
            return -1;
        }
        flash->iv = iv;
    }
    
    iv = flash->iv;
    iv->set_title(iv, &flash->title);
    iv->set_items(iv, flash_items, 0);
    iv->set_text(iv, &flash->text);
    iv->redraw(iv);
    usleep(1000000);      
    /* Create a thread to update screen */
    //pthread_create(&flash->update_thd, NULL, flash_update_thread, priv);
    //do
    //{
    //    chosen = iv->run(iv, &exit);
    //    switch (chosen)
    //    {
    //    case ITEM_PASS:
    //    case ITEM_FAIL:
    //    default:
    //        /* report test results */
    //        if (flash->base_rw_test_result == true)
    //        {
    //          flash->mod->test_result = FTM_TEST_PASS;
    //        }
    //        else
    //        {
    //          flash->mod->test_result = FTM_TEST_FAIL;
    //        }                       
    //        exit = true;
    //        break;
    //    }
    //    
    //    if (exit)
    //    {
    //        /* mark for exit update thread */
    //        flash->exit_thd = true;
    //        break;
    //    }        
    //}
    //while (1);
    //pthread_join(flash->update_thd, NULL); 
    if (flash->base_rw_test_result == true)            
    {                                                  
      flash->mod->test_result = FTM_TEST_PASS;         
    }                                                  
    else                                               
    {                                                  
      flash->mod->test_result = FTM_TEST_FAIL;         
    }                                                  
        
    return 0;
}