dji-sdk / Mobile-SDK-iOS

DJI Mobile SDK for iOS: http://developer.dji.com/mobile-sdk/
Other
576 stars 254 forks source link

CameraFPVViewController Swift flat camera use correction #511

Closed hdrpano closed 2 years ago

hdrpano commented 2 years ago

The actual swift demo does not separate normal and flat cameras. We have to fix that.

If you start a FPV view the first time you have to set the camera on photo shooting or video recording. The actual swift demo uses a camera delegate function to do it. It is simpler just to use a function. Call this function when the view is loaded and the aircraft is connected.

    /**
     *  DJICamera will send the live stream only when the mode is in DJICameraModeShootPhoto or DJICameraModeRecordVideo. Therefore, in order
     *  to demonstrate the FPV (first person view), we need to switch to mode to one of them.
     */
    extension CameraFPVViewController: DJICameraDelegate {
            func camera(_ camera: DJICamera, didUpdate systemState: DJICameraSystemState) {
                    if systemState.mode != .recordVideo && systemState.mode != .shootPhoto {
                          return
                    }
                    if needToSetMode == false {
                          return
                    }
                    needToSetMode = false
                    camera.setMode(.shootPhoto) { [weak self] (error) in
                            if error != nil {
                                  self?.needToSetMode = true
                            }
                    }
            }
    }

Replace this extension with

  //MARK: Flat Mode or not?
  func setCameraMode(cameraMode: DJICameraMode = .shootPhoto) {
          var flatMode: DJIFlatCameraMode = .photoSingle
          let camera = self.fetchCamera()
          if camera?.isFlatCameraModeSupported() == true {
                  NSLog("Flat camera mode detected")
                  switch cameraMode {
                  case .shootPhoto:
                        flatMode = .photoSingle
                  case .recordVideo:
                        flatMode = .videoNormal
                  default:
                        flatMode = .photoSingle
                  }
                  camera?.setFlatMode(flatMode, withCompletion: { (error: Error?) in
                          if error != nil {
                                NSLog("Error set camera flat mode photo/video");
                          }
                  })
          } else {
                  camera?.setMode(cameraMode, withCompletion: { (error: Error?) in
                          if error != nil {
                                NSLog("Error set mode photo/video");
                          }
                  })
          }
   }

Hope this helps to get your APP run with flat cameras like the DJI Mini 2

dji-dev commented 2 years ago

Agent comment from DJI SDK in Zendesk ticket #62506:

尊敬的开发者,感谢您联系DJI 大疆创新 由于github不是我们主要的咨询渠道,您的问题可能跟进不及时。我们建议您通过填写表单( https://djisdksupport.zendesk.com/hc/zh-cn/requests/new )向我们反馈问题。或者您也可以在论坛发帖,与其它开发者交流。论坛链接:https://djisdksupport.zendesk.com/hc/zh-cn/community/topics

Dear developer, thank you for contacting DJI. Since github is not our main consultation channel, your questions may not be followed up in time. We recommend that you fill in the form (https://djisdksupport.zendesk.com/hc/en-us/requests/new) to report problems to us. Or you can post in the forum to communicate with other developers. Forum link: https://djisdksupport.zendesk.com/hc/zh-cn/community/topics

°°°

DJI-William commented 2 years ago

Record, we will raise a ticket about updating this old Swift demo.

hdrpano commented 2 years ago

You could use this free update for Swift based on the DJI demo with a virtual stick example and a lot of fixes. demo

DJI-William commented 2 years ago

You could use this free update for Swift based on the DJI demo with a virtual stick example and a lot of fixes. demo

Very impressive work, well done!

DJI-William commented 2 years ago

The github has been updated.