-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContentView.swift
More file actions
115 lines (97 loc) · 3.33 KB
/
Copy pathContentView.swift
File metadata and controls
115 lines (97 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// ContentView.swift
// KlipschControl
//
// Created by William Leese on 17/02/2024.
//
import SwiftUI
let bluetooth = Data([0x00])
let digital = Data([0x01])
let usbComputer = Data([0x02])
let usbStorage = Data([0x03])
let analog = Data([0x04])
struct ContentView: View {
@StateObject var speaker: Speaker
init(speaker: Speaker) {
_speaker = StateObject(wrappedValue: speaker)
}
var body: some View {
VStack {
Text("Speaker").font(.title).bold()
let speakerImage = Image(systemName: "speaker.3.fill")
.font(.system(size: 140))
.padding()
if speaker.deviceReady {
speakerImage.foregroundColor(.green)
} else {
speakerImage.foregroundColor(.red)
}
}.padding()
Text(speaker.statusText)
.onTapGesture { speaker.triggerScan() }
Divider()
VStack {
HStack {
let inputTv = Button(action: {
speaker.switchInput(data: digital)
}) {
Text("Television")
.padding(.horizontal, 30)
.padding(.vertical, 16)
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
.bold()
}
let inputUsbComputer = Button(action: {
speaker.switchInput(data: usbComputer)
}) {
Text("Speaker Only")
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
.bold()
}
if speaker.activeInput == digital {
inputTv
} else {
inputTv.opacity(0.7).fontWeight(.regular)
}
if speaker.activeInput == usbComputer {
inputUsbComputer
} else {
inputUsbComputer.opacity(0.7).fontWeight(.regular)
}
}
}.padding().padding()
VStack {
let vol = speaker.volume.withUnsafeBytes { $0.load(as: UInt8.self) }
Text("Volume (\(vol))").font(.title3).bold()
Button(action: {
speaker.volumeUp()
}) {
Image(systemName: "arrow.up").bold()
.padding(.horizontal, 60)
.padding(.vertical, 30)
.background(Color.green)
.foregroundColor(.black)
.cornerRadius(10)
}
Button(action: {
speaker.volumeDown()
}) {
Image(systemName: "arrow.down").bold()
.padding(.horizontal, 60)
.padding(.vertical, 30)
.background(Color.red)
.foregroundColor(.black)
.cornerRadius(10)
}
}.padding()
Spacer()
}
}
#Preview {
ContentView(speaker: Speaker())
}