Advertisement
Guest User

metawear-i2c-send-receive-command

a guest
Oct 19th, 2016
135
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. readBtn.setOnClickListener(new View.OnClickListener() {
  2.     @Override
  3.     public void onClick(View v) {
  4.         byte[] cmdGetFirmware = new byte[]{
  5.                 (byte) 0x00,
  6.                 (byte) 0x00,
  7.                 (byte) 0xff,
  8.                 (byte) 0x02,
  9.                 (byte) 0xfe,
  10.                 (byte) 0xd4,
  11.                 (byte) 0x02,
  12.                 (byte) 0x2a,
  13.                 (byte) 0x00
  14.         };
  15.  
  16.         final byte registerAddr = 0x00;
  17.         final byte deviceAddr = 0x24;
  18.         final int nBytes = 7;
  19.  
  20.  
  21.         String deviceAndRegister = "Device: " + String.format("0x%02X", deviceAddr) + " Register: " + String.format("0x%02X", registerAddr);
  22.         System.out.println(deviceAndRegister);
  23.  
  24.         try {
  25.             byte[] cmd = cmdGetFirmware;
  26.  
  27.             System.out.println("Write CMD with length: " + cmd.length);
  28.  
  29.             i2cModule.writeData(deviceAddr, registerAddr, cmd);
  30.             Thread.sleep(500);
  31.  
  32.             System.out.println("Try to read: ");
  33.             i2cModule.readData(deviceAddr, registerAddr, (byte) nBytes).onComplete(new CompletionHandler<byte[]>() {
  34.                 @Override
  35.                 public void success(byte[] result) {
  36.                     System.out.println("Result: " + arrayToHexString(result));
  37.                 }
  38.             });
  39.  
  40.  
  41.         } catch (InterruptedException e) {
  42.             e.printStackTrace();
  43.         }
  44.     }
  45. });
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement