コード例 #1
0
ファイル: I2CActivity.java プロジェクト: kisese/melody-smart
  @Override
  public void onDestroy() {
    i2CService.enableNotifications(false);
    i2CService.unregisterListener(this);

    super.onDestroy();
  }
コード例 #2
0
ファイル: I2CActivity.java プロジェクト: kisese/melody-smart
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.i2c_activity);

    i2CService = MelodySmartDevice.getInstance().getI2CService();
    i2CService.enableNotifications(true);
    i2CService.registerListener(this);

    incomingData = (EditText) findViewById(R.id.incomingDataTextEdit);
    outgoingData = (EditText) findViewById(R.id.outgoingDataTextEdit);
    writeButton = (Button) findViewById(R.id.writeButton);
    readButton = (Button) findViewById(R.id.readButton);

    deviceAddress = (EditText) findViewById(R.id.deviceEditText);
    registerAddress = (EditText) findViewById(R.id.registerEditText);

    writeButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            byte[] register = toBytes(registerAddress.getText().toString());
            byte[] data = toBytes(outgoingData.getText().toString());
            byte[] fullData = new byte[register.length + data.length];
            System.arraycopy(register, 0, fullData, 0, register.length);
            System.arraycopy(data, 0, fullData, register.length, data.length);
            i2CService.writeData(fullData, toByte(deviceAddress.getText().toString()));
          }
        });

    readButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            byte[] writePortion = toBytes(registerAddress.getText().toString());
            i2CService.readData(
                writePortion, toByte(deviceAddress.getText().toString()), (byte) 16);
          }
        });
  }