Skip to content

Commit

Permalink
adress spinner added and working
Browse files Browse the repository at this point in the history
  • Loading branch information
hehopmajieh committed Oct 31, 2012
1 parent e6e05f8 commit e133c68
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 20 deletions.
Binary file modified bin/axon.test.testJNI.TestJNIActivity.apk
Binary file not shown.
Binary file modified bin/classes.dex
Binary file not shown.
Binary file modified bin/classes/axon/test/testJNI/R$id.class
Binary file not shown.
Binary file modified bin/classes/axon/test/testJNI/R$layout.class
Binary file not shown.
Binary file modified bin/classes/axon/test/testJNI/R$string.class
Binary file not shown.
Binary file modified bin/classes/axon/test/testJNI/TestJNIActivity$1$1$1.class
Binary file not shown.
Binary file modified bin/classes/axon/test/testJNI/TestJNIActivity$1$1$2.class
Binary file not shown.
Binary file modified bin/classes/axon/test/testJNI/TestJNIActivity$1$1$3.class
Binary file not shown.
Binary file modified bin/classes/axon/test/testJNI/TestJNIActivity$1$1$4.class
Binary file not shown.
Binary file modified bin/classes/axon/test/testJNI/TestJNIActivity$1$1.class
Binary file not shown.
Binary file modified bin/classes/axon/test/testJNI/TestJNIActivity$1.class
Binary file not shown.
Binary file modified bin/classes/axon/test/testJNI/TestJNIActivity.class
Binary file not shown.
Binary file modified bin/resources.ap_
Binary file not shown.
2 changes: 2 additions & 0 deletions gen/axon/test/testJNI/R.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static final class id {
public static final int button3=0x7f060003;
public static final int button4=0x7f060004;
public static final int button5=0x7f060005;
public static final int button6=0x7f060010;
public static final int editText1=0x7f060011;
public static final int spinner1=0x7f060000;
public static final int textView1=0x7f060006;
public static final int textView10=0x7f06000f;
Expand Down
21 changes: 19 additions & 2 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="true"
android:orientation="vertical"
tools:context=".TestJNIActivity" >

<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/addresses" />
android:layout_height="wrap_content" />

<Button
android:id="@+id/button1"
Expand Down Expand Up @@ -108,4 +108,21 @@
android:layout_height="wrap_content"
android:text="AN4:" />

<Button
android:id="@+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Change MOD-IO Address" />

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number|text" >

<requestFocus />
</EditText>

</LinearLayout>
97 changes: 79 additions & 18 deletions src/axon/test/testJNI/TestJNIActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,67 @@


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class TestJNIActivity extends Activity {
private static final String TAG = "I2C-Test";
axonI2C i2c;
int slaveAddr = 0x58;
int slaveAddr=0x58;
int relay = 0;
int[] state = new int[4];
int bits;
double adc1,adc2,adc3,adc4;
TextView DPort1,DPort2,DPort3,DPort4,APort1,APort2,APort3,APort4;
EditText AddrInput;
private Spinner spinner1;
/** Called when the activity is first created. */
@Override

public void addItemsOnSpinner() {

spinner1 = (Spinner) findViewById(R.id.spinner1);
List<String> list = new ArrayList<String>();
list.add("0x58");
list.add("0x59");
list.add("0x5A");
list.add("0x5B");
list.add("0x5C");
list.add("0x5D");
list.add("0x5E");
list.add("0x5F");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(dataAdapter);
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.spinner1);

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.addresses, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);



this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
i2c = new axonI2C();
state[0] = 0;
state[1] = 0;
state[2] = 0;
state[3] = 0; //save restore/state
//toDo : States @!
addItemsOnSpinner();

new Thread() {
@Override
Expand All @@ -55,6 +75,8 @@ public void run() {
public void run() {

DPort1 = (TextView)findViewById(R.id.textView2); //Analog Port Labels
AddrInput = (EditText)findViewById(R.id.editText1);

DPort2 = (TextView)findViewById(R.id.textView3);
DPort3 = (TextView)findViewById(R.id.textView4);
DPort4 = (TextView)findViewById(R.id.textView5);
Expand All @@ -64,23 +86,24 @@ public void run() {
APort3 = (TextView)findViewById(R.id.textView9);
APort4 = (TextView)findViewById(R.id.textView10);


Log.i(TAG, String.valueOf(spinner1.getSelectedItem()));
slaveAddr = Integer.decode(String.valueOf(spinner1.getSelectedItem()));
String[] hin1 = { "su", "-c","chmod 777 /dev/i2c-2" }; //gain root access
try {
Runtime.getRuntime().exec(hin1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
;


final Button button = (Button) findViewById(R.id.button1);
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {


public void onClick(View v) {

WriteI2C(slaveAddr, 1); //ToDo: check port

}
Expand Down Expand Up @@ -115,13 +138,25 @@ public void onClick(View v) {

}
});
final Button button6 = (Button) findViewById(R.id.button6);
button6.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

//Log.i(TAG,)
DPort1.setText(AddrInput.getText().toString());


}
});


switch (ReadI2CDigital(slaveAddr,0x20)) {
case 1 : DPort1.setText("Digital Port1: High"); break;
case 1 : //DPort1.setText("Digital Port1: High");
break;
case 2 : DPort2.setText("Digital Port2: High"); break;
case 4 : DPort3.setText("Digital Port3: High"); break;
case 8 : DPort4.setText("Digital Port4: High"); break;
default: DPort1.setText("Digital Port1: Low");
default: //DPort1.setText("Digital Port1: Low");
DPort2.setText("Digital Port2: Low");
DPort3.setText("Digital Port3: Low");
DPort4.setText("Digital Port4: Low"); break;
Expand Down Expand Up @@ -172,7 +207,7 @@ void WriteI2C(int slaveAddr, int relay)
buf[0] = 0x10; //set reg
buf[1] = relay; //set out

i2c.write(fileHandle, 0x58, 0, buf, 2);
i2c.write(fileHandle, slaveAddr, 0, buf, 2);

i2c.close(fileHandle);

Expand All @@ -192,7 +227,7 @@ int ReadI2CDigital(int slaveAddr, int register)
Log.w(TAG, "Could not open I2C interface");
}
buf[0] = register;
i2c.write(fileHandle, 0x58, 0, buf, 1);
i2c.write(fileHandle, slaveAddr, 0, buf, 1);


i2c.read(fileHandle, slaveAddr, buf, 4);
Expand Down Expand Up @@ -220,7 +255,7 @@ int ReadI2CAnalog(int slaveAddr, int register)
}
buf[0] = register;

i2c.write(fileHandle, 0x58, 0, buf, 1);
i2c.write(fileHandle, slaveAddr, 0, buf, 1);


i2c.read(fileHandle, slaveAddr, buf, 4);
Expand All @@ -234,5 +269,31 @@ int ReadI2CAnalog(int slaveAddr, int register)
return buf[0];
}

void ChangeSlaveAddr(int CurrentAddr, int NewAddr)
{
int fileHandle = 0;
int[] buf = new int[4];

try
{
fileHandle = i2c.open("/dev/i2c-2");
}
catch(Exception e)
{
Log.w(TAG, "Could not open I2C interface");
}
buf[0] = 0xF0;
buf[1] = NewAddr;
i2c.write(fileHandle, CurrentAddr, 0, buf, 2);



/*Log.w(TAG,
"buf0= " + Integer.toHexString(buf[0]) + " buf1= "
+ Integer.toHexString(buf[1]) + " buf2= "
+ Integer.toHexString(buf[2]) + " buf=3 "
+ Integer.toHexString(buf[3])); */

i2c.close(fileHandle);
}
}

0 comments on commit e133c68

Please sign in to comment.