Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement service notification and wakelocks, fix gyro-less case #45

Merged
merged 20 commits into from
Dec 19, 2014

Conversation

sthalik
Copy link
Contributor

@sthalik sthalik commented Dec 9, 2014

No description provided.

Pressing the notification creates a new activity, hence the need to save
settings when starting.
Sensor event handler and send both modify member variables, and run
asynchronously. Both blocks need synchronization as result.

Gyro-less data is mostly useless, but it's not necessary to crash on
such devices in any case.
@AndersMalmgren
Copy link
Owner

First test didnt work, nothing is received in FreePIE, will have to debug and see whats going on

@AndersMalmgren
Copy link
Owner

Hmm, onServiceConnected never fires which sets udpSenderService

@sthalik
Copy link
Contributor Author

sthalik commented Dec 11, 2014

If startService()'s commented out, does it connect then?

@AndersMalmgren
Copy link
Owner

I cant try at work since its a bank and we cant connect our phones to the dev-env :D
Will try first thing tonight

@sthalik
Copy link
Contributor Author

sthalik commented Dec 11, 2014

It worked fine as-is on my 4.1.2 device. Docs say it's possible to both bind to and start a service. But who knows.

@AndersMalmgren
Copy link
Owner

I have a HTC m8 with Android 4.4.4
All I need to do is to run the app for it to work right? Check if you have missed to commit any crucial files etc

@sthalik
Copy link
Contributor Author

sthalik commented Dec 11, 2014

Only whitespace remained to be committed, there's nothing left to be added.

There should be some indication as to why the service isn't starting. Keep in mind that commenting out startService() won't make it work fully, only provide insight as to why it won't start. It needs to be there for the service not to die when the app exits/hits oom.

@sthalik
Copy link
Contributor Author

sthalik commented Dec 11, 2014

Try changing getBaseContext() to "this" on the added line. It's useless for me to do it, as it works either way on my 4.1.2 device.

     private void bindService() {
+        startService(new Intent(getBaseContext(), UdpSenderService.class));
         bindService(new Intent(this, UdpSenderService.class), conn, Context.BIND_AUTO_CREATE);
     }

Don't create array values in each iteration of the sensor event loop.
This puts unnecessary GC pressure and so CPU load.

Reuse initialized values held in member variables instead.
Java contains condition variable primitive in the "Object" base class.
CyclicBarrier isn't suited for this.
Registering an event handler from a running application makes that event
handler go stale and presumably crash when a service calls it after the
app doesn't exist anymore.

Switch to polling for debug events. This also simplifies logic where the
service had to keep track of the handler and whether to generate the
events.
@sthalik
Copy link
Contributor Author

sthalik commented Dec 11, 2014

@AndersMalmgren please include project files for Android Studio, import changes directory structure and that breaks Git workflow of committing all the time.

The last commit changes the way service's started (getBaseContext() -> this) and it might fix it for you.

@AndersMalmgren
Copy link
Owner

Now it works! :D
Error handling is broken, try to write a faulty address like "foo" it crashes on he first line in this statement

synchronized (this_) {
                            this_.wait();
                            Send();
                        }

What was wrong with using cyclic barrier?

@sthalik
Copy link
Contributor Author

sthalik commented Dec 16, 2014

@AndersMalmgren is there anything against a third flag in datagrams for accelerometer output? We'd need integration on the phone due to sparsity of updates over the wire.

I'd also like to shorten the very long list of device ids.

@AndersMalmgren
Copy link
Owner

I do not follow you, if you are doing it on the phone what do you need a new flag for?
edit: I thought Opentrack only used orientation data btww?

@sthalik
Copy link
Contributor Author

sthalik commented Dec 17, 2014

To avoid breaking old clients with no accelerometer data.

opentrack can use data when it's available.

What's status on merging? Should we fork the app? The changes make the app usable to begin with.

@AndersMalmgren
Copy link
Owner

Ok so we had a byte telling which sensors are supported in raw mode?
This is probably best done in a branch

@sthalik
Copy link
Contributor Author

sthalik commented Dec 17, 2014

There's room for 8 bits so there's no need to break the protocol any further.

@AndersMalmgren
Copy link
Owner

I don't think I understand what you wanna do, but I'm running a high fever so my brain is not what it should be :)

@KyokushinPL
Copy link

@AndersMalmgren and how your brain? ;) fever gone? Can we back to 'work' ;) and pull changes?

AndersMalmgren added a commit that referenced this pull request Dec 19, 2014
implement service notification and wakelocks, fix gyro-less case
@AndersMalmgren AndersMalmgren merged commit 8328493 into AndersMalmgren:master Dec 19, 2014
@AndersMalmgren
Copy link
Owner

Its merged, but we still need to discuss the changes for devices thats missing raw sensors (I thought that opentrack onlt used the orientation data btw)

@sthalik
Copy link
Contributor Author

sthalik commented Dec 19, 2014

It only uses orientation data, yes. In case of gyro lackage zeros are returned.

I haven't done the change to push position data over the wire yet.

@AndersMalmgren
Copy link
Owner

If you do please do it in a branch since I'm not 100 sure how you will do it :)

@AndersMalmgren
Copy link
Owner

position data? A IMU cant be used for position only rotation, the acc is way to inaccurate for it

edit: Now I understand what you ment with integrating the acc on the device, bu the result will be way to inaccurate for any kind of usage, you need militray grade senors for inertial navigation :D

@sthalik
Copy link
Contributor Author

sthalik commented Dec 19, 2014

It's doable using a spring to push the value gradually toward zero. That's how it was done in opentrack for Rift DK1. For a case of @KyokushinPL sitting with phone on his head the spring does the trick since he spends most of the time near zero anyway.

@AndersMalmgren
Copy link
Owner

I guess best approuch is just a new flag called Translation or something?
edit: We can have the same code in FreePIE then

@sthalik
Copy link
Contributor Author

sthalik commented Dec 20, 2014

Yeah, position it at the end so old receiver can ignore the data without changes.

Remains to be seen how much error there is. A day always has too few hours to do all the stuff though.

@AndersMalmgren
Copy link
Owner

Will the spring code be in Opentrack/FreePIE or in the App?

@sthalik
Copy link
Contributor Author

sthalik commented Dec 20, 2014

Needs to be in the app to integrate as quickly as possible.

Does the app introduce heavy load when running for you too? Even on slower settings 30-50% of one core is used no matter what.

@AndersMalmgren
Copy link
Owner

Around 8%
I have change some of the code btw, you can merge it. I only poll the service if debugging is checked

@KyokushinPL
Copy link

@AndersMalmgren Could you compile app and sign it? We would like to put it to opentrack soon as possible and give to users updated solution.

@AndersMalmgren
Copy link
Owner

You dont wanna wait for the acc stuff?

@sthalik
Copy link
Contributor Author

sthalik commented Dec 23, 2014

It's gonna take a while given it's some actual math usage, more than calling an API as per before previous changes. It's also not guaranteed to work out.

We'd like to release opentrack 2.3 finally and having a signed build of the .apk sure helps.

cheers due to xmas!
-sh

@AndersMalmgren
Copy link
Owner

I'm out of town for xmas, but will remote and fix

@KyokushinPL
Copy link

@AndersMalmgren Merry Xmas from octopus team ;)
opentrack_xmas

@sthalik
Copy link
Contributor Author

sthalik commented Dec 24, 2014

@AndersMalmgren the octopus approves. Cheers, and happy winter solstice.

@AndersMalmgren
Copy link
Owner

There you go guys
https://dl.dropboxusercontent.com/u/33026505/com.freepie.android.imu.apk

Happy Xmas!

If any of you C++ pros wanna give me the perfect xmas present it would be to implement support for decrypted TrackIR titles :D

@sthalik
Copy link
Contributor Author

sthalik commented Dec 24, 2014

You can use the same .dll that we do. The way to give it pad keys is described in freetrack protocol. The memory mapping's in the header and you can use it from p/invoke. And the scramble keys are in the .csv file.

@AndersMalmgren
Copy link
Owner

The code is not in the opentrack repo?

@sthalik
Copy link
Contributor Author

sthalik commented Jan 8, 2015

Here's the data structures used by the code: https://github.com/opentrack/opentrack/blob/unstable/freetrackclient/fttypes.h

Keep in mind that as per C memory layout FTData is embedded inside FTHeap. There are no pointers used -- after all, memory can't be shared across processed like that.

Use this logic to transmit game id along with the padding key embedded in the .csv file https://github.com/opentrack/opentrack/blob/unstable/ftnoir_protocol_ft/ftnoir_protocol_ft.cpp.

Keep in mind the "correct()" function misnomer. It runs first to verify whether protocol prerequisites are in place, but here is misused as initialization code.

runOnUiThread(new Runnable() {
@Override
public void run() {
if (udpSenderService != null && udpSenderService.isRunning()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a mistake here. Please add checking chkDebug.isChecked() before allocating data with new. It runs on UI thread anyway so it can do with no locks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants