can I prevent disconnect of the ioio

58 visualizações
Pular para a primeira mensagem não lida

Ilan Tal

não lida,
10 de mar. de 2016, 00:39:0110/03/2016
para ioio-users
I need a bit of general advice. We need to measure a sample for 10 min. The android screen turns off, which is no problem, but it also breaks the connection to the ioio which is a problem.
Is there any well known way to tell the android NOT to break the connection to the ioio board? If not then we need to prevent the screen from going off.
Any suggestions?

Thanks,
Ilan

Ytai Ben-Tsvi

não lida,
10 de mar. de 2016, 13:25:3210/03/2016
para ioio-...@googlegroups.com
You have several options:
  1. Use IOIOService to have the communication with the IOIO going on in the background always.
  2. Fork IOIOActivity to your own class, which triggers the start()/stop() events at different times in the application lifecycle.
  3. Prevent the phone from sleeping while the app is running by using a WakeLock (might have unpleasant side effects like draining the phone battery much faster).

--
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 ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Ilan Tal

não lida,
13 de mar. de 2016, 07:33:4613/03/2016
para ioio-users
Thanks for the advice Ytai. I'm still not out of the woods though.
My first attempt was to try IOIOService. That is a bit too powerful as MainActivity has some graphic elements that I need to communicate with.
I ran into real trouble with runOnUiThread since in the IOIOService I no longer have the Main Activity class. That got a finish command.

Your second idea of Fork IOIOActivity looks more promising but since I'm still new to the android world I don't know how to do the fork.
I understand that it is basically a new thread which perhaps I can send the MainActivity object, so that I can do a runOnUiThread on the main activity object.
The nuts and bolts of exactly how to do this are unclear to me. I tried to google around for some sort of example or tutorial but I must be missing the appropriate key words.

It also isn't clear to me why in the original application the IOIO board was disconnected when my application itself kept running. I have a timer in my application and I can see that it keeps progressing even when the IOIO board has been disconnected. It is clear to me why the application would continue but the connection to the IOIO board wouldn't continue.

In any case, presumably if I fork off my own class which has IOIOActivity, then that class wouldn't die when the android display shut down. Exactly the correct commands to create and control such a class are not clear to me. On the other hand I do want my main activity, or something else, to have control over what the IOIO board is doing.

If you can point me in the right direction to get my hands on some sample code, I would greatly appreciate it.

Thanks,
Ilan

Ytai Ben-Tsvi

não lida,
15 de mar. de 2016, 00:42:0315/03/2016
para ioio-...@googlegroups.com
When I said "fork" I didn't mean "fork" in the sense of "create a new process", but rather in the sense of "copy the existing code to a new class and change it". If you look at the implementation of IOIOActivity, you'll notice that it calls start()/stop() etc. at different times in its lifecycle, causing the IOIO connection to get created / destroyed respectively. You can change that so that these methods are invoked in response to different events.
However, keep in mind that Android makes no guarantees about when it is going to pause()/stop()/destroy() your app, so if you want 100% guarantee that the IOIO connection will be kept alive you need to either prevent the phone from sleeping or use IOIOService. There are standard mechanisms to communicate between the app and the service. One simple thing you can do is use those mechanism to just provide the IOIO interface to the Activity as soon as one is available.

Ilan Tal

não lida,
15 de mar. de 2016, 02:24:1715/03/2016
para ioio-users
Ytai thanks,
In my usual Java software when I have a lengthy calculation I use SwingWorker where I override doInBackground. I suspect swing doesn't exist in android, or at least isn't used. Android is a different mind set, and one which I am not yet used to.
I looked in Git for the source code for IOIOActivity, but I didn't find it, probably because I don't know exactly where to look. In any case it sounds like a great idea to look at the source code so I can see up front the proper way to do things, and which calls are used. I suspect that it should be no big problem to bring across the main activity object so I can use runOnUIThread.

I'm not sure that I really need a 100% guarantee that the IOIO connection will be kept alive. As long as it comes back in 0.5 second or so, I can live with it.

First I want to see how your code handles start and stop, so I know I am doing something similar. If I follow your way of doing things, I am confident that it will be correct. If you can give me a link to the implementation of IOIOActivity it would be a big help.

Thanks,
Ilan

Ytai Ben-Tsvi

não lida,
16 de mar. de 2016, 01:58:0616/03/2016
para ioio-...@googlegroups.com

Ilan Tal

não lida,
16 de mar. de 2016, 02:05:1216/03/2016
para ioio-users
Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem