Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma mark -
- #pragma mark Socket Actions
- -(void) connect
- {
- _socket = [[AsyncSocket alloc] init];
- [_socket setDelegate:self];
- //[_socket connectToHost:@"localhost" onPort:80 withTimeout:15.0f error:nil];
- [_socket connectToHost:[[NSUserDefaults standardUserDefaults] objectForKey:@"ip"] onPort:2001 error:nil];
- _connectionStatusLabel.text = NSLocalizedString(@"Waiting for connection",nil);
- }
- - (IBAction)lcdPressed:(id)sender {
- NSString *cmd = @"HITK OK";
- [self sendDataToSo
- -(void)disconnect
- {
- [_socket disconnect];
- [_socket release];
- _socket = nil;
- }
- -(void)sendDataToSocket:(NSData*)data {
- if (_socket != nil) {
- [_socket writeData:data withTimeout:15 tag:1];
- }
- }
- #pragma mark -
- #pragma mark General Actions
- -(IBAction) connectButtonPressed:(id)sender {
- if (_connected) {
- [self disconnect];
- } else {
- [self connect];
- }
- }
- - (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
- [self dismissModalViewControllerAnimated:YES];
- }
- - (IBAction)showInfo:(id)sender {
- FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
- controller.delegate = self;
- controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
- [self presentModalViewController:controller animated:YES];
- [controller release];
- }
- - (IBAction)pageControlDidChange:(UIPageControl*)sender
- {
- [_scrollView scrollRectToVisible:CGRectMake(sender.currentPage*_scrollView.frame.size.width, 0, _scrollView.frame.size.width, _scrollView.frame.size.height) animated:YES];
- }
- #pragma mark -
- #pragma mark Sender Actions
- #pragma mark -
- #pragma mark Socket Delegates
- - (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port {
- _connectionStatusLabel.text = NSLocalizedString(@"Connection established",nil);
- _connected = YES;
- [_connectButton setTitle:NSLocalizedString(@"Disconnect",nil) forState:UIControlStateNormal];
- }
- - (void)onSocketDidDisconnect:(AsyncSocket *)sock {
- _connectionStatusLabel.text = NSLocalizedString(@"Not connected",nil);
- _connected = NO;
- [_connectButton setTitle:NSLocalizedString(@"Connect",nil) forState:UIControlStateNormal];
- }
- #pragma mark -
- #pragma mark UIScrollView delegate
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)aScrollView
- {
- _pageControl.currentPage = _scrollView.contentOffset.x / _scrollView.frame.size.width;
- if (_pageControl.currentPage == 2) {
- [_commandTextField becomeFirstResponder];
- } else {
- [_commandTextField resignFirstResponder];
- }
- }
- #pragma mark -
- #pragma mark TextField delegate
- - (BOOL)textFieldShouldReturn:(UITextField *)textField
- {
- [textField resignFirstResponder];
- NSString *cmd = textField.text;
- [self sendDataToSocket:[cmd dataUsingEncoding:NSUTF8StringEncoding]];
- return YES;
- }
- - (BOOL)textFieldShouldEndEditing:(UITextField *)textField
- {
- return YES;
- }
- #pragma mark -
- #pragma mark Memory Management
- - (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
- // Release any cached data, images, etc. that aren't in use.
- }
- - (void)viewDidUnload {
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- }
- - (void)dealloc {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement