|
@@ -22,13 +22,20 @@
|
22
|
22
|
#define TEXT_VRAM_USAGE @"VRAM Usage"
|
23
|
23
|
#define TEXT_CPU_TEMPERATURE @"CPU Temperature"
|
24
|
24
|
#define TEXT_GPU_TEMPERATURE @"GPU Temperature"
|
|
25
|
+#define TEXT_RGB_FADE @"RGB Fade"
|
|
26
|
+#define TEXT_HSV_FADE @"HSV Fade"
|
25
|
27
|
|
26
|
28
|
#define KEY_CPU_TEMPERATURE @"TC0D"
|
27
|
29
|
#define KEY_GPU_TEMPERATURE @"TG0D"
|
28
|
30
|
|
29
|
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
|
40
|
@end
|
34
|
41
|
|
|
@@ -38,12 +45,13 @@
|
38
|
45
|
@synthesize menuColors, menuAnimations, menuVisualizations, menuPorts;
|
39
|
46
|
@synthesize buttonOff, buttonLights;
|
40
|
47
|
@synthesize statusItem, statusImage;
|
41
|
|
-@synthesize staticColors;
|
|
48
|
+@synthesize staticColors, animation;
|
42
|
49
|
@synthesize serial, lastLEDMode;
|
43
|
50
|
|
44
|
51
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
45
|
52
|
serial = [[Serial alloc] init];
|
46
|
53
|
lastLEDMode = nil;
|
|
54
|
+ animation = nil;
|
47
|
55
|
|
48
|
56
|
// Prepare status bar menu
|
49
|
57
|
statusImage = [NSImage imageNamed:@"MenuIcon"];
|
|
@@ -110,7 +118,18 @@
|
110
|
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
|
134
|
JSKSystemMonitor *systemMonitor = [JSKSystemMonitor systemMonitor];
|
116
|
135
|
|
|
@@ -294,6 +313,63 @@
|
294
|
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
|
373
|
- (void)selectedVisualization:(NSMenuItem *)sender {
|
298
|
374
|
// Turn off all other LED menu items
|
299
|
375
|
if (menuColors != nil) {
|
|
@@ -314,64 +390,44 @@
|
314
|
390
|
[buttonOff setState:NSOffState];
|
315
|
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
|
428
|
#ifdef DEBUG
|
372
|
|
- NSLog(@"Stored new mode: \"%@\"!\n", [sender title]);
|
|
429
|
+ NSLog(@"Stored new mode: \"%@\"!\n", [sender title]);
|
373
|
430
|
#endif
|
374
|
|
- }
|
375
|
431
|
}
|
376
|
432
|
|
377
|
433
|
- (void)selectedSerialPort:(NSMenuItem *)source {
|
|
@@ -398,7 +454,31 @@
|
398
|
454
|
if ([serial openPort] != 0) {
|
399
|
455
|
[source setState:NSOffState];
|
400
|
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
|
|