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

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