Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
805 - 1
// ///////////////////////////////////////////////////////////////////////////////
2
// Copyright (C) 2010, Frank Blumenberg
3
//
4
// See License.txt for complete licensing and attribution information.
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included in all
13
// copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
// THE SOFTWARE.
22
//
23
// ///////////////////////////////////////////////////////////////////////////////
24
#import "EngineValues.h"
25
#import "EngineTestViewController.h"
26
#import "EngineTestSliderCell.h"
27
#import "TTCorePreprocessorMacros.h"
28
 
29
 
30
//////////////////////////////////////////////////////////////////////////////////////////////
31
 
32
@interface EngineTestViewController ()
33
- (IBAction)engineValueChangedForAllAction:(UISlider *)sender;
34
- (IBAction)engineValueChangedAction:(UISlider *)sender;
35
@end
36
 
37
//////////////////////////////////////////////////////////////////////////////////////////////
38
@implementation EngineTestViewController
39
 
40
#pragma mark -
41
#pragma mark View lifecycle
42
 
43
 
44
- (void)viewDidLoad {
45
  [super viewDidLoad];
46
 
47
  UIBarButtonItem* spacer;
48
  spacer =  [[[UIBarButtonItem alloc]
49
              initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
50
              target:nil
51
              action:nil] autorelease];
52
 
53
  NSArray* segmentItems = [NSArray arrayWithObjects:@"Quadro",@"Hexa",@"Okto",nil];
54
  segment = [[UISegmentedControl alloc] initWithItems:segmentItems];
55
  segment.segmentedControlStyle=UISegmentedControlStyleBar;
56
 
57
  [segment addTarget:self
58
              action:@selector(changeDevice)
59
    forControlEvents:UIControlEventValueChanged];
60
 
61
  UIBarButtonItem* segmentButton;
62
  segmentButton =  [[[UIBarButtonItem alloc]
63
                     initWithCustomView:segment] autorelease];
64
 
65
        [self setToolbarItems:[NSArray arrayWithObjects:spacer,segmentButton,spacer,nil]];
66
 
67
  segment.selectedSegmentIndex=0;
68
}
69
 
70
 
71
//////////////////////////////////////////////////////////////////////////////////////////////
72
 
73
- (void)viewWillAppear:(BOOL)animated {
74
  [super viewWillAppear:animated];
75
 
76
  engineValues = [[EngineValues alloc] init];
77
}
78
 
79
- (void)viewDidAppear:(BOOL)animated {
80
  [super viewDidAppear:animated];
81
  [engineValues start];
82
}
83
 
84
- (void)viewWillDisappear:(BOOL)animated {
85
  [super viewWillDisappear:animated];
86
  [engineValues stop];
87
  TT_RELEASE_SAFELY(engineValues);
88
}
89
 
90
- (void)viewDidDisappear:(BOOL)animated {
91
  [super viewDidDisappear:animated];
92
}
93
 
94
//////////////////////////////////////////////////////////////////////////////////////////////
95
#pragma mark -
96
#pragma mark Table view data source
97
 
98
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
99
  // Return the number of sections.
100
  return 2;
101
}
102
 
103
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
104
 
105
  if(section==0)
106
    return 1;
107
 
108
  // Return the number of rows in the section.
109
  static NSInteger numberOfRows[3]={4,6,8};
110
  return numberOfRows[segment.selectedSegmentIndex];
111
}
112
 
113
- (IBAction) changeDevice {
114
  [self.tableView reloadData];
115
}
116
 
117
 
118
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
119
 
120
  static NSString *CellIdentifier = @"MotorTestSliderCell";
121
 
122
  EngineTestSliderCell *cell = (EngineTestSliderCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
123
  if (cell == nil) {
124
    cell = [[[EngineTestSliderCell alloc] initWithReuseIdentifier:CellIdentifier] autorelease];
125
  }
126
 
127
  if(indexPath.section==0 ) {
128
    cell.textLabel.text = [NSString stringWithFormat:@"All", [indexPath row]];
129
 
130
    [cell.valueSlider addTarget:self
131
                         action:@selector(engineValueChangedForAllAction:)
132
               forControlEvents:UIControlEventValueChanged ];
133
  }
134
  else {
135
 
136
    cell.textLabel.text = [NSString stringWithFormat:@"Motor %d", [indexPath row]+1];
137
    cell.valueSlider.tag = indexPath.row;
138
 
139
    [cell.valueSlider addTarget:self
140
                         action:@selector(engineValueChangedAction:)
141
               forControlEvents:UIControlEventValueChanged];
142
  }
143
 
144
  return cell;
145
}
146
 
147
//////////////////////////////////////////////////////////////////////////////////////////////
148
#pragma mark -
149
 
150
- (IBAction)engineValueChangedForAllAction:(UISlider *)sender {
151
  [engineValues setValueForAllEngines:(uint8_t)(sender.value*255.0)];
152
}
153
 
154
- (IBAction)engineValueChangedAction:(UISlider *)sender {
155
  NSInteger theEngine=sender.tag;
156
  [engineValues setValueForEngine:theEngine value:(uint8_t)(sender.value*255.0)];
157
}
158
 
159
 
160
 
161
//////////////////////////////////////////////////////////////////////////////////////////////
162
#pragma mark -
163
#pragma mark Table view delegate
164
 
165
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
166
  return nil;
167
}
168
 
169
//////////////////////////////////////////////////////////////////////////////////////////////
170
#pragma mark -
171
#pragma mark Memory management
172
 
173
- (void)didReceiveMemoryWarning {
174
  [super didReceiveMemoryWarning];
175
}
176
 
177
- (void)viewDidUnload {
178
  TT_RELEASE_SAFELY(segment);
179
}
180
 
181
 
182
- (void)dealloc {
183
  TT_RELEASE_SAFELY(engineValues);
184
  [super dealloc];
185
}
186
 
187
 
188
@end
189