source: orbit/iOS/Orbit/Orbit/controllers/AdvancedViewController.m @ 0a45bc8

Servo
Last change on this file since 0a45bc8 was 0a45bc8, checked in by Steve Castellotti <sc@…>, 6 years ago
  • Presets buttons added (Hover, Forward, Left and Right)
  • Property mode set to 100644
File size: 3.1 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   NSLog(@"DEBUG: hoverButtonPressed");
94}
95
96- (IBAction) forwardButtonPressed:(id)sender {
97   NSLog(@"DEBUG: forwardButtonPressed");
98}
99
100- (IBAction) leftButtonPressed:(id)sender {
101   NSLog(@"DEBUG: leftButtonPressed");
102}
103
104- (IBAction) rightButtonPressed:(id)sender {
105   NSLog(@"DEBUG: rightButtonPressed");
106}
107
108
109
110- (IBAction)changeSwitchTiltSensorControl:(id)sender{
111
112   if([sender isOn]){
113      NSLog(@"DEBUG: Tilt Sensor Enabled");
114      [_switchTiltSensorControlThrottle setEnabled:YES];
115   } else{
116      NSLog(@"DEBUG: Tilt Sensor Disabled");
117      [_switchTiltSensorControlThrottle setOn:NO animated:YES];
118      [_switchTiltSensorControlThrottle setEnabled:NO];
119   }
120   
121}
122
123- (IBAction)changeSwitchTiltSensorControlThrottle:(id)sender{
124   
125   if([sender isOn]){
126      NSLog(@"DEBUG: Throttle Tilt Sensor Enabled");
127   } else{
128      NSLog(@"DEBUG: Throttle Tilt Sensor Disabled");
129   }
130   
131}
132
133@end
Note: See TracBrowser for help on using the repository browser.