Browse Source

Prepared for implementation of all animated visualizations

Thomas Buck 8 years ago
parent
commit
5e16b1f968
3 changed files with 137 additions and 64 deletions
  1. 0
    7
      CaseLights/AppDelegate.h
  2. 136
    56
      CaseLights/AppDelegate.m
  3. 1
    1
      CaseLights/Info.plist

+ 0
- 7
CaseLights/AppDelegate.h View File

23
 @property (weak) IBOutlet NSMenuItem *buttonOff;
23
 @property (weak) IBOutlet NSMenuItem *buttonOff;
24
 @property (weak) IBOutlet NSMenuItem *buttonLights;
24
 @property (weak) IBOutlet NSMenuItem *buttonLights;
25
 
25
 
26
-@property (strong) NSStatusItem *statusItem;
27
-@property (strong) NSImage *statusImage;
28
-
29
-@property (strong) NSDictionary *staticColors;
30
-
31
-@property (strong) Serial *serial;
32
-
33
 @end
26
 @end
34
 
27
 

+ 136
- 56
CaseLights/AppDelegate.m View File

22
 #define TEXT_VRAM_USAGE @"VRAM Usage"
22
 #define TEXT_VRAM_USAGE @"VRAM Usage"
23
 #define TEXT_CPU_TEMPERATURE @"CPU Temperature"
23
 #define TEXT_CPU_TEMPERATURE @"CPU Temperature"
24
 #define TEXT_GPU_TEMPERATURE @"GPU Temperature"
24
 #define TEXT_GPU_TEMPERATURE @"GPU Temperature"
25
+#define TEXT_RGB_FADE @"RGB Fade"
26
+#define TEXT_HSV_FADE @"HSV Fade"
25
 
27
 
26
 #define KEY_CPU_TEMPERATURE @"TC0D"
28
 #define KEY_CPU_TEMPERATURE @"TC0D"
27
 #define KEY_GPU_TEMPERATURE @"TG0D"
29
 #define KEY_GPU_TEMPERATURE @"TG0D"
28
 
30
 
29
 @interface AppDelegate ()
31
 @interface AppDelegate ()
30
 
32
 
31
-@property (weak) NSMenuItem *lastLEDMode;
33
+@property (strong) NSStatusItem *statusItem;
34
+@property (strong) NSImage *statusImage;
35
+@property (strong) NSDictionary *staticColors;
36
+@property (strong) NSTimer *animation;
37
+@property (strong) Serial *serial;
38
+@property (strong) NSMenuItem *lastLEDMode;
32
 
39
 
33
 @end
40
 @end
34
 
41
 
38
 @synthesize menuColors, menuAnimations, menuVisualizations, menuPorts;
45
 @synthesize menuColors, menuAnimations, menuVisualizations, menuPorts;
39
 @synthesize buttonOff, buttonLights;
46
 @synthesize buttonOff, buttonLights;
40
 @synthesize statusItem, statusImage;
47
 @synthesize statusItem, statusImage;
41
-@synthesize staticColors;
48
+@synthesize staticColors, animation;
42
 @synthesize serial, lastLEDMode;
49
 @synthesize serial, lastLEDMode;
43
 
50
 
44
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
51
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
45
     serial = [[Serial alloc] init];
52
     serial = [[Serial alloc] init];
46
     lastLEDMode = nil;
53
     lastLEDMode = nil;
54
+    animation = nil;
47
     
55
     
48
     // Prepare status bar menu
56
     // Prepare status bar menu
49
     statusImage = [NSImage imageNamed:@"MenuIcon"];
57
     statusImage = [NSImage imageNamed:@"MenuIcon"];
110
         [menuColors addItem:item];
118
         [menuColors addItem:item];
111
     }
119
     }
112
     
120
     
113
-    // TODO Prepare animations menu
121
+    // Prepare animations menu
122
+    NSArray *animationStrings = [NSArray arrayWithObjects:
123
+                        TEXT_RGB_FADE,
124
+                        TEXT_HSV_FADE,
125
+                        nil];
126
+    for (NSString *key in animationStrings) {
127
+        NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:key action:@selector(selectedVisualization:) keyEquivalent:@""];
128
+        if ([key isEqualToString:lastMode]) {
129
+            [self selectedVisualization:item];
130
+        }
131
+        [menuAnimations addItem:item];
132
+    }
114
     
133
     
115
     JSKSystemMonitor *systemMonitor = [JSKSystemMonitor systemMonitor];
134
     JSKSystemMonitor *systemMonitor = [JSKSystemMonitor systemMonitor];
116
     
135
     
294
     [store synchronize];
313
     [store synchronize];
295
 }
314
 }
296
 
315
 
316
+- (void)visualizeGPUUsage:(NSTimer *)timer {
317
+}
318
+
319
+- (void)visualizeVRAMUsage:(NSTimer *)timer {
320
+}
321
+
322
+- (void)visualizeCPUUsage:(NSTimer *)timer {
323
+}
324
+
325
+- (void)visualizeRAMUsage:(NSTimer *)timer {
326
+}
327
+
328
+- (void)visualizeGPUTemperature:(NSTimer *)timer {
329
+}
330
+
331
+- (void)visualizeCPUTemperature:(NSTimer *)timer {
332
+}
333
+
334
+- (void)visualizeRGBFade:(NSTimer *)timer {
335
+}
336
+
337
+- (void)visualizeHSVFade:(NSTimer *)timer {
338
+}
339
+
340
+- (BOOL)timedVisualization:(NSString *)mode {
341
+    // Stop previous timer setting
342
+    if (animation != nil) {
343
+        [animation invalidate];
344
+        animation = nil;
345
+    }
346
+    
347
+    // Schedule next invocation for this animation...
348
+    if ([mode isEqualToString:TEXT_GPU_USAGE]) {
349
+        animation = [NSTimer timerWithTimeInterval:5.0 target:self selector:@selector(visualizeGPUUsage:) userInfo:mode repeats:YES];
350
+    } else if ([mode isEqualToString:TEXT_VRAM_USAGE]) {
351
+        animation = [NSTimer timerWithTimeInterval:5.0 target:self selector:@selector(visualizeVRAMUsage:) userInfo:mode repeats:YES];
352
+    } else if ([mode isEqualToString:TEXT_CPU_USAGE]) {
353
+        animation = [NSTimer timerWithTimeInterval:5.0 target:self selector:@selector(visualizeCPUUsage:) userInfo:mode repeats:YES];
354
+    } else if ([mode isEqualToString:TEXT_RAM_USAGE]) {
355
+        animation = [NSTimer timerWithTimeInterval:20.0 target:self selector:@selector(visualizeRAMUsage:) userInfo:mode repeats:YES];
356
+    } else if ([mode isEqualToString:TEXT_CPU_TEMPERATURE]) {
357
+        animation = [NSTimer timerWithTimeInterval:5.0 target:self selector:@selector(visualizeCPUTemperature:) userInfo:mode repeats:YES];
358
+    } else if ([mode isEqualToString:TEXT_GPU_TEMPERATURE]) {
359
+        animation = [NSTimer timerWithTimeInterval:5.0 target:self selector:@selector(visualizeGPUTemperature:) userInfo:mode repeats:YES];
360
+    } else if ([mode isEqualToString:TEXT_RGB_FADE]) {
361
+        animation = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(visualizeRGBFade:) userInfo:mode repeats:YES];
362
+    } else if ([mode isEqualToString:TEXT_HSV_FADE]) {
363
+        animation = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(visualizeHSVFade:) userInfo:mode repeats:YES];
364
+    } else {
365
+        return NO;
366
+    }
367
+    
368
+    // ...and also execute it right now
369
+    [animation fire];
370
+    return YES;
371
+}
372
+
297
 - (void)selectedVisualization:(NSMenuItem *)sender {
373
 - (void)selectedVisualization:(NSMenuItem *)sender {
298
     // Turn off all other LED menu items
374
     // Turn off all other LED menu items
299
     if (menuColors != nil) {
375
     if (menuColors != nil) {
314
     [buttonOff setState:NSOffState];
390
     [buttonOff setState:NSOffState];
315
     [sender setState:NSOnState];
391
     [sender setState:NSOnState];
316
     
392
     
317
-    if ([sender.title isEqualToString:TEXT_GPU_USAGE]) {
318
-        // TODO send command
319
-        
320
-    } else if ([sender.title isEqualToString:TEXT_VRAM_USAGE]) {
321
-        // TODO send command
322
-        
323
-    } else if ([sender.title isEqualToString:TEXT_GPU_TEMPERATURE]) {
324
-        // TODO send command
325
-        
326
-    } else if ([sender.title isEqualToString:TEXT_CPU_USAGE]) {
327
-        // TODO send command
328
-        
329
-    } else if ([sender.title isEqualToString:TEXT_CPU_TEMPERATURE]) {
330
-        // TODO send command
331
-        
332
-    } else if ([sender.title isEqualToString:TEXT_RAM_USAGE]) {
333
-        // TODO send command
334
-        
335
-    } else {
336
-        BOOL found = NO;
337
-        
338
-        // Check if a static color was selected
339
-        if (staticColors != nil) {
340
-            for (NSString *key in [staticColors allKeys]) {
341
-                if ([sender.title isEqualToString:key]) {
342
-                    found = YES;
343
-                    
344
-                    NSColor *color = [staticColors valueForKey:key];
345
-                    unsigned char red = [color redComponent] * 255;
346
-                    unsigned char green = [color greenComponent] * 255;
347
-                    unsigned char blue = [color blueComponent] * 255;
348
-                    NSString *string = [NSString stringWithFormat:@"RGB %d %d %d\n", red, green, blue];
349
-                    
350
-                    if ([serial isOpen]) {
351
-                        [serial sendString:string];
352
-                    }
393
+    // Check if a static color was selected
394
+    BOOL found = NO;
395
+    if (staticColors != nil) {
396
+        for (NSString *key in [staticColors allKeys]) {
397
+            if ([sender.title isEqualToString:key]) {
398
+                found = YES;
399
+                
400
+                NSColor *color = [staticColors valueForKey:key];
401
+                unsigned char red = [color redComponent] * 255;
402
+                unsigned char green = [color greenComponent] * 255;
403
+                unsigned char blue = [color blueComponent] * 255;
404
+                NSString *string = [NSString stringWithFormat:@"RGB %d %d %d\n", red, green, blue];
405
+                
406
+                if ([serial isOpen]) {
407
+                    [serial sendString:string];
353
                 }
408
                 }
409
+                
410
+                break;
354
             }
411
             }
355
         }
412
         }
356
-        
357
-        if (found) goto end_found;
358
-        
359
-        // TODO Check if an animation was selected
360
-        
361
-        NSLog(@"Unknown LED Visualization selected!\n");
362
-        return;
363
     }
413
     }
364
-
365
-    end_found: {
366
-        // Store changed value in preferences
367
-        NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
368
-        [store setObject:[sender title] forKey:PREF_LED_MODE];
369
-        [store synchronize];
370
-        
414
+    
415
+    if (!found) {
416
+        // Check if an animated visualization was selected
417
+        if ([self timedVisualization:[sender title]] == NO) {
418
+            NSLog(@"Unknown LED Visualization selected!\n");
419
+            return;
420
+        }
421
+    }
422
+    
423
+    // Store changed value in preferences
424
+    NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
425
+    [store setObject:[sender title] forKey:PREF_LED_MODE];
426
+    [store synchronize];
427
+    
371
 #ifdef DEBUG
428
 #ifdef DEBUG
372
-        NSLog(@"Stored new mode: \"%@\"!\n", [sender title]);
429
+    NSLog(@"Stored new mode: \"%@\"!\n", [sender title]);
373
 #endif
430
 #endif
374
-    }
375
 }
431
 }
376
 
432
 
377
 - (void)selectedSerialPort:(NSMenuItem *)source {
433
 - (void)selectedSerialPort:(NSMenuItem *)source {
398
     if ([serial openPort] != 0) {
454
     if ([serial openPort] != 0) {
399
         [source setState:NSOffState];
455
         [source setState:NSOffState];
400
     } else {
456
     } else {
401
-        // TODO Restore the current configuration
457
+        // Restore the current configuration
458
+        for (int i = 0; i < [menuColors numberOfItems]; i++) {
459
+            if ([[menuColors itemAtIndex:i] state] == NSOnState) {
460
+                [self selectedVisualization:[menuColors itemAtIndex:i]];
461
+            }
462
+        }
463
+        for (int i = 0; i < [menuAnimations numberOfItems]; i++) {
464
+            if ([[menuAnimations itemAtIndex:i] state] == NSOnState) {
465
+                [self selectedVisualization:[menuAnimations itemAtIndex:i]];
466
+            }
467
+        }
468
+        for (int i = 0; i < [menuVisualizations numberOfItems]; i++) {
469
+            if ([[menuVisualizations itemAtIndex:i] state] == NSOnState) {
470
+                [self selectedVisualization:[menuVisualizations itemAtIndex:i]];
471
+            }
472
+        }
473
+        if ([buttonOff state] == NSOnState) {
474
+            [buttonOff setState:NSOffState];
475
+            [self turnLEDsOff:buttonOff];
476
+        }
477
+        if ([buttonLights state] == NSOnState) {
478
+            [serial sendString:@"UV 1\n"];
479
+        } else {
480
+            [serial sendString:@"UV 0\n"];
481
+        }
402
     }
482
     }
403
 }
483
 }
404
 
484
 

+ 1
- 1
CaseLights/Info.plist View File

21
 	<key>CFBundleSignature</key>
21
 	<key>CFBundleSignature</key>
22
 	<string>????</string>
22
 	<string>????</string>
23
 	<key>CFBundleVersion</key>
23
 	<key>CFBundleVersion</key>
24
-	<string>83</string>
24
+	<string>84</string>
25
 	<key>LSApplicationCategoryType</key>
25
 	<key>LSApplicationCategoryType</key>
26
 	<string>public.app-category.utilities</string>
26
 	<string>public.app-category.utilities</string>
27
 	<key>LSMinimumSystemVersion</key>
27
 	<key>LSMinimumSystemVersion</key>

Loading…
Cancel
Save