Ejemplo n.º 1
0
main()
{
 char c,s[10];
 int y[3],x[4],i;

 timeinit();
 
 while(1)
 {
  if(rrawad(&i) == 0)
  {
   x[3] = x[2];
   x[2] = x[1];
   x[1] = x[0];
   x[0] = i;
   y[2] = y[1];
   y[1] = y[0];
   y[0] = (x[0] + 3 * x[1] + 3 * x[2] + x[3] - 2 * y[2]) / 6;
   sprintf(s,"%6u",y[0]);
   disp(s,10);
   sprintf(s,"%5u",x[0]);
   disp(s,0);
   fprintf(stderr,"%d\n",tmcount);
  }
  if((c = rrawkey()))
  {
   fprintf(stderr,"%d\n",(unsigned char)c);
   if(c < 10)
    printf("i1%d\n",c);
   else if(c < 20)
    printf("i0%d\n",c - 10);
  }
 }
}
Ejemplo n.º 2
0
int program_make(struct program *prog, struct shader **shader, int num)
{
	int i;
	GLchar log[256] = "nil";
	GLsizei len = 0;
	GLint res = GL_FALSE;

	if (!prog) {
		errno = EFAULT;
		return -1;
	}

	timeinit();

	prog->id = glCreateProgram();
	if (prog->id == 0) {
		glerr("glCreateProgram() failed");
		return -1;
	}

	prog->shader = shader;
	prog->shader_num = num;

	for (i = 0; i < num; i++) {
		if (make_shader(shader[i]) < 0) {
			_err("shader %s failed\n", shader[i]->name);
			goto err;
		}
		glAttachShader(prog->id, shader[i]->id);
	}

	timestart();
	glLinkProgram(prog->id);
	glGetProgramiv(prog->id, GL_LINK_STATUS, &res);
	if (res != GL_TRUE) {
		_err("failed to link program\n");
		goto err;
	}

	timestop("program %d linked\n", prog->id);
	return prog->id;

err:
	if (prog->id > 0) {
		glGetProgramInfoLog(prog->id, sizeof (log), &len, log);
		_msg("len: %d, log: %s\n", len, log);
	}

	program_clean(prog);
	return -1;
}
Ejemplo n.º 3
0
static int make_shader(struct shader *shader)
{
	GLint res = GL_FALSE;
	GLsizei len = 0;
	GLchar log[4096] = "nil";/* FIXME: some drivers return wrong values for
				 * GL_INFO_LOG_LENGTH use a fixed size instead
				 */
	timeinit();

	if (!shader) {
		errno = EFAULT;
		return -1;
	}

	timestart();

	shader->id = glCreateShader(shader->type);
	if (shader->id == 0) {
		glerr("glCreateShader(%s) failed", shader->name);
		goto error;
	}

	glShaderSource(shader->id, 1, &shader->code, NULL);
	glCompileShader(shader->id);
	glGetShaderiv(shader->id, GL_COMPILE_STATUS, &res);
	if (res != GL_TRUE) {
		glerr("glCompileShader(%s) failed", shader->name);
		goto error;
	}

	timestop("compiled shader %s, id %d type 0x%04x\n", shader->name,
		 shader->id, shader->type);
	return 0;

error:
	if (shader->id > 0) {
		glGetShaderInfoLog(shader->id, sizeof(log), &len, log);
		_msg("len: %d, log: %s\n", len, log);
		glDeleteShader(shader->id);
		shader->id = 0;
	}
	return -1;
}
Ejemplo n.º 4
0
void
main(int argc, char **argv)
{
	Word *w;
	char *s, *temp;
	char *files[256], **f = files, **ff;
	int sflag = 0;
	int i;
	int tfd = -1;
	Biobuf tb;
	Bufblock *buf;
	Bufblock *whatif;

	/*
	 *  start with a copy of the current environment variables
	 *  instead of sharing them
	 */

	Binit(&bout, 1, OWRITE);
	buf = newbuf();
	whatif = 0;
	USED(argc);
	for(argv++; *argv && (**argv == '-'); argv++)
	{
		bufcpy(buf, argv[0], strlen(argv[0]));
		insert(buf, ' ');
		switch(argv[0][1])
		{
		case 'a':
			aflag = 1;
			break;
		case 'd':
			if(*(s = &argv[0][2]))
				while(*s) switch(*s++)
				{
				case 'p':	debug |= D_PARSE; break;
				case 'g':	debug |= D_GRAPH; break;
				case 'e':	debug |= D_EXEC; break;
				}
			else
				debug = 0xFFFF;
			break;
		case 'e':
			explain = &argv[0][2];
			break;
		case 'f':
			if(*++argv == 0)
				badusage();
			*f++ = *argv;
			bufcpy(buf, argv[0], strlen(argv[0]));
			insert(buf, ' ');
			break;
		case 'i':
			iflag = 1;
			break;
		case 'k':
			kflag = 1;
			break;
		case 'n':
			nflag = 1;
			break;
		case 's':
			sflag = 1;
			break;
		case 't':
			tflag = 1;
			break;
		case 'u':
			uflag = 1;
			break;
		case 'w':
			if(whatif == 0)
				whatif = newbuf();
			else
				insert(whatif, ' ');
			if(argv[0][2])
				bufcpy(whatif, &argv[0][2], strlen(&argv[0][2]));
			else {
				if(*++argv == 0)
					badusage();
				bufcpy(whatif, &argv[0][0], strlen(&argv[0][0]));
			}
			break;
		default:
			badusage();
		}
	}
#ifdef	PROF
	{
		extern etext();
		monitor(main, etext, buf, sizeof buf, 300);
	}
#endif

	if(aflag)
		iflag = 1;
	usage();
	syminit();
	initenv();
	usage();

	/*
		assignment args become null strings
	*/
	temp = 0;
	for(i = 0; argv[i]; i++) if(utfrune(argv[i], '=')){
		bufcpy(buf, argv[i], strlen(argv[i]));
		insert(buf, ' ');
		if(tfd < 0){
			temp = maketmp();
			if(temp == 0) {
				perror("temp file");
				Exit();
			}
			close(create(temp, OWRITE, 0600));
			if((tfd = open(temp, 2)) < 0){
				perror(temp);
				Exit();
			}
			Binit(&tb, tfd, OWRITE);
		}
		Bprint(&tb, "%s\n", argv[i]);
		*argv[i] = 0;
	}
	if(tfd >= 0){
		Bflush(&tb);
		LSEEK(tfd, 0L, 0);
		parse("command line args", tfd, 1);
		remove(temp);
	}

	if (buf->current != buf->start) {
		buf->current--;
		insert(buf, 0);
	}
	symlook("MKFLAGS", S_VAR, (void *) stow(buf->start));
	buf->current = buf->start;
	for(i = 0; argv[i]; i++){
		if(*argv[i] == 0) continue;
		if(i)
			insert(buf, ' ');
		bufcpy(buf, argv[i], strlen(argv[i]));
	}
	insert(buf, 0);
	symlook("MKARGS", S_VAR, (void *) stow(buf->start));
	freebuf(buf);

	if(f == files){
		if(access(MKFILE, 4) == 0)
			parse(MKFILE, open(MKFILE, 0), 0);
	} else
		for(ff = files; ff < f; ff++)
			parse(*ff, open(*ff, 0), 0);
	if(DEBUG(D_PARSE)){
		dumpw("default targets", target1);
		dumpr("rules", rules);
		dumpr("metarules", metarules);
		dumpv("variables");
	}
	if(whatif){
		insert(whatif, 0);
		timeinit(whatif->start);
		freebuf(whatif);
	}
	execinit();
	/* skip assignment args */
	while(*argv && (**argv == 0))
		argv++;

	catchnotes();
	if(*argv == 0){
		if(target1)
			for(w = target1; w; w = w->next)
				mk(w->s);
		else {
			fprint(2, "mk: nothing to mk\n");
			Exit();
		}
	} else {
		if(sflag){
			for(; *argv; argv++)
				if(**argv)
					mk(*argv);
		} else {
			Word *head, *tail, *t;

			/* fake a new rule with all the args as prereqs */
			tail = 0;
			t = 0;
			for(; *argv; argv++)
				if(**argv){
					if(tail == 0)
						tail = t = newword(*argv);
					else {
						t->next = newword(*argv);
						t = t->next;
					}
				}
			if(tail->next == 0)
				mk(tail->s);
			else {
				head = newword("command line arguments");
				addrules(head, tail, strdup(""), VIR, mkinline, 0);
				mk(head->s);
			}
		}
	}
	if(uflag)
		prusage();
	exits(0);
}
Ejemplo n.º 5
0
main( int argc, char **argv )
{
	char c,s[10];
	int y[3],x[4],i;//i為AD值
	unsigned int x_w;
	unsigned int y_w;
	unsigned int net;
	
	
	unsigned int tare = 0;//容器重(AD)
	/*
	char *c_addr;
	int shmid;
	*/
	
	if( ( re = fopen( "/home/allways/simulator/src/simtogoal", "r+" ) ) == NULL )
		printf( "%s\n", strerror( errno ) );
	
	if( ( wr = fopen( "/home/allways/simulator/src/goaltosim", "w+" ) ) == NULL )
		printf( "%s\n", strerror( errno ));
	
	
	//printf("The argument has %d\n", argc );
	//printf("test is %s\n",argv[0]);
	
	/*
	shmid = (int)atoi( argv[ 0 ] );
	c_addr = shmat( shmid, 0, 0 );
	printf("test is %s\n",c_addr);
	shmdt( c_addr );
	*/
	
	timeinit();
	
	while(1)
	{
		if( rrawad( &i ) == 0 )//i便是由函數rrawad所指回來的ad值
		{			
			//i -= tare;//把皮重A/D減掉
			x[3] = x[2];
			x[2] = x[1];
			x[1] = x[0];
			x[0] = i;
			y[2] = y[1];
			y[1] = y[0];
			y[0] = ( x[0] + 3 * x[1] + 3 * x[2] + x[3] - 2 * y[2] ) / 6;
			//讓讀入的值只有整數而沒有小數點
			
			sprintf(s,"%7u",x[0]);
			disp(s,0);//生ad
			
			x_w = ( x[ 0 ] - adstart ) * slope;
			sprintf( s, "%6u", x_w );
			disp(s,16);//生重量
			
			sprintf(s,"%7u",y[0]);//y[0]是濾波後的值
			disp(s,8);//熟ad
			
			y_w = ( y[ 0 ] - adstart ) * slope;
			sprintf(s,"%6u",y_w);
			disp(s,23);//熟重量

			net = y_w - tare;
			//printf("net = %d\n",net);
			sprintf(s,"%6u",net);
			disp(s,30);//淨重
		}
		
		if( ( c = rrawkey() ) )//'0'表示目前沒有任何的按鍵被按
		{
			switch( c )
			{
				case 12 : tare = 0; break;//12為回歸鍵
				case 13 : tare = y_w; break;//13扣重鍵
				case 17 :
					  {
						fprintf( wr, "c\n" );//做為校正傳值的記號
						fflush( wr );
						
						fscanf( re, "%lf", &adstart );
						fscanf( re, "%lf", &slope );
						//printf("adstart number: %f\n",adstart);
						//printf("slope number: %f\n",slope);
						break;
					  }
			}
			
			/*
			if(c < 10)
			{
				printf("i1%d\n",c);
				//fprintf(stderr,"i1%d\n",(unsigned char)c);
			}
			else if(c < 20)
			{
				printf("i0%d\n",c - 10);
				//fprintf(stderr,"i0%d\n",(unsigned char)c-10);
			}
			*/
		}
	}
}