To invoke some action, such as arming the quadcopter, the code simply access a specific URL on the Pi’s CherryPy web server, which then causes the python code to use the DroneKit libraries to set the quadcopter as armed. I made a simple request method that makes a request to any url asynchronously:

To save the picture to the camera roll, I am downloading a still shot provided by the MJPG web application. This process needs to be asynchronous since downloading images takes a significant amount of time and downloading in synchronously causes the button press animation to hang up.

Inside ViewController.swift

The code for displaying the live stream video:

1

2

3

4

5

@IBOutlet weak varvideoStreamer:UIWebView!

url=NSURL(string:"http://\(model.ipadress):8080/stream_simple.html"

let requestObj=NSURLRequest(URL:url!)

videoStreamer.loadRequest(requestObj);

I haven’t quite figured out yet how to center the video feed perfectly with no white space on the screen, so I’m now stuck with having to using the pinch and pan gestures to manually arrange the stream.

To create the nice rounded rect effect around each of the label/buttons, I created outlets to each of the UI elements and a method named roundView which rounds the UIView it receives.

1

2

3

4

func roundView(view:UIView){

view.layer.cornerRadius=8.0

view.clipsToBounds=true

}

I then individually call roundView on all of the different UIViews I want rounded on the storyboard. I could have also subclassed UILabel and UIButton as UIRoundedLabel and UIButton for cleaner code.

To update the statistics live, I set a NSTimer that “rings” every 0.25 seconds by calling the method update.

Since none of the Apple UI objects were perfect, I made my own combobox type object for selecting the Flight mode. Its very simple and there is a just a group of other possible flight modes to choose hanging under the current flight mode that are usually hidden.

When the current flight mode is clicked, the other flight modes unhide themselves, When one of these alternate flight modes are chosen, the group hides again. Instead of updating the current flight mode immediately after the new flight mode is chosen, the program instead waits for the next time update() is called to update the current flight mode when the drone’s flight mode has already been changed.