Ejemplo n.º 1
0
// Main program
int main(void)
{
    char i;
    char *heap_end;
    
    // Initialize all modules
    uart_init(115200);
    accel_init();
    touch_init((1 << 9) | (1 << 10));       // Channels 9 and 10
    // usb_init();
    setvbuf(stdin, NULL, _IONBF, 0);        // No buffering

    // Run tests
    tests();
    delay(500);
    RGB_LED(0,100,0);                       // Green

    // Welcome banner
    iprintf("\r\n\r\n====== Freescale Freedom FRDM-LK25Z\r\n");
    iprintf("Built: %s %s\r\n\r\n", __DATE__, __TIME__);
    heap_end = _sbrk(0);
    iprintf("Heap:  %p to %p (%d bytes used)\r\n", __heap_start, heap_end, heap_end - __heap_start);
    iprintf("Stack: %p to %p (%d bytes used)\r\n", &i, __StackTop, __StackTop - &i);
    iprintf("%d bytes free\r\n", &i - heap_end);
    
    for(;;) {
        iprintf("monitor> ");
        getchar();
        iprintf("\r\n");
        iprintf("Inputs:  x=%5d   y=%5d   z=%5d ", accel_x(), accel_y(), accel_z());
        iprintf("touch=(%d,%d)\r\n", touch_data(9), touch_data(10));
        // usb_dump();
    }
}
Ejemplo n.º 2
0
double SensorsWidget::rawValue(const int &i) const
{
	double val = 0;
	if(i < 8) val = analog10(i);
	else if(i < 12) val = get_motor_position_counter(i - 8);
	else if(i == 12) val = accel_x();
	else if(i == 13) val = accel_y();
	else if(i == 14) val = accel_z();
	return val;
}
Ejemplo n.º 3
0
// Main program
int main(void)
{
    char i;
    char ch;
    char *heap_end;
    char inBuffer[BUF_SIZE];
    int readLen,bufPos;
    int n;
    int nargs[10];
    int hasAccelData = 0;
    int hasTouchData = 0;

    // Initialize all modules
    RGB_LED(100,0,0);
    //uart_init(115200);
    uart_init(9600);
    accel_init();
    touch_init((1 << 9) | (1 << 10));       // Channels 9 and 10
    // usb_init();
    setvbuf(stdin, NULL, _IONBF, 0);        // No buffering

    // Run tests
    tests();
    delay(500);

    // Welcome banner
    iprintf("\r\n\r\n====== Freescale Freedom FRDM-LK25Z\r\n");
    iprintf("Built: %s %s\r\n\r\n", __DATE__, __TIME__);
    heap_end = _sbrk(0);
    iprintf("Heap:  %p to %p (%d bytes used)\r\n", __heap_start, heap_end, 
                heap_end - (char *)__heap_start);
    iprintf("Stack: %p to %p (%d bytes used)\r\n", &i, __StackTop, 
                (char *)__StackTop - &i);
    iprintf("%d bytes free\r\n", &i - heap_end);
    
    inBuffer[0] = 0;  // reset buffer
    bufPos = 0;

    RGB_LED(0,100,0);                       // Green

    for(;;) {
        readLen = uart_read_nonblock(inBuffer+bufPos,BUF_SIZE-(bufPos+2));
        if (readLen>0) {
            bufPos+=readLen;
            // quick trim
            while(bufPos>0 && isspace(inBuffer[bufPos-1]))
                  bufPos--;
            inBuffer[bufPos] = 0;
            if (inBuffer[bufPos-1] == ';') {
                iprintf("(in buf = '%s', len=%d)\r\n",inBuffer,bufPos);
                switch(inBuffer[0]) {
                case 'C':
                    n = sscanf(inBuffer+1,"%i,%i,%i",&nargs[0],&nargs[1],&nargs[2]);
                    if(n==3) RGB_LED(nargs[0],nargs[1],nargs[2]);
                    break;
                case 'R':
                    RGB_LED(100,0,0);
                    break;
                case 'G':
                    RGB_LED(0,100,0);
                    break;
                case 'B':
                    RGB_LED(0,0,100);
                    break;
                case 'A':
                    hasAccelData = 1;
                    break;
                case 'a':
                    hasAccelData = 0;
                    break;
                case 'T':
                    hasTouchData = 1;
                    break;
                case 't':
                    hasTouchData = 0;
                    break;
                case 'i':
                    iprintf("[efb,0.1] empiriKit Freescale Board, v.0.1\r\n");
                    break;
                }
                bufPos = 0;  // "clear" the buffer
            }
        }
        if (hasAccelData)
            iprintf("a%d,%d,%d;\r\n", accel_x(), accel_y(), accel_z());
        if (hasTouchData)
            iprintf("t%d,%d;\r\n", touch_data(9), touch_data(10));
    }
}
Ejemplo n.º 4
0
void kissSimComputerDraw()
{
	int oriX=ksWindow.simWidth, oriY=0, i;
	static char digitals[]="0 0 0 0 0 0 0 0";
	static char buttons[]="0 0 0 0 0 0 0";
	static char analogs[11][10]={"         ","         ","         ","         ","         ","         ","         ","         ","         ","         ","         "};
	static char actuators[4][25]={"                        ","                        ","                        ","                        "};
	static char servos[4][25]={"                        ","                        ","                        ","                        "};
	if(!glfwGetWindowParam(GLFW_OPENED)) return;
	graphics_rectangle_fill(oriX,oriY,oriX+1,ksWindow.height,BLACK); // draw left border
	draw_bg(oriX+5,oriY+9,0.36); // Botguy
	NOBOLD g_printString(" CBC SIMULATOR",oriX+25, oriY+10,TEAL,1.0);
	NOBOLD g_printString("    DIGITALS  ",oriX+25, oriY+40,TEAL,1.0);
	NOBOLD g_printString("0 1 2 3 4 5 6 7",oriX+25, oriY+55,TEAL,1.0);
	NOBOLD g_printString("    BUTTONS  ",oriX+25, oriY+90,TEAL,1.0);
	//NOBOLD g_printString("< ^ V > A B .",oriX+30, oriY+105,TEAL,1.0);
	NOBOLD g_printString("\xb \xd \xe \xc A B .",oriX+30, oriY+105,TEAL,1.0);
    // hex b, c, d, e are left, right, up, and down arrows
	NOBOLD g_printString(digitals,oriX+25, oriY+70,WHITE,1.0); // erase old digital values
	NOBOLD g_printString("    ANALOGS  ",oriX+25, oriY+140,TEAL,1.0);
	for(i=0;i<8;i++){
		digitals[2*i]=48+digital(i);
	}
	NOBOLD g_printString(digitals,oriX+25, oriY+70,BLACK,1.0); // write new digital values
	NOBOLD g_printString(buttons,oriX+30, oriY+120,WHITE,1.0); // erase old button values
	buttons[0]=48+!!left_button();
	buttons[2]=48+!!up_button();
	buttons[4]=48+!!down_button();
	buttons[6]=48+!!right_button();
	buttons[8]=48+!!a_button();
	buttons[10]=48+!!b_button();
	_bob.button=!!kiss_get_key('.');
	buttons[12]=48+black_button();
	NOBOLD g_printString(buttons,oriX+30, oriY+120,BLACK,1.0); // erase old button values
	for(i=8;i<16;i++){//print out analogs
		analogs[i-8][1]=(i<10)?48+i:48+i-10;
		analogs[i-8][0]=(i<10)?32:49;
		analogs[i-8][2]=':';
		analogs[i-8][3]=' ';
		NOBOLD g_printString(analogs[i-8],oriX+5, oriY+155+(15*(i-8)),WHITE,1.0);
		convertNumToString(analog10(i),4,*analogs,10,i-8,3);
		graphics_rectangle_fill(oriX+30,oriY+155+(15*(i-8)),oriX+157, oriY+165+(15*(i-8)),GRAY);
		graphics_line(oriX+30+analog(i)/2, oriY+155+(15*(i-8)),oriX+30+analog(i)/2,oriY+165+(15*(i-8)),RED);
		NOBOLD g_printString(analogs[i-8],oriX+5, oriY+155+(15*(i-8)),BLACK,1.0);

	}
	analogs[8][1]='X';
	analogs[8][0]='A';
	analogs[8][2]=':';
	analogs[8][3]=' ';
	NOBOLD g_printString(analogs[8],oriX+5, oriY+155+(15*(8)),WHITE,1.0);
	convertNumToString(accel_x(),5,*analogs,10,8,3);
	graphics_rectangle_fill(oriX+30,oriY+155+(15*(8)),oriX+157, oriY+165+(15*(8)),GRAY);
	graphics_line(oriX+30+(accel_x()+2048)/32, oriY+155+(15*(8)),oriX+30+(accel_x()+2048)/32,oriY+165+(15*(8)),RED);
	NOBOLD g_printString(analogs[8],oriX+5, oriY+155+(15*(8)),BLACK,1.0);
	analogs[9][1]='Y';
	analogs[9][0]='A';
	analogs[9][2]=':';
	analogs[9][3]=' ';
	NOBOLD g_printString(analogs[9],oriX+5, oriY+155+(15*(9)),WHITE,1.0);
	convertNumToString(accel_y(),5,*analogs,10,9,3);
	graphics_rectangle_fill(oriX+30,oriY+155+(15*(9)),oriX+157, oriY+165+(15*(9)),GRAY);
	graphics_line(oriX+30+(accel_y()+2048)/32, oriY+155+(15*(9)),oriX+30+(accel_y()+2048)/32,oriY+165+(15*(9)),RED);
	NOBOLD g_printString(analogs[9],oriX+5, oriY+155+(15*(9)),BLACK,1.0);
	analogs[10][1]='Z';
	analogs[10][0]='A';
	analogs[10][2]=':';
	analogs[10][3]=' ';
	NOBOLD g_printString(analogs[10],oriX+5, oriY+155+(15*(10)),WHITE,1.0);
	convertNumToString(accel_z(),5,*analogs,10,10,3);
	graphics_rectangle_fill(oriX+30,oriY+155+(15*(10)),oriX+157, oriY+165+(15*(10)),GRAY);
	graphics_line(oriX+30+(accel_z()+2048)/32, oriY+155+(15*(10)),oriX+30+(accel_z()+2048)/32,oriY+165+(15*(10)),RED);
	NOBOLD g_printString(analogs[10],oriX+5, oriY+155+(15*(10)),BLACK,1.0);

	NOBOLD g_printString("MOT PWM TPS  ENCODER VAL",oriX+5, oriY+330,TEAL,1.0);
	for(i=0;i<4;i++){
		actuators[i][0]=48+i;
		actuators[i][1]=':';
		actuators[i][2]=' ';
		NOBOLD g_printString(actuators[i],oriX+5, oriY+345+(15*(i)),WHITE,1.0);
		convertNumToString(_bob.motor_pwm[i],4,*actuators,25,i,2);
		convertNumToString(_bob.motor_tps[i],4,*actuators,25,i,7);
		convertNumToString(_bob.motor_counter[i],10,*actuators,25,i,12);
		NOBOLD g_printString(actuators[i],oriX+5, oriY+345+(15*(i)),BLACK,1.0);
	}
	if(_bob.enable_servos){
		NOBOLD g_printString("SERVO TARGET DISABLED",oriX+5, oriY+410,WHITE,1.0);
		NOBOLD g_printString("SERVO TARGET ENABLED",oriX+5, oriY+410,TEAL,1.0);
	}
	else {
		NOBOLD g_printString("SERVO TARGET ENABLED",oriX+5, oriY+410,WHITE,1.0);
		NOBOLD g_printString("SERVO TARGET DISABLED",oriX+5, oriY+410,TEAL,1.0);
	}
	for(i=0;i<4;i++){
		servos[i][2]=49+i;//servos are 1 indexed!!
		servos[i][3]=':';
		servos[i][4]=' ';
		NOBOLD g_printString(servos[i],oriX+5, oriY+425+(15*(i)),WHITE,1.0);
		convertNumToString(_bob.servo_targets[i],4,*servos,25,i,6);
		NOBOLD g_printString(servos[i],oriX+5, oriY+425+(15*(i)),BLACK,1.0);
	}

}