master
esterTion 2020-03-02 16:29:21 +08:00
parent d9dc2d9620
commit a5e9598f66
9 changed files with 127 additions and 5 deletions

View File

@ -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 = "<group>"; };
19F13E22240A683200809B83 /* SocketDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SocketDelegate.h; sourceTree = "<group>"; };
19F13E29240A6F2200809B83 /* SocketDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SocketDelegate.m; sourceTree = "<group>"; };
19F13E2B240CDE3F00809B83 /* MainView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MainView.m; sourceTree = "<group>"; };
19F13E2D240CDF5400809B83 /* MainView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MainView.h; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
@ -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 */,

View File

@ -15,7 +15,7 @@
<viewControllerLayoutGuide type="top" id="26Q-bF-23b"/>
<viewControllerLayoutGuide type="bottom" id="15f-bj-ZYr"/>
</layoutGuides>
<view key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="8bC-Xf-vdC">
<view key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="8bC-Xf-vdC" customClass="MainView">
<rect key="frame" x="0.0" y="0.0" width="667" height="375"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>

View File

@ -0,0 +1,17 @@
//
// MainView.h
// Brokenithm-iOS
//
// Created by ester on 2020/3/2.
// Copyright © 2020 esterTion. All rights reserved.
//
#pragma once
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface MainView : UIView
@property ViewController *parent;
@end

View File

@ -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<UITouch *> *)touches withEvent:(UIEvent *)event { NSLog(@"began"); [self updateTouches:event]; }
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSLog(@"ended"); [self updateTouches:event]; }
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSLog(@"moved"); [self updateTouches:event]; }
-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSLog(@"cancel"); [self updateTouches:event]; }
-(void)updateTouches:(UIEvent *)event {
[self.parent updateTouches:event];
}
@end

View File

@ -17,10 +17,12 @@
@interface SocketDelegate : NSObject {
GCDAsyncSocket *server;
NSMutableArray *connectedSockets;
NSMutableArray<GCDAsyncSocket*> *connectedSockets;
}
@property ViewController *parentVc;
- (void)updateIO:(NSData*)io;
@end
#endif /* SocketDelegate_h */

View File

@ -74,5 +74,11 @@
}
}
- (void)updateIO:(NSData*)io {
for (GCDAsyncSocket* sock in connectedSockets) {
[sock writeData:io withTimeout:-1 tag:0];
}
}
@end

View File

@ -9,12 +9,16 @@
#pragma once
@class SocketDelegate;
@class MainView;
#import <UIKit/UIKit.h>
#import <CocoaAsyncSocket/GCDAsyncSocket.h>
#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];
};

View File

@ -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

View File

@ -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