|
@@ -29,6 +29,22 @@
|
29
|
29
|
#define KEY_CPU_TEMPERATURE @"TC0D"
|
30
|
30
|
#define KEY_GPU_TEMPERATURE @"TG0D"
|
31
|
31
|
|
|
32
|
+// Temperature in Celsius
|
|
33
|
+#define CPU_TEMP_MIN 20
|
|
34
|
+#define CPU_TEMP_MAX 90
|
|
35
|
+
|
|
36
|
+// HSV Color (S = V = 1)
|
|
37
|
+#define CPU_COLOR_MIN 120
|
|
38
|
+#define CPU_COLOR_MAX 0
|
|
39
|
+
|
|
40
|
+#define GPU_TEMP_MIN 20
|
|
41
|
+#define GPU_TEMP_MAX 90
|
|
42
|
+#define GPU_COLOR_MIN 120
|
|
43
|
+#define GPU_COLOR_MAX 0
|
|
44
|
+
|
|
45
|
+#define RAM_COLOR_MIN 0
|
|
46
|
+#define RAM_COLOR_MAX 120
|
|
47
|
+
|
32
|
48
|
@interface AppDelegate ()
|
33
|
49
|
|
34
|
50
|
@property (strong) NSStatusItem *statusItem;
|
|
@@ -135,16 +151,6 @@
|
135
|
151
|
[menuAnimations addItem:item];
|
136
|
152
|
}
|
137
|
153
|
|
138
|
|
- JSKSystemMonitor *systemMonitor = [JSKSystemMonitor systemMonitor];
|
139
|
|
-
|
140
|
|
-#ifdef DEBUG
|
141
|
|
- JSKMCPUUsageInfo cpuUsageInfo = systemMonitor.cpuUsageInfo;
|
142
|
|
- NSLog(@"CPU Usage: %.3f%%\n", cpuUsageInfo.usage);
|
143
|
|
-
|
144
|
|
- JSKMMemoryUsageInfo memoryUsageInfo = systemMonitor.memoryUsageInfo;
|
145
|
|
- NSLog(@"Memory Usage: %.2fGB Free + %.2fGB Used = %.2fGB\n", memoryUsageInfo.freeMemory / (1024.0 * 1024.0 * 1024.0), memoryUsageInfo.usedMemory / (1024.0 * 1024.0 * 1024.0), (memoryUsageInfo.freeMemory + memoryUsageInfo.usedMemory) / (1024.0 * 1024.0 * 1024.0));
|
146
|
|
-#endif
|
147
|
|
-
|
148
|
154
|
// Add CPU Usage menu item
|
149
|
155
|
NSMenuItem *cpuUsageItem = [[NSMenuItem alloc] initWithTitle:TEXT_CPU_USAGE action:@selector(selectedVisualization:) keyEquivalent:@""];
|
150
|
156
|
if ([lastMode isEqualToString:TEXT_CPU_USAGE]) {
|
|
@@ -324,27 +330,141 @@
|
324
|
330
|
}
|
325
|
331
|
|
326
|
332
|
- (void)visualizeGPUUsage:(NSTimer *)timer {
|
327
|
|
- // TODO
|
|
333
|
+ NSNumber *usage;
|
|
334
|
+ NSNumber *freeVRAM;
|
|
335
|
+ NSNumber *usedVRAM;
|
|
336
|
+ if ([GPUStats getGPUUsage:&usage freeVRAM:&freeVRAM usedVRAM:&usedVRAM] != 0) {
|
|
337
|
+ NSLog(@"Error reading GPU information\n");
|
|
338
|
+ } else {
|
|
339
|
+ double h = [self map:[usage doubleValue] FromMin:0.0 FromMax:100.0 ToMin:GPU_COLOR_MIN ToMax:GPU_COLOR_MAX];
|
|
340
|
+
|
|
341
|
+#ifdef DEBUG
|
|
342
|
+ NSLog(@"GPU Usage: %.3f%%\n", [usage doubleValue]);
|
|
343
|
+#endif
|
|
344
|
+
|
|
345
|
+ unsigned char r, g, b;
|
|
346
|
+ [self convertH:h S:1.0 V:1.0 toR:&r G:&g B:&b];
|
|
347
|
+
|
|
348
|
+ if ([serial isOpen]) {
|
|
349
|
+ [serial sendString:[NSString stringWithFormat:@"RGB %d %d %d\n", r, g, b]];
|
|
350
|
+ }
|
|
351
|
+ }
|
328
|
352
|
}
|
329
|
353
|
|
330
|
354
|
- (void)visualizeVRAMUsage:(NSTimer *)timer {
|
331
|
|
- // TODO
|
|
355
|
+ NSNumber *usage;
|
|
356
|
+ NSNumber *freeVRAM;
|
|
357
|
+ NSNumber *usedVRAM;
|
|
358
|
+ if ([GPUStats getGPUUsage:&usage freeVRAM:&freeVRAM usedVRAM:&usedVRAM] != 0) {
|
|
359
|
+ NSLog(@"Error reading GPU information\n");
|
|
360
|
+ } else {
|
|
361
|
+ double h = [self map:[freeVRAM doubleValue] FromMin:0.0 FromMax:([freeVRAM doubleValue] + [usedVRAM doubleValue]) ToMin:RAM_COLOR_MIN ToMax:RAM_COLOR_MAX];
|
|
362
|
+
|
|
363
|
+#ifdef DEBUG
|
|
364
|
+ NSLog(@"VRAM %.2fGB Free + %.2fGB Used = %.2fGB mapped to color %.2f!\n", [freeVRAM doubleValue] / (1024.0 * 1024.0 * 1024.0), [usedVRAM doubleValue] / (1024.0 * 1024.0 * 1024.0), ([freeVRAM doubleValue] + [usedVRAM doubleValue]) / (1024.0 * 1024.0 * 1024.0), h);
|
|
365
|
+#endif
|
|
366
|
+
|
|
367
|
+ unsigned char r, g, b;
|
|
368
|
+ [self convertH:h S:1.0 V:1.0 toR:&r G:&g B:&b];
|
|
369
|
+
|
|
370
|
+ if ([serial isOpen]) {
|
|
371
|
+ [serial sendString:[NSString stringWithFormat:@"RGB %d %d %d\n", r, g, b]];
|
|
372
|
+ }
|
|
373
|
+ }
|
332
|
374
|
}
|
333
|
375
|
|
334
|
376
|
- (void)visualizeCPUUsage:(NSTimer *)timer {
|
335
|
|
- // TODO
|
|
377
|
+ JSKMCPUUsageInfo cpuUsageInfo = [JSKSystemMonitor systemMonitor].cpuUsageInfo;
|
|
378
|
+
|
|
379
|
+ double h = [self map:cpuUsageInfo.usage FromMin:0.0 FromMax:100.0 ToMin:CPU_COLOR_MIN ToMax:CPU_COLOR_MAX];
|
|
380
|
+
|
|
381
|
+#ifdef DEBUG
|
|
382
|
+ NSLog(@"CPU Usage: %.3f%%\n", cpuUsageInfo.usage);
|
|
383
|
+#endif
|
|
384
|
+
|
|
385
|
+ unsigned char r, g, b;
|
|
386
|
+ [self convertH:h S:1.0 V:1.0 toR:&r G:&g B:&b];
|
|
387
|
+
|
|
388
|
+ if ([serial isOpen]) {
|
|
389
|
+ [serial sendString:[NSString stringWithFormat:@"RGB %d %d %d\n", r, g, b]];
|
|
390
|
+ }
|
336
|
391
|
}
|
337
|
392
|
|
338
|
393
|
- (void)visualizeRAMUsage:(NSTimer *)timer {
|
339
|
|
- // TODO
|
|
394
|
+ JSKMMemoryUsageInfo memoryUsageInfo = [JSKSystemMonitor systemMonitor].memoryUsageInfo;
|
|
395
|
+
|
|
396
|
+ double h = [self map:memoryUsageInfo.freeMemory FromMin:0.0 FromMax:(memoryUsageInfo.usedMemory + memoryUsageInfo.freeMemory) ToMin:RAM_COLOR_MIN ToMax:RAM_COLOR_MAX];
|
|
397
|
+
|
|
398
|
+#ifdef DEBUG
|
|
399
|
+ NSLog(@"RAM %.2fGB Free + %.2fGB Used = %.2fGB mapped to color %.2f!\n", memoryUsageInfo.freeMemory / (1024.0 * 1024.0 * 1024.0), memoryUsageInfo.usedMemory / (1024.0 * 1024.0 * 1024.0), (memoryUsageInfo.freeMemory + memoryUsageInfo.usedMemory) / (1024.0 * 1024.0 * 1024.0), h);
|
|
400
|
+#endif
|
|
401
|
+
|
|
402
|
+ unsigned char r, g, b;
|
|
403
|
+ [self convertH:h S:1.0 V:1.0 toR:&r G:&g B:&b];
|
|
404
|
+
|
|
405
|
+ if ([serial isOpen]) {
|
|
406
|
+ [serial sendString:[NSString stringWithFormat:@"RGB %d %d %d\n", r, g, b]];
|
|
407
|
+ }
|
340
|
408
|
}
|
341
|
409
|
|
342
|
410
|
- (void)visualizeGPUTemperature:(NSTimer *)timer {
|
343
|
|
- // TODO
|
|
411
|
+ JSKSMC *smc = [JSKSMC smc];
|
|
412
|
+ double temp = [smc temperatureInCelsiusForKey:KEY_GPU_TEMPERATURE];
|
|
413
|
+
|
|
414
|
+ if (temp > 1000.0) {
|
|
415
|
+ temp /= 1000.0;
|
|
416
|
+ }
|
|
417
|
+
|
|
418
|
+ if (temp > GPU_TEMP_MAX) {
|
|
419
|
+ temp = GPU_TEMP_MAX;
|
|
420
|
+ }
|
|
421
|
+
|
|
422
|
+ if (temp < GPU_TEMP_MIN) {
|
|
423
|
+ temp = GPU_TEMP_MIN;
|
|
424
|
+ }
|
|
425
|
+
|
|
426
|
+ double h = [self map:temp FromMin:GPU_TEMP_MIN FromMax:GPU_TEMP_MAX ToMin:GPU_COLOR_MIN ToMax:GPU_COLOR_MAX];
|
|
427
|
+
|
|
428
|
+#ifdef DEBUG
|
|
429
|
+ NSLog(@"GPU Temp %.2f mapped to color %.2f!\n", temp, h);
|
|
430
|
+#endif
|
|
431
|
+
|
|
432
|
+ unsigned char r, g, b;
|
|
433
|
+ [self convertH:h S:1.0 V:1.0 toR:&r G:&g B:&b];
|
|
434
|
+
|
|
435
|
+ if ([serial isOpen]) {
|
|
436
|
+ [serial sendString:[NSString stringWithFormat:@"RGB %d %d %d\n", r, g, b]];
|
|
437
|
+ }
|
344
|
438
|
}
|
345
|
439
|
|
346
|
440
|
- (void)visualizeCPUTemperature:(NSTimer *)timer {
|
347
|
|
- // TODO
|
|
441
|
+ JSKSMC *smc = [JSKSMC smc];
|
|
442
|
+ double temp = [smc temperatureInCelsiusForKey:KEY_CPU_TEMPERATURE];
|
|
443
|
+
|
|
444
|
+ if (temp > 1000.0) {
|
|
445
|
+ temp /= 1000.0;
|
|
446
|
+ }
|
|
447
|
+
|
|
448
|
+ if (temp > CPU_TEMP_MAX) {
|
|
449
|
+ temp = CPU_TEMP_MAX;
|
|
450
|
+ }
|
|
451
|
+
|
|
452
|
+ if (temp < CPU_TEMP_MIN) {
|
|
453
|
+ temp = CPU_TEMP_MIN;
|
|
454
|
+ }
|
|
455
|
+
|
|
456
|
+ double h = [self map:temp FromMin:CPU_TEMP_MIN FromMax:CPU_TEMP_MAX ToMin:CPU_COLOR_MIN ToMax:CPU_COLOR_MAX];
|
|
457
|
+
|
|
458
|
+#ifdef DEBUG
|
|
459
|
+ NSLog(@"CPU Temp %.2f mapped to color %.2f!\n", temp, h);
|
|
460
|
+#endif
|
|
461
|
+
|
|
462
|
+ unsigned char r, g, b;
|
|
463
|
+ [self convertH:h S:1.0 V:1.0 toR:&r G:&g B:&b];
|
|
464
|
+
|
|
465
|
+ if ([serial isOpen]) {
|
|
466
|
+ [serial sendString:[NSString stringWithFormat:@"RGB %d %d %d\n", r, g, b]];
|
|
467
|
+ }
|
348
|
468
|
}
|
349
|
469
|
|
350
|
470
|
- (void)visualizeRGBFade:(NSTimer *)timer {
|
|
@@ -553,6 +673,11 @@
|
553
|
673
|
[application orderFrontStandardAboutPanel:self];
|
554
|
674
|
}
|
555
|
675
|
|
|
676
|
+- (double)map:(double)val FromMin:(double)fmin FromMax:(double)fmax ToMin:(double)tmin ToMax:(double)tmax {
|
|
677
|
+ double norm = (val - fmin) / (fmax - fmin);
|
|
678
|
+ return (norm * (tmax - tmin)) + tmin;
|
|
679
|
+}
|
|
680
|
+
|
556
|
681
|
- (void)convertH:(double)h S:(double)s V:(double)v toR:(unsigned char *)r G:(unsigned char *)g B:(unsigned char *)b {
|
557
|
682
|
// Adapted from:
|
558
|
683
|
// https://gist.github.com/hdznrrd/656996
|