예제 #1
0
void frssort1(string strings[], size_t scnt)
{
    list listnodes;
    size_t i;

    /* allocate memory based on the number of strings in the array */
    listnodes = (list ) calloc(scnt, sizeof(struct listrec));

    /* point the linked list nodes to the strings in the array */
    for( i=0; i<scnt; i++)
    {
        listnodes[i].str = strings[i];
        if (i<(scnt-1))
            listnodes[i].next = &listnodes[i+1];
        else
            listnodes[i].next = NULL;
    }

    /* sort */
    list sortednodes = forward1(listnodes, scnt);

    /* write the strings back into the array */
    for (i = 0;  i < scnt ; i++, sortednodes=sortednodes->next)
        strings[i] = sortednodes->str;

    free(listnodes);
}
예제 #2
0
void JogShuttle::customEvent(QEvent* e)
{
    switch (e->type()) {
    case JOG_BACK1:
        emit rewind1();
        break;
    case JOG_FWD1:
        emit forward1();
        break;
    case JOG_BACK:
        emit rewind(-1);
        break;
    case JOG_FWD:
        emit forward(1);
        break;
    case JOG_BACK_SLOW:
        emit rewind(-0.5);
        break;
    case JOG_FWD_SLOW:
        emit forward(0.5);
        break;
    case JOG_BACK_FAST:
        emit rewind(-2);
        break;
    case JOG_FWD_FAST:
        emit forward(2);
        break;
    case JOG_STOP:
        emit stop();
        break;
    default:
        emit button(e->type() - 20000);
    }
}
예제 #3
0
void    autonomous_routine1(void)

{
    unsigned int            sonar_distance = 0;
    static unsigned long    elapsed_time,
			    old_time = 0,
			    start_time;
    
    controller_begin_autonomous_mode();
    elapsed_time = start_time = SYSTEM_TIMER_SECONDS();
    
    /*
     *  An autonomous loop with sensor input.  Loop terminates when
     *  a button sensor on port 5 is pressed, or the 20 second time
     *  period runs out.
     */
    
    forward1(MOTOR_POWER1); 
    while ( (elapsed_time - start_time) < ROUTINE1_DURATION )
    {
	sonar_distance = sonar_read(SONAR_INTERRUPT_PORT);
	
	if ( (sonar_distance < ROUTINE1_SONAR_DISTANCE) ||
	     (io_read_digital(BUMPER_LEFT_PORT) == 0) ||
	     (io_read_digital(BUMPER_RIGHT_PORT) == 0) )
	{
	    reverse1(MOTOR_POWER1);
	    delay_msec(ROUTINE1_BACKUP_MS);
	    sonar_distance = sonar_read(SONAR_INTERRUPT_PORT);
	    spin1(MOTOR_POWER1, ROUTINE1_SPIN_MS);
	    forward1(MOTOR_POWER1);
	    sonar_distance = sonar_read(SONAR_INTERRUPT_PORT);
	}
	
	elapsed_time = SYSTEM_TIMER_MS();
	
	/* Adjust sonar direction every 40 ms */
	if ( elapsed_time % ROUTINE1_SONAR_SERVO_DELAY == 0 )
	    sonar_scan(SONAR_SERVO_PORT);
	
	/* Produce debug output once per second */
	elapsed_time /= MS_PER_SEC;
	if ( elapsed_time > old_time )
	{
	    old_time = elapsed_time;
	    /*
	    if ( rc_new_data_available() )
	    {
		DPRINTF("ET: %ld  RC: %x  A[1,2]: %x %x  "
		    "D[5,6]: %d %d  Shaft I[%d,%d]: %d %d Sonar[%d]: %d\n",
		    elapsed_time - start_time, rc_read_status(),
		    io_read_analog(1),  io_read_analog(2),
		    io_read_digital(5), io_read_digital(6),
		    LEFT_ENCODER_INTERRUPT_PORT, RIGHT_ENCODER_INTERRUPT_PORT,
		    shaft_encoder_read_std(LEFT_ENCODER_INTERRUPT_PORT),
		    shaft_encoder_read_std(RIGHT_ENCODER_INTERRUPT_PORT),
		    SONAR_INTERRUPT_PORT, sonar_distance);
	    }
	    */
	}
    }
    pwm_write(RIGHT_DRIVE_PORT, MOTOR_STOP);
    pwm_write(LEFT_DRIVE_PORT, MOTOR_STOP);
    controller_submit_data(NO_WAIT);

    controller_end_autonomous_mode();
}