Example #1
0
void process(Servo *servo, Instruction b) {
	enum opcode operation = OPCODE(b);
	int parameter = PARAM(b);

	switch(operation) {
		case MOV:
			mov(servo, parameter);
			break;
		case WAIT:
			wait(servo, parameter);
			break;
		case LOOP_START:
			loop_start(servo, parameter);
			execute(servo, servo->recipe[servo->pc]);
			break;
		case END_LOOP:
			end_loop(servo);
			execute(servo, servo->recipe[servo->pc]);
			break;
		case RECIPE_END:
			recipe_end(servo);
			break;
		default: /* Opcode not defined */
			break;
	}
}
Example #2
0
//executes 1 command line
void execute_command(char * command_line){
    
    if (command_line[0]=='#') return; //=comments
    
    if (write_to_thread_buffer){
        if (strncmp(command_line, "thread_stop", 11)==0){
            if (mode==MODE_TCP){
                write_to_thread_buffer=0;
                if (debug) printf("Thread stop.\n");
                if (thread_write_index>0) start_thread=1; //remember to start the thread when client closes the TCP/IP connection
            }        
        }else{
            if (debug) printf("Write to thread buffer: %s\n", command_line);
            while (*command_line!=0){
                write_thread_buffer(*command_line); //for TCP/IP we write to the thread buffer
                command_line++;
            }
            write_thread_buffer(';');
        }
    }else{
 
        char * arg = strchr(command_line, ' ');
        char * command =  strtok(command_line, " \r\n");    
        
        if (arg!=NULL) arg++;
        
        if (strcmp(command, "render")==0){
            render(arg);
        }else if (strcmp(command, "rotate")==0){
            rotate(arg);
        }else if (strcmp(command, "delay")==0){
            if (arg!=NULL)	usleep((atoi(arg)+1)*1000);
        }else if (strcmp(command, "brightness")==0){
            brightness(arg);
        }else if (strcmp(command, "rainbow")==0){
            rainbow(arg);
        }else if (strcmp(command, "fill")==0){	
            fill(arg);
        }else if (strcmp(command, "do")==0){
            start_loop(arg);
        }else if (strcmp(command, "loop")==0){
            end_loop(arg);
        }else if (strcmp(command, "thread_start")==0){ //start a new thread that processes code
            if (thread_running==0 && mode==MODE_TCP) init_thread(arg);
        }else if (strcmp(command, "setup")==0){
            setup_ledstring(arg);
        }else if (strcmp(command, "settings")==0){
            print_settings();
        }else if (strcmp(command, "debug")==0){
            if (debug) debug=0;
            else debug=1;
        }else if (strcmp(command, "exit")==0){
            printf("Exiting.\n");
            exit_program=1;
        }else{
            printf("Unknown cmd: %s\n", command_line);
        }
    }
}
Example #3
0
void
draw_clock(int x, int y, int w, int h, GR_WINDOW_ID pmap, GR_GC_ID gc,
	   GR_WINDOW_ID window)
{
    int i;

    GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_WINDOW));
    GrFillRect(pmap, gc, 0, 0, w, h);

    tick();
    push_matrix();
    translate(x + w / 2.0 - .5, y + h / 2.0 - .5);
    scale_xy((w - 1) / 28.0, (h - 1) / 28.0);
    if (type() == ROUND_CLOCK) {
	GrSetGCForeground(gc, BLACK);
	begin_polygon();
	circle(0, 0, 14, pmap, gc, w, h);
	end_polygon(pmap, gc);
	GrSetGCForeground(gc, BLACK);
	begin_loop();
	circle(0, 0, 14, pmap, gc, w, h);
	end_loop(pmap, gc);
    }
    //draw the shadows
    push_matrix();
    translate(0.60, 0.60);
    draw_clock_hands(LTGRAY, LTGRAY, pmap, gc);
    pop_matrix();
    //draw the tick marks
    push_matrix();
    GrSetGCForeground(gc, BLACK);
    for (i = 0; i < 12; i++) {
	if (6 == i)
	    rect(-0.5, 9, 1, 2, pmap, gc);
	else if (3 == i || 0 == i || 9 == i)
	    rect(-0.5, 9.5, 1, 1, pmap, gc);
	else
	    rect(-0.25, 9.5, .5, 1, pmap, gc);
	rotate(-30);
    }
    pop_matrix();
    //draw the hands
    draw_clock_hands(GRAY, BLACK, pmap, gc);
    pop_matrix();
    GrCopyArea(window, gc, 0, 0, w, h, pmap, 0, 0, MWROP_SRCCOPY);
}
Example #4
0
void HelpEditHook(int Key) {
	pdebug("HelpEditHook()\n");

	char Type;

	Type = 0;
	if (Key < 256) {
		Type = 1;
	} else switch(Key) {
		case KEY_LEFT:
		case KEY_RIGHT:
		case KEY_UP:
		case KEY_DOWN:
		case KEY_HOME:
		case KEY_END:
		case KEY_PPAGE:
		case KEY_NPAGE:
		case KEY_IC:
		case '\t':
		case KEY_BACKSPACE:
		case KEY_ENTER:
		case KEY_F(9): /* XXX */
			Type = 1;
			break;
	}
	if (Type == 1 && !IsNonModal) {
		if (in_help) {
			end_loop_help(Key);
		} else {
			end_loop(Key);
		}

		if (HelpWindow) {
			/* in_help value may be different here ? */
			if (in_help) {
				start_loop_help();
			} else {
				start_loop();
			}
		}
	} else {
		ProcessSpecialKey(Key);
	}
}
Example #5
0
static void
drawhand(double ang, const float v[][2], GR_COLOR fill,
	 GR_COLOR line, GR_WINDOW_ID pmap, GR_GC_ID gc)
{
    int i;

    push_matrix();
    rotate(ang);

    GrSetGCForeground(gc, fill);
    begin_polygon();
    for (i = 0; i < 4; i++)
	vertex(v[i][0], v[i][1]);
    end_polygon(pmap, gc);
    GrSetGCForeground(gc, line);
    begin_loop();
    for (i = 0; i < 4; i++)
	vertex(v[i][0], v[i][1]);
    end_loop(pmap, gc);
    pop_matrix();
}
Example #6
0
int		select_loop(int svr_sock, t_select *slt_par, t_game *game)
{
  t_svr_vector	vec;
  int		err;

  slt_cont = 1;
  init_vector(&vec, slt_par);
  while (slt_cont)
    {
      err = select(slt_par->fd_max, &(slt_par->fd_read), NULL, NULL,
		   slt_par->time);
      if (err > 0)
	{
	  if (FD_ISSET(svr_sock, &(slt_par->fd_read)))
	    if (add_client(&vec, slt_par, svr_sock) == EXIT_FAILURE)
	      fprintf(stderr, "add client error");
	  fetch_instr(&vec, slt_par, game);
	}
      end_loop(&vec, slt_par, game, svr_sock);
    }
  close_client(&vec, slt_par);
  return (EXIT_SUCCESS);
}