tested and working
authorbongo <bongo@bird.localdomain>
Sat, 1 Oct 2011 18:58:50 +0000 (20:58 +0200)
committerbongo <bongo@bird.localdomain>
Sat, 1 Oct 2011 18:58:50 +0000 (20:58 +0200)
16 files changed:
bin/HQBeamer.apk
bin/classes.dex
bin/de/bongo/android/hqbeamer/HQBeamerActivity$1.class
bin/de/bongo/android/hqbeamer/HQBeamerActivity$2.class
bin/de/bongo/android/hqbeamer/HQBeamerActivity$3.class
bin/de/bongo/android/hqbeamer/HQBeamerActivity$4.class
bin/de/bongo/android/hqbeamer/HQBeamerActivity$5.class
bin/de/bongo/android/hqbeamer/HQBeamerActivity$6.class
bin/de/bongo/android/hqbeamer/HQBeamerActivity$7.class
bin/de/bongo/android/hqbeamer/HQBeamerActivity$8.class
bin/de/bongo/android/hqbeamer/HQBeamerActivity$ConnectThread.class
bin/de/bongo/android/hqbeamer/HQBeamerActivity$ConnectedThread.class
bin/de/bongo/android/hqbeamer/HQBeamerActivity.class
bin/resources.ap_
res/layout/main.xml
src/de/bongo/android/hqbeamer/HQBeamerActivity.java

index eeeee98..eb7a8bb 100644 (file)
Binary files a/bin/HQBeamer.apk and b/bin/HQBeamer.apk differ
index e632f31..bda68ec 100644 (file)
Binary files a/bin/classes.dex and b/bin/classes.dex differ
index 6e5f0cd..5cd4e5e 100644 (file)
Binary files a/bin/de/bongo/android/hqbeamer/HQBeamerActivity$1.class and b/bin/de/bongo/android/hqbeamer/HQBeamerActivity$1.class differ
index a5e0d35..02cc03d 100644 (file)
Binary files a/bin/de/bongo/android/hqbeamer/HQBeamerActivity$2.class and b/bin/de/bongo/android/hqbeamer/HQBeamerActivity$2.class differ
index 04d477e..2c888b0 100644 (file)
Binary files a/bin/de/bongo/android/hqbeamer/HQBeamerActivity$3.class and b/bin/de/bongo/android/hqbeamer/HQBeamerActivity$3.class differ
index 33c70ec..5a04bac 100644 (file)
Binary files a/bin/de/bongo/android/hqbeamer/HQBeamerActivity$4.class and b/bin/de/bongo/android/hqbeamer/HQBeamerActivity$4.class differ
index e3c5ed5..780e241 100644 (file)
Binary files a/bin/de/bongo/android/hqbeamer/HQBeamerActivity$5.class and b/bin/de/bongo/android/hqbeamer/HQBeamerActivity$5.class differ
index d1fdc02..1b782ab 100644 (file)
Binary files a/bin/de/bongo/android/hqbeamer/HQBeamerActivity$6.class and b/bin/de/bongo/android/hqbeamer/HQBeamerActivity$6.class differ
index 16899d8..51780f2 100644 (file)
Binary files a/bin/de/bongo/android/hqbeamer/HQBeamerActivity$7.class and b/bin/de/bongo/android/hqbeamer/HQBeamerActivity$7.class differ
index c27a44a..01a7cd6 100644 (file)
Binary files a/bin/de/bongo/android/hqbeamer/HQBeamerActivity$8.class and b/bin/de/bongo/android/hqbeamer/HQBeamerActivity$8.class differ
index a19ff09..3a805c1 100644 (file)
Binary files a/bin/de/bongo/android/hqbeamer/HQBeamerActivity$ConnectThread.class and b/bin/de/bongo/android/hqbeamer/HQBeamerActivity$ConnectThread.class differ
index e21ccda..0ae5bb0 100644 (file)
Binary files a/bin/de/bongo/android/hqbeamer/HQBeamerActivity$ConnectedThread.class and b/bin/de/bongo/android/hqbeamer/HQBeamerActivity$ConnectedThread.class differ
index 758e707..78a8260 100644 (file)
Binary files a/bin/de/bongo/android/hqbeamer/HQBeamerActivity.class and b/bin/de/bongo/android/hqbeamer/HQBeamerActivity.class differ
index 948a2fb..e837854 100644 (file)
Binary files a/bin/resources.ap_ and b/bin/resources.ap_ differ
index dcbf9de..9864fd3 100644 (file)
@@ -5,8 +5,12 @@
                                xmlns:android="http://schemas.android.com/apk/res/android">
         <ToggleButton android:layout_height="wrap_content"
                                  android:text="powerToggle"
-                                 android:layout_width="wrap_content"
+                                 android:layout_width="match_parent"
                                  android:id="@+id/powerToggle"
-                                 android:layout_centerVertical="true"
-                                 android:layout_centerHorizontal="true"/>
+                                 android:layout_centerHorizontal="true"
+                                 android:layout_alignParentBottom="true"
+                                 android:layout_marginLeft="35dp"
+                                 android:layout_marginRight="35dp"
+                                 android:layout_marginBottom="10dp"
+                                 android:checked="false"/>
     </RelativeLayout>
index eccd08c..9d13a99 100644 (file)
@@ -47,12 +47,16 @@ public class HQBeamerActivity extends Activity {
        private BluetoothDevice beamer;
        /* BEGIN Bluetooth / Beamer Messages */
                /* Begin IDs */
-               public static final String UUID_RFCOMM = "00000003-0000-1000-8000-00805f9b34fb";
+               public static final String UUID_RFCOMM = "00001101-0000-1000-8000-00805f9b34fb";
                private static final int MESSAGE_READ = 0;
                private static final int MESSAGE_WRITE = 1;
                /* end IDs */
        private static final byte[] POWER_ON = {0x21}; // !
        private static final byte[] POWER_OFF = {0x22}; // "
+       private static final byte[] IS_POWER_ON = {0x76, 0x50};
+//     private static final byte[] IS_POWERED_OFF = {}
+       private static final byte[] LAMP_MODE_NORMAL = {0x4C, 0x4D, 0x30};
+       private static final byte[] LAMP_MODE_LOW = {0x4C, 0x4D, 0x31};
 
        private static final byte[] preCmdSeq = {0x30, 0x30}; // 0 0
        private static final byte[] postCmdSeq = {0x0D}; // \r
@@ -63,6 +67,7 @@ public class HQBeamerActivity extends Activity {
     
     private static final Boolean D = true; // enable Debug mode
     private static final String TAG = "HQBeamer Main";
+       protected static final String UnicodeEncoding = null;
     
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -90,22 +95,6 @@ public class HQBeamerActivity extends Activity {
         Intent serverIntent = new Intent(this, DeviceListActivity.class);
         startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
         
-               /* UI Element Setup */
-               this.powerToggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
-                       public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-                               if(connectedThread != null){
-                                       if(isChecked){
-                                               connectedThread.write(POWER_ON);
-                                       }
-                                       else {
-                                               connectedThread.write(POWER_OFF);
-                                       }
-                               }
-                               else {
-                                       Toast.makeText(HQBeamerActivity.this, "Connection failed", Toast.LENGTH_SHORT).show();
-                               }
-                       }
-               });
     }
     
     private class ConnectThread extends Thread {
@@ -165,7 +154,7 @@ public class HQBeamerActivity extends Activity {
         public void cancel() {
             try {
                 mmSocket.close();
-            } catch (IOException e) { }
+            } catch (IOException e) { }   
         }
     }
     
@@ -201,7 +190,7 @@ public class HQBeamerActivity extends Activity {
                     bytes = mmInStream.read(buffer);
                     // Send the obtained bytes to the UI Activity
                     mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer)
-                            .sendToTarget();
+                            .sendToTarget(); // process read message
                 } catch (IOException e) {
                     break;
                 }
@@ -229,13 +218,13 @@ public class HQBeamerActivity extends Activity {
        @Override
         public void handleMessage(Message msg) {
             switch (msg.what) {
-            case MESSAGE_WRITE:
-                byte[] writeBuf = (byte[]) msg.obj;
-               break;
-            case MESSAGE_READ:
-                byte[] readBuf = (byte[]) msg.obj;
-                // FIXME check if correct code comes back
-                break;
+                   case MESSAGE_WRITE:
+                       byte[] writeBuf = (byte[]) msg.obj;
+                       break;
+                   case MESSAGE_READ:
+                       byte[] readBuf = (byte[]) msg.obj;
+                       // FIXME check if correct code comes back
+                       break;
             }
         }
     };
@@ -243,7 +232,7 @@ public class HQBeamerActivity extends Activity {
     private void manageConnectedSocket(BluetoothSocket socket){
        if(D) Log.d(TAG, "entered manageConnectedSocket");
        try {
-               socket.getOutputStream().write(Byte.parseByte("\0")); // test write with a nullbyte
+               socket.getOutputStream().write(new Integer(0).byteValue()); // test write with a nullbyte
        }
        catch(IOException excp){
                showDialog(ERROR_CONNECTING);
@@ -251,7 +240,27 @@ public class HQBeamerActivity extends Activity {
        }
        if(connectThread.isConnected()){
                this.connectedThread = new ConnectedThread(socket);
-               connectedThread.start();
+               this.connectedThread.start();
+               if(D) Log.d(TAG, "connectedThread.toString(): " + connectedThread.toString());
+               
+               /* UI Element Setup */
+                       this.powerToggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
+                               public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+                                       if(connectedThread != null){
+                                               if(isChecked){ 
+                                                       connectedThread.write(POWER_ON);
+                                                       if(D) Log.d(TAG, "wrote "+(new String(POWER_ON))+" to socket");
+                                               }
+                                               else {
+                                                       connectedThread.write(POWER_OFF);
+                                                       if(D) Log.d(TAG, "wrote "+(new String(POWER_OFF))+" to socket");
+                                               }
+                                       }
+                                       else {
+                                               Toast.makeText(HQBeamerActivity.this, "Connection failed", Toast.LENGTH_SHORT).show();
+                                       }
+                               }
+                       });
        }
        else{
                showDialog(ERROR_CONNECTING);
@@ -350,10 +359,21 @@ protected Dialog onCreateDialog(int id){
                    break;
        }
     }
+    
     protected void onStart(){
        super.onStart();
     }
     
+    protected void onPause(){
+       super.onPause();
+       if(connectedThread!=null){
+               this.connectedThread.cancel(); // stop listening
+       }
+       if(connectThread!=null){
+               this.connectThread.cancel(); //  close socket
+       }
+    }
+    
     protected void onDestroy(){
        if(mReceiver!=null){
                unregisterReceiver(mReceiver);