Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2023 Update #18

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions SmartController3.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
New,
);
LastSwiftUpdateCheck = 1340;
LastUpgradeCheck = 1340;
LastUpgradeCheck = 1500;
TargetAttributes = {
FB8D25A3285D94BC000F0F35 = {
CreatedOnToolsVersion = 13.4.1;
Expand Down Expand Up @@ -272,6 +272,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand All @@ -286,7 +287,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -332,6 +333,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 2;
Expand All @@ -341,7 +343,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand All @@ -360,7 +362,7 @@
CODE_SIGN_ENTITLEMENTS = SmartController3/SmartController3.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2023.9.9;
CURRENT_PROJECT_VERSION = 2023.9.27;
DEVELOPMENT_ASSET_PATHS = "\"SmartController3/Preview Content\"";
DEVELOPMENT_TEAM = V9J6H8S566;
ENABLE_PREVIEWS = YES;
Expand All @@ -378,7 +380,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 4.2.2;
MARKETING_VERSION = 4.2.4;
PRODUCT_BUNDLE_IDENTIFIER = com.smart.controller.x;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -397,7 +399,7 @@
CODE_SIGN_ENTITLEMENTS = SmartController3/SmartController3.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2023.9.9;
CURRENT_PROJECT_VERSION = 2023.9.27;
DEVELOPMENT_ASSET_PATHS = "\"SmartController3/Preview Content\"";
DEVELOPMENT_TEAM = V9J6H8S566;
ENABLE_PREVIEWS = YES;
Expand All @@ -415,7 +417,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 4.2.2;
MARKETING_VERSION = 4.2.4;
PRODUCT_BUNDLE_IDENTIFIER = com.smart.controller.x;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
129 changes: 111 additions & 18 deletions SmartController3/Interface/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SwiftUI

struct ContentView: View {
@ObservedObject var nodeConnectionClassObject = NodeConnection()

@State private var showSettings = false
@State private var showSystemInfo = true
@State private var showSlowMode = false
Expand All @@ -17,7 +17,12 @@ struct ContentView: View {
@State private var showVersion = false
@State private var pressGear = false
@State private var needLongPress = false


@State private var keyborad_open = false

@State private var str = ""
@State private var id_str = ""

private let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
private let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String

Expand All @@ -32,39 +37,66 @@ struct ContentView: View {
showSlowMode = UserDefaults.standard.object(forKey: "showSlowMode") as? Bool ?? false
showBigSlowMode = UserDefaults.standard.object(forKey: "showBigSlowMode") as? Bool ?? false
showEnergency = UserDefaults.standard.object(forKey: "showEnergency") as? Bool ?? true

nodeConnectionClassObject.slow_mode_value = UserDefaults.standard.object(forKey: "slow_mode_value") as? Float ?? 0.5
nodeConnectionClassObject.comID = UserDefaults.standard.object(forKey: "comID") as? UInt8 ?? 10

}
.onDisappear(){
UserDefaults.standard.set(showSystemInfo, forKey: "showSystemInfo")
UserDefaults.standard.set(showSlowMode, forKey: "showSlowMode")
UserDefaults.standard.set(showBigSlowMode, forKey: "showBigSlowMode")
UserDefaults.standard.set(showEnergency, forKey: "showEnergency")

UserDefaults.standard.set(nodeConnectionClassObject.slow_mode_value, forKey: "slow_mode_value")
UserDefaults.standard.set(nodeConnectionClassObject.comID, forKey: "comID")
}
}

// MARK: - Private Helpers
private func baseView() -> some View {
ZStack {
backgroundGradient()
VStack {
nodeStatusView()
ZStack{
HStack {
Spacer()
Text("ID: \(nodeConnectionClassObject.comID)")
.foregroundStyle(.secondary)
Spacer()
Text("Rcv: \(nodeConnectionClassObject.rcvID[0])")
.foregroundStyle(.secondary)
if(nodeConnectionClassObject.rcvID[1] != 0){
Text("\(nodeConnectionClassObject.rcvID[1])")
.foregroundStyle(.secondary)
}
if(nodeConnectionClassObject.rcvID[2] != 0){
Text("\(nodeConnectionClassObject.rcvID[2])")
.foregroundStyle(.secondary)
}
Spacer()
}
.animation(.easeIn(duration: 0.2), value: nodeConnectionClassObject.rcvID)
}
.padding(.all , 0.5)

scrollViewContent()
}
.onTapGesture {
showSettings = false
UIApplication.shared.closeKeyboard()
}
}
}

private func backgroundGradient() -> some View {
LinearGradient(gradient: Gradient(colors: [.blue.opacity(0.2), .green.opacity(0.3)]), startPoint: .top, endPoint: .bottom)
.ignoresSafeArea()
.onTapGesture {
showSettings = false
UIApplication.shared.closeKeyboard()
}
}

private func nodeStatusView() -> some View {
ZStack {
NodeStatus(nodeConnectionClassObject: nodeConnectionClassObject)
Expand All @@ -79,7 +111,7 @@ struct ContentView: View {
}
}
}

private func scrollViewContent() -> some View {
ScrollView(showsIndicators: false) {
VStack {
Expand All @@ -103,30 +135,31 @@ struct ContentView: View {
}

if showEnergency {
EmergencyCall()
EmergencyCall(nodeConnectionClass: nodeConnectionClassObject)
.frame(height: 150)
}
}
.padding([.leading, .bottom, .trailing])

}
}

private func longPressHint() -> some View {
Text("長押ししてください")
.font(.callout)
.foregroundStyle(.secondary)
.opacity(needLongPress ? 1.0 : 0.0)
.animation(.easeOut(duration: 0.2), value: needLongPress)
}

private func gearIcon() -> some View {
Image(systemName: "gear")
.font(.title3)
.foregroundStyle(.secondary)
.padding(.horizontal)
.opacity(pressGear ? 0.5 : 1.0)
}

private func settingsView() -> some View {
VStack {
Spacer()
Expand All @@ -149,15 +182,68 @@ struct ContentView: View {
Toggle("スローモード", isOn: $showSlowMode)
Toggle("最大 スローモード", isOn: $showBigSlowMode)
Toggle("緊急停止", isOn: $showEnergency)

HStack {
Text("SlowMode値")
Spacer()
TextField("0 to 1", text: $str)
.keyboardType(.decimalPad)
.font(.headline)
.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardDidShowNotification)) { _ in
keyborad_open = true
str = "\(nodeConnectionClassObject.slow_mode_value)"
}.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardDidHideNotification)) { _ in
keyborad_open = false
if let fp = Float(str){
nodeConnectionClassObject.slow_mode_value = fp
UserDefaults.standard.set(nodeConnectionClassObject.slow_mode_value, forKey: "slow_mode_value")
}else{
nodeConnectionClassObject.slow_mode_value = 0.0
str = "\(nodeConnectionClassObject.slow_mode_value)"
}

}
}
HStack {
Text("ID")
Spacer()
TextField("id", text: $id_str)
.keyboardType(.decimalPad)
.font(.headline)
.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardDidShowNotification)) { _ in
keyborad_open = true
id_str = "\(nodeConnectionClassObject.comID)"
}.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardDidHideNotification)) { _ in
keyborad_open = false
if let ui = UInt8(id_str){
nodeConnectionClassObject.comID = ui
UserDefaults.standard.set(nodeConnectionClassObject.comID, forKey: "comID")
}else{
nodeConnectionClassObject.comID = 0
id_str = "\(nodeConnectionClassObject.comID)"
}

}
}

Spacer()
}.padding(.all)
}
.frame(height: 300)
.offset(y: showSettings ? 100 : 600)
.frame(height: 350)
.offset(y: showSettings ? 50 : 600)
.offset(y: keyborad_open ? -50 : 0)
.animation(.easeInOut(duration: 0.2), value: showSettings)
.onTapGesture {
UIApplication.shared.closeKeyboard()
keyborad_open = false
}
.onAppear(){
id_str = "\(nodeConnectionClassObject.comID)"
str = "\(nodeConnectionClassObject.slow_mode_value)"
}
}
}

private func longPressIndicator() -> some View {
VStack {
Rectangle()
Expand All @@ -167,7 +253,7 @@ struct ContentView: View {
Spacer()
}
}

private func longPressGesture() -> some Gesture {
LongPressGesture(minimumDuration: 0.3)
.onEnded { _ in
Expand All @@ -178,7 +264,7 @@ struct ContentView: View {
handleLongPressChange()
}
}

private func handleLongPressChange() {
pressGear = true //for gear animation
DispatchQueue.main.asyncAfter(deadline: .now() + 0.31) {
Expand All @@ -190,9 +276,16 @@ struct ContentView: View {
needLongPress = false
}
}

if showSettings {
showSettings = false
UIApplication.shared.closeKeyboard()
}
}
}

extension UIApplication {
func closeKeyboard() {
sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
24 changes: 5 additions & 19 deletions SmartController3/Interface/EmergencyCall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import CoreTelephony
import TriggerSlider

struct EmergencyCall: View {
@State private var nwcCallback : NWConnection?
@State private var queue = DispatchQueue(label: "EmergencyCall", qos: .background , attributes: .concurrent)
@ObservedObject var nodeConnectionClass : NodeConnection

@State private var offset: CGFloat = 0.0

@State private var emergencyCallStatus = false

var body: some View {
Expand Down Expand Up @@ -51,16 +50,13 @@ struct EmergencyCall: View {
.overlay(Image(systemName: "arrow.right").font(.system(size: 30)))
}, textView: {
Text("スライドして緊急停止").foregroundColor(Color.black)
},
backgroundView: {
},backgroundView: {
RoundedRectangle(cornerRadius: 30, style: .continuous)
.fill(Color.orange.opacity(0.5))
}, offsetX: $offset,
didSlideToEnd: {
print("Triggered right direction slider!")
nwcCallback = NWConnection(host: "255.255.255.255", port: 64202, using: .udp)
nwcCallback?.start(queue: self.queue)
send(item: "EMERGENCY")
nodeConnectionClass.mrm = true
emergencyCallStatus = true
}, settings: TriggerSliderSettings(sliderViewVPadding: 5, slideDirection: .right))
.padding(.vertical, 10)
Expand All @@ -73,18 +69,8 @@ struct EmergencyCall: View {
.gesture(LongPressGesture(minimumDuration: 0.3)
.onEnded { _ in
emergencyCallStatus = false
nodeConnectionClass.mrm = false
offset = 0
})
}

func send(item : String){
let payload = item.data(using: .utf8)!
nwcCallback!.send(content: payload, completion: NWConnection.SendCompletion.contentProcessed(({ (NWError) in
if (NWError == nil) {
NSLog("ROSC:Send:Data was sent to UDP")
} else {
NSLog("ROSC:Send:NWError:\(NWError!)")
}
})))
}
}
Loading