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;
}
Exemplo n.º 2
0
/**************************************************************
 *  Name                 :  Task1_10ticks
 *  Description          :  Init function of Scheduler module
 *  Parameters           :  void
 *  Return               :  void
 *  Precondition         :  This function must be called after cpu initialization.
 *  Postcondition        :  Function gsc_sch_core_exec can be called.
 **************************************************************/
 void Task1_1ticks(void)
{
	toggle_led1();
}