Please select Into the mobile phone version | Continue to access the computer ver.
DJI Gimbal - how to get callbacks from hardware buttons when pressed
90 7 6-23 11:13
Uploading and Loding Picture ...(0/1)
o(^-^)o
djiuser_b9fA0wj643ey
lvl.1

Germany
Offline

I'm working on a camera app using Android Camera2 SDK which has button for start/stop recording, and a zoom functionality. I've integrated the DJI mobile SDK and I did the registration with the API key generated from the developer account. When I start the app, I receive a `REGISTRATION_SUCCESS` from `DJISDKManager.SDKManagerCallback()#onRegister()` and the Gimbal is connected through Bluetooth to the phone.

Now the issue is, how can I intercept the hardware button press events from the Gimbal ? For example if I press the hardware record button of the Gimbal, the camera app starts recording.

I tried something like this, but it doesn't work. I couldn't find any documentation about how to receive callbacks when hardware buttons are pressed.

    OSMOMobileHandheldController osmoMobileHandheldController = new OSMOMobileHandheldController();
        osmoMobileHandheldController.setHardwareStateCallback(hardwareState -> {

            switch (hardwareState.getRecordAndShutterButtons()) {
                case IDLE: {
                    Log.e("wkh01", "getRecordAndShutterButtons IDLE");
                    break;
                }
                case RECORD_CLICK: {
                    Log.e(TAG, "getRecordAndShutterButtons RECORD_CLICK");
                    break;
                }
                case SHUTTER_CLICK: {
                    Log.e(TAG, "getRecordAndShutterButtons SHUTTER_CLICK");
                    break;
                }
                case SHUTTER_LONG_CLICK: {
                    Log.e(TAG, "getRecordAndShutterButtons SHUTTER_LONG_CLICK");
                    break;
                }
                default: {
                    Log.e(TAG, "getRecordAndShutterButtons UNKNOWN");
                }
            }

            switch (hardwareState.getZoomState()) {
                case IDLE: {
                    Log.e(TAG, "getZoomState IDLE");
                    break;
                }
                case ZOOM_IN: {
                    Log.e(TAG, "getZoomState ZOOM_IN");
                    break;
                }
                case ZOOM_OUT: {
                    Log.e(TAG, "getZoomState ZOOM_OUT");
                    break;
                }
                default: {
                    Log.e(TAG, "getTriggerButton UNKNOWN");
                }
            }

        });



6-23 11:13
Use props
Mats Bohlinsson
First Officer
Flight distance : 1632543 ft
  • >>>
Sweden
Offline

You cant just create an object. You must call the sdk to get the correct instance.
https://developer.dji.com/api-re ... ager_product_inline

So something like:
DJISDKManager.getInstance().getProduct().getHandheld.....
6-24 01:37
Use props
djiuser_b9fA0wj643ey
lvl.1

Germany
Offline

Thx for the reply, I did like you said

HandHeld handHeld = (HandHeld) DJISDKManager.getInstance().getProduct();         
handHeld.getHandHeldController().setHardwareStateCallback(new HardwareState.Callback() {
            @Override            
            public void onUpdate(HardwareState hardwareState) {
                     switch (hardwareState.getRecordAndShutterButtons()) {
                    case IDLE: {
                        Log.e("wkh01", "getRecordAndShutterButtons IDLE");
                        break;
                    }
                    case RECORD_CLICK: {
                        Log.e(TAG, "getRecordAndShutterButtons RECORD_CLICK");
                        break;
                    }
                    case SHUTTER_CLICK: {
                        Log.e(TAG, "getRecordAndShutterButtons SHUTTER_CLICK");
                        break;
                    }
                    case SHUTTER_LONG_CLICK: {
                        Log.e(TAG, "getRecordAndShutterButtons SHUTTER_LONG_CLICK");
                        break;
                    }
                    default: {
                        Log.e(TAG, "getRecordAndShutterButtons UNKNOWN");
                    }
                }

                switch (hardwareState.getZoomState()) {
                    case IDLE: {
                        Log.e(TAG, "getZoomState IDLE");
                        break;
                    }
                    case ZOOM_IN: {
                        Log.e(TAG, "getZoomState ZOOM_IN");
                        break;
                    }
                    case ZOOM_OUT: {
                        Log.e(TAG, "getZoomState ZOOM_OUT");
                        break;
                    }
                    default: {
                        Log.e(TAG, "getTriggerButton UNKNOWN");
                    }
                }

            }         
});

I get only IDLE state, and I get them randomly, not when I press a button...
In the log I see that handHeld is of time OSMOMobile which is correct because its my Gimbal.
But it didn't work, when I press the button I receive nothing..

It would be awesome that you could help me with this, thank you!
6-24 02:32
Use props
Mats Bohlinsson
First Officer
Flight distance : 1632543 ft
  • >>>
Sweden
Offline

djiuser_b9fA0wj643ey Posted at 6-24 02:32
Thx for the reply, I did like you said

HandHeld handHeld = (HandHeld) DJISDKManager.getInstance().getProduct();         

Sounds like you not connected to the product.
Test with:
https://developer.dji.com/api-re ... ct_connected_inline
And of course you must have connected to the product first, which I exepct you have.
https://developer.dji.com/api-re ... thcompletion_inline
6-24 12:13
Use props
djiuser_b9fA0wj643ey
lvl.1

Germany
Offline

Thank you for your response.

Actually I tried to connect to the Gimbal using BluetoothProductConnector, but I always receive from the onResult(error) callback, error="Param Illegal (255)".
So I tried to connect through the phone's parameter by going to bluetooth and pairing manually to the Gimbal. I tried it using the sample app [Sample Code] and it says connected as you can see the below image


Before calling handHeld.getHandHeldController().setHardwareStateCallback(), I test the connectivity using handHeld.isConnected() and it returns true, so everything is fine.

I tested hardwareState.getStickVerticalDirection() and hardwareState.getStickHorizontalDirection(), by moving the joystick analog and I get approximately the correct values (left/right/up/down)
but all other functions like hardwareState.getZoomState() or hardwareState.getRecordAndShutterButtons() they always return IDLE state. (when I press the record button, for some reason it increases the audio of the phone, and the volume seek bar appears, its like Im pressing the volume button)

These are some logs from handHeld.getHandHeldController().setHardwareStateCallback():

/com.dji.sdk.sample E/wkh01: getRecordAndShutterButtons IDLE
/com.dji.sdk.sample E/wkh01: getZoomState IDLE
/com.dji.sdk.sample E/wkh01: getTriggerButton IDLE
/com.dji.sdk.sample E/wkh01: getModeButton IDLE
/com.dji.sdk.sample E/wkh01: getRecordAndShutterButtons IDLE
/com.dji.sdk.sample E/wkh01: getZoomState IDLE
/com.dji.sdk.sample E/wkh01: getTriggerButton IDLE
/com.dji.sdk.sample E/wkh01: getModeButton IDLE
/com.dji.sdk.sample E/wkh01: getRecordAndShutterButtons IDLE
/com.dji.sdk.sample E/wkh01: getZoomState IDLE
/com.dji.sdk.sample E/wkh01: getTriggerButton IDLE
/com.dji.sdk.sample E/wkh01: getModeButton IDLE


I get these even when I don't press any button.

The model name is: OM5-602S46
Im using the Sample code app to test these hardware buttons callbacks.

It would be great that you could help me on this, we need this in our company.

289845219_5743346619027739_5879231910811046178_n.jpg
6-26 05:18
Use props
Mats Bohlinsson
First Officer
Flight distance : 1632543 ft
  • >>>
Sweden
Offline

djiuser_b9fA0wj643ey Posted at 6-26 05:18
Thank you for your response.

Actually I tried to connect to the Gimbal using BluetoothProductConnector, but I always receive from the onResult(error) callback, error="Param Illegal (255)".

ok, I'm only used the sdk on drones, and not over bluetooth.

I don't think I can help you. If I were you, I would investigate why you cant use the sdk connect functionality. As it is now it seems like android sees your bluetooth as an device and might interfear with the events sent. A wild guess though :-/

Hope someone else can chime in.
6-26 11:40
Use props
djiuser_b9fA0wj643ey
lvl.1

Germany
Offline

Thank you Mats, I hope anyone else could help me on this..
6-26 12:04
Use props
Garrygb
lvl.2

Ukraine
Offline

https://mlsdev.com/services/business-analysis already drew the line. Websites without their mobile versions should be ready for consequence in 2017. With the growing trend of purchases through mobiles, sellers are required to offer buyers a clutter-free buying experience. They ought to launch a responsive version of their ecommerce website that adapts to every device it’s being accessed on.
7-13 04:04
Use props
Advanced
You need to log in before you can reply Login | Register now

Credit Rules