diff options
author | NicoleYarroch <nicole@livio.io> | 2017-10-20 15:47:49 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2017-10-20 15:47:49 -0400 |
commit | b09fb2af2db483c8573645ff03dfbab845388145 (patch) | |
tree | 207783c88cef02adb36aa135778c15e299855c0b | |
parent | 6b5aa120e6af0d97e546432b65cdfae22a922e61 (diff) | |
download | sdl_ios-b09fb2af2db483c8573645ff03dfbab845388145.tar.gz |
Added more RPCs to the menu
9 files changed, 212 insertions, 42 deletions
diff --git a/SmartDeviceLink_Example/Classes/ProxyManager.m b/SmartDeviceLink_Example/Classes/ProxyManager.m index 00afa0206..6cde7f703 100644 --- a/SmartDeviceLink_Example/Classes/ProxyManager.m +++ b/SmartDeviceLink_Example/Classes/ProxyManager.m @@ -10,10 +10,8 @@ #import "SoftButtonManager.h" #import "TemplateManager.h" -NSString *const SDLAppName = @"Antelope"; -// @"SDL Example App"; -NSString *const SDLAppId = @"2626965156"; -// @"9999"; +NSString *const SDLAppName = @"SDL Example App"; +NSString *const SDLAppId = @"9999"; typedef NS_ENUM(NSUInteger, SDLHMIFirstState) { SDLHMIFirstStateNone, diff --git a/SmartDeviceLink_Example/Managers/AddCommandManager.h b/SmartDeviceLink_Example/Managers/AddCommandManager.h index 852effb16..1e758c7e4 100644 --- a/SmartDeviceLink_Example/Managers/AddCommandManager.h +++ b/SmartDeviceLink_Example/Managers/AddCommandManager.h @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN + (SDLAddCommand *)addCommandWithManager:(SDLManager *)manager commandId:(int)commandId menuName:(NSString *)menuName handler:(void (^)(void))handler; + (SDLDeleteCommand *)deleteCommandWithId:(int)commandId; ++ (SDLDeleteCommand *)deleteSubMenuCommandWithId:(int)commandId; @end diff --git a/SmartDeviceLink_Example/Managers/AddCommandManager.m b/SmartDeviceLink_Example/Managers/AddCommandManager.m index ceea14aee..9053b467d 100644 --- a/SmartDeviceLink_Example/Managers/AddCommandManager.m +++ b/SmartDeviceLink_Example/Managers/AddCommandManager.m @@ -33,6 +33,10 @@ NS_ASSUME_NONNULL_BEGIN return [[SDLDeleteCommand alloc] initWithId:commandId]; } ++ (SDLDeleteCommand *)deleteSubMenuCommandWithId:(int)commandId { + return [[SDLDeleteCommand alloc] initWithId:commandId]; +} + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/AlertManager.h b/SmartDeviceLink_Example/Managers/AlertManager.h index 5e1aab05b..69b113abb 100644 --- a/SmartDeviceLink_Example/Managers/AlertManager.h +++ b/SmartDeviceLink_Example/Managers/AlertManager.h @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN @interface AlertManager : NSObject + (void)alertCommand_showText:(NSString *)text softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons duration:(int)duration withManager:(SDLManager *)manager; ++ (void)alertCommand_showText:(NSString *)text1 text2:(NSString *)text2 softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons duration:(int)duration withManager:(SDLManager *)manager; + (void)defaultAlertWithManager:(SDLManager *)manager; diff --git a/SmartDeviceLink_Example/Managers/AlertManager.m b/SmartDeviceLink_Example/Managers/AlertManager.m index d0c7c975a..e052bc7f8 100644 --- a/SmartDeviceLink_Example/Managers/AlertManager.m +++ b/SmartDeviceLink_Example/Managers/AlertManager.m @@ -13,19 +13,36 @@ NS_ASSUME_NONNULL_BEGIN @implementation AlertManager -+ (void)alertCommand_showText:(NSString *)text softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons duration:(int)duration withManager:(SDLManager *)manager { ++ (SDLAlert *)sdlex_defaultAlert:(NSString *)text1 text2:(nullable NSString *)text2 softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons duration:(int)duration { int durationInMilliseconds = duration * 1000; - SDLAlert *alert = [[SDLAlert alloc] initWithAlertText1:text alertText2:nil alertText3:nil duration:durationInMilliseconds softButtons:softButtons]; - alert.ttsChunks = [SDLTTSChunk textChunksFromString:text]; + SDLAlert *alert = [[SDLAlert alloc] initWithAlertText1:text1 alertText2:text2 alertText3:nil duration:durationInMilliseconds softButtons:softButtons]; + alert.ttsChunks = [SDLTTSChunk textChunksFromString:text1]; + return alert; +} + ++ (void)sdlex_alertResponse:(nullable SDLRPCResponse *)response error:(nullable NSError *)error { + if (error != nil) { + SDLLogE(@"Error showing the alert (%@)", error); + } else if (![response.resultCode isEqualToEnum:SDLResultSuccess]) { + SDLLogE(@"The alert was not shown successfully (%@)", response.resultCode); + } else { + SDLLogV(@"Alert shown successfully"); + } +} + ++ (void)alertCommand_showText:(NSString *)text softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons duration:(int)duration withManager:(SDLManager *)manager { + SDLAlert *alert = [self.class sdlex_defaultAlert:text text2:nil softButtons:softButtons duration:duration]; + + [manager sendRequest:alert withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [self.class sdlex_alertResponse:response error:error]; + }]; +} + ++ (void)alertCommand_showText:(NSString *)text1 text2:(NSString *)text2 softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons duration:(int)duration withManager:(SDLManager *)manager { + SDLAlert *alert = [self.class sdlex_defaultAlert:text1 text2:text2 softButtons:softButtons duration:duration]; [manager sendRequest:alert withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { - if (error != nil) { - SDLLogE(@"Error showing the alert (%@)", error); - } else if (![response.resultCode isEqualToEnum:SDLResultSuccess]) { - SDLLogE(@"The alert was not shown successfully (%@)", response.resultCode); - } else { - SDLLogD(@"Alert shown successfully"); - } + [self.class sdlex_alertResponse:response error:error]; }]; } diff --git a/SmartDeviceLink_Example/Managers/SubscribeButtonManager.h b/SmartDeviceLink_Example/Managers/SubscribeButtonManager.h index 9109b8c8e..c9c9cd86a 100644 --- a/SmartDeviceLink_Example/Managers/SubscribeButtonManager.h +++ b/SmartDeviceLink_Example/Managers/SubscribeButtonManager.h @@ -17,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN + (SDLUnsubscribeButton *)removeSubscribeButtonWithName:(SDLButtonName)subscribeButtonName ; + (NSArray<SDLSubscribeButton *> *)mediaTemplateSubscribeButtonsWithManager:(SDLManager *)manager; ++ (NSArray<SDLUnsubscribeButton *> *)mediaTemplateUnSubscribeButtons; + (NSArray<SDLSubscribeButton *> *)presetSubscribeButtonsWithManager:(SDLManager *)manager; @end diff --git a/SmartDeviceLink_Example/Managers/SubscribeButtonManager.m b/SmartDeviceLink_Example/Managers/SubscribeButtonManager.m index d9a3b24d8..8b5c0aee8 100644 --- a/SmartDeviceLink_Example/Managers/SubscribeButtonManager.m +++ b/SmartDeviceLink_Example/Managers/SubscribeButtonManager.m @@ -29,16 +29,27 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Subscribe button arrays +// Tuneup and Tunedown are hard buttons only, the rest are both hard and soft buttons ++ (NSArray<SDLButtonName> *)sdlex_mediaTemplateSubscribeButtonNames { + return [[NSArray alloc] initWithObjects:SDLButtonNameOk, SDLButtonNameSeekLeft, SDLButtonNameSeekRight, SDLButtonNameTuneUp, SDLButtonNameTuneDown, nil]; +} + + (NSArray<SDLSubscribeButton *> *)mediaTemplateSubscribeButtonsWithManager:(SDLManager *)manager { NSMutableArray *subscribeButtons = [NSMutableArray array]; - // Tuneup and Tunedown are hard buttons only, the rest are both hard and soft buttons - NSArray<SDLButtonName> *mediaTemplateSubscribeButtons = [[NSArray alloc] initWithObjects:SDLButtonNameOk, SDLButtonNameSeekLeft, SDLButtonNameSeekRight, SDLButtonNameTuneUp, SDLButtonNameTuneDown, nil]; - for(SDLButtonName buttonName in mediaTemplateSubscribeButtons) { + for(SDLButtonName buttonName in [self.class sdlex_mediaTemplateSubscribeButtonNames]) { [subscribeButtons addObject:[self.class createSubscribeButtonWithName:buttonName withManager:manager]]; } return subscribeButtons; } ++ (NSArray<SDLUnsubscribeButton *> *)mediaTemplateUnSubscribeButtons { + NSMutableArray *unSubscribeButtons = [NSMutableArray array]; + for(SDLButtonName buttonName in [self.class sdlex_mediaTemplateSubscribeButtonNames]) { + [unSubscribeButtons addObject:[self.class removeSubscribeButtonWithName:buttonName]]; + } + return unSubscribeButtons; +} + + (NSArray<SDLSubscribeButton *> *)presetSubscribeButtonsWithManager:(SDLManager *)manager { NSMutableArray *subscribeButtons = [NSMutableArray array]; // Hard buttons only (i.e. no corresponding soft button will show up on the screen) diff --git a/SmartDeviceLink_Example/Managers/TemplateManager.m b/SmartDeviceLink_Example/Managers/TemplateManager.m index 4cdcbbac9..8d4ebd8e1 100644 --- a/SmartDeviceLink_Example/Managers/TemplateManager.m +++ b/SmartDeviceLink_Example/Managers/TemplateManager.m @@ -20,8 +20,11 @@ NS_ASSUME_NONNULL_BEGIN + (void)changeTemplateWithManager:(SDLManager *)manager toTemplate:(SDLPredefinedLayout)template image:(SDLImage *)image { void (^templateChangedHandler)(void); - if (![manager.registerResponse.displayCapabilities.templatesAvailable containsObject:template]) { + + // For SDLCore - only supports DEFAULT template + [manager sendRequest:[[SDLSetDisplayLayout alloc] initWithPredefinedLayout:SDLPredefinedLayoutDefault]]; + [AlertManager alertCommand_showText:[NSString stringWithFormat:@"This template, %@, is not supported on this head unit (%@)", template, manager.registerResponse.displayCapabilities.displayType] softButtons:[SoftButtonManager alertButtons] diff --git a/SmartDeviceLink_Example/ProxyMenuManager.m b/SmartDeviceLink_Example/ProxyMenuManager.m index 8def1fb42..7e3a3617f 100644 --- a/SmartDeviceLink_Example/ProxyMenuManager.m +++ b/SmartDeviceLink_Example/ProxyMenuManager.m @@ -10,9 +10,11 @@ #import "AddCommandManager.h" #import "AlertManager.h" #import "ImageManager.h" +#import "MediaClockTimerManager.h" #import "SDLNames.h" #import "ShowManager.h" #import "SoftButtonManager.h" +#import "SubscribeButtonManager.h" #import "TemplateManager.h" NS_ASSUME_NONNULL_BEGIN @@ -131,11 +133,6 @@ NS_ASSUME_NONNULL_BEGIN [self.class sdlex_encodedSyncPData:manager]; }]]; - // End Audio Pass Thru - [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:(commandId++) menuName:@"End Audio Pass Thru" handler:^{ - [self.class sdlex_endAudioPassThru:manager]; - }]]; - // Send Location [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:(commandId++) menuName:@"Send Location" handler:^{ [self.class sdlex_sendLocation:manager]; @@ -185,6 +182,51 @@ NS_ASSUME_NONNULL_BEGIN [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:(commandId++) menuName:@"Send Haptic Rect" handler:^{ [self.class sdlex_createHapticRectWithManager:manager]; }]]; + + // Button press + [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:(commandId++) menuName:@"Button Press" handler:^{ + [self.class sdlex_createButtonPressWithManager:manager]; + }]]; + + // Subscribe button + [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:(commandId++) menuName:@"Subscribe buttons" handler:^{ + [self.class sdlex_subscribeButtonWithManager:manager]; + }]]; + + // Unsubscribe button + [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:(commandId++) menuName:@"Unsubscribe buttons" handler:^{ + [self.class sdlex_unSubscribeButtonWithManager:manager]; + }]]; + + // Get interior vehicle data + [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:(commandId++) menuName:@"Get Interior vehicle data" handler:^{ + [self.class sdlex_getInteriorVehicleDataWithManager:manager]; + }]]; + + // Set interior vehicle data + [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:(commandId++) menuName:@"Set Interior vehicle data" handler:^{ + [self.class sdlex_setInteriorVehicleDataWithManager:manager]; + }]]; + + // Audio pass thru + [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:(commandId++) menuName:@"Send Audio Pass Thru" handler:^{ + [self.class sdlex_audioPassThruRequestWithManager:manager]; + }]]; + + // End audio pass thru + [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:(commandId++) menuName:@"Send End Audio Pass Thru" handler:^{ + [self.class sdlex_endAudioPassThruRequestWithManager:manager]; + }]]; + + // Show Media playback bar + [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:(commandId++) menuName:@"Set Media Clock Timer" handler:^{ + [self.class sdlex_showMediaClockTimerWithManager:manager]; + }]]; + + // Hide Media playback bar + [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:(commandId++) menuName:@"Remove Media Clock Timer" handler:^{ + [self.class sdlex_hideMediaClockTimerWithManager:manager]; + }]]; } #pragma mark - Templates menu and submenu @@ -398,6 +440,40 @@ static const int choiceId = 10005; }]; } ++ (void)sdlex_getInteriorVehicleDataWithManager:(SDLManager *)manager { + SDLGetInteriorVehicleData *interiorVehicleData = [[SDLGetInteriorVehicleData alloc] init]; + interiorVehicleData.moduleType = SDLModuleTypeRadio; + interiorVehicleData.subscribe = @YES; + [manager sendRequest:interiorVehicleData withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [AlertManager alertCommand_showText:@"Get Interior Vehicle Data RPC sent" text2:[NSString stringWithFormat:@"Response %@", response] softButtons:nil duration:3 withManager:manager]; + }]; +} + ++ (void)sdlex_setInteriorVehicleDataWithManager:(SDLManager *)manager { + SDLRadioControlData* radioData = [[SDLRadioControlData alloc] init]; + radioData.frequencyInteger = @101; + radioData.frequencyFraction = @7; + radioData.band = SDLRadioBandAM; + radioData.rdsData = [[SDLRDSData alloc] init]; + radioData.availableHDs = @2; + radioData.hdChannel = @2; + radioData.signalStrength = @54; + radioData.signalChangeThreshold = @76; + radioData.radioEnable = @YES; + radioData.state = SDLRadioStateNotFound; + + SDLModuleData *moduleData = [[SDLModuleData alloc] init]; + moduleData.moduleType = SDLModuleTypeRadio; + moduleData.radioControlData = radioData; + + SDLSetInteriorVehicleData *interiorVehicleData = [[SDLSetInteriorVehicleData alloc] init]; + interiorVehicleData.moduleData = moduleData; + + [manager sendRequest:interiorVehicleData withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [AlertManager alertCommand_showText:@"Set Interior Vehicle Data RPC sent" text2:[NSString stringWithFormat:@"Response %@", response] softButtons:nil duration:3 withManager:manager]; + }]; +} + #pragma mark - Waypoints + (void)sdlex_subscribeWaypoints:(SDLManager *)manager { @@ -511,10 +587,63 @@ static const int choiceId = 10005; return speak; } -+ (void)sdlex_endAudioPassThru:(SDLManager *)manager { - SDLEndAudioPassThru *endAudioPassThru = [[SDLEndAudioPassThru alloc] init]; - [manager sendRequest:endAudioPassThru withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { - [self.class sdlex_sendAlert:manager message:[NSString stringWithFormat:@"End Audio Pass Thru RPC sent. Response: %@", response.resultCode]]; +#pragma mark - Buttons + ++ (void)sdlex_subscribeButtonWithManager:(SDLManager *)manager { + for(SDLSubscribeButton *subscribeButton in [SubscribeButtonManager mediaTemplateSubscribeButtonsWithManager:manager]) { + [manager sendRequest:subscribeButton]; + } +} + ++ (void)sdlex_unSubscribeButtonWithManager:(SDLManager *)manager { + for(SDLUnsubscribeButton *unsubscribeButton in [SubscribeButtonManager mediaTemplateUnSubscribeButtons]) { + [manager sendRequest:unsubscribeButton]; + } +} + +#pragma mark - Menu / PICS + ++ (void)sdlex_deleteCommandWithManager:(SDLManager *)manager { + +} + ++ (void)sdlex_deleteInteractionChoiceSetWithManager:(SDLManager *)manager { + +} + ++ (void)sdlex_deleteSubMenuWithManager:(SDLManager *)manager { + +} + +#pragma mark - Timer + ++ (void)sdlex_showMediaClockTimerWithManager:(SDLManager *)manager { + [manager sendRequest:[MediaClockTimerManager addMediaClockTimerWithManager:manager] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + SDLLogV(@"show media clock timer response: %@", response.resultCode); + }]; +} + ++ (void)sdlex_hideMediaClockTimerWithManager:(SDLManager *)manager { + [manager sendRequest:[MediaClockTimerManager removeMediaClockTimer] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + SDLLogV(@"hide media clock timer response: %@", response.resultCode); + }]; +} + +#pragma mark - Audio + ++ (void)sdlex_audioPassThruRequestWithManager:(SDLManager *)manager { + SDLPerformAudioPassThru *passThru = [[SDLPerformAudioPassThru alloc] initWithInitialPrompt:nil audioPassThruDisplayText1:@"Listening" audioPassThruDisplayText2:@"Say Something" samplingRate:SDLSamplingRate16KHZ bitsPerSample:SDLBitsPerSample16Bit audioType:SDLAudioTypePCM maxDuration:5000 muteAudio:true audioDataHandler:^(NSData * _Nullable audioData) { + SDLLogD(@"Getting audio data"); + }]; + [manager sendRequest:passThru withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + SDLLogD(@"Got Peform Audio Pass Thru response: %@, error: %@, request: %@", response, error, request); + }]; +} + ++ (void)sdlex_endAudioPassThruRequestWithManager:(SDLManager *)manager { + SDLEndAudioPassThru *endPassThru = [[SDLEndAudioPassThru alloc] init]; + [manager sendRequest:endPassThru withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + SDLLogD(@"Got End Peform Audio Pass Thru response: %@, error: %@, request: %@", response, error, request); }]; } @@ -537,21 +666,15 @@ static const int choiceId = 10005; } + (void)sdlex_setGlobalProperties:(SDLManager *)manager { - SDLSetGlobalProperties *globalProperties = [[SDLSetGlobalProperties alloc] init]; - - SDLTTSChunk* chunk1 = [[SDLTTSChunk alloc] init]; - SDLTTSChunk* chunk2 = [[SDLTTSChunk alloc] init]; - SDLVRHelpItem* help = [[SDLVRHelpItem alloc] init]; - SDLImage* image = [[SDLImage alloc] init]; - SDLKeyboardProperties* keyboard = [[SDLKeyboardProperties alloc] init]; - - globalProperties.helpPrompt = [@[chunk1] mutableCopy]; - globalProperties.timeoutPrompt = [@[chunk2] mutableCopy]; - globalProperties.vrHelpTitle = @"vr"; - globalProperties.vrHelp = [@[help] mutableCopy]; - globalProperties.menuTitle = @"TheNewMenu"; - globalProperties.menuIcon = image; - globalProperties.keyboardProperties = keyboard; + SDLSetGlobalProperties *globalProperties = [[SDLSetGlobalProperties alloc] initWithHelpText:@"new help text" timeoutText:@"new timeout text"]; + +// globalProperties.helpPrompt = [SDLTTSChunk textChunksFromString:@"setting global properties"]; +// globalProperties.timeoutPrompt = [SDLTTSChunk textChunksFromString:@"timing out"]; +// globalProperties.vrHelpTitle = @"vr"; +// globalProperties.vrHelp = @[[[SDLVRHelpItem alloc] initWithText:@"Voice Command" image:nil]]; +// globalProperties.menuTitle = @"The New Menu"; +// globalProperties.menuIcon = [ImageManager mainGraphicImage]; +// // globalProperties.keyboardProperties [manager sendRequest:globalProperties withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { [self.class sdlex_sendAlert:manager message:[NSString stringWithFormat:@"Set Global Properties RPC sent. Response: %@", response.resultCode]]; @@ -680,6 +803,17 @@ static const int choiceId = 10005; }]; } ++ (void)sdlex_createButtonPressWithManager:(SDLManager *)manager { + SDLButtonPress* buttonPress = [[SDLButtonPress alloc] init]; + buttonPress.moduleType = SDLModuleTypeClimate; + buttonPress.buttonName = SDLButtonNameFanUp; + buttonPress.buttonPressMode = SDLButtonPressModeShort; + + [manager sendRequest:buttonPress withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [AlertManager alertCommand_showText:@"Button Press RPC sent" text2:[NSString stringWithFormat:@"Response %@", response] softButtons:nil duration:3 withManager:manager]; + }]; +} + @end NS_ASSUME_NONNULL_END |