diff --git a/Brokenithm-iOS.xcodeproj/project.pbxproj b/Brokenithm-iOS.xcodeproj/project.pbxproj index 4393989..ab931a0 100644 --- a/Brokenithm-iOS.xcodeproj/project.pbxproj +++ b/Brokenithm-iOS.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 1968E72E24086C2B00784829 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1968E72D24086C2B00784829 /* Assets.xcassets */; }; 1968E73424086C2B00784829 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 1968E73324086C2B00784829 /* main.m */; }; 19F13E2A240A6F2200809B83 /* SocketDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 19F13E29240A6F2200809B83 /* SocketDelegate.m */; }; + 19F13E2C240CDE4000809B83 /* MainView.m in Sources */ = {isa = PBXBuildFile; fileRef = 19F13E2B240CDE3F00809B83 /* MainView.m */; }; D023549DD3B09C46EBA2E321 /* libPods-Brokenithm-iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5A7EE02147010843456A2152 /* libPods-Brokenithm-iOS.a */; }; /* End PBXBuildFile section */ @@ -28,6 +29,8 @@ 1968E73324086C2B00784829 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 19F13E22240A683200809B83 /* SocketDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SocketDelegate.h; sourceTree = ""; }; 19F13E29240A6F2200809B83 /* SocketDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SocketDelegate.m; sourceTree = ""; }; + 19F13E2B240CDE3F00809B83 /* MainView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MainView.m; sourceTree = ""; }; + 19F13E2D240CDF5400809B83 /* MainView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MainView.h; sourceTree = ""; }; 259804D4CC006A58255BC938 /* Pods-Brokenithm-iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Brokenithm-iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-Brokenithm-iOS/Pods-Brokenithm-iOS.release.xcconfig"; sourceTree = ""; }; 5A7EE02147010843456A2152 /* libPods-Brokenithm-iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Brokenithm-iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; B78B36B35C6A90E4F71F84B4 /* Pods-Brokenithm-iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Brokenithm-iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Brokenithm-iOS/Pods-Brokenithm-iOS.debug.xcconfig"; sourceTree = ""; }; @@ -68,6 +71,8 @@ children = ( 1968E72424086C2200784829 /* AppDelegate.h */, 1968E72524086C2200784829 /* AppDelegate.m */, + 19F13E2D240CDF5400809B83 /* MainView.h */, + 19F13E2B240CDE3F00809B83 /* MainView.m */, 1968E72724086C2200784829 /* ViewController.h */, 1968E72824086C2200784829 /* ViewController.m */, 1968E72A24086C2200784829 /* Main.storyboard */, @@ -188,6 +193,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 19F13E2C240CDE4000809B83 /* MainView.m in Sources */, 1968E72924086C2200784829 /* ViewController.m in Sources */, 1968E73424086C2B00784829 /* main.m in Sources */, 1968E72624086C2200784829 /* AppDelegate.m in Sources */, diff --git a/Brokenithm-iOS/Base.lproj/Main.storyboard b/Brokenithm-iOS/Base.lproj/Main.storyboard index 320f42a..ab08237 100644 --- a/Brokenithm-iOS/Base.lproj/Main.storyboard +++ b/Brokenithm-iOS/Base.lproj/Main.storyboard @@ -15,7 +15,7 @@ - + diff --git a/Brokenithm-iOS/MainView.h b/Brokenithm-iOS/MainView.h new file mode 100644 index 0000000..dd92b60 --- /dev/null +++ b/Brokenithm-iOS/MainView.h @@ -0,0 +1,17 @@ +// +// MainView.h +// Brokenithm-iOS +// +// Created by ester on 2020/3/2. +// Copyright © 2020 esterTion. All rights reserved. +// + +#pragma once + +#import +#import +#import "ViewController.h" + +@interface MainView : UIView +@property ViewController *parent; +@end diff --git a/Brokenithm-iOS/MainView.m b/Brokenithm-iOS/MainView.m new file mode 100644 index 0000000..27672b2 --- /dev/null +++ b/Brokenithm-iOS/MainView.m @@ -0,0 +1,29 @@ +// +// MainView.m +// Brokenithm-iOS +// +// Created by ester on 2020/3/2. +// Copyright © 2020 esterTion. All rights reserved. +// + +#import "MainView.h" + + +@implementation MainView + +-(id)init{ + id val = [super init]; + self.multipleTouchEnabled = YES; + return val; +} + +-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"began"); [self updateTouches:event]; } +-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"ended"); [self updateTouches:event]; } +-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"moved"); [self updateTouches:event]; } +-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"cancel"); [self updateTouches:event]; } + +-(void)updateTouches:(UIEvent *)event { + [self.parent updateTouches:event]; +} + +@end diff --git a/Brokenithm-iOS/SocketDelegate.h b/Brokenithm-iOS/SocketDelegate.h index 239d269..dae8821 100644 --- a/Brokenithm-iOS/SocketDelegate.h +++ b/Brokenithm-iOS/SocketDelegate.h @@ -17,10 +17,12 @@ @interface SocketDelegate : NSObject { GCDAsyncSocket *server; - NSMutableArray *connectedSockets; + NSMutableArray *connectedSockets; } @property ViewController *parentVc; +- (void)updateIO:(NSData*)io; + @end #endif /* SocketDelegate_h */ diff --git a/Brokenithm-iOS/SocketDelegate.m b/Brokenithm-iOS/SocketDelegate.m index b8442b8..d252bc9 100644 --- a/Brokenithm-iOS/SocketDelegate.m +++ b/Brokenithm-iOS/SocketDelegate.m @@ -74,5 +74,11 @@ } } +- (void)updateIO:(NSData*)io { + for (GCDAsyncSocket* sock in connectedSockets) { + [sock writeData:io withTimeout:-1 tag:0]; + } +} + @end diff --git a/Brokenithm-iOS/ViewController.h b/Brokenithm-iOS/ViewController.h index 423a80b..4c87206 100644 --- a/Brokenithm-iOS/ViewController.h +++ b/Brokenithm-iOS/ViewController.h @@ -9,12 +9,16 @@ #pragma once @class SocketDelegate; +@class MainView; #import #import #import "SocketDelegate.h" +#import "MainView.h" @interface ViewController : UIViewController { + float screenWidth; + float screenHeight; SocketDelegate *server; } @property UIView *airIOView; @@ -22,5 +26,13 @@ @property CAGradientLayer *ledBackground; -(void)updateLed:(NSData*)rgbData; +-(void)updateTouches:(UIEvent *)event; @end + +struct ioBuf { + uint8_t len; + char head[3]; + uint8_t air[6]; + uint8_t slider[32]; +}; diff --git a/Brokenithm-iOS/ViewController.m b/Brokenithm-iOS/ViewController.m index 9eaf02d..95ee3b5 100644 --- a/Brokenithm-iOS/ViewController.m +++ b/Brokenithm-iOS/ViewController.m @@ -16,18 +16,22 @@ - (void)viewDidLoad { [super viewDidLoad]; + ((MainView*)(self.view)).parent = self; + self.view.multipleTouchEnabled = YES; // network permission + /* { NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://captive.apple.com/"]]; [NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *resp, NSData *data, NSError *error) {}]; } + */ CGRect screenSize = [UIScreen mainScreen].bounds; - float screenWidth = screenSize.size.width; - float screenHeight = screenSize.size.height; + screenWidth = screenSize.size.width; + screenHeight = screenSize.size.height; float offsetY = 0, sliderHeight = screenHeight*0.6; self.airIOView = [[UIView alloc] initWithFrame:CGRectMake(0, offsetY, screenWidth, screenHeight*0.4)]; offsetY += screenHeight*0.4; @@ -103,4 +107,50 @@ -(BOOL)prefersHomeIndicatorAutoHidden { return YES; } -(UIStatusBarStyle) preferredStatusBarStyle { return UIStatusBarStyleLightContent;} +-(void)updateTouches:(UIEvent *)event { + float airHeight = screenHeight * 0.4; + float airIOHeight = airHeight / 6; + float sliderIOWidth = screenWidth / 16; + struct ioBuf buf = {0}; + buf.len = sizeof(buf) - 1; + buf.head[0] = 'I'; + buf.head[1] = 'N'; + buf.head[2] = 'P'; + for (UITouch *touch in event.allTouches) { + UITouchPhase phase = touch.phase; + if (phase == UITouchPhaseBegan || phase == UITouchPhaseMoved || phase == UITouchPhaseStationary) { + CGPoint point = [touch locationInView:self.view]; + float pointX = screenWidth - point.x, pointY = point.y; + if (pointY < airHeight) { + int idx = point.y / airIOHeight; + uint8_t airIdx[] = {4,5,2,3,0,1}; + buf.air[airIdx[idx]] = 1; + } else { + float pointPos = pointX / sliderIOWidth; + int idx = pointPos; + int setIdx = idx*2; + if (buf.slider[ setIdx ] != 0) { + setIdx++; + } + buf.slider[ setIdx ] = 0x80; + if (idx > 0 && (pointPos - idx) * 4 < 1) { + setIdx = (idx - 1) * 2; + if (buf.slider[ setIdx ] != 0) { + setIdx++; + } + buf.slider[ setIdx ] = 0x80; + } else if (idx < 31 && (pointPos - idx) * 4 > 3) { + setIdx = (idx + 1) * 2; + if (buf.slider[ setIdx ] != 0) { + setIdx++; + } + buf.slider[ setIdx ] = 0x80; + } + } + } + } + NSData* io = [NSData dataWithBytes:&buf length:sizeof(buf)]; + [server updateIO:io]; +} + @end diff --git a/README.md b/README.md index 55af9b9..59dc2e0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Brokenithm-iOS -A version of Brokenithm, based on Brokenithm-Evolved, Based on Brokenithm. +A version of Brokenithm, based on Brokenithm-Evolved, based on Brokenithm. Using usbmux to communicate over USB, rather than wifi to prevent sudden lag. ### Branches