source: orbit/iOS/Orbit/Orbit/controllers/AdvancedViewController.m @ 6db346c

Servo
Last change on this file since 6db346c was 6db346c, checked in by Steve Castellotti <sc@…>, 6 years ago
  • Scoring fields added
  • Tilt Control widgets added
  • Property mode set to 100644
File size: 3.2 KB
Line 
1//
2//  AdvancedViewController.m
3//  orbit
4//
5//  Copyright (c) 2013 Puzzlebox Productions, LLC. All rights reserved.
6//  Originally created by Jonathon Horsman.
7//
8//  This code is released under the GNU Public License (GPL) version 2
9//  For more information please refer to http://www.gnu.org/copyleft/gpl.html
10//
11
12#import "AdvancedViewController.h"
13#import "SignalConverter.h"
14#import "AppDelegate.h"
15
16@interface AdvancedViewController ()
17
18@end
19
20@implementation AdvancedViewController {
21    SignalConverter *signalConverter;
22}
23
24@synthesize pitch, pitchPercent, yaw, yawPercent, throttle, throttlePercent;
25
26- (void)viewDidLoad
27{
28    [super viewDidLoad];
29    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
30    signalConverter = appDelegate.signalConverter;
31   
32//   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Help Wanted" message:@"Please join our Open Source development community to help us port this feature! See link to Forums under Support tab" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
33//   [alert show];
34   
35   
36   UISwitch *switchTiltSensorControl = [[UISwitch alloc] initWithFrame:CGRectMake(10, 310, 0, 0)];
37   [switchTiltSensorControl addTarget:self action:@selector(changeSwitchTiltSensorControl:) forControlEvents:UIControlEventValueChanged];
38   [self.view addSubview:switchTiltSensorControl];
39   
40   UISwitch *switchTiltSensorControlThrottle = [[UISwitch alloc] initWithFrame:CGRectMake(148, 310, 0, 0)];
41   [switchTiltSensorControlThrottle addTarget:self action:@selector(changeSwitchTiltSensorControlThrottle:) forControlEvents:UIControlEventValueChanged];
42   [self.view addSubview:switchTiltSensorControlThrottle];
43   
44}
45
46- (IBAction) pitchChanged:(id) sender
47{
48    pitchPercent.text = [self percentStringFromSlider:pitch];
49    [self adjustValues];
50}
51
52- (IBAction) yawChanged:(id) sender
53{
54    yawPercent.text = [self percentStringFromSlider:yaw];
55    [self adjustValues];
56}
57
58- (IBAction) throttleChanged:(id) sender
59{
60    throttlePercent.text = [self percentStringFromSlider:throttle];
61    [self adjustValues];
62}
63
64- (NSString *) percentStringFromSlider:(UISlider *) slider
65{
66    return [NSString stringWithFormat:@"%i%%", (int)((slider.value - 0.5) * 200)]; // between -100% and 100%
67}
68
69- (void) adjustValues
70{
71    [signalConverter setYaw:[self yawValue]throttle:[self throttleValue] pitch:[self pitchValue]];
72}
73
74- (int) yawValue
75{
76    return round(yaw.value * 100);
77}
78
79- (int) pitchValue
80{
81    return round(pitch.value * 100);
82}
83
84- (int) throttleValue
85{
86    return round(throttle.value * 100);
87}
88
89- (IBAction) resetButtonPressed:(id)button
90{
91    pitch.value = 0.5;
92    yaw.value = 0.5;
93    throttle.value = 0.5;
94    NSString *zero = @"0%";
95    throttlePercent.text = zero;
96    yawPercent.text = zero;
97    pitchPercent.text = zero;
98    [self adjustValues];
99}
100
101- (void)changeSwitchTiltSensorControl:(id)sender{
102   
103   if([sender isOn]){
104      NSLog(@"DEBUG: Tilt Sensor Enabled");
105   } else{
106      NSLog(@"DEBUG: Tilt Sensor Disabled");
107   }
108   
109}
110
111- (void)changeSwitchTiltSensorControlThrottle:(id)sender{
112   
113   if([sender isOn]){
114      NSLog(@"DEBUG: Throttle Tilt Sensor Enabled");
115   } else{
116      NSLog(@"DEBUG: Throttle Tilt Sensor Disabled");
117   }
118   
119}
120
121@end
Note: See TracBrowser for help on using the repository browser.