<commit_before>//
//  NuimoController.swift
//  Nuimo
//
//  Created by <NAME> on 10/9/15.
//  Copyright © 2015 Senic. All rights reserved.
//
//  This software may be modified and distributed under the terms
//  of the MIT license.  See the LICENSE file for details.

@objc public protocol NuimoController {
    var uuid: String {get}
    var delegate: NuimoControllerDelegate? {get set}

    var connectionState: NuimoConnectionState {get}
    // Battery level 0..100
    var batteryLevel: Int {get set}
    // Display interval in seconds
    var defaultMatrixDisplayInterval: NSTimeInterval {get set}
    // Brightness 0..1 (1=max)
    var matrixBrightness: Float {get set}

    func connect() -> Bool

    func disconnect() -> Bool

    /// Writes an LED matrix for an interval with options (options is of type Int for compatibility with Objective-C)
    func writeMatrix(matrix: NuimoLEDMatrix, interval: NSTimeInterval, options: Int)
}

public extension NuimoController {
    /// Writes an LED matrix with options defaulting to ResendsSameMatrix and WithWriteResponse
    func writeMatrix(matrix: NuimoLEDMatrix, interval: NSTimeInterval) {
        writeMatrix(matrix, interval: interval, options: 0)
    }

    /// Writes an LED matrix using the default display interval and with options defaulting to ResendsSameMatrix and WithWriteResponse
    public func writeMatrix(matrix: NuimoLEDMatrix) {
        writeMatrix(matrix, interval: defaultMatrixDisplayInterval)
    }

    /// Writes an LED matrix for an interval and with options
    public func writeMatrix(matrix: NuimoLEDMatrix, interval: NSTimeInterval, options: NuimoLEDMatrixWriteOptions) {
        writeMatrix(matrix, interval: defaultMatrixDisplayInterval, options: options.rawValue)
    }

    /// Writes an LED matrix using the default display interval and with options defaulting to ResendsSameMatrix and WithWriteResponse
    public func writeMatrix(matrix: NuimoLEDMatrix, options: NuimoLEDMatrixWriteOptions) {
        writeMatrix(matrix, interval: defaultMatrixDisplayInterval, options: options)
    }
}

@objc public enum NuimoLEDMatrixWriteOption: Int {
    case IgnoreDuplicates     = 1
    case WithFadeTransition   = 2
    case WithoutWriteResponse = 4
}

public struct NuimoLEDMatrixWriteOptions: OptionSetType {
    public let rawValue: Int

    public init(rawValue: Int) {
        self.rawValue = rawValue
    }

    public static let IgnoreDuplicates     = NuimoLEDMatrixWriteOptions(rawValue: NuimoLEDMatrixWriteOption.IgnoreDuplicates.rawValue)
    public static let WithFadeTransition   = NuimoLEDMatrixWriteOptions(rawValue: NuimoLEDMatrixWriteOption.WithFadeTransition.rawValue)
    public static let WithoutWriteResponse = NuimoLEDMatrixWriteOptions(rawValue: NuimoLEDMatrixWriteOption.WithoutWriteResponse.rawValue)
}

@objc public enum NuimoConnectionState: Int {
    case
    Connecting,
    Connected,
    Disconnecting,
    Disconnected,
    Invalidated
}

@objc public protocol NuimoControllerDelegate {
    optional func nuimoControllerDidStartConnecting(controller: NuimoController)
    optional func nuimoControllerDidConnect(controller: NuimoController)
    optional func nuimoController(controller: NuimoController, didFailToConnect error: NSError?)
    optional func nuimoController(controller: NuimoController, didDisconnect error: NSError?)
    optional func nuimoControllerDidInvalidate(controller: NuimoController)
    optional func nuimoController(controller: NuimoController, didUpdateBatteryLevel bateryLevel: Int)
    optional func nuimoController(controller: NuimoController, didReceiveGestureEvent event: NuimoGestureEvent)
    optional func nuimoControllerDidDisplayLEDMatrix(controller: NuimoController)
}<commit_msg>Clean code<commit_after>//
//  NuimoController.swift
//  Nuimo
//
//  Created by <NAME> on 10/9/15.
//  Copyright © 2015 Senic. All rights reserved.
//
//  This software may be modified and distributed under the terms
//  of the MIT license.  See the LICENSE file for details.

@objc public protocol NuimoController {
    var uuid: String {get}
    var delegate: NuimoControllerDelegate? {get set}

    var connectionState: NuimoConnectionState {get}
    /// Battery level 0..100
    //TODO: Remove battery level since is emitted through the delegate, that's enough, no need to store it
    var batteryLevel: Int {get}
    /// Display interval in seconds
    var defaultMatrixDisplayInterval: NSTimeInterval {get set}
    /// Brightness 0..1 (1=max)
    var matrixBrightness: Float {get set}

    func connect() -> Bool

    func disconnect() -> Bool

    /// Writes an LED matrix for an interval with options (options is of type Int for compatibility with Objective-C)
    func writeMatrix(matrix: NuimoLEDMatrix, interval: NSTimeInterval, options: Int)
}

public extension NuimoController {
    /// Writes an LED matrix with options defaulting to ResendsSameMatrix and WithWriteResponse
    func writeMatrix(matrix: NuimoLEDMatrix, interval: NSTimeInterval) {
        writeMatrix(matrix, interval: interval, options: 0)
    }

    /// Writes an LED matrix using the default display interval and with options defaulting to ResendsSameMatrix and WithWriteResponse
    public func writeMatrix(matrix: NuimoLEDMatrix) {
        writeMatrix(matrix, interval: defaultMatrixDisplayInterval)
    }

    /// Writes an LED matrix for an interval and with options
    public func writeMatrix(matrix: NuimoLEDMatrix, interval: NSTimeInterval, options: NuimoLEDMatrixWriteOptions) {
        writeMatrix(matrix, interval: defaultMatrixDisplayInterval, options: options.rawValue)
    }

    /// Writes an LED matrix using the default display interval and with options defaulting to ResendsSameMatrix and WithWriteResponse
    public func writeMatrix(matrix: NuimoLEDMatrix, options: NuimoLEDMatrixWriteOptions) {
        writeMatrix(matrix, interval: defaultMatrixDisplayInterval, options: options)
    }
}

@objc public enum NuimoLEDMatrixWriteOption: Int {
    case IgnoreDuplicates     = 1
    case WithFadeTransition   = 2
    case WithoutWriteResponse = 4
}

public struct NuimoLEDMatrixWriteOptions: OptionSetType {
    public let rawValue: Int

    public init(rawValue: Int) {
        self.rawValue = rawValue
    }

    public static let IgnoreDuplicates     = NuimoLEDMatrixWriteOptions(rawValue: NuimoLEDMatrixWriteOption.IgnoreDuplicates.rawValue)
    public static let WithFadeTransition   = NuimoLEDMatrixWriteOptions(rawValue: NuimoLEDMatrixWriteOption.WithFadeTransition.rawValue)
    public static let WithoutWriteResponse = NuimoLEDMatrixWriteOptions(rawValue: NuimoLEDMatrixWriteOption.WithoutWriteResponse.rawValue)
}

@objc public enum NuimoConnectionState: Int {
    case
    Connecting,
    Connected,
    Disconnecting,
    Disconnected,
    Invalidated
}

@objc public protocol NuimoControllerDelegate {
    optional func nuimoControllerDidStartConnecting(controller: NuimoController)
    optional func nuimoControllerDidConnect(controller: NuimoController)
    optional func nuimoController(controller: NuimoController, didFailToConnect error: NSError?)
    optional func nuimoController(controller: NuimoController, didDisconnect error: NSError?)
    optional func nuimoControllerDidInvalidate(controller: NuimoController)
    optional func nuimoController(controller: NuimoController, didUpdateBatteryLevel batteryLevel: Int)
    optional func nuimoController(controller: NuimoController, didReceiveGestureEvent event: NuimoGestureEvent)
    optional func nuimoControllerDidDisplayLEDMatrix(controller: NuimoController)
}
{'fraction_non_alphanumeric': 0.06302854122621565, 'fraction_numerical': 0.005285412262156448, 'mean_word_length': 4.418038654259127, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2233397', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1948, 'n_words': 639}