<commit_before>//
//  MavlinkController.swift
//  MavlinkSwiftConnectDemo
//
//  Created by <NAME> on 5/10/2015.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Cocoa
import ORSSerial

class MavlinkController: NSObject, ORSSerialPortDelegate {

    let serialPortManager = ORSSerialPortManager.sharedSerialPortManager()
	
    var serialPort: ORSSerialPort? {
        didSet {
            oldValue?.close()
            oldValue?.delegate = nil
            serialPort?.delegate = self
        }
    }
	
    @IBOutlet weak var openCloseButton: NSButton!

    // MARK: Actions

    @IBAction func openOrClosePort(sender: AnyObject) {
        print("Button press")
    }

    // MARK: ORSSerialPortDelegate Protocol

    func serialPortWasRemovedFromSystem(serialPort: ORSSerialPort) {
        self.serialPort = nil
        self.openCloseButton.title = "Open"
    }
}
<commit_msg>Start Mavlink on open button press<commit_after>//
//  MavlinkController.swift
//  MavlinkSwiftConnectDemo
//
//  Created by <NAME> on 5/10/2015.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Cocoa
import ORSSerial

class MavlinkController: NSObject, ORSSerialPortDelegate {

    let serialPortManager = ORSSerialPortManager.sharedSerialPortManager()
	
    var serialPort: ORSSerialPort? {
        didSet {
            oldValue?.close()
            oldValue?.delegate = nil
            serialPort?.delegate = self
        }
    }
	
    @IBOutlet weak var openCloseButton: NSButton!

    // MARK: Actions

    @IBAction func openOrClosePort(sender: AnyObject) {
        if let port = serialPort {
            if (port.open) {
                port.close()
            }
            else {
    			port.baudRate = 57600
    			port.numberOfStopBits = 1
    			port.parity = .None
                port.open()
    			if let data = "mavlink start -d /dev/ttyACM0\n".dataUsingEncoding(NSUTF32LittleEndianStringEncoding) {
    				port.sendData(data)
    			}
            }
        }
    }

    // MARK: ORSSerialPortDelegate Protocol

    func serialPortWasOpened(serialPort: ORSSerialPort) {
        self.openCloseButton.title = "Close"
    }
    
    func serialPortWasClosed(serialPort: ORSSerialPort) {
        self.openCloseButton.title = "Open"
    }
    
    func serialPortWasRemovedFromSystem(serialPort: ORSSerialPort) {
        self.serialPort = nil
        self.openCloseButton.title = "Open"
    }
}

{'fraction_non_alphanumeric': 0.09136212624584718, 'fraction_numerical': 0.01287375415282392, 'mean_word_length': 2.290983606557377, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2622707', 'n_tokens_mistral': 784, 'n_tokens_neox': 716, 'n_words': 152}