Exemplo n.º 1
0
u8 get_a_char()
{
	u8 ch;
	if (ch_peek != -1) {
		ch = ch_peek;
		ch_peek = -1;
		close_keyboard(1);
		return ch;
	}
	int v = read(0,&ch,1);
	close_keyboard(1);
	if (v == 0)
		return 0;
	return ch;
}
Exemplo n.º 2
0
int _getch() {
	init_keyboard();
	kbhit();
	char c = readch();
	close_keyboard();
	return c;
}
Exemplo n.º 3
0
int normal_mode(void)
{
	int ret, arg = 0, pos[6];

	init_keyboard();
	ioctl(gldev, NORMAL_MODE, arg);
	while (1)
	{
		char buf[10] = "\0";
		if (kbhit())
		{
			char key = getkey();
			if (key == '\n') break;
		}

		ret = read(gldev, buf, 10);
		if (buf[0] != 0)
		{
			pos[0] = buf[0];
			pos[1] = buf[1];
			pos[2] = ((buf[3] << 8) | (buf[2]));
			pos[3] = ((buf[5] << 8) | (buf[4]));
			pos[4] = ((buf[7] << 8) | (buf[6]));
			pos[5] = ((buf[9] << 8) | (buf[8]));			

			printf("touching=%d oldtouching=%d x1=%-3d y1=%-3d x2=%-3d y2=%-3d\n", pos[0], pos[1],
					pos[2], pos[3], pos[4], pos[5]);

		}
	}

	close_keyboard();
	return ret;
}
Exemplo n.º 4
0
void set_echo_off(Bool echo_off) 
{ 
	init_keyboard();
	if (echo_off) t_orig.c_lflag &= ~ECHO;
	else t_orig.c_lflag |= ECHO;
	close_keyboard(0);
}
Exemplo n.º 5
0
DEFINE_THREAD_ROUTINE(KeyboardController, data)
{
  init_keyboard();
  update_keyboard();
  close_keyboard();  
  return (THREAD_RET) 0;

}
Exemplo n.º 6
0
int main(int argc, char** argv)
{
  time_t t = time(NULL);
  struct tm *tms = localtime(&t);
  snprintf(logdir, sizeof(logdir), "%d-%02d-%02d-%02d-%02d-%02d",
           tms->tm_year+1900, tms->tm_mon+1, tms->tm_mday,
           tms->tm_hour     , tms->tm_min  , tms->tm_sec);
  printf("log directory: %s", logdir);
  mkdir(logdir, 0755);
  string motlog = logdir + string("/mot.txt");
  FILE *mot_log = fopen(motlog.c_str(), "w");
  if (!mot_log)
  {
    printf("couldn't open motor log\n");
    return 1;
  }
  mot = new IPDCMOT(ipdcmot_ip, 0, false);
  mot->set_pos_deg_blocking(left_scan_extent);
  usleep(500000);
  scan = new urg_laser_scan_t;
  if (start())
  {
    printf("bogus. couldn't start the laser.\n");
    return 1;
  }
  pthread_t urg_thread;
  pthread_create(&urg_thread, NULL, urg_thread_func, NULL);
  mot->set_patrol(left_scan_extent, right_scan_extent, 1.9, 1);
  init_keyboard();
  int count = 0;
  while (!bail && !_kbhit())
  {
    double pos;
    if (!mot->get_pos_blocking(&pos, NULL, 1))
    {
      printf("woah! couldn't get position\n");
      break;
    }
    if (mot->get_patrol_dir() < 0)
    {
      printf("scan complete\n");
      break;
    }
    ros::Time t = ros::Time::now();
    fprintf(mot_log, "%d.%09d %f\n", t.sec, t.nsec, pos);
    if (!(count++ % 100))
      printf("%f\t", pos);
  }
  printf("\n");
  mot->stop();
  fclose(mot_log);
  bail = true;
  pthread_join(urg_thread, NULL);
  stop();
  close_keyboard();
  return 0;
}
Exemplo n.º 7
0
int readch()
{
  char ch;
  init_keyboard();
  if( peek_character != -1 ) {
    ch = peek_character;
    peek_character = -1;
    return( ch );
  }
  read( 0, &ch, 1 );
  close_keyboard();
  return( ch );
}
Exemplo n.º 8
0
int main(int argc, char* argv[]) {
    /*X10I BOARD*/
    void *xBoard;
    Authenticate x15Authenticate;
    BYTE fittedBoard;

    /* initialise the firefly device */
    xBoard = XlineInitBoard();
    if (xBoard == NULL) {
        return ( XlineExit("initialisation failed.", xBoard, &x15Authenticate, 1));
    }
    /* Determine which board type is fitted, and unlock the IO security accordingly */


    XlineGetFittedBoard(xBoard, &fittedBoard);

    if (fittedBoard == X10I_BOARD)
        UnlockX10c(xBoard);
    else
        return ( XlineExit("unknown board fitted.", xBoard, &x15Authenticate, 1));

    printf("success.\n\n");

#ifdef X10_LINUX_BUILD
    InitialiseConsole();
#endif
    printf("Bismillah start X10i jogging. \n\n");



    int charkey = 0;
    run_menu();
    init_keyboard();


    for (;;) {
        if (keyboard_hit()) {
            charkey = read_charkey();
            printf("You hit keyboard key: char = %c or int = %d \n", charkey, charkey);
            cmd_interpreter(xBoard,charkey);
        } //END IF
    } // END FOR



    close_keyboard();
    printf("Alhamdulillah. finish Raspberry Pi jogging. \n\n");

    return ( XlineExit("Leaving program.", xBoard, &x15Authenticate, 0));

}
Exemplo n.º 9
0
Arquivo: bitmap.c Projeto: dugoh/tcb
int bitmap_play(char * filename)
{
    char ch;

    if (fb_init())
    {
	printf ("Unable to init framebuffer device\n");
	return 2;
    }

    fb_pixel * bmp_buffer;

    if ((bmp_buffer = bitmap_load(filename)) == NULL)
    {
	fb_uninit();
	printf ("Error while reading bitmap\n");
	return 1;
    }

    fb_clear_screen(screen);

    bitmap_render(bmp_buffer);

    init_keyboard();

    ch=0;
    while (1)
    {
	if (!kbhit()) 
	{
	    ch = readch();
	    if (ch == KEY_ESC) break;
	    if (ch == KEY_UP && position_y >= JUMP_SIZE) position_y-=JUMP_SIZE;
	    if (ch == KEY_DOWN && fb_yres <= (bmp_info.bi_height-position_y-JUMP_SIZE)) position_y+=JUMP_SIZE;
	    if (ch == KEY_LEFT && position_x >= JUMP_SIZE) position_x-=JUMP_SIZE;
	    if (ch == KEY_RIGHT && fb_xres <= (bmp_info.bi_width-position_x-JUMP_SIZE)) position_x+=JUMP_SIZE;
	    ch = 0;
	    bitmap_render(bmp_buffer);
	}
    }

    close_keyboard();

    fflush(stdin);

    fb_clear_screen(screen);

    bitmap_free(bmp_buffer);
    fb_uninit();
    return 0;
}
Exemplo n.º 10
0
int main(int argc, char **argv)
{
    struct 	sigaction   handler;
	char	num[100];
	int		n = 0;

    // Set Interrrupt Signal Handler
	memset(&handler, 0, sizeof(struct sigaction));
    handler.sa_handler = SignalCatcher;
    sigfillset(&handler.sa_mask);
	sigaction(SIGINT, &handler, 0);
    sigaction(SIGTERM, &handler, 0);

    tcgetattr(0, &oldtio);
    init_keyboard();

	for(;!m_bExitSignalPending;)
	{
		display_menu();

		memset(num, 0, 100);
        n = readch();
		printf("\r\n");

		switch(n) {
		  case '0' :	
			   m_bExitSignalPending = 1;
			   break;

		  case '1' :
               if(m_bFirmwareInstalled) break;
			   printf("\r\n");
               system("/usr/bin/tftp -g -r factoryInstall 192.168.10.20");
               system("chmod +x /tmp/factoryInstall");
               system("/tmp/factoryInstall factory");
			   printf("\r\n");
			   break;

		  case '2' :
               if(!m_bFirmwareInstalled) break;
			   system("/app/sw/hwtest");
			   break;
		}
	}

    close_keyboard();

	return 0;
}
Exemplo n.º 11
0
int main() {
    int ch = 0;
    init_keyboard();

    while (ch != 'q') {
        printf("looping\n");
        sleep(1);
        if (kbhit()) {
            ch = readch();
            printf("You hit '%c'\n", ch);
        }
    }
    close_keyboard();
    return 0;
}
Exemplo n.º 12
0
int main()
{
    char ch;

    init_keyboard();
    init_game(1);

    do {
        ch = readch();
        printf("%c %d\n", ch, ch);
    } while (ch != 'q');

    close_keyboard();
    return 0;
}
Exemplo n.º 13
0
int main(int argc, const char *argv[])
{
  int ch = 0;

  init_keyboard();
  while (ch != 'q') {
    printf("looping\n");
    sleep(1);
    if (kbhit()) {
      ch = readch();
      printf("you hit %c\n", ch);
    }
  }
  close_keyboard();
  return 0;
}
Exemplo n.º 14
0
int main()
{
	int ch = 0;

	init_keyboard();
	while(ch != 'q'){
		printf("looping\n");
		sleep(1);
		if(kbhit()){
			ch = readch();
			printf("you hit %c\n",ch);
		}
	}
	close_keyboard();
	exit(0);
}
Exemplo n.º 15
0
int main()
{
    int ch=0;
    init_keyboard();
    while(ch!='q')
    {
        printf("looping \n");
        sleep(2);/*pause for 1 second*/
        if(kbhit())
        {
            ch=readch();
            printf("You hit %c\n",ch);
        }
    }
    close_keyboard();
    exit(0);
}
// ------------------------------------------------------------------------------
//   Listen Thread
// ------------------------------------------------------------------------------
void
Autopilot_Interface::
listen_thread()
{
	listening_status = true;
	init_keyboard();
	while ( ! time_to_exit )
	{
		kbhit();
		receive_ch = readch();
		printf("\n%d\n", receive_ch);
		receive_flag = true;
	}

	reading_status = false;
	close_keyboard();
	return;
}
char stdinputch()
{
    char ch = 0;
    init_keyboard();
    bool keypressed = false;
    while(!keypressed)
    {
        if(kbhit())
        {
            ch = readch();
            printf("%c",ch);
            fflush(stdout);
            keypressed = true;
        }
    }
    close_keyboard();
    return ch;
}
Exemplo n.º 18
0
Bool has_input()
{
	u8 ch;
	s32 nread;

	init_keyboard();
	if (ch_peek != -1) return 1;
	t_new.c_cc[VMIN]=0;
	tcsetattr(0, TCSANOW, &t_new);
	nread = read(0, &ch, 1);
	t_new.c_cc[VMIN]=1;
	tcsetattr(0, TCSANOW, &t_new);
	if(nread == 1) {
		ch_peek = ch;
		return 1;
	}
	close_keyboard(0);
	return 0;
}
Exemplo n.º 19
0
Arquivo: main.c Projeto: monaka/B-Free
static void
doit (DDEV_REQ *packet)
{
  switch (packet->header.msgtyp)
    {
    case DEV_OPN:
      /* デバイスのオープン */
      if (!initialized)
	{
	  init_keyboard ();
	}
      open_keyboard (packet->header.mbfid, &(packet->body.opn_req));
      break;

    case DEV_CLS:
      /* デバイスのクローズ */
      close_keyboard (packet->header.mbfid, &(packet->body.cls_req));
      break;

    case DEV_REA:
      read_keyboard (packet->header.mbfid, &(packet->body.rea_req));
      break;

    case DEV_PRD:
      posix_read_keyboard (packet->header.mbfid, packet->header.tskid,
			   &(packet->body.prd_req));
      break;

    case DEV_RLY:
      relay_keyboard (packet->header.mbfid, &(packet->body.rly_req));
      break;

    case DEV_WRI:
      write_keyboard (packet->header.mbfid, &(packet->body.wri_req));
      break;

    case DEV_CTL:
      control_keyboard (packet->header.mbfid, &(packet->body.ctl_req));
      break;
    }
}
Exemplo n.º 20
0
int main(int argc, char *argv[])
{
    int ret = 0;

    setlocale(LC_ALL,"");

    init_keyboard();
    initscr();

    init_allwin();
    resize_allwin();

    signal(SIGWINCH, sig_winch);

    work_thread_start();
    main_loop();

    close_keyboard();
    cleanup();

    for (int i = 30; i<129;i++) {
        printf("%d %c\t", i, i);
    }
    printf("\n");

    struct winsize size;
    Win *win = NULL;
    ioctl(STDIN_FILENO,TIOCGWINSZ,&size);
    Windows::iterator iter;
    for (iter=windows.begin(); iter!=windows.end(); iter++) {
        win = &iter->second;
        printf("%s @(%d,%d), (%dx%d) %s\n", win->name,
                win->locate.x, win->locate.y,
                win->locate.w, win->locate.h,
                win->title);
    }
    printf("SCREEN: %d x %d\n", size.ws_col, size.ws_row);

    return ret;
}
Exemplo n.º 21
0
int main(int argc, char** argv){
	double offset_x,offset_y,offset_th;

  offset_x=0;
  offset_y=0;
  offset_th=0;

  ros::init(argc, argv, "my_tf_listener");
  ros::NodeHandle node;
  tf::TransformListener listener;
  tf::TransformBroadcaster br;

  ros::Rate rate(10.0);

	int ch=0;
 
	init_keyboard();
	while (node.ok()){
		tf::StampedTransform transform;
    try
    {
			listener.lookupTransform("/ar_marker", "/usb_cam",  ros::Time(0), transform);

			double now_x = transform.getOrigin().x();
			double now_y = transform.getOrigin().y();
			double now_th = tf::getYaw(transform.getRotation());

			if(kbhit())
			{
				ch = readch();
				ROS_INFO("you hit %X : %c",ch,ch);

				offset_x = now_x * cos(-now_th) - now_y * sin(-now_th);
				offset_y = now_x * sin(-now_th) + now_y * cos(-now_th);
				offset_th= now_th;
			}

			double diff_th = -(now_th-offset_th);

			double rot_x = now_x * cos(-now_th) - now_y * sin(-now_th) - offset_x;
			double rot_y = now_x * sin(-now_th) + now_y * cos(-now_th) - offset_y;

			double rot_x2 = rot_x * cos(offset_th) - rot_y * sin(offset_th);
			double rot_y2 = rot_x * sin(offset_th) + rot_y * cos(offset_th);

			ROS_INFO("x:%f\ty=%f\tyaw:%f", rot_x2, rot_y2,diff_th*180/M_PI);
        
			transform.setOrigin( tf::Vector3(rot_x2, rot_y2, 0.0) );
 			transform.setRotation( tf::Quaternion(diff_th, 0, 0) );
        
			br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "ar_marker", "robot_position"));
    }
    catch (tf::TransformException ex){
      ROS_ERROR("%s",ex.what());
    }
    rate.sleep();
    
    if(ch==0x03){
        close_keyboard();
        break;
    }
  }
  return 0;
};
Exemplo n.º 22
0
void tango2(int type, int mode, char flag)
{
	int i, ret, len, fptr = -1;
	unsigned char xline = 0;
	unsigned char yline = 0;
	unsigned char xline2 = 0;
	unsigned char buf[131];ioctl(gldev, RESET_TP, 0);
	short int xyraw1[34], xyraw2[32], xy_tmp[66];

	if (flag)
	{
		char *fdat = "./rawdata.txt";
		fptr = open(fdat, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
		if (fptr == -1)
		{
			puts("Open raw.dat failed.");
			return;
		}
	}

	init_keyboard();
	ioctl(gldev, DISABLE_IRQ, 0);
	ioctl(gldev, mode, 2);
	while (1)
	{
		if (kbhit())
		{
			char key = getkey();
			if (key == '\n')
			{
				ioctl(gldev, ENABLE_IRQ, 0);
				break;
			}
		}

		ret = read(gldev, buf, 131);
		xline = buf[64];
		yline = buf[65];
		xline2 = buf[66];    // printf("xline=%d yline=%d xline2=%d\n", xline, yline, xline2);
		for (i = 0; i < 32; i++)
		{
			xyraw1[i] = ((buf[i * 2 + 1] << 8) | buf[i * 2]);
			xyraw2[i] = ((buf[67 + i * 2 + 1] << 8) | buf[67 + i * 2]);
		}

		for (i = 0; i < xline - 1; i++)
		{
			xy_tmp[i] = xyraw2[i];
		}
		if (xline2)
		{
			for (i = 0; i < xline2 - 1; i++)
			{
				xy_tmp[xline - 1 + i] = xyraw1[i];
			}
			len = xline - 1 + xline2 - 1;
		}
		else
		{
			len = xline - 1;
		}
		show_raw('X', len, 0, xy_tmp, flag, fptr);	
		show_raw('Y', yline - 1, xline2, xyraw1, flag, fptr);
	}
	close_keyboard();
	if (flag)
	{
		close(fptr);
	}
}
Exemplo n.º 23
0
int32_t notmain (uint32_t earlypc) {
    hardware_init();
    int32_t samplerate = audio_init();
    Lv2World *lv2_world = lv2_init(samplerate);
    led_init();
    switch_init();

    printf("\r\nPiTracker console\r\n");
    printf("Samplerate: %d\r\n", samplerate);

    uint32_t inkey;
    uint32_t counter=0;
    LV2_Atom_Forge_Frame midi_seq_frame;
    int buffer_processed = 0;
    const Lv2Plugin *plugin;
    plugin = lv2_world->plugin_list;

    lv2_port *output_left = new_lv2_port(lv2_audio_port, 1);
    lv2_port *output_right = new_lv2_port(lv2_audio_port, 2);
    lv2_port *midi_in = new_lv2_port(lv2_atom_port, 3);

    plugin->descriptor->connect_port(plugin->handle, midi_in->id, midi_in->buffer);
    plugin->descriptor->connect_port(plugin->handle, output_left->id, output_left->buffer);
    plugin->descriptor->connect_port(plugin->handle, output_right->id, output_right->buffer);

    lv2_atom_forge_set_buffer(&forge,
                              midi_in->buffer,
                              LV2_ATOM_BUFFER_SIZE);
    lv2_atom_forge_sequence_head(&forge, &midi_seq_frame, 0);
    
    init_midi_source(&forge);
    
    while (1) {
#ifdef DEBUG
        if(kbhit()) {
            inkey = readch();
            //printf("%x", inkey);
            switch(inkey) {
                case 0x03:
#ifdef RASPBERRY_PI
                    printf("Rebooting\r\n");
                    usleep(2);
                    reboot();
#else
                    printf("Exiting\r\n");
                    close_keyboard();
                    exit(0);
#endif
                    break;
                case 0x31:
                    if (plugin->next) plugin = plugin->next;
                    else plugin = lv2_world->plugin_list;
                    plugin->descriptor->connect_port(plugin->handle, midi_in->id, midi_in->buffer);
                    plugin->descriptor->connect_port(plugin->handle, output_left->id, output_left->buffer);
                    plugin->descriptor->connect_port(plugin->handle, output_right->id, output_right->buffer);
                    break;
                case 0x0d:
                    printf("\r\n");
                    break;
                default:
                    putc(inkey, stdout);
#ifdef LINUX
                    fflush(stdout);
#endif
                    break;
            }
        }
#endif

        if (!buffer_processed) {
            forge_midi_input();

            lv2_atom_forge_pop(&forge, &midi_seq_frame);
            plugin->descriptor->run(plugin->handle, LV2_AUDIO_BUFFER_SIZE);
            lv2_atom_forge_set_buffer(&forge,
                                      midi_in->buffer,
                                      sizeof(uint8_t) * midi_in->buffer_sz);
            lv2_atom_forge_sequence_head(&forge, &midi_seq_frame, 0);
            buffer_processed = 1;
        }

        if (buffer_processed && audio_buffer_free_space() > LV2_AUDIO_BUFFER_SIZE * 2) {
            audio_buffer_write(output_left->buffer, output_right->buffer, output_left->buffer_sz);
            buffer_processed = 0;
            counter++;
        }
    }
}
Exemplo n.º 24
0
int main()
	{
	int			status;
	FILE			*fd;
	int			fdc;
	char			fname[64];
	char			devname[64];
	char			str[256];
	unsigned short	data[6];
	int			comNo;
	int			tick;
	int			clk, clkb, clkb2, clk0;
	int			tw;
	int			num;
	int			n;


	fd = NULL;
	fdc = -1;

start :
	// COMポートをオープン
	printf("Enter COM port > ");
	scanf("%d", &comNo);
	printf("Open /dev/ttyUSB%d\n", comNo);

	sprintf(devname, "/dev/ttyUSB%d", comNo);
	fdc = open(devname, O_RDWR | O_NOCTTY | O_NONBLOCK);
	if (fdc < 0)
		goto over;

	// サンプリング周期を得る
	tw = 16;
	printf("Enter sampling time (ms) > ");
	scanf("%d", &tw);
	printf("Sampling time = %d ms\n", tw);

	printf("Enter File name > ");
	scanf("%s", fname);
	fd = fopen(fname, "w");
	if (!fd)
		goto over;

	// COMポートのボーレート等を設定
	SetComAttr(fdc);

	// データを読み出す
	printf("=== record data ===\n");
	clk0 = clock() / (CLOCKS_PER_SEC / 1000);
	clkb = 0;
	clkb2 = 0;
	num = 0;

	// 単データリクエスト(初回分)
	write(fdc, "R", 1);

	init_keyboard();

	while (true)
		{
		// サンプリング周期だけ待つ
		while (true)
			{
			clk = clock() / (CLOCKS_PER_SEC / 1000) - clk0;

			if (clk >= clkb + tw)
				{
				clkb = clk / tw * tw;
				break;
				}
			}

		// 単データリクエスト(次回分)
		write(fdc, "R", 1);

		// 単データを得る
		n = read(fdc, str, 27);	
		if (n < 27)
			{
//			printf ("=== error ! n = %d ===\n", n);
			goto skip;
			}

		sscanf(str, "%1d%4hx%4hx%4hx%4hx%4hx%4hx",
			 &tick, &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]);

		sprintf(str, "%05d,%d,%05d,%05d,%05d,%05d,%05d,%05d\n",
			clk / tw * tw, tick,
			data[0], data[1], data[2], data[3], data[4], data[5]);

		fprintf(fd, str);
		num++;

skip :
		if (clk >= 10000)
			break;

		// コンソールに間引き表示
		if (clk >= clkb2 + 1000)
			{
			printf(str);
			if (kbhit() &&
				readch() == '.')
				break;
			clkb2 = clk / 1000 * 1000;
			}
		}

over1 :
	close_keyboard();
over :
	if (fd)
		{
		fclose(fd);
		fd = NULL;
		}

	if (fdc >= 0)
		{
		close(fdc);
		fdc = -1;
		}

	printf ("=== num = %d ===\n", num);

	printf("exit (y / n) ? > ");
	scanf("%s", str);
	if (str[0] == 'y')
		{
//		exit(0);
		}
	else
		{
		goto start;
		}
	}
Exemplo n.º 25
0
void cmd_interpreter( void *xBoard,int pressed_key) {
    // ================================================
    //printf("I am inside  cmd_interpreter() before switch. \n");
    switch (pressed_key) {

        case 117:
            // pressed_key char = u or int = 117
            // DRIVE CNC ALONG Y-AXIS
            printf("u \tdrive_up    (500) y-axis (12,8   CW)\t==> Y-axis PINS = (0)(0) (1/0)(1) (0)(0) running ... ");
            drive_up(xBoard, 500); // DRIVE (12,8 CW)
            printf("done.\n");
            break;

        case 100:
            // pressed_key char = d or int = 100
            // DRIVE CNC ALONG Y-AXIS
            printf("d \tdrive_down  (500) y-axis (4,0   CCW)\t==> Y-axis PINS = (0)(0) (1)(0) (0)(0)   running ... ");
            drive_down(xBoard, 500); // DRIVE (4,0 CCW)
            printf("done.\n");
            break;

        case 114:
            // pressed_key char = r or int = 114
            // DRIVE CNC ALONG X-AXIS
            printf("r \tdrive_right (500) x-axis (3,2    CW)\t==> X-axis PINS = (1/0)(1) (0)(0) (0)(0) running ... ");
            drive_right(xBoard, 500); // DRIVE (3,2 CW)
            printf("done.\n");
            break;

        case 108:
            // pressed_key char = l or int = 108
            // DRIVE CNC ALONG X-AXIS
            printf("l \tdrive_left  (500) x-axis (1,0   CCW)\t==> X-axis PINS = (1)(0) (0)(0) (0)(0)   running ... ");
            drive_left(xBoard, 500); // DRIVE (1,0 CCW)
            printf("done.\n");
            break;

        case 122:
            // pressed_key char = z or int = 122
            // DRIVE CNC ALONG Z-AXIS
            printf("z \tdrivepen_up  (500) z-axis (16,0   CW)\t==> Z-axis PINS = (0)(0) (0)(0) (1)(0)   running ... ");
            pen_up(xBoard, 500); // DRIVE (16,0 CW)
            printf("done.\n");
            break;

        case 115:
            // pressed_key char = s or int = 115
            // DRIVE CNC ALONG Z-AXIS
            printf("s \tdrivepen_down(500) z-axis (48,32 CCW)\t==> Z-axis PINS = (0)(0) (0)(0) (1/0)(1) running ... ");
            pen_down(xBoard, 500); // DRIVE (48,32 CCW)
            printf("done.\n");
            break;

            //===========
        case 113:
            // pressed_key char = q or int = 113
            // QUIT AND EXIT PROGRAM
            printf("q \tQuit and exit. \t\t==> Alhamdulillah. Done. \n\n");
            // reset_CNC();
            // RELEASE IO_PORTADDRESS WITH VALUE 0
            printf("Alhamdulillah. Parallel port successfully released. \n\n");
            close_keyboard();
            exit(0);

        default:
            printf("%c \tERROR: Invalid command: ==> char %c or int %d \n", pressed_key, pressed_key, pressed_key);
    }
    //printf("I am exiting cmd_interpreter() after switch. \n");
}
Exemplo n.º 26
0
void tango1(int type, int mode, char flag)
{
	int buflen, rawlen;
	int i, ret, fptr = -1;		
	unsigned char xline = 0;
	unsigned char yline = 0;
	unsigned char buf[98];
	short int xyraw[48];
	
	if(type==3)
	{
		buflen = 98;
		rawlen = 48;
	}	
	else
	{
		buflen = 66;
		rawlen = 32;
	}
	if (flag)
	{
		char *fdat = "./rawdata.txt";
		fptr = open(fdat, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
		if (fptr == -1)
		{
			puts("Open raw.dat failed.");
			return;
		}
	}

	init_keyboard();
	ioctl(gldev, DISABLE_IRQ, 0);
	ioctl(gldev, mode, 1);
	while (1)
	{
		if (kbhit())
		{
			char key = getkey();
			if (key == '\n')
			{
				ioctl(gldev, ENABLE_IRQ, 0);
				printf("break debug.\n");
				break;
			}
		}

		ret = read(gldev, buf, buflen);
		xline = buf[buflen-2];
		yline = buf[buflen-1];
		
/*        {			*/
/*			for(i = 0; i < buflen; i++)*/
/*			{				*/
/*				printf("%x ", buf[i]);*/
/*				if(i%50==0 && i>0) printf("\n");*/
/*			}*/
/*			printf("\n");*/
/*		}		*/

		for (i = 0; i < rawlen; i++)
		{
			xyraw[i] = ((buf[i * 2 + 1] << 8) | buf[i * 2]);
		}
		show_raw('X', xline-1, yline - 1, xyraw, flag, fptr);
		show_raw('Y', yline-1, 0, xyraw, flag, fptr);		
	}
	close_keyboard();
	if (flag)
	{
		close(fptr);
	}
}
Exemplo n.º 27
0
int main(int argc, char* argv[])
{
int channel = 0;
unsigned short result;
float min,max,current;
int x,c;
int res;
int res2;
pthread_t a_thread;
pthread_t b_thread;

	// We'll keep track of the minimum and maximum voltage values
	// we see on a channel as well as the count of conversions
	// completed.

	max = -10.0;
	min	= 10.0;
	count = 0;

	// The default channel is 0 but an alternate channel can be specified
	// as a command line argument.

	if(argc > 1)
		channel = atoi(argv[1]);

	// Check for a valid channel number. Abort if bad

	if(channel <0 || channel > 15)
	{
		printf("Channel numbers must be between 0 and 15 - Aborting\n");
		exit(0);
	}

	// This call sets the mode for the specified channel. We are going to
	// set up for single-ended +/- 10 V range. That way any legal input 
	// can be accomodated.

	adc_set_channel_mode(channel,ADC_SINGLE_ENDED,ADC_BIPOLAR,ADC_TOP_10V);

	if(mio_error_code)
	{
		printf("\nError occured - %s\n",mio_error_string);
		exit(1);
	}

	/* Enable interrupts on both controllers */

	enable_adc_interrupt(0);
	enable_adc_interrupt(1);

	if(mio_error_code)
	{
		printf("\nError occured - %s\n",mio_error_string);
		exit(1);
	}


    res = pthread_create(&a_thread,NULL,thread_function,NULL);

    if(res != 0)
    {
		perror("Thread 1 creation failed");
		exit(EXIT_FAILURE);
    }


    res2 = pthread_create(&b_thread,NULL,thread_function2,NULL);

    if(res != 0)
    {
		perror("Thread 2 creation failed");
		exit(EXIT_FAILURE);
    }



	init_keyboard();

	while(1)
	{
			// We'll keep running until a recognized key is pressed 
		if(kbhit())
		{
				c = readch();

				// The 'C' key clears the min/max and count values

				if(c== 'c' || c == 'C')
				{
					count = 0;
					min = 10.0;
					max = -10.0;
				}

				// The 'N' key moves to the next channel, wrapping from 15
				// back to 0 when appropriate.

				else if(c == 'n' || c == 'N')
				{
					printf("\n");
					channel++;
					if(channel > 15)
						channel = 0;

					// When we change channels we need to make sure we set
					// the channel's mode to a valid range.

					adc_set_channel_mode(channel,ADC_SINGLE_ENDED,ADC_BIPOLAR,ADC_TOP_10V);
					if(mio_error_code)
					{
						printf("\nError occured - %s\n",mio_error_string);
						exit(1);
					}

					// A new channel also clears the count and min/max values.

					count = 0;
					min = 10.0;
					max = -10.0;
				}
				else
				{
					disable_adc_interrupt(0);
					disable_adc_interrupt(1);
				    pthread_cancel(a_thread);
					exit_flag = 1;
					close_keyboard();
					printf("\n\n");
					exit(0);
				}
		}

		// Finally the real thing. This function-call results in 2000
		// conversions on the specified channel with the results going into
		// a buffer called "values".

		adc_convert_single_repeated(channel,2000,values);

		if(mio_error_code)
		{
			printf("\nError occured - %s\n",mio_error_string);
			exit(1);
		}

		// Bump up the count

;		count += 2000;

		// Now we'll read out the 2000 conversion values. Convert them to 
		// floating point voltages and set the min and max values as appropriate
		
		for(x=0; x<2000; x++)
		{
			result = values[x];
			
			current = adc_convert_to_volts(channel,result);

			// Check and load the min/max values as needed

			if(current < min)
				min = current;

			if(current > max)
				max = current;

			// Print the values

			printf("CH %02d %09ld %9.5f Min =%9.5f Max =%9.5f\r",channel,count,current,min,max);
		}
	}


	return 0;
}
Exemplo n.º 28
0
int borplay(FILE *fd, char *fname, unsigned int off, unsigned int size) {
	bor_header bh;
	int len, kb = 0;
	short *out;
	unsigned char *in;
	char *p, *artist, *title;
	

	if(fseek(fd, off, SEEK_SET) < 0) std_err();
	if(!fread(&bh, sizeof(bh), 1, fd)) return(-1);
	size -= sizeof(bh);

	if(strncmp(bh.identifier, BOR_IDENTIFIER, sizeof(bh.identifier))) return(0);

	if((bh.version != BOR_MUSIC_VERSION) && (bh.version != NEW_MUSIC_VERSION)) {
		printf("- warning: unknown file version (%08x)\n", bh.version);
	}
	
	// fix title
	for(p = bh.title; *p; p++) {
		if (*p == '_') *p = ' ';
	}
	
	// fix artist
	for(p = bh.artist; *p; p++) {
		if (*p == '_') *p = ' ';
	}
	
	// force mono if it's a v1 file
	if ((bh.version == BOR_MUSIC_VERSION) && (bh.channels != 1))
	{
		printf("- warning: forcing mono playback because of file version; "
				"use the newest Wav2Bor from LavaLit.com to create BOR files "
				"with more than 1 channel of audio\n");
		bh.channels = 1;
	}

	printf("- %08x (%dhz %dch) %s\n",
		off,
		bh.frequency,   bh.channels,
		fname);
	
	// only print title and artist if at least one of them is specified
	if (strlen(bh.artist) && strlen(bh.title))
		printf("  %s - %s\n", bh.artist, bh.title);
	else if (strlen(bh.artist))
		printf("  %s\n", bh.artist);
	else if (strlen(bh.title))
		printf("  %s\n", bh.title);

	if(bh.datastart > sizeof(bh)) {
		bh.datastart -= sizeof(bh);
		if(fseek(fd, bh.datastart, SEEK_CUR) < 0) std_err();
		size -= bh.datastart;
	}

	in = malloc(MUSIC_BUF_SIZE);
	if(!in) std_err();
	out = malloc(MUSIC_BUF_SIZE * 4);
	if(!out) std_err();

	aoinit_fmt(bh.channels, bh.frequency);

#ifndef WIN32
	init_keyboard();
#endif

	while(size && (len = fread(in, 1, MUSIC_BUF_SIZE, fd))) {
		if(size < len) len = size;
		size -= len;
		
		adpcm_decode(in, out, len, bh.channels);
		
		if(!ao_play(device, (void *)out, len * 4)) break;
		
		kb = check_kbhit();
		if(kb) break;
	}

#ifndef WIN32
	close_keyboard();
#endif

	ao_close(device);
	free(in);
	free(out);
	return(kb);
}