Update SmartEyeglass display every 40ms

135 Views Asked by At

I created a bitmap on the screen of my Sony SmartEyeglass like this:

private void updateLayout(){
    this.showBitmap(bitmap);
}

Now I want to update it every 40 milliseconds or so.

I tried calling it again and again from another thread and added this.clearDisplay() but it doesn't work.

How can I achieve regular update of the display?


Update:

I used the suggested code below.
Result: Stuttering image that overlaps the previous which doesn't get cleared from the screen.

Tried adding canvas.drawRect(new Rect(0, 0, 500, 500), paint); before redrawing.
Result: It still flickers, but now also won't show the new images.

Does anybody have any experience with real time graphics on SmartEyeglass. Reloading the Extension with different message to draw from is not an option!

2

There are 2 best solutions below

2
On

By creating a postDelayed() handler you can run a method periodically.

your code should be like this.

Handler handler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      handler.post(sendData);
}

@Override
protected void onDestroy() {
      super.onDestroy();
      handler.removeCallbacks(sendData);
}

private void updateLayout(){
    this.showBitmap(bitmap);
}


private final Runnable sendData = new Runnable(){
    public void run(){
        try {
            //your method need to call here

                    updateLayout();

            handler.postDelayed(this, 1000);  // 1000 milliseconds means 1 sec.. here you can change your time limit     
        }
        catch (Exception e) {
            e.printStackTrace();
        }   
    }
};
7
On

Instead of showBitmap use SmartEyeglassControlUtils.showBitmapWithCallback. This way, after the rendering process on SmartEyeglass is done, you will receive a callback in onResultShowBitmap.

Inside of that callback, you can call showBitmapWithCallback again, to update the display as fast as possible.

The speed is limited to the speed of connection so:

  1. Consider using POWER_MODE_HIGH to get wifi connection betweeen SmartEyeglass and phone
  2. Consider using showBitmapWithCallback(Bitmap bitmap, int x, int y, int transactionNumber) with defining the x,y position and sending only that part of the Bitmap, which needs to be updated.