Browse Source

Added empty Thread, fixed being in foreground when showing About window

Thomas Buck 8 years ago
parent
commit
cc3801f9b0

+ 6
- 0
CaseLights.xcodeproj/project.pbxproj View File

@@ -8,6 +8,7 @@
8 8
 
9 9
 /* Begin PBXBuildFile section */
10 10
 		E9AB18011C29F8CD00BF3C51 /* Serial.m in Sources */ = {isa = PBXBuildFile; fileRef = E9AB18001C29F8CD00BF3C51 /* Serial.m */; };
11
+		E9AB18061C2A173500BF3C51 /* Thread.m in Sources */ = {isa = PBXBuildFile; fileRef = E9AB18051C2A173500BF3C51 /* Thread.m */; };
11 12
 		E9F13E031C28B3D3004C6B95 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E9F13E021C28B3D3004C6B95 /* AppDelegate.m */; };
12 13
 		E9F13E061C28B3D3004C6B95 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E9F13E051C28B3D3004C6B95 /* main.m */; };
13 14
 		E9F13E081C28B3D3004C6B95 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E9F13E071C28B3D3004C6B95 /* Assets.xcassets */; };
@@ -17,6 +18,8 @@
17 18
 /* Begin PBXFileReference section */
18 19
 		E9AB17FF1C29F8CD00BF3C51 /* Serial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Serial.h; sourceTree = "<group>"; };
19 20
 		E9AB18001C29F8CD00BF3C51 /* Serial.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Serial.m; sourceTree = "<group>"; };
21
+		E9AB18041C2A173500BF3C51 /* Thread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Thread.h; sourceTree = "<group>"; };
22
+		E9AB18051C2A173500BF3C51 /* Thread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Thread.m; sourceTree = "<group>"; };
20 23
 		E9F13DFE1C28B3D3004C6B95 /* CaseLights.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CaseLights.app; sourceTree = BUILT_PRODUCTS_DIR; };
21 24
 		E9F13E011C28B3D3004C6B95 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
22 25
 		E9F13E021C28B3D3004C6B95 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -58,6 +61,8 @@
58 61
 			children = (
59 62
 				E9F13E011C28B3D3004C6B95 /* AppDelegate.h */,
60 63
 				E9F13E021C28B3D3004C6B95 /* AppDelegate.m */,
64
+				E9AB18041C2A173500BF3C51 /* Thread.h */,
65
+				E9AB18051C2A173500BF3C51 /* Thread.m */,
61 66
 				E9F13E071C28B3D3004C6B95 /* Assets.xcassets */,
62 67
 				E9F13E091C28B3D3004C6B95 /* MainMenu.xib */,
63 68
 				E9F13E0C1C28B3D3004C6B95 /* Info.plist */,
@@ -166,6 +171,7 @@
166 171
 				E9AB18011C29F8CD00BF3C51 /* Serial.m in Sources */,
167 172
 				E9F13E061C28B3D3004C6B95 /* main.m in Sources */,
168 173
 				E9F13E031C28B3D3004C6B95 /* AppDelegate.m in Sources */,
174
+				E9AB18061C2A173500BF3C51 /* Thread.m in Sources */,
169 175
 			);
170 176
 			runOnlyForDeploymentPostprocessing = 0;
171 177
 		};

+ 1
- 0
CaseLights/AppDelegate.h View File

@@ -11,6 +11,7 @@
11 11
 @interface AppDelegate : NSObject <NSApplicationDelegate>
12 12
 
13 13
 @property (weak) IBOutlet NSMenu *statusMenu;
14
+@property (weak) IBOutlet NSApplication *application;
14 15
 
15 16
 @property (weak) IBOutlet NSMenu *menuColors;
16 17
 @property (weak) IBOutlet NSMenu *menuAnimations;

+ 7
- 1
CaseLights/AppDelegate.m View File

@@ -18,9 +18,10 @@
18 18
 
19 19
 @implementation AppDelegate
20 20
 
21
-@synthesize statusMenu, statusItem, statusImage;
21
+@synthesize statusMenu, application;
22 22
 @synthesize menuColors, menuAnimations, menuVisualizations, menuPorts;
23 23
 @synthesize buttonOff, buttonLights;
24
+@synthesize statusItem, statusImage;
24 25
 @synthesize staticColors;
25 26
 
26 27
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
@@ -159,4 +160,9 @@
159 160
     // TODO Try to open selected port
160 161
 }
161 162
 
163
+- (IBAction)showAbout:(id)sender {
164
+    [NSApp activateIgnoringOtherApps:YES];
165
+    [application orderFrontStandardAboutPanel:self];
166
+}
167
+
162 168
 @end

+ 3
- 2
CaseLights/Base.lproj/MainMenu.xib View File

@@ -14,6 +14,7 @@
14 14
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
15 15
         <customObject id="Voe-Tx-rLC" customClass="AppDelegate">
16 16
             <connections>
17
+                <outlet property="application" destination="-3" id="3TG-JL-HaQ"/>
17 18
                 <outlet property="buttonLights" destination="tLQ-BA-kGu" id="FZv-Ju-l7n"/>
18 19
                 <outlet property="buttonOff" destination="gT4-tm-Hvn" id="EEv-lf-Qo7"/>
19 20
                 <outlet property="menuAnimations" destination="FJm-ND-abA" id="iGI-Hg-tms"/>
@@ -33,7 +34,7 @@
33 34
                             <menuItem title="About CaseLights" id="5kV-Vb-QxS">
34 35
                                 <modifierMask key="keyEquivalentModifierMask"/>
35 36
                                 <connections>
36
-                                    <action selector="orderFrontStandardAboutPanel:" target="-1" id="Exp-CZ-Vem"/>
37
+                                    <action selector="showAbout:" target="Voe-Tx-rLC" id="1ud-LX-A1L"/>
37 38
                                 </connections>
38 39
                             </menuItem>
39 40
                             <menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
@@ -712,7 +713,7 @@
712 713
                 <menuItem title="About CaseLights" id="GeK-ey-XEn">
713 714
                     <modifierMask key="keyEquivalentModifierMask"/>
714 715
                     <connections>
715
-                        <action selector="orderFrontStandardAboutPanel:" target="-1" id="SFx-g1-SMR"/>
716
+                        <action selector="showAbout:" target="Voe-Tx-rLC" id="Odh-zd-kmk"/>
716 717
                     </connections>
717 718
                 </menuItem>
718 719
                 <menuItem title="Quit CaseLights" keyEquivalent="q" id="2cH-5V-zpa">

+ 1
- 1
CaseLights/Info.plist View File

@@ -21,7 +21,7 @@
21 21
 	<key>CFBundleSignature</key>
22 22
 	<string>????</string>
23 23
 	<key>CFBundleVersion</key>
24
-	<string>33</string>
24
+	<string>34</string>
25 25
 	<key>LSApplicationCategoryType</key>
26 26
 	<string>public.app-category.utilities</string>
27 27
 	<key>LSMinimumSystemVersion</key>

+ 23
- 0
CaseLights/Thread.h View File

@@ -0,0 +1,23 @@
1
+//
2
+//  Thread.h
3
+//  SerialGamepad
4
+//
5
+//  Created by Thomas Buck on 15.12.15.
6
+//  Copyright © 2015 xythobuz. All rights reserved.
7
+//
8
+
9
+#import <Foundation/Foundation.h>
10
+
11
+@class AppDelegate;
12
+
13
+@interface Thread : NSThread
14
+
15
+@property BOOL running;
16
+@property int fd;
17
+@property (strong) NSString *portName;
18
+@property (weak) AppDelegate *appDelegate;
19
+
20
+- (id)initWithDelegate:(AppDelegate *)delegate;
21
+- (NSInteger)openPort;
22
+
23
+@end

+ 93
- 0
CaseLights/Thread.m View File

@@ -0,0 +1,93 @@
1
+//
2
+//  Thread.m
3
+//  SerialGamepad
4
+//
5
+//  Created by Thomas Buck on 15.12.15.
6
+//  Copyright © 2015 xythobuz. All rights reserved.
7
+//
8
+
9
+#import <termios.h>
10
+#import <fcntl.h>
11
+#import <unistd.h>
12
+#include <poll.h>
13
+
14
+#import "Thread.h"
15
+#import "AppDelegate.h"
16
+
17
+@implementation Thread
18
+
19
+@synthesize running, fd, portName, appDelegate;
20
+
21
+- (id)initWithDelegate:(AppDelegate *)delegate {
22
+    self = [super init];
23
+    if (self != nil) {
24
+        appDelegate = delegate;
25
+    }
26
+    return self;
27
+}
28
+
29
+- (NSInteger)openPort {
30
+    if (portName == nil) {
31
+        return 1;
32
+    }
33
+    
34
+    // Open port read-only, without controlling terminal, non-blocking
35
+    fd = open([portName UTF8String], O_RDONLY | O_NOCTTY | O_NONBLOCK);
36
+    if (fd == -1) {
37
+        NSLog(@"Error opening serial port \"%@\"!\n", portName);
38
+        return 1;
39
+    }
40
+    
41
+    fcntl(fd, F_SETFL, 0); // Enable blocking I/O
42
+    
43
+    // Read current settings
44
+    struct termios options;
45
+    tcgetattr(fd, &options);
46
+    
47
+    options.c_lflag = 0;
48
+    options.c_oflag = 0;
49
+    options.c_iflag = 0;
50
+    options.c_cflag = 0;
51
+    
52
+    options.c_cflag |= CS8; // 8 data bits
53
+    options.c_cflag |= CREAD; // Enable receiver
54
+    options.c_cflag |= CLOCAL; // Ignore modem status lines
55
+    
56
+    cfsetispeed(&options, B115200);
57
+    cfsetospeed(&options, B115200);
58
+    
59
+    options.c_cc[VMIN] = 0; // Return even with zero bytes...
60
+    options.c_cc[VTIME] = 1; // ...but only after .1 seconds
61
+    
62
+    // Set new settings
63
+    tcsetattr(fd, TCSANOW, &options);
64
+    tcflush(fd, TCIOFLUSH);
65
+    
66
+    return 0;
67
+}
68
+
69
+- (NSInteger)hasData {
70
+    struct pollfd fds;
71
+    fds.fd = fd;
72
+    fds.events = (POLLIN | POLLPRI); // Data may be read
73
+    if (poll(&fds, 1, 0) > 0) {
74
+        return 1;
75
+    } else {
76
+        return 0;
77
+    }
78
+}
79
+
80
+- (void)main {
81
+    NSLog(@"Connection running...\n");
82
+    
83
+    running = YES;
84
+    while (running) {
85
+        
86
+    }
87
+    
88
+    close(fd);
89
+    NSLog(@"Connection closed...\n");
90
+    fd = -1;
91
+}
92
+
93
+@end

Loading…
Cancel
Save