Пример #1
0
static void test_display(void) {
  U32 counter = 0;
  nx_display_clear();
  while(1) {
    counter++;
    nx_display_cursor_set_pos(0,0);
    nx_display_hex(counter);
    nx_display_end_line();
    nx_display_hex(sleep_iter);
    nx_display_end_line();
    nx_display_uint(sleep_time);
    nx_display_string(" / ");
    nx_display_uint(wakeup_time);
  }
}
Пример #2
0
void nx__abort(bool data, U32 pc, U32 cpsr) {
  nx_interrupts_disable();
  nx_display_auto_refresh(FALSE);
  //nx_display_clear();
  if (data) {
    nx_display_string("Data");
  } else {
    nx_display_string("Prefetch");
  }
  nx_display_string(" abort\nPC: ");
  nx_display_hex(pc);
  nx_display_string("\nCPSR: ");
  nx_display_hex(cpsr);
  nx__lcd_sync_refresh();
  while(1);
}
Пример #3
0
void tests_tachy(void) {
  int i;
  hello();

  nx_motors_rotate_angle(0, 80, 1024, TRUE);
  nx_motors_rotate_time(1, -80, 3000, FALSE);
  nx_motors_rotate(2, 80);

  for (i=0; i<30; i++) {
    nx_display_clear();
    nx_display_cursor_set_pos(0,0);

    nx_display_clear();
    nx_display_cursor_set_pos(0,0);
    nx_display_string("Tachymeter  test\n"
		      "----------------\n");

    nx_display_string("Tach A: ");
    nx_display_hex(nx_motors_get_tach_count(0));
    nx_display_end_line();

    nx_display_string("Tach B: ");
    nx_display_hex(nx_motors_get_tach_count(1));
    nx_display_end_line();

    nx_display_string("Tach C: ");
    nx_display_hex(nx_motors_get_tach_count(2));
    nx_display_end_line();

    nx_display_string("Refresh: ");
    nx_display_uint(i);
    nx_display_end_line();

    nx_systick_wait_ms(250);
  }

  nx_motors_stop(2, TRUE);

  goodbye();
}
Пример #4
0
void tests_usb(void) {
  U16 i;
  U32 lng = 0;

  char buffer[NX_USB_PACKET_SIZE];

  hello();

  while(1) {
    nx_display_cursor_set_pos(0, 0);
    nx_display_string("Waiting command ...");

    nx_usb_read((U8 *)&buffer, NX_USB_PACKET_SIZE * sizeof(char));

    for (i = 0 ; i < 500 && !nx_usb_data_read(); i++)
    {
      nx_systick_wait_ms(200);
    }

    if (i >= 500)
      break;

    nx_display_clear();

    lng = nx_usb_data_read();

    if ((lng+1) < NX_USB_PACKET_SIZE)
      buffer[lng+1] = '\0';
    else
      buffer[NX_USB_PACKET_SIZE-1] = '\0';

    nx_display_cursor_set_pos(0, 0);
    nx_display_string("==");
    nx_display_uint(lng);

    nx_display_cursor_set_pos(0, 1);
    nx_display_string(buffer);

    nx_display_cursor_set_pos(0, 2);
    nx_display_hex((U32)(CMD_UNKNOWN));

    /* Start interpreting */

    i = tests_command(buffer);

    if (i == 2) {
      break;
    }

    if (i == 1) {
      nx_usb_write((U8 *)CMD_UNKNOWN, sizeof(CMD_UNKNOWN)-1);
    }

    if (i == 0) {
      nx_usb_write((U8 *)CMD_OK, sizeof(CMD_OK)-1);
    }

    nx_systick_wait_ms(500);

    nx_display_clear();

  }

  goodbye();
}
Пример #5
0
/**
 * @return 0 if success ; 1 if unknown command ; 2 if halt
 */
static int tests_command(char *buffer) {
  int i;
  S32 t;

  /* Start interpreting */

  i = 0;
  if (streq(buffer, "motor"))
    tests_motor();
  else if (streq(buffer, "sound"))
    tests_sound();
  else if (streq(buffer, "util"))
    tests_util();
  else if (streq(buffer, "display"))
    tests_display();
  else if (streq(buffer, "sysinfo"))
    tests_sysinfo();
  else if (streq(buffer, "sensors"))
    tests_sensors();
  else if (streq(buffer, "tachy"))
    tests_tachy();
  else if (streq(buffer, "radar"))
    tests_radar();
  else if (streq(buffer, "ht_compass"))
    tests_ht_compass();
  else if (streq(buffer, "ht_accel"))
    tests_ht_accel();
  else if (streq(buffer, "ht_gyro"))
    tests_ht_gyro();
  else if (streq(buffer, "ht_irlink"))
    tests_ht_irlink();
  else if (streq(buffer, "digitemp"))
    tests_digitemp();
  else if (streq(buffer, "bt"))
    tests_bt();
  else if (streq(buffer, "bt2"))
    tests_bt2();
  else if (streq(buffer, "all"))
    tests_all();
  else if (streq(buffer, "halt"))
    return 2;
  else if (streq(buffer, "Al"))
    nx_motors_rotate_angle(0, 90, 100, 1);
  else if (streq(buffer, "Ar"))
    nx_motors_rotate_angle(0, -90, 100, 1);
  else if (streq(buffer, "Ac")) {
    nx_motors_rotate(0, 75);
    while((t = nx_motors_get_tach_count(0)) != 0) {
      if (t < 0) {
        nx_motors_rotate(0, 75);
      } else {
        nx_motors_rotate(0, -75);
      }
      nx_display_cursor_set_pos(1, 1);
      nx_display_hex(t);
      nx_display_string("          ");
    }
    nx_motors_stop(0, 1);
  } else if (streq(buffer, "BCf")) {
    nx_motors_rotate(1, -100);
    nx_motors_rotate(2, -100);
    nx_systick_wait_ms(MOVE_TIME_AV);
    nx_motors_stop(1, 0);
    nx_motors_stop(2, 0);
  } else if (streq(buffer, "BCr")) {
    nx_motors_rotate(1, 80);
    nx_motors_rotate(2, 80);
    nx_systick_wait_ms(MOVE_TIME_AR);
    nx_motors_stop(1, 0);
    nx_motors_stop(2, 0);
  }
  else {
    i = 1;
  }

  return i;
}
Пример #6
0
void tests_ht_irlink(void) {
  U32 sensor = 2;
  U8 buffer[15];

  hello();
  nx_display_clear();
  nx_display_cursor_set_pos(0, 0);
  nx_display_string("Test of IRLink\n");
  //nx_i2c_init();
  nx_display_string("Press OK to stop\n");
  ht_irlink_init(sensor);

  if( ! ht_irlink_detect(sensor) ) {
    nx_display_string("No IRLink!\n");
    nx_systick_wait_ms(10000);
    goodbye();
    return;
  }

  ht_irlink_info(sensor);

  /* This test is build for use with the Motorized Bulldozer (8275).
   * You need about 1m x 0.5m space where the Bulldozer will drive.
   * Because we don't have motor-feedback or encoders, all times are
   * approximately and depending heavily on the battery-level of the PF
   * and the ground over which the bulldozer drives.
   *
   * It should'nt be any problem to use this test with other models or
   * just plain connected motors to see if all works.
   *
   * Maybe I've made a mistake building the bulldozer, but my model
   * requires to backward drive motor A on channel 0 to drive the left side
   * forward, it might be that you have to change that.
   *
   * The sequence of commands is the following:
   *
   * (1) Backward drive motor A (red, blade) and forward drive
   *     motor B (blue, ripper) on channel 1 with full power for 7s to
   *     be sure the front blade and the ripper are up.
   * (2) Forward drive motor A (left) and backward drive motor B (right)
   *     on channel 0 with full power for 5s to drive the bulldozer
   *     about 1m forwards.
   * (3) Forward drive motor A on channel 1 for 5s then backward drive
   *     him for 5s to move the front blade down an up.
   * (4) Forward drive both motors on channel 0 with full power for 3s to turn
   *     the bulldozer to the right about 180 degrees,
   * (5) Forward drive both motors on channel 0 pwm-controlled, raising the
   *     power from 3 to 6 and backwards to 0 to drive the bulldozer
   *     about 1m forwards.
   * (6) Backward drive both motors on channel 0 pwm-controlled with power 7
   *     to turn the bulldoze to the left about 180 degrees.
   * (7) Backward drive motor B on channel 1 for 5s then forward drive
   *     him for 5s to move the ripper down an up.
   */
  U8 count;
  /* (1) */
  count = ht_irlink_encode_bitstream(HT_IRLINK_MODE_PF,
    build_bitstream_PF_direct(1, PF_MOTOR_A_BACKWARD | PF_MOTOR_B_FORWARD),
    buffer);
  for ( unsigned i = 0; i < 7; ++i ) {
    ht_irlink_transmit_buffer_4x(sensor, buffer, count);
    nx_systick_wait_ms(1000);
  }
  /* (2) */
  count = ht_irlink_encode_bitstream(HT_IRLINK_MODE_PF,
    build_bitstream_PF_direct(0, PF_MOTOR_A_FORWARD | PF_MOTOR_B_BACKWARD),
    buffer);
  for ( unsigned i = 0; i < 5; ++i ) {
    ht_irlink_transmit_buffer_4x(sensor, buffer, count);
    nx_systick_wait_ms(1000);
  }
  /* (3) */
  count = ht_irlink_encode_bitstream(HT_IRLINK_MODE_PF,
    build_bitstream_PF_direct(1, PF_MOTOR_A_FORWARD ),
    buffer);
  for ( unsigned i = 0; i < 5; ++i ) {
    ht_irlink_transmit_buffer_4x(sensor, buffer, count);
    nx_systick_wait_ms(1000);
  }
  count = ht_irlink_encode_bitstream(HT_IRLINK_MODE_PF,
    build_bitstream_PF_direct(1, PF_MOTOR_A_BACKWARD ),
    buffer);
  for ( unsigned i = 0; i < 5; ++i ) {
    ht_irlink_transmit_buffer_4x(sensor, buffer, count);
    nx_systick_wait_ms(1000);
  }
  /* (4) */
  count = ht_irlink_encode_bitstream(HT_IRLINK_MODE_PF,
    build_bitstream_PF_direct(0, PF_MOTOR_A_FORWARD | PF_MOTOR_B_FORWARD),
    buffer);
  for ( unsigned i = 0; i < 3; ++i ) {
    ht_irlink_transmit_buffer_4x(sensor, buffer, count);
    nx_systick_wait_ms(1000);
  }
  /* (5) */
  for ( unsigned i = 0; i < 4; ++i ) {
    count = ht_irlink_encode_bitstream(HT_IRLINK_MODE_PF,
      build_bitstream_PF_pwm(0, PF_PWM_MOTOR_FWD_3 + i, PF_PWM_MOTOR_BACK_3 - i),
      buffer);
    ht_irlink_transmit_buffer_4x(sensor, buffer, count);
    nx_systick_wait_ms(1000);
  }
  for ( unsigned i = 3; i ; --i ) {
    count = ht_irlink_encode_bitstream(HT_IRLINK_MODE_PF,
      build_bitstream_PF_pwm(0, PF_PWM_MOTOR_FWD_3 + i, PF_PWM_MOTOR_BACK_3 - i),
      buffer);
    ht_irlink_transmit_buffer_4x(sensor, buffer, count);
    nx_systick_wait_ms(1000);
  }
  /* (6) */
  for ( unsigned i = 0; i < 3; ++i ) {
    count = ht_irlink_encode_bitstream(HT_IRLINK_MODE_PF,
      build_bitstream_PF_pwm(0, PF_PWM_MOTOR_BACK_7, PF_PWM_MOTOR_BACK_7),
      buffer);
    ht_irlink_transmit_buffer_4x(sensor, buffer, count);
    nx_systick_wait_ms(1000);
  }
  /* (7) */
  count = ht_irlink_encode_bitstream(HT_IRLINK_MODE_PF,
    build_bitstream_PF_direct(1, PF_MOTOR_B_BACKWARD ),
    buffer);
  for ( unsigned i = 0; i < 5; ++i ) {
    ht_irlink_transmit_buffer_4x(sensor, buffer, count);
    nx_systick_wait_ms(1000);
  }
  count = ht_irlink_encode_bitstream(HT_IRLINK_MODE_PF,
    build_bitstream_PF_direct(1, PF_MOTOR_B_FORWARD ),
    buffer);
  for ( unsigned i = 0; i < 5; ++i ) {
    ht_irlink_transmit_buffer_4x(sensor, buffer, count);
    nx_systick_wait_ms(1000);
  }
  /* Display the receive buffer */
  nx_display_cursor_set_pos(15, 4);
  nx_display_string(" ");
  nx_display_cursor_set_pos(12, 4);
  nx_display_uint(count);
  nx_display_string("):\n");
  nx_display_string("                                             ");
  nx_display_cursor_set_pos(0, 5);
  for(unsigned i = 0; i < count; ++i) {
    nx_display_hex(buffer[i]);
    nx_display_string(" ");
  }

  nx_systick_wait_ms(10000);
/* this will display received messages continuously */
/*
  while(nx_avr_get_button() != BUTTON_OK) {
    // TODO: Check how to correctly handle receiving of messages.
    count = ht_irlink_get_receive_buffer(sensor, buffer);
    if(count) {
      ht_irlink_clear_receive_buffer(sensor);
      nx_display_cursor_set_pos(15, 4);
      nx_display_string(" ");
      nx_display_cursor_set_pos(12, 4);
      nx_display_uint(count);
      nx_display_string("):\n");
      nx_display_string("                                             ");
      nx_display_cursor_set_pos(0, 5);
      for(unsigned i = 0; i < count; ++i) {
        nx_display_hex(buffer[i]);
        nx_display_string(" ");
      }
      // Clear the receive buffer, to receive more bytes.
      // TODO: Is this really necessary?
      ht_irlink_clear_receive_buffer(sensor);
    }
    nx_systick_wait_ms(20);
  }
*/
  ht_irlink_close(sensor);
  goodbye();
}