0

I am creating an android application that uses bluetooth to connect to a NeuroSky headset. In the following code I am getting the error of "dead code" for my if statement and cannot figure out why?

Particular code block:

(I am trying to create functionality that if the headset registers an attention rating of over 25 then the message is outputted to screen, It is here that I get the dead code error).

Note that TGDevice.MSG_ATTENTION is an int value from 0-100

case TGDevice.MSG_ATTENTION:
                    tv.append("Attention: " + msg.arg1 + "\n");

                    if(TGDevice.MSG_ATTENTION>=25){
                        System.out.println("Over 25...");
                    }
                    break;

Full method:

/**
     * Handles messages from TGDevice
     */
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            switch (msg.what) {
            case TGDevice.MSG_STATE_CHANGE:

                switch (msg.arg1) {
                case TGDevice.STATE_IDLE:
                    break;
                case TGDevice.STATE_CONNECTING:
                    tv.append("Connecting...\n");
                    break;
                case TGDevice.STATE_CONNECTED:
                    tv.append("Connected.\n");
                    device.start();
                    break;
                case TGDevice.STATE_NOT_FOUND:
                    tv.append("Could not connect any of the paired BT devices.  Turn them on and try again.\n");
                    break;
                case TGDevice.STATE_ERR_NO_DEVICE:
                    tv.append("No Bluetooth devices paired.  Pair your device and try again.\n");
                    break;
                case TGDevice.STATE_ERR_BT_OFF:
                    tv.append("Bluetooth is off.  Turn on Bluetooth and try again.");
                    break;

                case TGDevice.STATE_DISCONNECTED:
                    tv.append("Disconnected.\n");
                } /* end switch on msg.arg1 */

                break;

            case TGDevice.MSG_POOR_SIGNAL:
                tv.append("PoorSignal: " + msg.arg1 + "\n");
                break;

            case TGDevice.MSG_HEART_RATE:
                tv.append("Heart rate: " + msg.arg1 + "\n");
                break;

            case TGDevice.MSG_RAW_DATA:
                /* Handle raw EEG/EKG data here */
                break;

            case TGDevice.MSG_ATTENTION:
                tv.append("Attention: " + msg.arg1 + "\n");

                if(TGDevice.MSG_ATTENTION>=25){
                    System.out.println("Over 25...");
                }
                break;

            case TGDevice.MSG_MEDITATION:
                tv.append("Meditation: " + msg.arg1 + "\n");
                break;

            case TGDevice.MSG_BLINK:
                tv.append("Blink: " + msg.arg1 + "\n");
                break;

            default:
                break;

            } /* end switch on msg.what */

            sv.fullScroll(View.FOCUS_DOWN);

        } /* end handleMessage() */

    }; /* end Handler */
  • Shouldn't you check for `msg.arg1` instead in that block? Something like `if (msg.arg1 >= 25) { .println("Over 25..."); }` – raina77ow Jun 25 '14 at 11:43
  • can you show the definition of TGDevice.MSG_ATTENTION - I think it is fixed to something <25 – ligi Jun 25 '14 at 11:48

1 Answers1

0

Try like this.. it may work

/**
     * Handles messages from TGDevice
     */
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            if(msg.what == TGDevice.MSG_ATTENTION) {
                //save your value in a global variable
            }

            switch (msg.what) {
            case TGDevice.MSG_STATE_CHANGE:

                switch (msg.arg1) {
                case TGDevice.STATE_IDLE:
                    break;
                case TGDevice.STATE_CONNECTING:
                    tv.append("Connecting...\n");
                    break;
                case TGDevice.STATE_CONNECTED:
                    tv.append("Connected.\n");
                    device.start();
                    break;
                case TGDevice.STATE_NOT_FOUND:
                    tv.append("Could not connect any of the paired BT devices.  Turn them on and try again.\n");
                    break;
                case TGDevice.STATE_ERR_NO_DEVICE:
                    tv.append("No Bluetooth devices paired.  Pair your device and try again.\n");
                    break;
                case TGDevice.STATE_ERR_BT_OFF:
                    tv.append("Bluetooth is off.  Turn on Bluetooth and try again.");
                    break;

                case TGDevice.STATE_DISCONNECTED:
                    tv.append("Disconnected.\n");
                } /* end switch on msg.arg1 */

                break;

            case TGDevice.MSG_POOR_SIGNAL:
                tv.append("PoorSignal: " + msg.arg1 + "\n");
                break;

            case TGDevice.MSG_HEART_RATE:
                tv.append("Heart rate: " + msg.arg1 + "\n");
                break;

            case TGDevice.MSG_RAW_DATA:
                /* Handle raw EEG/EKG data here */
                break;

            case TGDevice.MSG_ATTENTION:
                tv.append("Attention: " + msg.arg1 + "\n");

                if(that global variable value >= 25){
                    System.out.println("Over 25...");
                }
                break;

            case TGDevice.MSG_MEDITATION:
                tv.append("Meditation: " + msg.arg1 + "\n");
                break;

            case TGDevice.MSG_BLINK:
                tv.append("Blink: " + msg.arg1 + "\n");
                break;

            default:
                break;

            } /* end switch on msg.what */

            sv.fullScroll(View.FOCUS_DOWN);

        } /* end handleMessage() */

    }; /* end Handler */
saa
  • 1,538
  • 2
  • 17
  • 35