From 0f7ac5f35c423008f68b27c21d7c50cdf9b1121f Mon Sep 17 00:00:00 2001 From: patriot1889 Date: Thu, 21 Nov 2019 16:17:04 +0000 Subject: [PATCH] Start/Stop fixes uDMX will now gracefully fail if not connected and be able to be started again. Also added, red traffic light indicators for failed starts. --- LXNet2OpenDMX/AppDelegate.m | 9 +++++++-- LXNet2OpenDMX/LXOpenDMXInterface.m | 4 ++-- LXNet2OpenDMX/LXuDMXInterface.h | 3 +++ LXNet2OpenDMX/LXuDMXInterface.m | 8 ++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/LXNet2OpenDMX/AppDelegate.m b/LXNet2OpenDMX/AppDelegate.m index 553b457..69715ab 100755 --- a/LXNet2OpenDMX/AppDelegate.m +++ b/LXNet2OpenDMX/AppDelegate.m @@ -67,7 +67,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [udmxbutton setEnabled:NO]; statusString = [NSString stringWithFormat:@"%@Missing libusb.", statusString]; } - [statusField setStringValue:statusString]; } @@ -199,6 +198,7 @@ -(IBAction) toggleDMX:(id) sender { } [dmxbutton setTitle:@"Start OpenDMX"]; openDMXInterface = NULL; + dmxStatus.ledstate = 0; [CTStatusReporter alertUserToStatus:@"Stopped OpenDMX." level:CT_STATUS_LEVEL_NOLOG_GREEN]; } } @@ -207,7 +207,12 @@ -(IBAction) toggleUDMX:(id) sender { if ( uDMXInterface == NULL ) { uDMXInterface = [[LXuDMXInterface alloc] init]; [uDMXInterface startDevice]; - [udmxbutton setTitle:@"Stop µDMX"]; + if ( [uDMXInterface isActive] ) { + [udmxbutton setTitle:@"Stop µDMX"]; + }else{ + uDMXInterface = NULL; + [udmxbutton setTitle:@"Start µDMX"]; + } } else { uDMXInterface = NULL; [udmxbutton setTitle:@"Start µDMX"]; diff --git a/LXNet2OpenDMX/LXOpenDMXInterface.m b/LXNet2OpenDMX/LXOpenDMXInterface.m index cac8116..ab60b46 100755 --- a/LXNet2OpenDMX/LXOpenDMXInterface.m +++ b/LXNet2OpenDMX/LXOpenDMXInterface.m @@ -83,7 +83,7 @@ -(BOOL) openConnection { tries++; } - [CTStatusReporter alertUserToStatus:[NSString stringWithFormat:@"d2xx connection error: %@", [self ftErrorString:ft_Status]] level:CT_STATUS_INFORM_USER_RED]; + [CTStatusReporter alertUserToStatus:[NSString stringWithFormat:@"!d2xx connection error: %@", [self ftErrorString:ft_Status]] level:CT_STATUS_INFORM_USER_RED]; } //<-_libdf2xx_dylibHandle != NULL @@ -202,7 +202,7 @@ -(void) stopSending { [[NSNotificationCenter defaultCenter] removeObserver:self]; //post the status - [self statusChange:0]; + //[self statusChange:0]; } -(BOOL) isSending { diff --git a/LXNet2OpenDMX/LXuDMXInterface.h b/LXNet2OpenDMX/LXuDMXInterface.h index f986a86..307c1d5 100644 --- a/LXNet2OpenDMX/LXuDMXInterface.h +++ b/LXNet2OpenDMX/LXuDMXInterface.h @@ -52,6 +52,8 @@ NS_ASSUME_NONNULL_BEGIN */ BOOL _usb_init_called; + BOOL active; + /* * Array of DMX Level data including the start code */ @@ -70,6 +72,7 @@ NS_ASSUME_NONNULL_BEGIN -(void) startDevice; -(void) closeDevice; -(void) DMXReceived:(NSNotification*) note; +-(BOOL) isActive; @end diff --git a/LXNet2OpenDMX/LXuDMXInterface.m b/LXNet2OpenDMX/LXuDMXInterface.m index 4561563..77bde90 100644 --- a/LXNet2OpenDMX/LXuDMXInterface.m +++ b/LXNet2OpenDMX/LXuDMXInterface.m @@ -196,6 +196,7 @@ -(void) startDevice { if ( handle == NULL ) { if((handle = findDevice()) == NULL) { [self statusChange:LXuDMX_STATE_RED]; + active = NO; NSLog(@"Could not find USB device \"uDMX\" with vid=0x%x pid=0x%x\n", USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT); } } @@ -212,8 +213,10 @@ -(void) startDevice { if ( device_started ) { [self statusChange:LXuDMX_STATE_BLUE]; + active = YES; } else { [self statusChange:LXuDMX_STATE_RED]; + active = NO; } } @@ -231,9 +234,14 @@ -(void) closeDevice { } handle = NULL; + active = NO; } } +-(BOOL) isActive { + return active; +} + -(void) DMXReceived:(NSNotification*) note { if ( [[note object] receivedUniverse] == universe ) { uint8_t* idmx = [[note object] DMXArrayForRead];