Hi, I am using the following code with IOIO to act as "Motion sensor", the 
problem is the app stop working (because the IOIO disconnected) when my 
phone screen goes OFF and it resume working when it is go on!
I need to have the screen always off with keeping IOIO connected and my App 
running all the time!
Please how to solve this problem?


package com.LookHin.ioio_pir_motion_sensor;

import ioio.lib.api.AnalogInput;
import ioio.lib.api.DigitalOutput;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.BaseIOIOLooper;
import ioio.lib.util.IOIOLooper;
import ioio.lib.util.android.IOIOActivity;
import android.content.Intent;
import android.graphics.Color;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

/*
 * OUT = PIN 45
 * VCC = PIN +5V
 * GND = PIN GND
 */

public class MainActivity extends IOIOActivity {
    
    private ToggleButton toggleButton1;
    private TextView textView1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        textView1 = (TextView) findViewById(R.id.textView1);
        toggleButton1 = (ToggleButton) findViewById(R.id.toggleButton1);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is 
present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch (item.getItemId())
        {
        case R.id.action_about:
            //Toast.makeText(getApplicationContext(), "Show About", 
Toast.LENGTH_SHORT).show();
            
            Intent about = new Intent(this, AboutActivity.class);
            startActivity(about);
            
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    } 
    
    
    class Looper extends BaseIOIOLooper {
        
        private DigitalOutput digital_led0;
        private AnalogInput deigital_input;
        int i = 0;
        
        private float InputStatus;
        
        @Override
        protected void setup() throws ConnectionLostException {
            
            digital_led0 = ioio_.openDigitalOutput(0,true);
            deigital_input = ioio_.openAnalogInput(45);
                            
            runOnUiThread(new Runnable() {
                public void run() {
                    Toast.makeText(getApplicationContext(), "IOIO Connect", 
Toast.LENGTH_SHORT).show();
                }
            });
            
        }

        @Override
        public void loop() throws ConnectionLostException {
            
            
            try{
                digital_led0.write(!toggleButton1.isChecked());

                InputStatus = deigital_input.getVoltage();
                
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        
                        textView1.setText(String.format("%.02f",InputStatus
)+" v.");
                        
                        if(InputStatus >= 3.0){
                            textView1.setBackgroundColor(Color.RED);       
                   
                            if (i == 0){
                            Uri notification = RingtoneManager.getDefaultUri
(RingtoneManager.TYPE_NOTIFICATION);
                            Ringtone r = RingtoneManager.getRingtone(
getApplicationContext(), notification);
                            r.play();
                            i = 1;
                            };
                            
                        }else{
                            textView1.setBackgroundColor(Color.TRANSPARENT);
                            i = 0;
                        }
                        
                    }
                });
                
                Thread.sleep(100);
    
            }catch(InterruptedException e){
                e.printStackTrace();
            }
            
        }
    }
    

    @Override
    protected IOIOLooper createIOIOLooper() {
        return new Looper();
    }
        
}



-- 
You received this message because you are subscribed to the Google Groups 
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to