private Handler handler;
private Messenger messenger;
private Task task;
+ private Sensors sensors;
private Toast toast;
/* Widgets */
private LinearLayout state;
private TextView debug;
private ScrollView scroll;
+ private Button rstHdBttn;
+ private Button rstDstBttn;
/* Private helper methods */
private void notice(String text)
/* Private handler methods */
private void onRegister(Task task)
{
- Util.debug("Main: onRegister");
+ Util.debug("Main: onRegister_task");
this.task = task;
}
+
+ private void onRegister(Sensors sensors)
+ {
+ Util.debug("Main: onRegister_sensors");
+ this.sensors = sensors;
+ }
private void onPosition()
{
this.toast.show();
}
+ private void onShowData(float[] data){
+ TextView textView1 = null;
+ TextView textView2 = null;
+ TextView textView3 = null;
+ int displayNum = 3;
+ int dataId = (int)(data[0]+0.5);
+ CMD.Data dataType = CMD.Data.values()[dataId];
+ switch (dataType){
+ case ACC:
+ textView1 = (TextView)findViewById(R.id.accText1);
+ textView2 = (TextView)findViewById(R.id.accText2);
+ textView3 = (TextView)findViewById(R.id.accText3);
+ break;
+ case MAG:
+ return;
+ /*textView1 = (TextView)findViewById(R.id.magText1);
+ textView2 = (TextView)findViewById(R.id.magText2);
+ textView3 = (TextView)findViewById(R.id.magText3);
+ break;*/
+ case GYR:
+ textView1 = (TextView)findViewById(R.id.gyrText1);
+ textView2 = (TextView)findViewById(R.id.gyrText2);
+ textView3 = (TextView)findViewById(R.id.gyrText3);
+ break;
+ case ORIENT:
+ textView1 = (TextView)findViewById(R.id.orientText1);
+ textView2 = (TextView)findViewById(R.id.orientText2);
+ textView3 = (TextView)findViewById(R.id.orientText3);
+ break;
+ case WRDACC:
+ textView1 = (TextView)findViewById(R.id.wrdAccText1);
+ textView2 = (TextView)findViewById(R.id.wrdAccText2);
+ textView3 = (TextView)findViewById(R.id.wrdAccText3);
+ break;
+ case STPCNT:
+ textView1 = (TextView)findViewById(R.id.stepCntText);
+ textView2 = (TextView)findViewById(R.id.calGrvText);
+ displayNum = 2;
+ break;
+ case POSITION:
+ textView1 = (TextView)findViewById(R.id.curPosXText);
+ textView2 = (TextView)findViewById(R.id.curPosYText);
+ displayNum = 2;
+ break;
+ case HEADING:
+ textView1 = (TextView)findViewById(R.id.headingText);
+ displayNum = 1;
+ break;
+ case WRDGYR:
+ textView1 = (TextView)findViewById(R.id.wrdGyrText1);
+ displayNum = 1;
+ break;
+ case STABLE:
+ textView1 = (TextView)findViewById(R.id.stableText);
+ displayNum = 1;
+ break;
+ default:
+ Util.debug("Main: Nothing Matches");
+ }
+
+ textView1.setText(Float.toString(data[1]));
+ if (displayNum >1){
+ textView2.setText(Float.toString(data[2]));
+ }
+ if (displayNum >2){
+ textView3.setText(Float.toString(data[3]));
+ }
+ }
+
/* Private service methods */
private void register()
{
startService(new Intent(this, Task.class)
.putExtra("Command", CMD.Command.REGISTER)
.putExtra("Messenger", this.messenger));
+ startService(new Intent(this, Sensors.class)
+ .putExtra("Command", CMD.Command.REGISTER)
+ .putExtra("Messenger", this.messenger));
}
private void connect()
Util.debug("Main: connect");
startService(new Intent(this, Task.class)
.putExtra("Command", CMD.Command.CONNECT));
+ startService(new Intent(this, Sensors.class)
+ .putExtra("Command", CMD.Command.CONNECT));
}
private void disconnect()
Util.debug("Main: disconnect");
startService(new Intent(this, Task.class)
.putExtra("Command", CMD.Command.DISCONNECT));
+ startService(new Intent(this, Sensors.class)
+ .putExtra("Command", CMD.Command.DISCONNECT));
}
private void quit()
this.state = (LinearLayout) findViewById(R.id.state);
this.debug = (TextView) findViewById(R.id.debug);
this.scroll = (ScrollView) findViewById(R.id.debug_scroll);
+ this.rstHdBttn = (Button) findViewById(R.id.rstHdBttn);
+ this.rstDstBttn= (Button) findViewById(R.id.rstDstBttn);
+
+ // TODO - remove these
+ rstHdBttn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // TODO Auto-generated method stub
+ startService(new Intent(Main.this, Sensors.class)
+ .putExtra("Command", CMD.Command.RSTHEAD));
+ }
+ });
+
+ rstDstBttn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // TODO Auto-generated method stub
+ startService(new Intent(Main.this, Sensors.class)
+ .putExtra("Command", CMD.Command.RSTDST));
+ }
+ });
// Get a handle to the Map Fragment
//GoogleMap map = ((MapFragment)getFragmentManager()
// Add window tabs
this.window.setup();
- this.window.addTab(this.window
- .newTabSpec("map")
- .setIndicator("Map")
- .setContent(R.id.map));
this.window.addTab(this.window
.newTabSpec("state")
.setIndicator("State")
.setContent(R.id.state));
+ this.window.addTab(this.window
+ .newTabSpec("map")
+ .setIndicator("Map")
+ .setContent(R.id.map));
this.window.addTab(this.window
.newTabSpec("debug")
.setIndicator("Debug")
/* Handler class */
class MainHandler extends Handler
{
+ @Override
public void handleMessage(android.os.Message msg)
{
CMD.Response resp = CMD.Response.values()[msg.what];
switch (resp) {
- case POSITION:
- Main.this.onPosition();
+ case REGISTER_TASK:
+ Main.this.onRegister((Task)msg.obj);
+ break;
+ case REGISTER_SENSORS:
+ Main.this.onRegister((Sensors)msg.obj);
break;
case NOTIFY:
Main.this.onNotify((String)msg.obj);
break;
+ case SHOWDATA:
+ Main.this.onShowData((float[])msg.obj);
+ break;
default:
Util.debug("Main: unknown message - " + resp);
break;