Commit 6af754c1349b9d1329c94a85b1a09b59dc852d17
1 parent
ac650a20
--no commit message
Showing
15 changed files
with
711 additions
and
118 deletions
DUREX Vendor Control/CommunicationProtocol.h
0 → 100644
1 | +// | |
2 | +// CommunicationProtocol.h | |
3 | +// DUREX Vendor Control | |
4 | +// | |
5 | +// Created by Imanol Barba on 5/23/14. | |
6 | +// Copyright (c) 2014 Emmoco. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#import <Foundation/Foundation.h> | |
10 | +#import "EMFramework.h" | |
11 | + | |
12 | +#define MAX_STRING_LENGTH ((int)227) | |
13 | +#define MAX_RETRIES ((int)3) | |
14 | + | |
15 | +@interface CommunicationProtocol : NSObject | |
16 | + | |
17 | +-(Boolean) waitForMessageAvailable: (Boolean) status; | |
18 | +-(Boolean) writeMessage: (NSString*) message; | |
19 | +-(NSString*) readMessage; | |
20 | +-(Boolean) establishConnection; | |
21 | ++(id) sharedProtocol; | |
22 | +@property Boolean messageAvailable; | |
23 | + | |
24 | +@end | ... | ... |
DUREX Vendor Control/CommunicationProtocol.m
0 → 100644
1 | +// | |
2 | +// CommunicationProtocol.m | |
3 | +// DUREX Vendor Control | |
4 | +// | |
5 | +// Created by Imanol Barba on 5/23/14. | |
6 | +// Copyright (c) 2014 Emmoco. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#import "CommunicationProtocol.h" | |
10 | + | |
11 | +@interface CommunicationProtocol () | |
12 | + | |
13 | +@end | |
14 | + | |
15 | +@implementation CommunicationProtocol | |
16 | + | |
17 | ++ (id)sharedProtocol { | |
18 | + static CommunicationProtocol *shared = nil; | |
19 | + static dispatch_once_t onceToken; | |
20 | + dispatch_once(&onceToken, ^{ | |
21 | + shared = [[self alloc] init]; | |
22 | + }); | |
23 | + return shared; | |
24 | +} | |
25 | + | |
26 | +-(Boolean) waitForMessageAvailable: (Boolean) status | |
27 | +{ | |
28 | + uint8_t retries = 0; | |
29 | + while([self messageAvailable] != status) | |
30 | + { | |
31 | + [NSThread sleepForTimeInterval:5]; | |
32 | + if([self messageAvailable] != status) | |
33 | + { | |
34 | + if(retries++ == MAX_RETRIES) | |
35 | + { | |
36 | + return FALSE; | |
37 | + } | |
38 | + } | |
39 | + } | |
40 | + return TRUE; | |
41 | +} | |
42 | + | |
43 | +-(NSString*) readMessage | |
44 | +{ | |
45 | + __block uint8_t numPackets, numBytes; | |
46 | + __block NSMutableString *message; | |
47 | + [message setString:@""]; | |
48 | + if([self waitForMessageAvailable:TRUE]) | |
49 | + { | |
50 | + [[EMConnectionManager sharedManager] readResource:@"numPackets" onSuccess:^(id readValue) | |
51 | + { | |
52 | + numPackets = (uint8_t) [readValue unsignedCharValue]; | |
53 | + } | |
54 | + onFail:^(NSError *error) | |
55 | + { | |
56 | + NSLog(@"%@",error); | |
57 | + numPackets = 0; | |
58 | + }]; | |
59 | + if(numPackets) | |
60 | + { | |
61 | + for(int i = 0; i < numPackets; i++) | |
62 | + { | |
63 | + [[EMConnectionManager sharedManager] readResource:@"numBytes" onSuccess:^(id readValue) | |
64 | + { | |
65 | + numBytes = (uint8_t) [readValue unsignedCharValue]; | |
66 | + } | |
67 | + onFail:^(NSError *error) | |
68 | + { | |
69 | + NSLog(@"%@",error); | |
70 | + numBytes = 0; | |
71 | + }]; | |
72 | + if(numBytes) | |
73 | + { | |
74 | + [[EMConnectionManager sharedManager] readResource:@"data" onSuccess:^(id readValue) | |
75 | + { | |
76 | + [message appendString:[readValue stringValue]]; | |
77 | + } | |
78 | + onFail:^(NSError *error) | |
79 | + { | |
80 | + NSLog(@"%@",error); | |
81 | + }]; | |
82 | + } | |
83 | + } | |
84 | + } | |
85 | + } | |
86 | + [[EMConnectionManager sharedManager] writeValue:@"FALSE" toResource:@"messageAvailable" onSuccess:^ | |
87 | + { | |
88 | + | |
89 | + } | |
90 | + onFail:^(NSError *error) | |
91 | + { | |
92 | + NSLog(@"%@",error); | |
93 | + } | |
94 | + ]; | |
95 | + return message; | |
96 | +} | |
97 | + | |
98 | +-(Boolean) writeMessage: (NSString*) message | |
99 | +{ | |
100 | + unsigned long remainingBytes = [message length]; | |
101 | + uint8_t numBytes, current_index = 0; | |
102 | + __block Boolean status = FALSE; | |
103 | + [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithUnsignedChar:(unsigned char)([message length]/MAX_STRING_LENGTH)+1] toResource:@"numPackets" onSuccess:^ | |
104 | + { | |
105 | + status = TRUE; | |
106 | + } | |
107 | + onFail:^(NSError *error) | |
108 | + { | |
109 | + NSLog(@"%@",error); | |
110 | + status = FALSE; | |
111 | + } | |
112 | + ]; | |
113 | + if(status != FALSE) | |
114 | + { | |
115 | + while(remainingBytes) | |
116 | + { | |
117 | + if(![self waitForMessageAvailable:FALSE]) | |
118 | + { | |
119 | + status = FALSE; | |
120 | + break; | |
121 | + } | |
122 | + if(remainingBytes > MAX_STRING_LENGTH) | |
123 | + { | |
124 | + numBytes = MAX_STRING_LENGTH; | |
125 | + remainingBytes -= MAX_STRING_LENGTH; | |
126 | + } | |
127 | + else | |
128 | + { | |
129 | + numBytes = remainingBytes; | |
130 | + remainingBytes = 0; | |
131 | + } | |
132 | + [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithUnsignedChar:(unsigned char)numBytes] toResource:@"data" onSuccess:^ | |
133 | + { | |
134 | + status = TRUE; | |
135 | + } | |
136 | + onFail:^(NSError *error) | |
137 | + { | |
138 | + NSLog(@"%@",error); | |
139 | + status = FALSE; | |
140 | + } | |
141 | + ]; | |
142 | + if(status != FALSE) | |
143 | + { | |
144 | + NSString *data = [message substringWithRange:NSMakeRange(current_index, numBytes)]; | |
145 | + current_index += numBytes; | |
146 | + [[EMConnectionManager sharedManager] writeValue:data toResource:@"data" onSuccess:^ | |
147 | + { | |
148 | + status = TRUE; | |
149 | + } | |
150 | + onFail:^(NSError *error) | |
151 | + { | |
152 | + NSLog(@"%@",error); | |
153 | + status = FALSE; | |
154 | + } | |
155 | + ]; | |
156 | + if(status != FALSE) | |
157 | + { | |
158 | + [[EMConnectionManager sharedManager] writeValue:@"TRUE" toResource:@"messageAvailable" onSuccess:^ | |
159 | + { | |
160 | + status = TRUE; | |
161 | + } | |
162 | + onFail:^(NSError *error) | |
163 | + { | |
164 | + NSLog(@"%@",error); | |
165 | + status = FALSE; | |
166 | + } | |
167 | + ]; | |
168 | + } | |
169 | + } | |
170 | + } | |
171 | + } | |
172 | + return status; | |
173 | +} | |
174 | + | |
175 | +-(Boolean) establishConnection | |
176 | +{ | |
177 | + if([self writeMessage:@"Hello"]) | |
178 | + { | |
179 | + NSString *answer = [self readMessage]; | |
180 | + if([answer isEqualToString:@"Hello"]) | |
181 | + { | |
182 | + return TRUE; | |
183 | + } | |
184 | + } | |
185 | + return FALSE; | |
186 | +} | |
187 | + | |
188 | +@end | ... | ... |
DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj
... | ... | @@ -18,10 +18,13 @@ |
18 | 18 | 34AAB883189804FF0019860D /* DUREXAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AAB877189804FF0019860D /* DUREXAppDelegate.m */; }; |
19 | 19 | 34AAB884189804FF0019860D /* EMConnectingView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34AAB878189804FF0019860D /* EMConnectingView.xib */; }; |
20 | 20 | 34AAB885189804FF0019860D /* EMDevicePickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AAB87A189804FF0019860D /* EMDevicePickerViewController.m */; }; |
21 | - 34AAB886189804FF0019860D /* DUREXAppViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AAB87C189804FF0019860D /* DUREXAppViewController.m */; }; | |
22 | 21 | 34AAB889189804FF0019860D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AAB880189804FF0019860D /* main.m */; }; |
23 | 22 | 34AAB88A189804FF0019860D /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 34AAB881189804FF0019860D /* MainStoryboard.storyboard */; }; |
24 | 23 | 34AAB88D189805300019860D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 34AAB88C189805300019860D /* Images.xcassets */; }; |
24 | + F98356D6192E835F00EA6821 /* InitialViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F98356D5192E835F00EA6821 /* InitialViewController.m */; }; | |
25 | + F98356D8192E906600EA6821 /* bluetooth.png in Resources */ = {isa = PBXBuildFile; fileRef = F98356D7192E906600EA6821 /* bluetooth.png */; }; | |
26 | + F98356DB192EAFD400EA6821 /* CommunicationProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = F98356DA192EAFD400EA6821 /* CommunicationProtocol.m */; }; | |
27 | + F98356E1192EC84700EA6821 /* MenuTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F98356E0192EC84700EA6821 /* MenuTableViewController.m */; }; | |
25 | 28 | F9C77F4E192CDE18002DBE8A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F9C77F4C192CDE18002DBE8A /* InfoPlist.strings */; }; |
26 | 29 | F9C77F50192CDE30002DBE8A /* durex.json in Resources */ = {isa = PBXBuildFile; fileRef = F9C77F4F192CDE30002DBE8A /* durex.json */; }; |
27 | 30 | /* End PBXBuildFile section */ |
... | ... | @@ -64,13 +67,18 @@ |
64 | 67 | 34AAB878189804FF0019860D /* EMConnectingView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = EMConnectingView.xib; path = FirstAppExample/EMConnectingView.xib; sourceTree = SOURCE_ROOT; }; |
65 | 68 | 34AAB879189804FF0019860D /* EMDevicePickerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EMDevicePickerViewController.h; path = FirstAppExample/EMDevicePickerViewController.h; sourceTree = SOURCE_ROOT; }; |
66 | 69 | 34AAB87A189804FF0019860D /* EMDevicePickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EMDevicePickerViewController.m; path = FirstAppExample/EMDevicePickerViewController.m; sourceTree = SOURCE_ROOT; }; |
67 | - 34AAB87B189804FF0019860D /* DUREXAppViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DUREXAppViewController.h; path = FirstAppExample/DUREXAppViewController.h; sourceTree = SOURCE_ROOT; }; | |
68 | - 34AAB87C189804FF0019860D /* DUREXAppViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DUREXAppViewController.m; path = FirstAppExample/DUREXAppViewController.m; sourceTree = SOURCE_ROOT; }; | |
69 | 70 | 34AAB87E189804FF0019860D /* DUREX Vendor Control-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "DUREX Vendor Control-Info.plist"; path = "FirstAppExample/DUREX Vendor Control-Info.plist"; sourceTree = SOURCE_ROOT; }; |
70 | 71 | 34AAB87F189804FF0019860D /* DUREX Vendor Control-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "DUREX Vendor Control-Prefix.pch"; path = "FirstAppExample/DUREX Vendor Control-Prefix.pch"; sourceTree = SOURCE_ROOT; }; |
71 | 72 | 34AAB880189804FF0019860D /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = FirstAppExample/main.m; sourceTree = SOURCE_ROOT; }; |
72 | 73 | 34AAB881189804FF0019860D /* MainStoryboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = MainStoryboard.storyboard; path = FirstAppExample/MainStoryboard.storyboard; sourceTree = SOURCE_ROOT; }; |
73 | 74 | 34AAB88C189805300019860D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = FirstAppExample/Images.xcassets; sourceTree = SOURCE_ROOT; }; |
75 | + F98356D4192E835F00EA6821 /* InitialViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InitialViewController.h; sourceTree = SOURCE_ROOT; }; | |
76 | + F98356D5192E835F00EA6821 /* InitialViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InitialViewController.m; sourceTree = SOURCE_ROOT; }; | |
77 | + F98356D7192E906600EA6821 /* bluetooth.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bluetooth.png; sourceTree = SOURCE_ROOT; }; | |
78 | + F98356D9192EAFD400EA6821 /* CommunicationProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommunicationProtocol.h; sourceTree = SOURCE_ROOT; }; | |
79 | + F98356DA192EAFD400EA6821 /* CommunicationProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommunicationProtocol.m; sourceTree = SOURCE_ROOT; }; | |
80 | + F98356DF192EC84700EA6821 /* MenuTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuTableViewController.h; sourceTree = SOURCE_ROOT; }; | |
81 | + F98356E0192EC84700EA6821 /* MenuTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MenuTableViewController.m; sourceTree = SOURCE_ROOT; }; | |
74 | 82 | F9C77F4D192CDE18002DBE8A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = FirstAppExample/en.lproj/InfoPlist.strings; sourceTree = SOURCE_ROOT; }; |
75 | 83 | F9C77F4F192CDE30002DBE8A /* durex.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = durex.json; sourceTree = SOURCE_ROOT; }; |
76 | 84 | /* End PBXFileReference section */ |
... | ... | @@ -137,8 +145,12 @@ |
137 | 145 | 34AAB881189804FF0019860D /* MainStoryboard.storyboard */, |
138 | 146 | 34AAB876189804FF0019860D /* DUREXAppDelegate.h */, |
139 | 147 | 34AAB877189804FF0019860D /* DUREXAppDelegate.m */, |
140 | - 34AAB87B189804FF0019860D /* DUREXAppViewController.h */, | |
141 | - 34AAB87C189804FF0019860D /* DUREXAppViewController.m */, | |
148 | + F98356D4192E835F00EA6821 /* InitialViewController.h */, | |
149 | + F98356D5192E835F00EA6821 /* InitialViewController.m */, | |
150 | + F98356DF192EC84700EA6821 /* MenuTableViewController.h */, | |
151 | + F98356E0192EC84700EA6821 /* MenuTableViewController.m */, | |
152 | + F98356D9192EAFD400EA6821 /* CommunicationProtocol.h */, | |
153 | + F98356DA192EAFD400EA6821 /* CommunicationProtocol.m */, | |
142 | 154 | 34AAB88C189805300019860D /* Images.xcassets */, |
143 | 155 | 347186B91807290E00FA0FB2 /* Schemas */, |
144 | 156 | 347186A718070F7F00FA0FB2 /* Device Picker */, |
... | ... | @@ -152,6 +164,7 @@ |
152 | 164 | 3471866718070D9300FA0FB2 /* Supporting Files */ = { |
153 | 165 | isa = PBXGroup; |
154 | 166 | children = ( |
167 | + F98356D7192E906600EA6821 /* bluetooth.png */, | |
155 | 168 | 34AAB87E189804FF0019860D /* DUREX Vendor Control-Info.plist */, |
156 | 169 | 34AAB87F189804FF0019860D /* DUREX Vendor Control-Prefix.pch */, |
157 | 170 | 34AAB880189804FF0019860D /* main.m */, |
... | ... | @@ -285,6 +298,7 @@ |
285 | 298 | isa = PBXResourcesBuildPhase; |
286 | 299 | buildActionMask = 2147483647; |
287 | 300 | files = ( |
301 | + F98356D8192E906600EA6821 /* bluetooth.png in Resources */, | |
288 | 302 | 34AAB884189804FF0019860D /* EMConnectingView.xib in Resources */, |
289 | 303 | F9C77F50192CDE30002DBE8A /* durex.json in Resources */, |
290 | 304 | F9C77F4E192CDE18002DBE8A /* InfoPlist.strings in Resources */, |
... | ... | @@ -307,9 +321,11 @@ |
307 | 321 | isa = PBXSourcesBuildPhase; |
308 | 322 | buildActionMask = 2147483647; |
309 | 323 | files = ( |
324 | + F98356D6192E835F00EA6821 /* InitialViewController.m in Sources */, | |
310 | 325 | 34AAB885189804FF0019860D /* EMDevicePickerViewController.m in Sources */, |
311 | 326 | 34AAB883189804FF0019860D /* DUREXAppDelegate.m in Sources */, |
312 | - 34AAB886189804FF0019860D /* DUREXAppViewController.m in Sources */, | |
327 | + F98356DB192EAFD400EA6821 /* CommunicationProtocol.m in Sources */, | |
328 | + F98356E1192EC84700EA6821 /* MenuTableViewController.m in Sources */, | |
313 | 329 | 34AAB889189804FF0019860D /* main.m in Sources */, |
314 | 330 | ); |
315 | 331 | runOnlyForDeploymentPostprocessing = 0; | ... | ... |
DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate
No preview for this file type
DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
... | ... | @@ -2,4 +2,22 @@ |
2 | 2 | <Bucket |
3 | 3 | type = "1" |
4 | 4 | version = "2.0"> |
5 | + <Breakpoints> | |
6 | + <BreakpointProxy | |
7 | + BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> | |
8 | + <BreakpointContent | |
9 | + shouldBeEnabled = "Yes" | |
10 | + ignoreCount = "0" | |
11 | + continueAfterRunningActions = "No" | |
12 | + filePath = "CommunicationProtocol.m" | |
13 | + timestampString = "422490789.923751" | |
14 | + startingColumnNumber = "9223372036854775807" | |
15 | + endingColumnNumber = "9223372036854775807" | |
16 | + startingLineNumber = "20" | |
17 | + endingLineNumber = "20" | |
18 | + landmarkName = "+sharedProtocol" | |
19 | + landmarkType = "5"> | |
20 | + </BreakpointContent> | |
21 | + </BreakpointProxy> | |
22 | + </Breakpoints> | |
5 | 23 | </Bucket> | ... | ... |
DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcschemes/DUREX Vendor Control.xcscheme
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | <BuildableReference |
16 | 16 | BuildableIdentifier = "primary" |
17 | 17 | BlueprintIdentifier = "3471865C18070D9300FA0FB2" |
18 | - BuildableName = "FirstApp.app" | |
18 | + BuildableName = "DUREX Vendor Control.app" | |
19 | 19 | BlueprintName = "DUREX Vendor Control" |
20 | 20 | ReferencedContainer = "container:DUREX Vendor Control.xcodeproj"> |
21 | 21 | </BuildableReference> |
... | ... | @@ -33,7 +33,7 @@ |
33 | 33 | <BuildableReference |
34 | 34 | BuildableIdentifier = "primary" |
35 | 35 | BlueprintIdentifier = "3471867718070D9300FA0FB2" |
36 | - BuildableName = "FirstAppTests.xctest" | |
36 | + BuildableName = "DUREX Vendor ControlTests.xctest" | |
37 | 37 | BlueprintName = "DUREX Vendor ControlTests" |
38 | 38 | ReferencedContainer = "container:DUREX Vendor Control.xcodeproj"> |
39 | 39 | </BuildableReference> |
... | ... | @@ -43,7 +43,7 @@ |
43 | 43 | <BuildableReference |
44 | 44 | BuildableIdentifier = "primary" |
45 | 45 | BlueprintIdentifier = "3471865C18070D9300FA0FB2" |
46 | - BuildableName = "FirstApp.app" | |
46 | + BuildableName = "DUREX Vendor Control.app" | |
47 | 47 | BlueprintName = "DUREX Vendor Control" |
48 | 48 | ReferencedContainer = "container:DUREX Vendor Control.xcodeproj"> |
49 | 49 | </BuildableReference> |
... | ... | @@ -62,7 +62,7 @@ |
62 | 62 | <BuildableReference |
63 | 63 | BuildableIdentifier = "primary" |
64 | 64 | BlueprintIdentifier = "3471865C18070D9300FA0FB2" |
65 | - BuildableName = "FirstApp.app" | |
65 | + BuildableName = "DUREX Vendor Control.app" | |
66 | 66 | BlueprintName = "DUREX Vendor Control" |
67 | 67 | ReferencedContainer = "container:DUREX Vendor Control.xcodeproj"> |
68 | 68 | </BuildableReference> |
... | ... | @@ -80,7 +80,7 @@ |
80 | 80 | <BuildableReference |
81 | 81 | BuildableIdentifier = "primary" |
82 | 82 | BlueprintIdentifier = "3471865C18070D9300FA0FB2" |
83 | - BuildableName = "FirstApp.app" | |
83 | + BuildableName = "DUREX Vendor Control.app" | |
84 | 84 | BlueprintName = "DUREX Vendor Control" |
85 | 85 | ReferencedContainer = "container:DUREX Vendor Control.xcodeproj"> |
86 | 86 | </BuildableReference> | ... | ... |
DUREX Vendor Control/FirstAppExample/DUREXAppDelegate.h
DUREX Vendor Control/FirstAppExample/DUREXAppViewController.h
1 | 1 | #import <UIKit/UIKit.h> |
2 | 2 | |
3 | -@interface DUREXAppViewController : UIViewController | |
4 | 3 | |
5 | -@property (nonatomic, strong) IBOutlet UILabel *valueLabel; | |
6 | -@property (nonatomic, strong) IBOutlet UISlider *valueSlider; | |
4 | +@interface DUREXAppViewController : UITableViewController | |
7 | 5 | |
8 | 6 | |
9 | 7 | ... | ... |
DUREX Vendor Control/FirstAppExample/DUREXAppViewController.m
1 | 1 | #import "DUREXAppViewController.h" |
2 | 2 | #import "EMFramework.h" |
3 | +#import "CommunicationProtocol.h" | |
3 | 4 | |
4 | 5 | @interface DUREXAppViewController () |
5 | 6 | { |
6 | 7 | IBOutlet UIActivityIndicatorView *_activityIndicator; |
7 | 8 | NSTimer *_writeTimer; |
8 | 9 | } |
10 | +@property (nonatomic,strong) CommunicationProtocol* protocol; | |
9 | 11 | |
10 | 12 | @end |
11 | 13 | |
... | ... | @@ -25,33 +27,35 @@ |
25 | 27 | { |
26 | 28 | [super viewDidLoad]; |
27 | 29 | [_activityIndicator setHidden:YES]; |
28 | - [self setTitle:[[[EMConnectionManager sharedManager] connectedDevice] name]]; | |
29 | - [[EMConnectionManager sharedManager] readResource:@"data" onSuccess:^(id readValue) | |
30 | - { | |
31 | - [[self valueLabel] setText:[NSString stringWithFormat:@"%d", [readValue intValue]]]; | |
32 | - [[self valueSlider] setValue:[readValue floatValue]]; | |
33 | - } | |
34 | - onFail:^(NSError *error) | |
35 | - { | |
36 | - | |
37 | - } | |
38 | - ]; | |
39 | - | |
30 | + [self setTitle:@"DUREX Vendor Control"]; | |
31 | + _protocol = [CommunicationProtocol sharedProtocol]; | |
40 | 32 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotification:) name:kEMConnectionDidReceiveIndicatorNotificationName object:nil]; |
41 | - | |
42 | 33 | [[EMConnectionManager sharedManager] addObserver:self forKeyPath:@"connectionState" options:0 context:NULL]; |
34 | + [_protocol setMessageAvailable:false]; | |
43 | 35 | } |
44 | 36 | |
45 | 37 | -(void)didReceiveNotification:(NSNotification*) notification |
46 | 38 | { |
47 | 39 | id notificationValue = [[notification userInfo] objectForKey:kEMIndicatorResourceValueKey]; |
48 | 40 | NSString *resourceName = [[notification userInfo] objectForKey:kEMIndicatorNameKey]; |
49 | - NSString *resourceValue = [notificationValue stringValue]; | |
41 | + if([resourceName isEqualToString:@"messageAvailable"]) | |
42 | + { | |
43 | + NSString *resourceValue = [notificationValue stringValue]; | |
44 | + if([resourceValue isEqualToString:@"TRUE"]) | |
45 | + { | |
46 | + [_protocol setMessageAvailable:TRUE]; | |
47 | + } | |
48 | + else | |
49 | + { | |
50 | + [_protocol setMessageAvailable:FALSE]; | |
51 | + } | |
52 | + } | |
50 | 53 | } |
51 | 54 | |
52 | 55 | -(void)dealloc |
53 | 56 | { |
54 | 57 | [[EMConnectionManager sharedManager] removeObserver:self forKeyPath:@"connectionState"]; |
58 | + [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
55 | 59 | } |
56 | 60 | |
57 | 61 | -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context |
... | ... | @@ -68,66 +72,6 @@ |
68 | 72 | } |
69 | 73 | } |
70 | 74 | |
71 | --(NSString*) readMessage | |
72 | -{ | |
73 | - | |
74 | -} | |
75 | - | |
76 | --(Boolean) writeMessage: (NSString*) message | |
77 | -{ | |
78 | - __block Boolean status = FALSE; | |
79 | - [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithFloat:[[self valueSlider] value]] toResource:@"data" onSuccess:^ | |
80 | - { | |
81 | - status = TRUE; | |
82 | - } | |
83 | - onFail:^(NSError *error) | |
84 | - { | |
85 | - NSLog(@"%@",error); | |
86 | - status = FALSE; | |
87 | - } | |
88 | - ]; | |
89 | - if(status != FALSE) | |
90 | - { | |
91 | - [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithFloat:[[self valueSlider] value]] toResource:@"data" onSuccess:^ | |
92 | - { | |
93 | - status = TRUE; | |
94 | - } | |
95 | - onFail:^(NSError *error) | |
96 | - { | |
97 | - NSLog(@"%@",error); | |
98 | - status = FALSE; | |
99 | - } | |
100 | - ]; | |
101 | - if(status != FALSE) | |
102 | - { | |
103 | - [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithFloat:[[self valueSlider] value]] toResource:@"data" onSuccess:^ | |
104 | - { | |
105 | - status = TRUE; | |
106 | - } | |
107 | - onFail:^(NSError *error) | |
108 | - { | |
109 | - NSLog(@"%@",error); | |
110 | - status = FALSE; | |
111 | - } | |
112 | - ]; | |
113 | - if(status != FALSE) | |
114 | - { | |
115 | - [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithFloat:[[self valueSlider] value]] toResource:@"data" onSuccess:^ | |
116 | - { | |
117 | - status = TRUE; | |
118 | - } | |
119 | - onFail:^(NSError *error) | |
120 | - { | |
121 | - NSLog(@"%@",error); | |
122 | - status = FALSE; | |
123 | - } | |
124 | - ]; | |
125 | - } | |
126 | - } | |
127 | - } | |
128 | - return status; | |
129 | -} | |
130 | - | |
131 | 75 | #pragma mark - Interface actions |
132 | 76 | |
133 | 77 | ... | ... |
DUREX Vendor Control/FirstAppExample/MainStoryboard.storyboard
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/> |
5 | 5 | </dependencies> |
6 | 6 | <scenes> |
7 | - <!--Device Picker View Controller - First App--> | |
7 | + <!--Device Picker View Controller - Select device--> | |
8 | 8 | <scene sceneID="ZOj-VY-rze"> |
9 | 9 | <objects> |
10 | 10 | <tableViewController id="0dd-lZ-pDC" customClass="EMDevicePickerViewController" sceneMemberID="viewController"> |
... | ... | @@ -43,42 +43,53 @@ |
43 | 43 | <outlet property="delegate" destination="0dd-lZ-pDC" id="xbT-YH-9tN"/> |
44 | 44 | </connections> |
45 | 45 | </tableView> |
46 | - <navigationItem key="navigationItem" title="First App" id="exc-MP-jDa"/> | |
46 | + <navigationItem key="navigationItem" title="Select device" id="exc-MP-jDa"/> | |
47 | 47 | <connections> |
48 | - <segue destination="brh-a3-PgF" kind="push" identifier="ConnectionSegue" id="eBT-lM-aOh"/> | |
48 | + <segue destination="iNx-eR-wSX" kind="push" identifier="ConnectionSegue" id="3oK-BK-2Qs"/> | |
49 | 49 | </connections> |
50 | 50 | </tableViewController> |
51 | 51 | <placeholder placeholderIdentifier="IBFirstResponder" id="MD6-l6-Rrg" userLabel="First Responder" sceneMemberID="firstResponder"/> |
52 | 52 | </objects> |
53 | - <point key="canvasLocation" x="400" y="83"/> | |
53 | + <point key="canvasLocation" x="342" y="-9"/> | |
54 | 54 | </scene> |
55 | - <!--First App View Controller--> | |
56 | - <scene sceneID="QfO-jZ-O0T"> | |
55 | + <!--Menu Table View Controller - Connected to: --> | |
56 | + <scene sceneID="uT2-Qs-t9O"> | |
57 | 57 | <objects> |
58 | - <viewController id="brh-a3-PgF" customClass="EMFirstAppViewController" sceneMemberID="viewController"> | |
59 | - <layoutGuides> | |
60 | - <viewControllerLayoutGuide type="top" id="2xn-Vq-kdj"/> | |
61 | - <viewControllerLayoutGuide type="bottom" id="10Y-bX-QaE"/> | |
62 | - </layoutGuides> | |
63 | - <view key="view" contentMode="scaleToFill" id="hQU-HR-dCR"> | |
58 | + <tableViewController id="iNx-eR-wSX" customClass="MenuTableViewController" sceneMemberID="viewController"> | |
59 | + <tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="Ovd-l7-PYp"> | |
64 | 60 | <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> |
65 | - <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | |
66 | - <subviews> | |
67 | - <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" editable="NO" text="THE GAME" selectable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0W0-sW-zLj"> | |
68 | - <rect key="frame" x="20" y="86" width="280" height="173"/> | |
69 | - <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | |
70 | - <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/> | |
71 | - <fontDescription key="fontDescription" type="system" pointSize="14"/> | |
72 | - <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/> | |
73 | - </textView> | |
74 | - </subviews> | |
75 | - <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> | |
76 | - </view> | |
77 | - <navigationItem key="navigationItem" id="2ME-k3-mFZ"/> | |
78 | - </viewController> | |
79 | - <placeholder placeholderIdentifier="IBFirstResponder" id="pLK-Yw-jB4" userLabel="First Responder" sceneMemberID="firstResponder"/> | |
61 | + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | |
62 | + <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | |
63 | + <prototypes> | |
64 | + <tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="MenuCell" textLabel="iCG-eW-H8x" style="IBUITableViewCellStyleDefault" id="dlr-pm-ct7"> | |
65 | + <rect key="frame" x="0.0" y="86" width="320" height="44"/> | |
66 | + <autoresizingMask key="autoresizingMask"/> | |
67 | + <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="dlr-pm-ct7" id="ohH-UH-dvu"> | |
68 | + <rect key="frame" x="0.0" y="0.0" width="287" height="43"/> | |
69 | + <autoresizingMask key="autoresizingMask"/> | |
70 | + <subviews> | |
71 | + <label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="iCG-eW-H8x"> | |
72 | + <rect key="frame" x="15" y="0.0" width="270" height="43"/> | |
73 | + <autoresizingMask key="autoresizingMask"/> | |
74 | + <fontDescription key="fontDescription" type="system" pointSize="18"/> | |
75 | + <color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | |
76 | + <nil key="highlightedColor"/> | |
77 | + </label> | |
78 | + </subviews> | |
79 | + </tableViewCellContentView> | |
80 | + </tableViewCell> | |
81 | + </prototypes> | |
82 | + <sections/> | |
83 | + <connections> | |
84 | + <outlet property="dataSource" destination="iNx-eR-wSX" id="RrI-xM-BHG"/> | |
85 | + <outlet property="delegate" destination="iNx-eR-wSX" id="cfg-Zn-vZq"/> | |
86 | + </connections> | |
87 | + </tableView> | |
88 | + <navigationItem key="navigationItem" title="Connected to: " id="2rA-9H-FRE"/> | |
89 | + </tableViewController> | |
90 | + <placeholder placeholderIdentifier="IBFirstResponder" id="R4Z-ct-4GF" userLabel="First Responder" sceneMemberID="firstResponder"/> | |
80 | 91 | </objects> |
81 | - <point key="canvasLocation" x="791" y="83"/> | |
92 | + <point key="canvasLocation" x="834" y="-9"/> | |
82 | 93 | </scene> |
83 | 94 | <!--Navigation Controller--> |
84 | 95 | <scene sceneID="Ker-Z3-hzQ"> |
... | ... | @@ -88,14 +99,59 @@ |
88 | 99 | <autoresizingMask key="autoresizingMask"/> |
89 | 100 | </navigationBar> |
90 | 101 | <connections> |
91 | - <segue destination="0dd-lZ-pDC" kind="relationship" relationship="rootViewController" id="MoH-5d-iLd"/> | |
102 | + <segue destination="fM1-5w-fRr" kind="relationship" relationship="rootViewController" id="2aM-Mt-gu0"/> | |
92 | 103 | </connections> |
93 | 104 | </navigationController> |
94 | 105 | <placeholder placeholderIdentifier="IBFirstResponder" id="dsv-q5-bXD" userLabel="First Responder" sceneMemberID="firstResponder"/> |
95 | 106 | </objects> |
96 | - <point key="canvasLocation" x="-32" y="83"/> | |
107 | + <point key="canvasLocation" x="-587" y="-9"/> | |
108 | + </scene> | |
109 | + <!--Initial View Controller--> | |
110 | + <scene sceneID="j5L-Mq-Nck"> | |
111 | + <objects> | |
112 | + <viewController id="fM1-5w-fRr" customClass="InitialViewController" sceneMemberID="viewController"> | |
113 | + <layoutGuides> | |
114 | + <viewControllerLayoutGuide type="top" id="K1W-Vd-VIX"/> | |
115 | + <viewControllerLayoutGuide type="bottom" id="zNe-Ob-WsU"/> | |
116 | + </layoutGuides> | |
117 | + <view key="view" contentMode="scaleToFill" id="Psa-QF-ZdS"> | |
118 | + <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> | |
119 | + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | |
120 | + <subviews> | |
121 | + <button opaque="NO" contentMode="scaleAspectFit" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="bXZ-vt-REt"> | |
122 | + <rect key="frame" x="96" y="220" width="128" height="128"/> | |
123 | + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | |
124 | + <state key="normal" backgroundImage="bluetooth.png"> | |
125 | + <color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/> | |
126 | + </state> | |
127 | + <connections> | |
128 | + <action selector="connectPressed:" destination="fM1-5w-fRr" eventType="touchDown" id="yhT-cP-LLA"/> | |
129 | + </connections> | |
130 | + </button> | |
131 | + <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Connect to Device" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oyW-sA-Lfb"> | |
132 | + <rect key="frame" x="86" y="356" width="149" height="21"/> | |
133 | + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | |
134 | + <fontDescription key="fontDescription" type="system" pointSize="17"/> | |
135 | + <color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | |
136 | + <nil key="highlightedColor"/> | |
137 | + </label> | |
138 | + </subviews> | |
139 | + <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> | |
140 | + </view> | |
141 | + <navigationItem key="navigationItem" id="VgB-ne-yWx"/> | |
142 | + <connections> | |
143 | + <outlet property="connectButton" destination="bXZ-vt-REt" id="I34-aB-fJh"/> | |
144 | + <segue destination="0dd-lZ-pDC" kind="push" identifier="ShowDevices" id="MVz-xF-9GY"/> | |
145 | + </connections> | |
146 | + </viewController> | |
147 | + <placeholder placeholderIdentifier="IBFirstResponder" id="xI2-bK-Kvc" userLabel="First Responder" sceneMemberID="firstResponder"/> | |
148 | + </objects> | |
149 | + <point key="canvasLocation" x="-129" y="-9"/> | |
97 | 150 | </scene> |
98 | 151 | </scenes> |
152 | + <resources> | |
153 | + <image name="bluetooth.png" width="512" height="512"/> | |
154 | + </resources> | |
99 | 155 | <simulatedMetricsContainer key="defaultSimulatedMetrics"> |
100 | 156 | <simulatedStatusBarMetrics key="statusBar"/> |
101 | 157 | <simulatedOrientationMetrics key="orientation"/> | ... | ... |
DUREX Vendor Control/InitialViewController.h
0 → 100644
1 | +// | |
2 | +// InitialViewController.h | |
3 | +// DUREX Vendor Control | |
4 | +// | |
5 | +// Created by Imanol Barba on 5/22/14. | |
6 | +// Copyright (c) 2014 Emmoco. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#import <UIKit/UIKit.h> | |
10 | + | |
11 | +@interface InitialViewController : UIViewController | |
12 | + | |
13 | +@property (nonatomic,strong) IBOutlet UIButton *connectButton; | |
14 | + | |
15 | +- (IBAction) connectPressed:(UIButton*)button; | |
16 | + | |
17 | +@end | ... | ... |
DUREX Vendor Control/InitialViewController.m
0 → 100644
1 | +// | |
2 | +// InitialViewController.m | |
3 | +// DUREX Vendor Control | |
4 | +// | |
5 | +// Created by Imanol Barba on 5/22/14. | |
6 | +// Copyright (c) 2014 Emmoco. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#import "InitialViewController.h" | |
10 | + | |
11 | +@interface InitialViewController () | |
12 | + | |
13 | +@end | |
14 | + | |
15 | +@implementation InitialViewController | |
16 | + | |
17 | +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | |
18 | +{ | |
19 | + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | |
20 | + if (self) { | |
21 | + // Custom initialization | |
22 | + } | |
23 | + return self; | |
24 | +} | |
25 | + | |
26 | +- (void)viewDidLoad | |
27 | +{ | |
28 | + [super viewDidLoad]; | |
29 | + // Do any additional setup after loading the view. | |
30 | +} | |
31 | + | |
32 | +- (void)didReceiveMemoryWarning | |
33 | +{ | |
34 | + [super didReceiveMemoryWarning]; | |
35 | + // Dispose of any resources that can be recreated. | |
36 | +} | |
37 | + | |
38 | +- (IBAction) connectPressed:(UIButton*)button | |
39 | +{ | |
40 | + [self performSegueWithIdentifier:@"ShowDevices" sender:self]; | |
41 | +} | |
42 | + | |
43 | +/* | |
44 | +#pragma mark - Navigation | |
45 | + | |
46 | +// In a storyboard-based application, you will often want to do a little preparation before navigation | |
47 | +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender | |
48 | +{ | |
49 | + // Get the new view controller using [segue destinationViewController]. | |
50 | + // Pass the selected object to the new view controller. | |
51 | +} | |
52 | +*/ | |
53 | + | |
54 | +@end | ... | ... |
DUREX Vendor Control/MenuTableViewController.h
0 → 100644
1 | +// | |
2 | +// MenuTableViewController.h | |
3 | +// DUREX Vendor Control | |
4 | +// | |
5 | +// Created by Imanol Barba on 5/23/14. | |
6 | +// Copyright (c) 2014 Emmoco. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#import <UIKit/UIKit.h> | |
10 | +#import "EMFramework.h" | |
11 | +#import "CommunicationProtocol.h" | |
12 | + | |
13 | +#define num(x) [NSNumber numberWithUnsignedInt:x] | |
14 | + | |
15 | +#define MENU_ELEMENTS @"Maintenance",@"Basic Configuration",@"Sending a Report" | |
16 | +#define MENU_CELLS_PER_SECTION num(3) | |
17 | +#define MENU_SECTIONS 1 | |
18 | + | |
19 | +#define MAINTENANCE_ELEMENTS @"General Status",@"Sensor Report" | |
20 | +#define MAINTENANCE_CELLS_PER_SECTION num(2) | |
21 | +#define MAINTENANCE_SECTIONS 1 | |
22 | + | |
23 | +#define STATUS_ELEMENTS @"Time",@"20€ Notes",@"10€ Notes",@"5€ Notes",@"2€ Coins",@"1€ Coins",@"50c Coins",@"CPP_TABLE",@"1€ Change",@"50c Change" | |
24 | +#define STATUS_CELLS_PER_SECTION num(10) | |
25 | +#define STATUS_SECTIONS 1 | |
26 | + | |
27 | +#define CELL_IDENTIFIERS @"MenuCell",@"MaintenanceCell",@"ConfigCell",@"ReportCell" | |
28 | + | |
29 | +#define NUM_CHANNELS 8 | |
30 | + | |
31 | +enum { | |
32 | + MENU = 0, | |
33 | + MAINTENANCE, | |
34 | + BASIC_CONFIGURATION, | |
35 | + REPORT | |
36 | +} navigationLevel; | |
37 | + | |
38 | +@interface MenuTableViewController : UITableViewController | |
39 | + | |
40 | +@end | ... | ... |
DUREX Vendor Control/MenuTableViewController.m
0 → 100644
1 | +// | |
2 | +// MenuTableViewController.m | |
3 | +// DUREX Vendor Control | |
4 | +// | |
5 | +// Created by Imanol Barba on 5/23/14. | |
6 | +// Copyright (c) 2014 Emmoco. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#import "MenuTableViewController.h" | |
10 | + | |
11 | +@interface MenuTableViewController () | |
12 | +{ | |
13 | + IBOutlet UIActivityIndicatorView *_activityIndicator; | |
14 | + NSTimer *_writeTimer; | |
15 | +} | |
16 | +@property (nonatomic,strong) const NSArray *menuElements; | |
17 | +@property (nonatomic,strong) const NSArray *menuStructure; | |
18 | + | |
19 | +@property (nonatomic,strong) const NSArray *maintenanceElements; | |
20 | +@property (nonatomic,strong) const NSArray *maintenanceStructure; | |
21 | + | |
22 | +@property (nonatomic,strong) const NSArray *cellIdentifiers; | |
23 | + | |
24 | +@property (nonatomic,strong) CommunicationProtocol* protocol; | |
25 | +@property uint8_t currentNavLevel; | |
26 | +@property NSString *currentCellIdentifier; | |
27 | +@property const NSArray *currentElements; | |
28 | +@property const NSArray *currentStructure; | |
29 | + | |
30 | +@end | |
31 | + | |
32 | +@implementation MenuTableViewController | |
33 | + | |
34 | +- (id)initWithStyle:(UITableViewStyle)style | |
35 | +{ | |
36 | + self = [super initWithStyle:style]; | |
37 | + if (self) | |
38 | + { | |
39 | + // Custom initialization | |
40 | + } | |
41 | + return self; | |
42 | +} | |
43 | + | |
44 | +- (void) initializeMenuEntries | |
45 | +{ | |
46 | + [self setMenuElements:[[NSArray alloc] initWithObjects:MENU_ELEMENTS, nil]]; | |
47 | + [self setMenuStructure:[[NSArray alloc] initWithObjects:MENU_CELLS_PER_SECTION, nil]]; | |
48 | + | |
49 | + [self setMaintenanceElements:[[NSArray alloc] initWithObjects:MAINTENANCE_ELEMENTS, nil]]; | |
50 | + [self setMaintenanceStructure:[[NSArray alloc] initWithObjects:MAINTENANCE_CELLS_PER_SECTION, nil]]; | |
51 | + | |
52 | + [self setCellIdentifiers:[[NSArray alloc] initWithObjects:CELL_IDENTIFIERS, nil]]; | |
53 | +} | |
54 | + | |
55 | +- (void) changeNavLevel: (uint8_t) level | |
56 | +{ | |
57 | + [self setCurrentNavLevel:level]; | |
58 | + [self setCurrentCellIdentifier:[[self cellIdentifiers] objectAtIndex:[self currentNavLevel]]]; | |
59 | + if([self currentNavLevel] == MAINTENANCE) | |
60 | + { | |
61 | + [self setCurrentElements:[self maintenanceElements]]; | |
62 | + [self setCurrentStructure:[self maintenanceStructure]]; | |
63 | + } | |
64 | + //AND SO ON... | |
65 | + else | |
66 | + { | |
67 | + [self setCurrentElements:[self menuElements]]; | |
68 | + [self setCurrentStructure:[self menuStructure]]; | |
69 | + } | |
70 | +} | |
71 | + | |
72 | +- (void)viewDidLoad | |
73 | +{ | |
74 | + [super viewDidLoad]; | |
75 | + [_activityIndicator setHidden:YES]; | |
76 | + | |
77 | + //Set title | |
78 | + NSMutableString *title; | |
79 | + [title setString:[[self navigationItem] title]] ; | |
80 | + [title appendString:[[[EMConnectionManager sharedManager] connectedDevice] name]]; | |
81 | + [[self navigationItem] setTitle:title]; | |
82 | + | |
83 | + //Emmoco protocol initialization | |
84 | + _protocol = [CommunicationProtocol sharedProtocol]; | |
85 | + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotification:) name:kEMConnectionDidReceiveIndicatorNotificationName object:nil]; | |
86 | + [[EMConnectionManager sharedManager] addObserver:self forKeyPath:@"connectionState" options:0 context:NULL]; | |
87 | + | |
88 | + //DUREX protocol initialization | |
89 | + [_protocol setMessageAvailable:false]; | |
90 | + if(![_protocol establishConnection]) | |
91 | + { | |
92 | + UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Communication error" message:@"Error while trying to connect to the device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; | |
93 | + [alert show]; | |
94 | + UIViewController *previous = [[[self navigationController] viewControllers] objectAtIndex:[[[self navigationController] viewControllers] count]-2]; | |
95 | + [[self navigationController] popToViewController:previous animated:YES]; | |
96 | + } | |
97 | + | |
98 | + //Set navigation level | |
99 | + [self initializeMenuEntries]; | |
100 | + [self changeNavLevel:MENU]; | |
101 | + | |
102 | + // Uncomment the following line to preserve selection between presentations. | |
103 | + // self.clearsSelectionOnViewWillAppear = NO; | |
104 | + | |
105 | + // Uncomment the following line to display an Edit button in the navigation bar for this view controller. | |
106 | + // self.navigationItem.rightBarButtonItem = self.editButtonItem; | |
107 | +} | |
108 | + | |
109 | +-(void)didReceiveNotification:(NSNotification*) notification | |
110 | +{ | |
111 | + id notificationValue = [[notification userInfo] objectForKey:kEMIndicatorResourceValueKey]; | |
112 | + NSString *resourceName = [[notification userInfo] objectForKey:kEMIndicatorNameKey]; | |
113 | + if([resourceName isEqualToString:@"messageAvailable"]) | |
114 | + { | |
115 | + NSString *resourceValue = [notificationValue stringValue]; | |
116 | + if([resourceValue isEqualToString:@"TRUE"]) | |
117 | + { | |
118 | + [_protocol setMessageAvailable:TRUE]; | |
119 | + } | |
120 | + else | |
121 | + { | |
122 | + [_protocol setMessageAvailable:FALSE]; | |
123 | + } | |
124 | + } | |
125 | +} | |
126 | + | |
127 | +-(void)dealloc | |
128 | +{ | |
129 | + [[EMConnectionManager sharedManager] removeObserver:self forKeyPath:@"connectionState"]; | |
130 | + [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
131 | +} | |
132 | + | |
133 | +- (void)didReceiveMemoryWarning | |
134 | +{ | |
135 | + [super didReceiveMemoryWarning]; | |
136 | + // Dispose of any resources that can be recreated. | |
137 | +} | |
138 | + | |
139 | +-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context | |
140 | +{ | |
141 | + if (object == [EMConnectionManager sharedManager]) | |
142 | + { | |
143 | + if ([keyPath isEqualToString:@"connectionState"]) | |
144 | + { | |
145 | + if ([[EMConnectionManager sharedManager] connectionState] == EMConnectionStateDisrupted) | |
146 | + { | |
147 | + [[self navigationController] popToRootViewControllerAnimated:YES]; | |
148 | + } | |
149 | + } | |
150 | + } | |
151 | +} | |
152 | + | |
153 | +#pragma mark - Table view delegate | |
154 | + | |
155 | +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath | |
156 | +{ | |
157 | + [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
158 | + NSLog(@"%d:%s",(int)[indexPath row],[[[[[self tableView] cellForRowAtIndexPath:indexPath]textLabel]text]cStringUsingEncoding:NSUTF8StringEncoding]); | |
159 | +} | |
160 | + | |
161 | +#pragma mark - Table view data source | |
162 | + | |
163 | +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView | |
164 | +{ | |
165 | + return [[self currentStructure] count]; | |
166 | +} | |
167 | + | |
168 | +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section | |
169 | +{ | |
170 | + return [[[self currentStructure]objectAtIndex:section] integerValue]; | |
171 | +} | |
172 | + | |
173 | +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
174 | +{ | |
175 | + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[self currentCellIdentifier] forIndexPath:indexPath]; | |
176 | + | |
177 | + if (cell == nil) | |
178 | + { | |
179 | + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[self currentCellIdentifier]]; | |
180 | + } | |
181 | + | |
182 | + [[cell textLabel] setText:[[self currentElements] objectAtIndex:indexPath.row]]; | |
183 | + return cell; | |
184 | +} | |
185 | + | |
186 | + | |
187 | +/* | |
188 | +// Override to support conditional editing of the table view. | |
189 | +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath | |
190 | +{ | |
191 | + // Return NO if you do not want the specified item to be editable. | |
192 | + return YES; | |
193 | +} | |
194 | +*/ | |
195 | + | |
196 | +/* | |
197 | +// Override to support editing the table view. | |
198 | +- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath | |
199 | +{ | |
200 | + if (editingStyle == UITableViewCellEditingStyleDelete) { | |
201 | + // Delete the row from the data source | |
202 | + [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; | |
203 | + } else if (editingStyle == UITableViewCellEditingStyleInsert) { | |
204 | + // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view | |
205 | + } | |
206 | +} | |
207 | +*/ | |
208 | + | |
209 | +/* | |
210 | +// Override to support rearranging the table view. | |
211 | +- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath | |
212 | +{ | |
213 | +} | |
214 | +*/ | |
215 | + | |
216 | +/* | |
217 | +// Override to support conditional rearranging of the table view. | |
218 | +- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath | |
219 | +{ | |
220 | + // Return NO if you do not want the item to be re-orderable. | |
221 | + return YES; | |
222 | +} | |
223 | +*/ | |
224 | + | |
225 | +/* | |
226 | +#pragma mark - Navigation | |
227 | + | |
228 | +// In a storyboard-based application, you will often want to do a little preparation before navigation | |
229 | +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender | |
230 | +{ | |
231 | + // Get the new view controller using [segue destinationViewController]. | |
232 | + // Pass the selected object to the new view controller. | |
233 | +} | |
234 | +*/ | |
235 | + | |
236 | +@end | ... | ... |
DUREX Vendor Control/bluetooth.png
0 → 100644
1 MB