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
 
25
#import "OsdValue.h"
26
#import "MKConnectionController.h"
27
#import "NSData+MKCommandEncode.h"
28
#import "MKDatatypes.h"
29
#import "MKDataConstants.h"
30
 
31
@interface OsdValue()
32
- (void) sendOsdRefreshRequest;
33
- (void) osdNotification:(NSNotification *)aNotification;
34
@end
35
 
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37
 
38
@implementation OsdValue
39
 
40
@synthesize delegate=_delegate;
41
 
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
 
44
- (id) init
45
{
46
  self = [super init];
47
  if (self != nil) {
48
    NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
49
 
50
    [nc addObserver:self
51
           selector:@selector(osdNotification:)
52
               name:MKOsdNotification
53
             object:nil];
54
 
55
    [self performSelector:@selector(sendOsdRefreshRequest) withObject:self afterDelay:0.1];
56
 
57
  }
58
  return self;
59
}
60
 
61
- (void) dealloc
62
{
63
  NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
64
  [nc removeObserver:self];
65
 
66
  [super dealloc];
67
}
68
 
69
 
70
- (void) sendOsdRefreshRequest {
71
  MKConnectionController * cCtrl = [MKConnectionController sharedMKConnectionController];
72
  uint8_t refresh=50;
73
 
74
  NSData * data = [NSData dataWithCommand:MKCommandOsdRequest
75
                               forAddress:MKAddressFC
76
                           payloadForByte:refresh];
77
 
78
  [cCtrl sendRequest:data];
79
}
80
 
81
- (void) osdNotification:(NSNotification *)aNotification {
82
 
83
  NSData *value = [[aNotification userInfo] objectForKey:kMKDataKeyRawValue];
84
 
85
  NaviData_t data;
86
 
87
  memcpy(&data,[value bytes],sizeof(data));
88
 
89
  [self.delegate newValue:&data];
90
 
91
  NSLog(@"osdCount=%d",lcdCount);
92
  if (lcdCount++ >= 7 ) {
93
    [self sendOsdRefreshRequest];
94
    lcdCount = 0;
95
  }
96
}
97
 
98
@end