Permalink
Browse files

LED-Test removed, Terminal added

  • Loading branch information...
1 parent e144cba commit 83151c1d4a7ff6d5c0e0cc8dd90fb32df0d7a543 @frep committed Feb 23, 2012
@@ -19,6 +19,7 @@
502B15C014AF070500F73D7D /* EchoTestViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 502B15BF14AF070500F73D7D /* EchoTestViewController.m */; };
502B15C814AF073000F73D7D /* GCDAsyncUdpSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 502B15C714AF073000F73D7D /* GCDAsyncUdpSocket.m */; };
502B15CD14AF0EFF00F73D7D /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 502B15CC14AF0EFF00F73D7D /* CFNetwork.framework */; };
+ 502CCB4514F3A65300B363D4 /* TerminalViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 502CCB4414F3A65300B363D4 /* TerminalViewController.m */; };
5055899E14D5F5ED003F3A72 /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5055899D14D5F5ED003F3A72 /* CoreMotion.framework */; };
50865DDD14BE43E700E90B47 /* ArduinoUno_R3_Pinouts.png in Resources */ = {isa = PBXBuildFile; fileRef = 50865DDC14BE43E700E90B47 /* ArduinoUno_R3_Pinouts.png */; };
50865DE414BE479400E90B47 /* RCoIPViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50865DE314BE479400E90B47 /* RCoIPViewController.m */; };
@@ -52,6 +53,8 @@
502B15C614AF073000F73D7D /* GCDAsyncUdpSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDAsyncUdpSocket.h; sourceTree = "<group>"; };
502B15C714AF073000F73D7D /* GCDAsyncUdpSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDAsyncUdpSocket.m; sourceTree = "<group>"; };
502B15CC14AF0EFF00F73D7D /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
+ 502CCB4314F3A65300B363D4 /* TerminalViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TerminalViewController.h; sourceTree = "<group>"; };
+ 502CCB4414F3A65300B363D4 /* TerminalViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TerminalViewController.m; sourceTree = "<group>"; };
5055899D14D5F5ED003F3A72 /* CoreMotion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMotion.framework; path = System/Library/Frameworks/CoreMotion.framework; sourceTree = SDKROOT; };
50865DDC14BE43E700E90B47 /* ArduinoUno_R3_Pinouts.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ArduinoUno_R3_Pinouts.png; sourceTree = "<group>"; };
50865DE214BE479400E90B47 /* RCoIPViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCoIPViewController.h; sourceTree = "<group>"; };
@@ -142,6 +145,8 @@
50865DE314BE479400E90B47 /* RCoIPViewController.m */,
50865DE514BE4BAC00E90B47 /* RCTx.h */,
50865DE614BE4BAC00E90B47 /* RCTx.m */,
+ 502CCB4314F3A65300B363D4 /* TerminalViewController.h */,
+ 502CCB4414F3A65300B363D4 /* TerminalViewController.m */,
);
path = UDPMessenger;
sourceTree = "<group>";
@@ -235,6 +240,7 @@
50A69C2314B2373200B72A25 /* LEDTestViewController.m in Sources */,
50865DE414BE479400E90B47 /* RCoIPViewController.m in Sources */,
50865DE714BE4BAC00E90B47 /* RCTx.m in Sources */,
+ 502CCB4514F3A65300B363D4 /* TerminalViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -0,0 +1,50 @@
+//
+// TerminalViewController.h
+// UDPMessenger
+//
+// Created by Pascal Frehner on 21.02.12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "AppDelegate.h"
+
+@interface TerminalViewController : UIViewController
+{
+
+ IBOutlet UIButton *buttonClear;
+ IBOutlet UIButton *buttonSend;
+ IBOutlet UIButton *buttonStartStop;
+ IBOutlet UITextView *textViewTerminal;
+ IBOutlet UITextField *textFieldMessage;
+
+ AppDelegate *appDelegate;
+ bool receivingIsStopped;
+
+}
+
+@property (retain, nonatomic) UIButton *buttonClear;
+@property (retain, nonatomic) UIButton *buttonSend;
+@property (retain, nonatomic) UIButton *buttonStartStop;
+@property (retain, nonatomic) UITextView *textViewTerminal;
+@property (retain, nonatomic) UITextField *textFieldMessage;
+@property (retain, nonatomic) AppDelegate *appDelegate;
+@property (nonatomic) bool receivingIsStopped;
+
+-(IBAction)buttonSendPushed:(id)sender;
+-(IBAction)buttonClearPushed:(id)sender;
+-(IBAction)buttonStartStopPushed:(id)sender;
+-(IBAction)hideKeyboard:(id)sender;
+
+-(void)initTerminalViewController;
+
+-(void)clearTerminal;
+-(void)sendUDPMessage:(NSString*)message;
+-(void)toggleStartStop;
+-(void)startReceiving;
+-(void)stopReceiving;
+
+// methods called by observer-notifications
+-(void)processReceivedData:(NSNotification *)note;
+
+@end
@@ -0,0 +1,159 @@
+//
+// TerminalViewController.m
+// UDPMessenger
+//
+// Created by Pascal Frehner on 21.02.12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import "TerminalViewController.h"
+
+@implementation TerminalViewController
+
+@synthesize buttonClear, buttonSend, buttonStartStop, textViewTerminal, textFieldMessage, appDelegate, receivingIsStopped;
+
+#pragma mark - own methods
+
+-(void)initTerminalViewController
+{
+ NSLog(@"initTerminalViewController");
+ appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
+
+ [self stopReceiving];
+ [self clearTerminal];
+
+}
+
+-(IBAction)buttonSendPushed:(id)sender
+{
+ [self sendUDPMessage:[textFieldMessage text]];
+}
+
+-(IBAction)buttonClearPushed:(id)sender
+{
+ [self clearTerminal];
+}
+
+-(IBAction)buttonStartStopPushed:(id)sender
+{
+ [self toggleStartStop];
+}
+
+-(IBAction)hideKeyboard:(id)sender
+{
+ [sender resignFirstResponder];
+}
+
+-(void)clearTerminal
+{
+ [textViewTerminal setText:@""];
+}
+
+-(void)sendUDPMessage:(NSString*)message
+{
+ [[appDelegate udpController] sendMessage:message];
+}
+
+-(void)toggleStartStop
+{
+ if (receivingIsStopped)
+ {
+ [self startReceiving];
+ }
+ else
+ {
+ [self stopReceiving];
+ }
+}
+
+-(void)startReceiving
+{
+ // set internal state
+ [self setReceivingIsStopped:FALSE];
+ // add observer
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(processReceivedData:)
+ name:@"udpDataReceived"
+ object:nil];
+ // set button text
+ [buttonStartStop setTitle:@"stop" forState:UIControlStateNormal];
+ // send a message to tell the destination IP and destination PORT
+ [self sendUDPMessage:@"start"];
+}
+
+-(void)stopReceiving
+{
+ // set internal state
+ [self setReceivingIsStopped:TRUE];
+ // remove observer
+ [[NSNotificationCenter defaultCenter] removeObserver:self
+ name:@"udpDataReceived"
+ object:nil];
+ // set button text
+ [buttonStartStop setTitle:@"start" forState:UIControlStateNormal];
+}
+
+#pragma mark - observer notification methods
+
+-(void)processReceivedData:(NSNotification *)note
+{
+ NSString *message = [[NSString alloc] initWithData:[[appDelegate udpController] receivedData] encoding:NSUTF8StringEncoding];
+ NSLog(@"message: %@",message);
+ NSString *newText = [[NSString alloc] initWithFormat:@"%@\n%@", [textViewTerminal text], message];
+ [textViewTerminal setText:newText];
+ [textViewTerminal scrollRangeToVisible:NSMakeRange([textViewTerminal.text length], 0)];
+ [message release];
+ [newText release];
+}
+
+#pragma mark - some generated methods
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (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.
+}
+
+#pragma mark - View lifecycle
+
+/*
+// Implement loadView to create a view hierarchy programmatically, without using a nib.
+- (void)loadView
+{
+}
+*/
+
+
+// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+
+ [self initTerminalViewController];
+}
+
+
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+ [self stopReceiving];
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ // Return YES for supported orientations
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+@end
Oops, something went wrong.

0 comments on commit 83151c1

Please sign in to comment.