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 | |||
25 | #import "ChannelsViewController.h" |
||
26 | #import "ChannelsViewCell.h" |
||
27 | #import "MKConnectionController.h" |
||
28 | #import "NSData+MKCommandEncode.h" |
||
29 | #import "MKDatatypes.h" |
||
30 | #import "MKDataConstants.h" |
||
31 | |||
32 | #define kAnalogLabelFile @"AnalogLables.plist" |
||
33 | |||
34 | @interface ChannelsViewController (Private) |
||
35 | - (void) channelsValueNotification:(NSNotification *)aNotification; |
||
36 | - (void) requestChannelData; |
||
37 | @end |
||
38 | |||
39 | // /////////////////////////////////////////////////////////////////////////////// |
||
40 | |||
41 | @implementation ChannelsViewController |
||
42 | |||
43 | @synthesize updateTimer = _updateTimer; |
||
44 | |||
45 | #pragma mark - |
||
46 | #pragma mark View lifecycle |
||
47 | |||
48 | - (void) viewDidLoad { |
||
49 | [super viewDidLoad]; |
||
50 | |||
51 | |||
52 | } |
||
53 | |||
54 | - (void) viewWillAppear:(BOOL)animated { |
||
55 | |||
56 | NSNotificationCenter * nc = [NSNotificationCenter defaultCenter]; |
||
57 | [nc addObserver:self |
||
58 | selector:@selector(channelsValueNotification:) |
||
59 | name:MKChannelValuesNotification |
||
60 | object:nil]; |
||
61 | |||
62 | [super viewWillAppear:animated]; |
||
63 | |||
64 | self.updateTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 |
||
65 | target:self |
||
66 | selector:@selector(requestChannelData) |
||
67 | userInfo:nil |
||
68 | repeats:YES]; |
||
69 | [self requestChannelData]; |
||
70 | } |
||
71 | |||
72 | - (void) viewDidDisappear:(BOOL)animated { |
||
73 | |||
74 | [self.updateTimer invalidate]; |
||
75 | self.updateTimer=nil; |
||
76 | [_updateTimer release]; |
||
77 | |||
78 | NSNotificationCenter * nc = [NSNotificationCenter defaultCenter]; |
||
79 | [nc removeObserver:self]; |
||
80 | |||
81 | [super viewDidDisappear:animated]; |
||
82 | } |
||
83 | |||
84 | #pragma mark - |
||
85 | #pragma mark Memory management |
||
86 | |||
87 | - (void) didReceiveMemoryWarning { |
||
88 | [super didReceiveMemoryWarning]; |
||
89 | } |
||
90 | |||
91 | - (void) viewDidUnload { |
||
92 | } |
||
93 | |||
94 | - (void) dealloc { |
||
95 | [super dealloc]; |
||
96 | } |
||
97 | |||
98 | // //////////////////////////////////////////////////////////////////////////////////////////// |
||
99 | #pragma mark - |
||
100 | |||
101 | - (void) requestChannelData { |
||
102 | |||
103 | MKConnectionController * cCtrl = [MKConnectionController sharedMKConnectionController]; |
||
104 | NSData * data = [NSData dataWithCommand:MKCommandChannelsValueRequest |
||
105 | forAddress:MKAddressFC |
||
106 | payloadWithBytes:NULL |
||
107 | length:0]; |
||
108 | |||
109 | [cCtrl sendRequest:data]; |
||
110 | } |
||
111 | |||
112 | - (void) channelsValueNotification:(NSNotification *)aNotification { |
||
113 | |||
114 | NSData* data = [[aNotification userInfo] objectForKey:kMKDataKeyChannels]; |
||
115 | |||
116 | if([data length]>=sizeof(channelValues)) |
||
117 | memcpy(channelValues, [data bytes], sizeof(channelValues)); |
||
118 | |||
119 | [self.tableView reloadData]; |
||
120 | } |
||
121 | |||
122 | |||
123 | #pragma mark - |
||
124 | #pragma mark Table view data source |
||
125 | |||
126 | - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
||
127 | // Return the number of sections. |
||
128 | return 1; |
||
129 | } |
||
130 | |||
131 | - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
||
132 | return sizeof(channelValues); |
||
133 | } |
||
134 | |||
135 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
||
136 | static NSString * CellIdentifier = @"ChannelsTableCell"; |
||
137 | |||
138 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
||
139 | |||
140 | if (cell == nil) { |
||
141 | cell = [[[ChannelsViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; |
||
142 | } |
||
143 | |||
144 | cell.textLabel.text = [NSString stringWithFormat:@"Channel %d",indexPath.row]; |
||
145 | [(ChannelsViewCell*)cell setChannelValue:channelValues[indexPath.row]]; |
||
146 | cell.detailTextLabel.hidden = YES;//.text = [NSString stringWithFormat:@"%d",channelValues[indexPath.row]]; |
||
147 | |||
148 | return cell; |
||
149 | } |
||
150 | |||
151 | #pragma mark - |
||
152 | #pragma mark Table view delegate |
||
153 | |||
154 | - (NSIndexPath *) tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
||
155 | return nil; |
||
156 | } |
||
157 | |||
158 | @end |
||
159 |