source: orbit/iOS/Orbit/Orbit/controllers/AdvancedViewController.m @ 7f21a20

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