Skip to content

Commit

Permalink
Merge pull request #11 from MillerTechnologyPeru/swiftui
Browse files Browse the repository at this point in the history
Rewrite in SwiftUI
  • Loading branch information
colemancda authored Nov 19, 2022
2 parents 7dee82b + db1a833 commit 4283b82
Show file tree
Hide file tree
Showing 82 changed files with 2,633 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CachedManifest</key>
<dict>
<key>manifestData</key>
<data>
eyJkZXBlbmRlbmNpZXMiOlt7InNvdXJjZUNvbnRyb2wiOlt7ImlkZW50aXR5
IjoiZ2F0dCIsImxvY2F0aW9uIjp7InJlbW90ZSI6WyJodHRwczpcL1wvZ2l0
aHViLmNvbVwvUHVyZVN3aWZ0XC9HQVRULmdpdCJdfSwicHJvZHVjdEZpbHRl
ciI6bnVsbCwicmVxdWlyZW1lbnQiOnsicmFuZ2UiOlt7Imxvd2VyQm91bmQi
OiIzLjAuMyIsInVwcGVyQm91bmQiOiI0LjAuMCJ9XX19XX0seyJzb3VyY2VD
b250cm9sIjpbeyJpZGVudGl0eSI6ImJsdWV0b290aCIsImxvY2F0aW9uIjp7
InJlbW90ZSI6WyJodHRwczpcL1wvZ2l0aHViLmNvbVwvUHVyZVN3aWZ0XC9C
bHVldG9vdGguZ2l0Il19LCJwcm9kdWN0RmlsdGVyIjpudWxsLCJyZXF1aXJl
bWVudCI6eyJleGFjdCI6WyI2LjAuNSJdfX1dfV0sImRpc3BsYXlOYW1lIjoi
Qmx1ZXRvb3RoRXhwbG9yZXIiLCJwYWNrYWdlS2luZCI6eyJyb290Ijp7fX0s
InBsYXRmb3JtcyI6W3sib3B0aW9ucyI6W10sInBsYXRmb3JtTmFtZSI6Imlv
cyIsInZlcnNpb24iOiIxNS4yIn1dLCJwcm9kdWN0cyI6W3sibmFtZ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VCIsbnVsbF19LHsicHJvZHVjdCI6WyJEYXJ3
aW5HQVRUIiwiR0FUVCIsbnVsbF19LHsicHJvZHVjdCI6WyJCbHVldG9vdGgi
LCJCbHVldG9vdGgiLG51bGxdfV0sImV4Y2x1ZGUiOltdLCJuYW1lIjoiQmx1
ZXRvb3RoRXhwbG9yZXIiLCJwYXRoIjoiLiIsInJlc291cmNlcyI6W10sInNl
dHRpbmdzIjpbXSwidHlwZSI6ImV4ZWN1dGFibGUifX0sInRhcmdldHMiOlt7
ImRlcGVuZGVuY2llcyI6W3sicHJvZHVjdCI6WyJHQVRUIiwiR0FUVCIsbnVs
bF19LHsicHJvZHVjdCI6WyJEYXJ3aW5HQVRUIiwiR0FUVCIsbnVsbF19LHsi
cHJvZHVjdCI6WyJCbHVldG9vdGgiLCJCbHVldG9vdGgiLG51bGxdfV0sImV4
Y2x1ZGUiOltdLCJuYW1lIjoiQmx1ZXRvb3RoRXhwbG9yZXIiLCJwYXRoIjoi
LiIsInJlc291cmNlcyI6W10sInNldHRpbmdzIjpbXSwidHlwZSI6ImV4ZWN1
dGFibGUifV0sInRvb2xzVmVyc2lvbiI6eyJfdmVyc2lvbiI6IjUuNi4wIn19
</data>
<key>manifestHash</key>
<data>
9DWsv/VWsc0HFg4zdS7UVoIDhangEcWbGmGJ4SUCMXI=
</data>
<key>schemaVersion</key>
<integer>4</integer>
<key>swiftPMVersionString</key>
<string>5.6.0-dev</string>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DocumentThumbnailConfiguration</key>
<dict>
<key>accentColorHash</key>
<data>
MFe13OMFARMJ8HDqD5bDNSWxDg9LDdv8oq4TvGw4ZwM=
</data>
<key>appIconHash</key>
<data>
y2Z5w6td7Ho8gRBX1qV1v39wz1qzfrHHBc+uTnEZ1YA=
</data>
<key>thumbnailIsPrerendered</key>
<false/>
</dict>
</dict>
</plist>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions BluetoothExplorer.swiftpm/.swiftpm/playgrounds/Workspace.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AppSettings</key>
<dict>
<key>appIconPlaceholderGlyphName</key>
<string>running</string>
<key>appSettingsVersion</key>
<integer>1</integer>
</dict>
</dict>
</plist>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions BluetoothExplorer.swiftpm/App.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// App.swift
// BluetoothExplorer
//
// Created by Alsey Coleman Miller on 6/9/19.
// Copyright © 2019 Alsey Coleman Miller. All rights reserved.
//

import Foundation
import SwiftUI

@main
struct BluetoothExplorerApp: App {

let store = Store.shared

var body: some Scene {
WindowGroup {
NavigationView {
CentralList(store: store)
Text("Scan for devices")
}
.onAppear {
NativeCentral.shared.log = { print("Central: \($0)") }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"colors" : [
{
"color" : {
"platform" : "universal",
"reference" : "systemCyanColor"
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"filename" : "AppIcon-60@2x.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"filename" : "AppIcon-60@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"filename" : "AppIcon-76@2x.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"filename" : "AppIcon-83.5@2x.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"filename" : "AppIcon-1024.png",
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions BluetoothExplorer.swiftpm/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
67 changes: 67 additions & 0 deletions BluetoothExplorer.swiftpm/Extensions/Hexadecimal.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// Hexadecimal.swift
// Bluetooth
//
// Created by Alsey Coleman Miller on 3/2/16.
// Copyright © 2016 PureSwift. All rights reserved.
//

import Foundation

internal extension FixedWidthInteger {

func toHexadecimal() -> String {

var string = String(self, radix: 16)
while string.utf8.count < (MemoryLayout<Self>.size * 2) {
string = "0" + string
}
assert(string.utf8.count == MemoryLayout<Self>.size * 2)
return string.uppercased()
}

init?<T: StringProtocol>(hexadecimal string: T) {
self.init(string, radix: 16)
}
}

internal extension Collection where Element: FixedWidthInteger {

func toHexadecimal() -> String {
let length = count * MemoryLayout<Element>.size * 2
var string = ""
string.reserveCapacity(length)
string = reduce(into: string) { $0 += $1.toHexadecimal() }
assert(string.count == length)
return string
}
}

internal extension Data {

init?(hexadecimal string: String) {
let elementStringSize = MemoryLayout<Element>.size * 2 // 2 for UInt8
guard string.isEmpty == false else {
self.init()
return
}
guard string.count % elementStringSize == 0 else {
return nil
}
let elementsCount = string.count / elementStringSize
let elements = (0 ..< elementsCount)
.lazy
.map { ($0 * elementStringSize, ($0+1) * elementStringSize) }
.map { string.index(string.startIndex, offsetBy: $0.0) ..< string.index(string.startIndex, offsetBy: $0.1) }
.map { string[$0] }
self.init()
self.reserveCapacity(elementsCount)
for substring in elements {
guard let element = Element.init(hexadecimal: substring) else {
return nil
}
self.append(element)
}
assert(self.count == elementsCount)
}
}
31 changes: 31 additions & 0 deletions BluetoothExplorer.swiftpm/Model/AttributeValue.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// AttributeValue.swift
//
//
// Created by Alsey Coleman Miller on 22/12/21.
//

import Foundation

enum AttributeValueType: Equatable, Hashable {

case read
case write
case notification
}

struct AttributeValue: Equatable, Hashable {

let date: Date

let type: AttributeValueType

let data: Data
}

extension AttributeValue: Identifiable {

var id: Date {
date
}
}
31 changes: 31 additions & 0 deletions BluetoothExplorer.swiftpm/Model/BluetoothUUID.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// BluetoothUUID.swift
//
//
// Created by Alsey Coleman Miller on 22/12/21.
//

import Foundation
import Bluetooth

internal extension BluetoothUUID {

func description(for value: Data) -> String? {
switch self {
case .batteryLevel:
return value.first.flatMap { $0.description + "%" }
case .currentTime:
return nil
case .deviceName,
.serialNumberString,
.firmwareRevisionString,
.softwareRevisionString,
.hardwareRevisionString,
.modelNumberString,
.manufacturerNameString:
return String(data: value, encoding: .utf8)
default:
return nil
}
}
}
Loading

0 comments on commit 4283b82

Please sign in to comment.