Beispiel #1
0
  /** Displays test pattern of all defined characters. */
  public void displayTestPattern() {
    byte[] byte1 = new byte[10];

    Util.consoleLog();

    // first reset the transmit array to zeros.
    for (int c = 0; c < 10; c++) {
      byte1[c] = (byte) (0b00000000) & 0xFF;
    }

    // put single character data in the array and write to display.
    for (int c = 0; c < 9; c++) {
      byte1[0] = (byte) (0b0000111100001111);
      byte1[2] = charreg[4 * c + 3][0];
      byte1[3] = charreg[4 * c + 3][1];
      byte1[4] = charreg[4 * c + 2][0];
      byte1[5] = charreg[4 * c + 2][1];
      byte1[6] = charreg[4 * c + 1][0];
      byte1[7] = charreg[4 * c + 1][1];
      byte1[8] = charreg[4 * c][0];
      byte1[9] = charreg[4 * c][1];

      // send the array to the board
      i2c.writeBulk(byte1);

      Timer.delay(3);
    }
  }
Beispiel #2
0
 public void SendString(String writeStr) {
   char[] CharArray = writeStr.toCharArray();
   byte[] WriteData = new byte[CharArray.length];
   for (int i = 0; i < CharArray.length; i++) {
     WriteData[i] = (byte) CharArray[i];
   }
   i2cBus.transaction(WriteData, WriteData.length, null, 0);
 }
Beispiel #3
0
  public double getDegrees() {
    double timerDelta = Timer.getFPGATimestamp() - timerStart;
    byte[] angle = new byte[1];
    gyro.read(0x47, 1, angle);

    double rotation = (angle[0] * timerDelta) * 2;
    degrees += rotation;

    return -degrees;
  }
Beispiel #4
0
  /**
   * Enable/Disable character LED blink.
   *
   * @param blink True to blink.
   */
  public void blink(boolean blink) {
    byte[] buffer = new byte[1];

    Util.consoleLog("%b", blink);

    if (blink) buffer[0] = (byte) 0x83;
    else buffer[0] = (byte) 0x81;

    i2c.writeBulk(buffer);

    Timer.delay(.01);
  }
Beispiel #5
0
  /**
   * Display a message in the character LEDs.
   *
   * @param message 4 character message, 0-9 A-Z.
   */
  public void display(String message) {
    int len, idx = 8;
    byte[] byte1 = new byte[10];

    message = message.toUpperCase();

    Util.consoleLog(message);

    // first reset the transmit array to zeros.
    for (int c = 0; c < 10; c++) {
      byte1[c] = (byte) (0b00000000) & 0xFF;
    }

    // Set memory address command to location to store characters on revboard.
    // Note: this sets max address depending on board automatically wrapping
    // around to address of 1st character.
    byte1[0] = (byte) (0b0000111100001111);

    len = message.length();

    if (len > 4) len = 4;

    // Process each character in the message. Use char value to index into
    // charreg array and set the 2 bytes for each char in output array.
    for (int c = 0; c < len; c++) {
      char ch = message.charAt(c);
      int chidx = ch;

      if (chidx >= 65 && chidx <= 90) // Upper case letters.
      chidx -= 55;
      else if (chidx == 48) // zero.
      chidx = 9;
      else if (chidx == 32) // space.
      chidx = 36;
      else if (chidx >= 49 && chidx <= 57) // 1-9.
      chidx -= 49;

      Util.consoleLog("c=%d i=%d chidx=%d char=%s", c, idx, chidx, ch);

      byte1[idx] = charreg[chidx][0];
      byte1[idx + 1] = charreg[chidx][1];
      idx -= 2;
    }

    // send the array to the board
    i2c.writeBulk(byte1);
  }
  /*
   * reads the arduino and recieves 2 bytes to represent the digital inputs attached to it
   * saves the 2 bytes to 'loByte' and 'hiByte'
   * return: true if and only if it's successful
   */
  public boolean readArduino() {
    byte[] buffer = {0, 0};

    successful =
        !m_I2C.transaction(
            null, 0, buffer,
            2); // doesn't send anything and recieves 2 bytes of data; successful==true if
    // transaction is succesful
    DriverStationLCD.getInstance()
        .println(DriverStationLCD.Line.kUser1, 1, "                     ");
    DriverStationLCD.getInstance()
        .println(DriverStationLCD.Line.kUser2, 1, "                     ");
    DriverStationLCD.getInstance()
        .println(DriverStationLCD.Line.kUser1, 1, "success=" + successful);
    DriverStationLCD.getInstance()
        .println(DriverStationLCD.Line.kUser2, 1, "buffer=" + buffer[1] + ", " + buffer[0]);
    DriverStationLCD.getInstance().updateLCD();
    hiByte = buffer[1];
    loByte = buffer[0];

    return successful;
  }
  private void board_task() {
    byte[] osc = new byte[1];
    byte[] blink = new byte[1];
    byte[] bright = new byte[1];
    osc[0] = (byte) 0x21;
    blink[0] = (byte) 0x81;
    bright[0] = (byte) 0xEF;

    _display_board.writeBulk(osc);
    _display_board.writeBulk(bright);
    _display_board.writeBulk(blink);

    STATE mode = STATE.Voltage;

    long refresh = 0;

    while (_do_things) {
      update();

      if ((System.currentTimeMillis() - refresh) > _timeout) {
        mode = STATE.Voltage;
      }

      boolean update_refresh = true;

      if (getAOnRisingEdge()) {
        if (mode == STATE.Position) {
          pos = (pos + 1) % _positions.length; // just display current position on first press
        }
        mode = STATE.Position;

        //				System.out.println("pos");
      } else if (getBOnRisingEdge()) {
        if (mode == STATE.Obstacle) {
          obs = (obs + 1) % _obstacles.length;
        }
        mode = STATE.Obstacle; // display current obstacle on first press

        //				System.out.println("obs");
      } else {
        update_refresh = false;
      }

      if (pos == 0) {
        obs = 0;
      }
      if (pos > 0 && obs == 0) {
        obs++;
      }

      if (update_refresh) {
        refresh = System.currentTimeMillis();
      }

      if (mode == STATE.Position) {
        _display_board.writeBulk(output_pos(_positions[pos]));
      } else if (mode == STATE.Obstacle) {
        _display_board.writeBulk(output_obs(_obstacles[obs]));
      } else {
        _display_board.writeBulk(output_voltage());
      }

      try {
        Thread.sleep(40); // wait a while because people can't read that
        // fast
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
  /** This function is called periodically during operator control */
  public void teleopPeriodic() {

    // Commented and stuff
    // If it's wrong then uhh
    // My bad fam.

    if (joy.getRawButton(1)) { // Check if the button is pressed
      String WriteString =
          "RGB"; // String that is going to transfer; change to whatever the Arduino code has
      char[] CharArray = WriteString.toCharArray(); // Changes data type (string) to char array
      // Char array: array of chars
      byte[] WriteData =
          new byte
              [CharArray.length]; // Makes the char array able to transfer from roboRio to Arduino
      for (int i = 0; i < CharArray.length; i++) { // Repeats for each char in CharArray
        WriteData[i] = (byte) CharArray[i]; // Sets the char to byte
      }
      Wire.transaction(WriteData, WriteData.length, null, 0); // Finally does transaction
    }

    if (joy.getRawButton(2)) {
      String WriteString = "RGB";
      char[] CharArray = WriteString.toCharArray();
      byte[] WriteData = new byte[CharArray.length];
      for (int i = 0; i < CharArray.length; i++) {
        WriteData[i] = (byte) CharArray[i];
      }
      Wire.transaction(WriteData, WriteData.length, null, 0);
    }
    if (joy.getRawButton(3)) {
      String WriteString = "RGB";
      char[] CharArray = WriteString.toCharArray();
      byte[] WriteData = new byte[CharArray.length];
      for (int i = 0; i < CharArray.length; i++) {
        WriteData[i] = (byte) CharArray[i];
      }
      Wire.transaction(WriteData, WriteData.length, null, 0);
    }
    if (joy.getRawButton(4)) {
      String WriteString = "RGB";
      char[] CharArray = WriteString.toCharArray();
      byte[] WriteData = new byte[CharArray.length];
      for (int i = 0; i < CharArray.length; i++) {
        WriteData[i] = (byte) CharArray[i];
      }
      Wire.transaction(WriteData, WriteData.length, null, 0);
    }

    //    	if (joy.getRawButton(5)) {
    //    		String WriteString = "RGB";
    //    		char[] CharArray = WriteString.toCharArray();
    //    		byte[] WriteData = new byte[CharArray.length];
    //    		for (int i = 0; i < CharArray.length; i++) {
    //    			WriteData[i] = (byte) CharArray[i];
    //    		}
    //    		Wire.transaction(WriteData, WriteData.length, null, 0);
    //    	}
    //    	if (joy.getRawButton(6)) {
    //    		String WriteString = "RGB";
    //    		char[] CharArray = WriteString.toCharArray();
    //    		byte[] WriteData = new byte[CharArray.length];
    //    		for (int i = 0; i < CharArray.length; i++) {
    //    			WriteData[i] = (byte) CharArray[i];
    //    		}
    //    		Wire.transaction(WriteData, WriteData.length, null, 0);
    //    	}
    //    	if (joy.getRawButton(7)) {
    //    		String WriteString = "RGB";
    //    		char[] CharArray = WriteString.toCharArray();
    //    		byte[] WriteData = new byte[CharArray.length];
    //    		for (int i = 0; i < CharArray.length; i++) {
    //    			WriteData[i] = (byte) CharArray[i];
    //    		}
    //    		Wire.transaction(WriteData, WriteData.length, null, 0);
    //    	}
  }
Beispiel #9
0
  public RevDigitBoard() {
    Util.consoleLog();

    // Load the character registry.
    charreg[0][0] = (byte) 0b00000110;
    charreg[0][1] = (byte) 0b00000000; // 1
    charreg[1][0] = (byte) 0b11011011;
    charreg[1][1] = (byte) 0b00000000; // 2
    charreg[2][0] = (byte) 0b11001111;
    charreg[2][1] = (byte) 0b00000000; // 3
    charreg[3][0] = (byte) 0b11100110;
    charreg[3][1] = (byte) 0b00000000; // 4
    charreg[4][0] = (byte) 0b11101101;
    charreg[4][1] = (byte) 0b00000000; // 5
    charreg[5][0] = (byte) 0b11111101;
    charreg[5][1] = (byte) 0b00000000; // 6
    charreg[6][0] = (byte) 0b00000111;
    charreg[6][1] = (byte) 0b00000000; // 7
    charreg[7][0] = (byte) 0b11111111;
    charreg[7][1] = (byte) 0b00000000; // 8
    charreg[8][0] = (byte) 0b11101111;
    charreg[8][1] = (byte) 0b00000000; // 9
    charreg[9][0] = (byte) 0b00111111;
    charreg[9][1] = (byte) 0b00000000; // 0
    charreg[10][0] = (byte) 0b11110111;
    charreg[10][1] = (byte) 0b00000000; // A
    charreg[11][0] = (byte) 0b10001111;
    charreg[11][1] = (byte) 0b00010010; // B
    charreg[12][0] = (byte) 0b00111001;
    charreg[12][1] = (byte) 0b00000000; // C
    charreg[13][0] = (byte) 0b00001111;
    charreg[13][1] = (byte) 0b00010010; // D
    charreg[14][0] = (byte) 0b11111001;
    charreg[14][1] = (byte) 0b00000000; // E
    charreg[15][0] = (byte) 0b11110001;
    charreg[15][1] = (byte) 0b00000000; // F
    charreg[16][0] = (byte) 0b10111101;
    charreg[16][1] = (byte) 0b00000000; // G
    charreg[17][0] = (byte) 0b11110110;
    charreg[17][1] = (byte) 0b00000000; // H
    charreg[18][0] = (byte) 0b00001001;
    charreg[18][1] = (byte) 0b00010010; // I
    charreg[19][0] = (byte) 0b00011110;
    charreg[19][1] = (byte) 0b00000000; // J
    charreg[20][0] = (byte) 0b01110000;
    charreg[20][1] = (byte) 0b00001100; // K
    charreg[21][0] = (byte) 0b00111000;
    charreg[21][1] = (byte) 0b00000000; // L
    charreg[22][0] = (byte) 0b00110110;
    charreg[22][1] = (byte) 0b00000101; // M
    charreg[23][0] = (byte) 0b00110110;
    charreg[23][1] = (byte) 0b00001001; // N
    charreg[24][0] = (byte) 0b00111111;
    charreg[24][1] = (byte) 0b00000000; // O
    charreg[25][0] = (byte) 0b11110011;
    charreg[25][1] = (byte) 0b00000000; // P
    charreg[26][0] = (byte) 0b00111111;
    charreg[26][1] = (byte) 0b00001000; // Q
    charreg[27][0] = (byte) 0b11110011;
    charreg[27][1] = (byte) 0b00001000; // R
    charreg[28][0] = (byte) 0b10001101;
    charreg[28][1] = (byte) 0b00000001; // S
    charreg[29][0] = (byte) 0b00000001;
    charreg[29][1] = (byte) 0b00010010; // T
    charreg[30][0] = (byte) 0b00111110;
    charreg[30][1] = (byte) 0b00000000; // U
    charreg[31][0] = (byte) 0b00110000;
    charreg[31][1] = (byte) 0b00100100; // V
    charreg[32][0] = (byte) 0b00110110;
    charreg[32][1] = (byte) 0b00101000; // W
    charreg[33][0] = (byte) 0b00000000;
    charreg[33][1] = (byte) 0b00101101; // X
    charreg[34][0] = (byte) 0b00000000;
    charreg[34][1] = (byte) 0b00010101; // Y
    charreg[35][0] = (byte) 0b00001001;
    charreg[35][1] = (byte) 0b00100100; // Z
    charreg[36][0] = (byte) 0b00000000;
    charreg[36][1] = (byte) 0b00000000; // Space

    // set up the board - turn on, set blinking and brightness
    byte[] osc = new byte[1];
    byte[] blink = new byte[1];
    byte[] bright = new byte[1];

    osc[0] = (byte) 0x21;
    blink[0] = (byte) 0x81;
    bright[0] = (byte) 0xEF;

    i2c.writeBulk(osc);
    Timer.delay(.01);

    i2c.writeBulk(bright);
    Timer.delay(.01);

    i2c.writeBulk(blink);
    Timer.delay(.01);

    display("");
  }
Beispiel #10
0
 public I2CGyro() {
   gyro.write(0x6B, 0x03); // Power
   gyro.write(0x1A, 0x18); // Basic Config
   gyro.write(0x1B, 0x00); // Gyro Config
 }
Beispiel #11
0
 public void SendStateChange(char state) {
   i2cBus.write(0x02, state);
 }