source: orbit/iOS/Orbit/Orbit/controllers/AdvancedViewController.m @ d5f1a91

Servo
Last change on this file since d5f1a91 was d5f1a91, checked in by Steve Castellotti <sc@…>, 6 years ago
  • Tilt Control UISwitch controls Throttle Only UISwitch
  • Property mode set to 100644
File size: 3.9 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//   UISwitch *switchTiltSensorControl = [[UISwitch alloc] initWithFrame:CGRectMake(14, 310, 0, 0)];
36//   [switchTiltSensorControl addTarget:self action:@selector(changeSwitchTiltSensorControl:) forControlEvents:UIControlEventValueChanged];
37//   [self.view addSubview:switchTiltSensorControl];
38//   
39//   UISwitch *switchTiltSensorControlThrottle = [[UISwitch alloc] initWithFrame:CGRectMake(154, 310, 0, 0)];
40//   [switchTiltSensorControlThrottle addTarget:self action:@selector(changeSwitchTiltSensorControlThrottle:) forControlEvents:UIControlEventValueChanged];
41//   [self.view addSubview:switchTiltSensorControlThrottle];
42   
43   [_switchTiltSensorControlThrottle setOn:NO];
44   [_switchTiltSensorControlThrottle setEnabled:NO];
45   
46}
47
48- (IBAction) pitchChanged:(id) sender
49{
50    pitchPercent.text = [self percentStringFromSlider:pitch];
51    [self adjustValues];
52}
53
54- (IBAction) yawChanged:(id) sender
55{
56    yawPercent.text = [self percentStringFromSlider:yaw];
57    [self adjustValues];
58}
59
60- (IBAction) throttleChanged:(id) sender
61{
62    throttlePercent.text = [self percentStringFromSlider:throttle];
63    [self adjustValues];
64}
65
66- (NSString *) percentStringFromSlider:(UISlider *) slider
67{
68    return [NSString stringWithFormat:@"%i%%", (int)((slider.value - 0.5) * 200)]; // between -100% and 100%
69}
70
71- (void) adjustValues
72{
73    [signalConverter setYaw:[self yawValue]throttle:[self throttleValue] pitch:[self pitchValue]];
74}
75
76- (int) yawValue
77{
78    return round(yaw.value * 100);
79}
80
81- (int) pitchValue
82{
83    return round(pitch.value * 100);
84}
85
86- (int) throttleValue
87{
88    return round(throttle.value * 100);
89}
90
91- (IBAction) resetButtonPressed:(id)button
92{
93    pitch.value = 0.5;
94    yaw.value = 0.5;
95    throttle.value = 0.5;
96    NSString *zero = @"0%";
97    throttlePercent.text = zero;
98    yawPercent.text = zero;
99    pitchPercent.text = zero;
100    [self adjustValues];
101}
102
103
104//-(IBAction)Switch {
105//   
106//   if (Switch.on) {
107//      label.text = @"The switch is on, button 1 is now shown";
108//      button1.hidden = NO;
109//      button2.hidden = YES;
110//   }
111//   
112//   else {
113//      label.text = @"The switch is on, button 2 is now shown";
114//      button1.hidden = YES;
115//      button2.hidden = NO;
116//   }
117//   
118//}
119
120
121//- (void)changeSwitchTiltSensorControl:(id)sender{
122- (IBAction)changeSwitchTiltSensorControl:(id)sender{
123
124   if([sender isOn]){
125      NSLog(@"DEBUG: Tilt Sensor Enabled");
126      [_switchTiltSensorControlThrottle setEnabled:YES];
127   } else{
128      NSLog(@"DEBUG: Tilt Sensor Disabled");
129      [_switchTiltSensorControlThrottle setOn:NO animated:YES];
130      [_switchTiltSensorControlThrottle setEnabled:NO];
131   }
132   
133}
134
135//- (void)changeSwitchTiltSensorControlThrottle:(id)sender{
136- (IBAction)changeSwitchTiltSensorControlThrottle:(id)sender{
137   
138   if([sender isOn]){
139      NSLog(@"DEBUG: Throttle Tilt Sensor Enabled");
140   } else{
141      NSLog(@"DEBUG: Throttle Tilt Sensor Disabled");
142   }
143   
144}
145
146@end
Note: See TracBrowser for help on using the repository browser.