source: orbit/iOS/Orbit/Orbit/controllers/AdvancedViewController.m @ 4a94f92

Servo
Last change on this file since 4a94f92 was 4a94f92, checked in by Steve Castellotti <sc@…>, 6 years ago
  • Comment cleanup
  • Property mode set to 100644
File size: 2.8 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) pitchChanged:(id) sender
38{
39    pitchPercent.text = [self percentStringFromSlider:pitch];
40    [self adjustValues];
41}
42
43- (IBAction) yawChanged:(id) sender
44{
45    yawPercent.text = [self percentStringFromSlider:yaw];
46    [self adjustValues];
47}
48
49- (IBAction) throttleChanged:(id) sender
50{
51    throttlePercent.text = [self percentStringFromSlider:throttle];
52    [self adjustValues];
53}
54
55- (NSString *) percentStringFromSlider:(UISlider *) slider
56{
57    return [NSString stringWithFormat:@"%i%%", (int)((slider.value - 0.5) * 200)]; // between -100% and 100%
58}
59
60- (void) adjustValues
61{
62    [signalConverter setYaw:[self yawValue]throttle:[self throttleValue] pitch:[self pitchValue]];
63}
64
65- (int) yawValue
66{
67    return round(yaw.value * 100);
68}
69
70- (int) pitchValue
71{
72    return round(pitch.value * 100);
73}
74
75- (int) throttleValue
76{
77    return round(throttle.value * 100);
78}
79
80- (IBAction) resetButtonPressed:(id)button
81{
82    pitch.value = 0.5;
83    yaw.value = 0.5;
84    throttle.value = 0.5;
85    NSString *zero = @"0%";
86    throttlePercent.text = zero;
87    yawPercent.text = zero;
88    pitchPercent.text = zero;
89    [self adjustValues];
90}
91
92- (IBAction)changeSwitchTiltSensorControl:(id)sender{
93
94   if([sender isOn]){
95      NSLog(@"DEBUG: Tilt Sensor Enabled");
96      [_switchTiltSensorControlThrottle setEnabled:YES];
97   } else{
98      NSLog(@"DEBUG: Tilt Sensor Disabled");
99      [_switchTiltSensorControlThrottle setOn:NO animated:YES];
100      [_switchTiltSensorControlThrottle setEnabled:NO];
101   }
102   
103}
104
105- (IBAction)changeSwitchTiltSensorControlThrottle:(id)sender{
106   
107   if([sender isOn]){
108      NSLog(@"DEBUG: Throttle Tilt Sensor Enabled");
109   } else{
110      NSLog(@"DEBUG: Throttle Tilt Sensor Disabled");
111   }
112   
113}
114
115@end
Note: See TracBrowser for help on using the repository browser.