void auto_raw(void) { //while there is not a button pressed while(!(UCSR0A & (1 << RXC0))) { //prints the raw vaues with a '$,' start and ',#' end printf("$,"); printf("%d,", x_accel()); printf("%d,", y_accel()); printf("%d,", z_accel()); printf("%d,", x_gyro()); printf("%d,", y_gyro()); printf("%d,", z_gyro()); magnetometer(); printf("%d,", x_mag); printf("%d,", y_mag); printf("%d,", z_mag); printf("#\n\r"); } //if a button is pressed and that button is ctrl-z, reset autorun, display menu if(uart_getchar() == 0x1A) { write_to_EEPROM(10,0); config_menu(); } auto_raw(); }
void config_read(void) { uint8_t choice=0; if(read_from_EEPROM(10) != 48) { while(1) { choice = uart_getchar(); putchar('\n'); putchar('\r'); if(choice=='1') { while(!(UCSR0A & (1 << RXC0)))adxl345(); config_menu(); } if(choice=='2') { while(!(UCSR0A & (1 << RXC0))) { hmc5843(); delay_ms(550);//at least 100ms interval between measurements } config_menu(); } if(choice=='3') { while(!(UCSR0A & (1 << RXC0)))stgyros(); config_menu(); } if(choice=='4') { while(!(UCSR0A & (1 << RXC0)))raw(); config_menu(); } if(choice=='5') { self_test(); } if(choice==0x1A) //if ctrl-z { write_to_EEPROM(10,48); auto_raw(); } if(choice==0x3F) //if ? { help(); config_menu(); } } }else auto_raw(); }
void auto_raw(void) { //while there is not a button pressed while(!(UCSR0A & (1 << RXC0))) { raw(); } //if a button is pressed and that button is ctrl-z, reset autorun, display menu if(uart_getchar() == 0x1A) { write_to_EEPROM(1,0); config_menu(); } auto_raw(); }
void config_read(void) { uint8_t choice=0; if(read_from_EEPROM(1) != 48) { while(1) { choice = uart_getchar(); putchar('\n'); putchar('\r'); if(choice=='1') { while(!(UCSR0A & (1 << RXC0)))print_adxl345(); config_menu(); } else if(choice=='2') { while(!(UCSR0A & (1 << RXC0))) { print_hmc5883(); delay_ms(100);//at least 100ms interval between measurements } config_menu(); } else if(choice=='3') { while(!(UCSR0A & (1 << RXC0)))print_itg3200(); config_menu(); } else if(choice=='4') { while(!(UCSR0A & (1 << RXC0)))raw(); config_menu(); } else if(choice=='5') { baud_menu(); config_menu(); } else if(choice==0x10) //if ctrl-p { self_test(); } else if(choice==0x1A) //if ctrl-z { write_to_EEPROM(1,48); auto_raw(); } else if(choice==0x3F) //if ? { help(); while(!(UCSR0A & (1 << RXC0))); config_menu(); } else if(choice==0xFF) config_read(); } }else auto_raw(); }
void baud_menu(void) { printf("\n\rBaud Rate Select Menu\n\r"); printf("[1] 4800\n\r"); printf("[2] 9600\n\r"); printf("[3] 19200\n\r"); printf("[4] 38400\n\r"); printf("[5] 57600\n\r"); uint8_t choicer=0; while(1) { choicer = uart_getchar(); putchar('\n'); putchar('\r'); if(choicer=='1') //4800 { //outside of default flag: used to notify init not to run default baud value write_to_EEPROM(2, 99); //clear other EEPROM values write_to_EEPROM(4, 0); write_to_EEPROM(5, 0); write_to_EEPROM(6, 0); write_to_EEPROM(7, 0); write_to_EEPROM(3, 4); //baud change flag printf("!change baud rate to 4800bps, reset board!"); delay_ms(50); UART_Init(207); while(1); } else if(choicer=='2') //9600 { write_to_EEPROM(2, 99); //outside of default flag //clear other EEPROM values write_to_EEPROM(3, 0); write_to_EEPROM(5, 0); write_to_EEPROM(6, 0); write_to_EEPROM(7, 0); write_to_EEPROM(4, 9); //baud change flag printf("!change baud rate to 9600bps, reset board!"); delay_ms(50); UART_Init(103); while(1); } else if(choicer=='3') //19200 { write_to_EEPROM(2, 99); //outside of default flag //clear other EEPROM values write_to_EEPROM(3, 0); write_to_EEPROM(4, 0); write_to_EEPROM(6, 0); write_to_EEPROM(7, 0); write_to_EEPROM(5, 19); //baud change flag printf("!change baud rate to 19200bps, reset board!"); delay_ms(50); UART_Init(51); while(1); } else if(choicer=='4') //38400 { write_to_EEPROM(2, 99); //outside of default flag //clear other EEPROM values write_to_EEPROM(3, 0); write_to_EEPROM(4, 0); write_to_EEPROM(5, 0); write_to_EEPROM(7, 0); write_to_EEPROM(6, 38); //baud change flag printf("!change baud rate to 38400bps, reset board!"); delay_ms(50); UART_Init(25); while(1); } else if(choicer=='5') //57600 { write_to_EEPROM(2, 99); //outside of default flag //clear other EEPROM values write_to_EEPROM(3, 0); write_to_EEPROM(4, 0); write_to_EEPROM(5, 0); write_to_EEPROM(6, 0); write_to_EEPROM(7, 57); //baud change flag printf("!change baud rate to 57600bps, reset board!"); delay_ms(50); UART_Init(16); while(1); } else if((choicer < 0X31) || (choicer > 0x35))config_menu(); //if choice is not #s 1-5 goto conig menu } config_menu(); }
void set_byte( byte menu_num, byte submenu_num ) { byte var_in_eeprom; byte plus5 = 0; char limitPilih = -1; lcd_clear(); lcd_gotoxy(0, 0); switch (menu_num) { case 1: // PID switch (submenu_num) { case 1: // Kp lcd_putsf("Set Kp : "); var_in_eeprom = Kp; break; case 2: // Ki lcd_putsf("Set Ki : "); var_in_eeprom = Ki; break; case 3: // Kd lcd_putsf("Set Kd : "); var_in_eeprom = Kd; break; } break; case 2: // Speed plus5 = 1; switch (submenu_num) { case 1: // MAX lcd_putsf("Set MAX Speed : "); var_in_eeprom = max_speed; break; case 2: // MIN lcd_putsf("Set MIN Speed : "); var_in_eeprom = min_speed; break; } break; } while (sw_cancel) { delay_ms(150); lcd_gotoxy(0, 1); lcd_please_display(var_in_eeprom); if (!sw_ok) { // If switch OK is pressed lcd_clear(); write_to_EEPROM( menu_num, submenu_num, var_in_eeprom ); goto exitSetByte; } if (!sw_down) { // If switch arrow-down is pressed if ( plus5 ) { if ( var_in_eeprom == 0 ) { var_in_eeprom = 255; } else { var_in_eeprom -= 5; } } else { if ( !limitPilih ) { var_in_eeprom--; } else { if ( var_in_eeprom == 0 ) { var_in_eeprom = limitPilih; } else { var_in_eeprom--; } } } } if (!sw_up) { // If switch arrow-up is pressed if ( plus5 ) { if ( var_in_eeprom == 255 ) { var_in_eeprom = 0; } else { var_in_eeprom += 5; } } else { if ( !limitPilih ) { var_in_eeprom++; } else { if ( var_in_eeprom == limitPilih ) { var_in_eeprom = 0; } else { var_in_eeprom++; } } } } } exitSetByte: delay_ms(100); lcd_clear(); }