Commit ec14656c authored by Roddi Deecke's avatar Roddi Deecke Committed by Thomas Mellenthin

fix identifier names

parent f3839a7d
......@@ -5,14 +5,13 @@ excluded: # paths to ignore during linting. Takes precedence over `included`.
identifier_name:
min_length: 2 # only warning
max_length: # warning and error
warning: 40
error: 50
warning: 50
error: 60
excluded: Carthage # excluded via string
# disable those *for* *now* so that the compile step
# does not create issues for not yet fixed issues
disabled_rules:
- identifier_name
- function_parameter_count
- line_length
- force_cast
......@@ -21,5 +20,4 @@ disabled_rules:
- function_body_length
- cyclomatic_complexity
- type_body_length
- vertical_parameter_alignment
\ No newline at end of file
......@@ -26,6 +26,8 @@
BF4952E3230AD92900A12944 /* UInt+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF4952E2230AD92900A12944 /* UInt+Extension.swift */; };
BF647C58230C491E00DF6265 /* Card10TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF647C57230C491E00DF6265 /* Card10TabBarController.swift */; };
D4A8821222E92670E899561E /* Pods_card10badge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7C391F1792BB7FCA2208D837 /* Pods_card10badge.framework */; };
DD01715A2310279500E5F7FA /* RGBLED.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0171592310279500E5F7FA /* RGBLED.swift */; };
DD01715C231027DF00E5F7FA /* AboveLEDs.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD01715B231027DF00E5F7FA /* AboveLEDs.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
......@@ -52,6 +54,8 @@
B864A7E1B7A4A7505C7F3979 /* Pods-card10badge.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-card10badge.debug.xcconfig"; path = "Pods/Target Support Files/Pods-card10badge/Pods-card10badge.debug.xcconfig"; sourceTree = "<group>"; };
BF4952E2230AD92900A12944 /* UInt+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UInt+Extension.swift"; sourceTree = "<group>"; };
BF647C57230C491E00DF6265 /* Card10TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Card10TabBarController.swift; sourceTree = "<group>"; };
DD0171592310279500E5F7FA /* RGBLED.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RGBLED.swift; sourceTree = "<group>"; };
DD01715B231027DF00E5F7FA /* AboveLEDs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboveLEDs.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -141,12 +145,14 @@
B4CBD21E2306D8C40064E6D7 /* Bluetooth */ = {
isa = PBXGroup;
children = (
BF4952E2230AD92900A12944 /* UInt+Extension.swift */,
B479A2072305925B007C9672 /* BluetoothManager.swift */,
B4CBD2212306DD1B0064E6D7 /* DataTransferManager.swift */,
B4CBD21F2306D8FA0064E6D7 /* ChunkedDataReader.swift */,
B4CBD22323075F8F0064E6D7 /* CRC32.swift */,
B4CBD225230762240064E6D7 /* DataExtension.swift */,
B4CBD2212306DD1B0064E6D7 /* DataTransferManager.swift */,
DD0171592310279500E5F7FA /* RGBLED.swift */,
BF4952E2230AD92900A12944 /* UInt+Extension.swift */,
DD01715B231027DF00E5F7FA /* AboveLEDs.swift */,
);
path = Bluetooth;
sourceTree = "<group>";
......@@ -299,7 +305,9 @@
B4CBD2222306DD1B0064E6D7 /* DataTransferManager.swift in Sources */,
B46C7E202309F45900B12DE4 /* HatcheryRootTableViewController.swift in Sources */,
BF4952E3230AD92900A12944 /* UInt+Extension.swift in Sources */,
DD01715C231027DF00E5F7FA /* AboveLEDs.swift in Sources */,
BF647C58230C491E00DF6265 /* Card10TabBarController.swift in Sources */,
DD01715A2310279500E5F7FA /* RGBLED.swift in Sources */,
B46C7E242309F61500B12DE4 /* HatcheryClient.swift in Sources */,
B46A7C3C230D8D2900404143 /* HatcheryRootTableViewCell.swift in Sources */,
B479A2082305925B007C9672 /* BluetoothManager.swift in Sources */,
......
//
// AboveLEDs.swift
// card10badge
//
// Created by Ruotger Deecke on 23.8.19.
// Copyright © 2019 Brechler, Philip. All rights reserved.
//
import Foundation
struct AboveLEDs {
let LEDs: [RGBLED]
public var data: Data {
assert(LEDs.count == 11)
var result = Data()
for led in LEDs {
result.append(led.data)
}
return result
}
public static func randomRGB() -> AboveLEDs {
var LEDs: [RGBLED] = []
for _ in 0 ..< 11 {
LEDs.append(RGBLED.randomRGB())
}
return AboveLEDs(LEDs: LEDs)
}
}
......@@ -29,16 +29,6 @@ extension BluetoothManagerDelegate {
func didUpdateProgressOnFile(_ progress: Double) {}
}
struct RGBLED {
let r: UInt8
let g: UInt8
let b: UInt8
public var data: Data {
return Data([r, g, b])
}
}
public struct FoundPeripheral: Hashable {
let peripheral: CBPeripheral
let advertisementName: String?
......@@ -253,17 +243,7 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
}
/// Set's the 11 RGB leds at the top. Parameters are from left to right.
public func setLEDsAbove(a: RGBLED,
b: RGBLED,
c: RGBLED,
d: RGBLED,
e: RGBLED,
f: RGBLED,
g: RGBLED,
h: RGBLED,
i: RGBLED,
j: RGBLED,
k: RGBLED) {
public func setLEDsAbove(_ aboveLEDs: AboveLEDs) {
guard let peripheral = self.connectedPeripheral else { return } //TODO: Tell the delegate it failed?
guard let aboveCharacteristic = self.findCharacteristic(on: peripheral,
......@@ -273,40 +253,11 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
return
}
self.connectedPeripheral?.writeValue(mergeLedsAboveIntoData(a: a, b: b, c: c, d: d, e: e, f: f, g: g, h: h, i: i, j: j, k: k),
self.connectedPeripheral?.writeValue(aboveLEDs.data,
for: aboveCharacteristic,
type: .withoutResponse)
}
private func mergeLedsAboveIntoData(a: RGBLED,
b: RGBLED,
c: RGBLED,
d: RGBLED,
e: RGBLED,
f: RGBLED,
g: RGBLED,
h: RGBLED,
i: RGBLED,
j: RGBLED,
k: RGBLED) -> Data {
var data = Data()
data.append(a.data)
data.append(b.data)
data.append(c.data)
data.append(d.data)
data.append(e.data)
data.append(f.data)
data.append(g.data)
data.append(h.data)
data.append(i.data)
data.append(j.data)
data.append(k.data)
return data
}
public func getLightSensorData() {
guard let peripheral = self.connectedPeripheral else { return } //TODO: Tell the delegate it failed?
......
......@@ -5,9 +5,9 @@
class CRC32 {
static var table: [UInt32] = {
(0...255).map { i -> UInt32 in
(0..<8).reduce(UInt32(i), { c, _ in
(c % 2 == 0) ? (c >> 1) : (0xEDB88320 ^ (c >> 1))
(0...255).map { idx -> UInt32 in
(0..<8).reduce(UInt32(idx), { crc, _ in
(crc % 2 == 0) ? (crc >> 1) : (0xEDB88320 ^ (crc >> 1))
})
}
}()
......
......@@ -8,6 +8,8 @@
import CoreBluetooth
// To make those identifiers look more C-lick we'll make an exception here
// swiftlint:disable identifier_name
enum TransferState {
case IDLE
case START_SENT
......@@ -26,6 +28,7 @@ enum PackageType: String {
case ERROR = "e"
case ERROR_ACK = "E"
}
// swiftlint:enable identifier_name
protocol DataTransferManagerDelegate: class {
func wantsToSendPackage(_ package: Data)
......
//
// RGBLED.swift
// card10badge
//
// Created by Ruotger Deecke on 23.8.19.
// Copyright © 2019 Brechler, Philip. All rights reserved.
//
import Foundation
struct RGBLED {
let red: UInt8
let green: UInt8
let blue: UInt8
public var data: Data {
return Data([red, green, blue])
}
public static func randomRGB() -> RGBLED {
var red: UInt8 = 0
var green: UInt8 = 0
var blue: UInt8 = 0
while UInt64(red) + UInt64(green) + UInt64(blue) == UInt64(0) {
red = UInt8.random(in: 0..<3) * 127 // 128 would overflow UInt 😬
green = UInt8.random(in: 0..<3) * 127
blue = UInt8.random(in: 0..<3) * 127
}
return RGBLED(red: red, green: green, blue: blue)
}
}
......@@ -179,35 +179,12 @@ extension ConnectedViewController {
}
func setRandomBackgroundLedColors() {
BluetoothManager.sharedInstance().setBackgroundLEDs(topLeft: randomRGB(),
topRight: randomRGB(),
bottomRight: randomRGB(),
bottomLeft: randomRGB())
BluetoothManager.sharedInstance().setLEDsAbove(a: randomRGB(),
b: randomRGB(),
c: randomRGB(),
d: randomRGB(),
e: randomRGB(),
f: randomRGB(),
g: randomRGB(),
h: randomRGB(),
i: randomRGB(),
j: randomRGB(),
k: randomRGB())
}
fileprivate func randomRGB() -> RGBLED {
var r: UInt8 = 0
var g: UInt8 = 0
var b: UInt8 = 0
while UInt64(r) + UInt64(g) + UInt64(b) == UInt64(0) {
r = UInt8.random(in: 0..<3) * 127 // 128 would overflow UInt 😬
g = UInt8.random(in: 0..<3) * 127
b = UInt8.random(in: 0..<3) * 127
}
return RGBLED(r: r, g: g, b: b)
BluetoothManager.sharedInstance().setBackgroundLEDs(topLeft: RGBLED.randomRGB(),
topRight: RGBLED.randomRGB(),
bottomRight: RGBLED.randomRGB(),
bottomLeft: RGBLED.randomRGB())
BluetoothManager.sharedInstance().setLEDsAbove(AboveLEDs.randomRGB())
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment