|
@@ -15,6 +15,7 @@
|
15
|
15
|
#define PREF_SERIAL_PORT @"SerialPort"
|
16
|
16
|
#define PREF_LIGHTS_STATE @"LightState"
|
17
|
17
|
#define PREF_LED_MODE @"LEDMode"
|
|
18
|
+#define PREF_BRIGHTNESS @"Brightness"
|
18
|
19
|
|
19
|
20
|
#define TEXT_CPU_USAGE @"CPU Usage"
|
20
|
21
|
#define TEXT_RAM_USAGE @"RAM Usage"
|
|
@@ -61,6 +62,7 @@
|
61
|
62
|
@synthesize statusMenu, application;
|
62
|
63
|
@synthesize menuColors, menuAnimations, menuVisualizations, menuPorts;
|
63
|
64
|
@synthesize buttonOff, buttonLights;
|
|
65
|
+@synthesize brightnessItem, brightnessSlider, brightnessLabel;
|
64
|
66
|
@synthesize statusItem, statusImage;
|
65
|
67
|
@synthesize staticColors, animation;
|
66
|
68
|
@synthesize serial, lastLEDMode;
|
|
@@ -84,11 +86,18 @@
|
84
|
86
|
NSMutableDictionary *appDefaults = [NSMutableDictionary dictionaryWithObject:@"" forKey:PREF_SERIAL_PORT];
|
85
|
87
|
[appDefaults setObject:[NSNumber numberWithBool:NO] forKey:PREF_LIGHTS_STATE];
|
86
|
88
|
[appDefaults setObject:@"" forKey:PREF_LED_MODE];
|
|
89
|
+ [appDefaults setObject:[NSNumber numberWithFloat:50.0] forKey:PREF_BRIGHTNESS];
|
87
|
90
|
[store registerDefaults:appDefaults];
|
88
|
91
|
[store synchronize];
|
89
|
92
|
NSString *savedPort = [store stringForKey:PREF_SERIAL_PORT];
|
90
|
93
|
BOOL turnOnLights = [store boolForKey:PREF_LIGHTS_STATE];
|
91
|
94
|
NSString *lastMode = [store stringForKey:PREF_LED_MODE];
|
|
95
|
+ float brightness = [store floatForKey:PREF_BRIGHTNESS];
|
|
96
|
+
|
|
97
|
+ // Prepare brightness menu
|
|
98
|
+ brightnessItem.view = brightnessSlider;
|
|
99
|
+ [brightnessSlider setFloatValue:brightness];
|
|
100
|
+ [brightnessLabel setTitle:[NSString stringWithFormat:@"Value: %.0f%%", brightness]];
|
92
|
101
|
|
93
|
102
|
// Prepare serial port menu
|
94
|
103
|
NSArray *ports = [Serial listSerialPorts];
|
|
@@ -234,6 +243,20 @@
|
234
|
243
|
[serial closePort];
|
235
|
244
|
}
|
236
|
245
|
}
|
|
246
|
+
|
|
247
|
+- (void)setLightsR:(unsigned char)r G:(unsigned char)g B:(unsigned char)b {
|
|
248
|
+ if ([serial isOpen]) {
|
|
249
|
+ unsigned char red = r * ([brightnessSlider floatValue] / 100.0);
|
|
250
|
+ unsigned char green = g * ([brightnessSlider floatValue] / 100.0);
|
|
251
|
+ unsigned char blue = b * ([brightnessSlider floatValue] / 100.0);
|
|
252
|
+ [serial sendString:[NSString stringWithFormat:@"RGB %d %d %d\n", red, green, blue]];
|
|
253
|
+ } else {
|
|
254
|
+#ifdef DEBUG
|
|
255
|
+ NSLog(@"Trying to send RGB without opened port!\n");
|
|
256
|
+#endif
|
|
257
|
+ }
|
|
258
|
+}
|
|
259
|
+
|
237
|
260
|
- (IBAction)relistSerialPorts:(id)sender {
|
238
|
261
|
// Refill port list
|
239
|
262
|
NSArray *ports = [Serial listSerialPorts];
|
|
@@ -252,6 +275,15 @@
|
252
|
275
|
}
|
253
|
276
|
}
|
254
|
277
|
|
|
278
|
+- (IBAction)brightnessMoved:(NSSlider *)sender {
|
|
279
|
+ [brightnessLabel setTitle:[NSString stringWithFormat:@"Value: %.0f%%", [sender floatValue]]];
|
|
280
|
+
|
|
281
|
+ // Store changed value in preferences
|
|
282
|
+ NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
|
|
283
|
+ [store setObject:[NSNumber numberWithFloat:[sender floatValue]] forKey:PREF_BRIGHTNESS];
|
|
284
|
+ [store synchronize];
|
|
285
|
+}
|
|
286
|
+
|
255
|
287
|
- (IBAction)turnLEDsOff:(NSMenuItem *)sender {
|
256
|
288
|
if ([sender state] == NSOffState) {
|
257
|
289
|
lastLEDMode = nil;
|
|
@@ -295,9 +327,7 @@
|
295
|
327
|
#endif
|
296
|
328
|
|
297
|
329
|
// Send command to turn off LEDs
|
298
|
|
- if ([serial isOpen]) {
|
299
|
|
- [serial sendString:@"RGB 0 0 0\n"];
|
300
|
|
- }
|
|
330
|
+ [self setLightsR:0 G:0 B:0];
|
301
|
331
|
} else {
|
302
|
332
|
// Try to restore last LED setting
|
303
|
333
|
if (lastLEDMode != nil) {
|
|
@@ -344,10 +374,7 @@
|
344
|
374
|
|
345
|
375
|
unsigned char r, g, b;
|
346
|
376
|
[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
|
|
- }
|
|
377
|
+ [self setLightsR:r G:g B:b];
|
351
|
378
|
}
|
352
|
379
|
}
|
353
|
380
|
|
|
@@ -366,10 +393,7 @@
|
366
|
393
|
|
367
|
394
|
unsigned char r, g, b;
|
368
|
395
|
[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
|
|
- }
|
|
396
|
+ [self setLightsR:r G:g B:b];
|
373
|
397
|
}
|
374
|
398
|
}
|
375
|
399
|
|
|
@@ -384,10 +408,7 @@
|
384
|
408
|
|
385
|
409
|
unsigned char r, g, b;
|
386
|
410
|
[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
|
|
- }
|
|
411
|
+ [self setLightsR:r G:g B:b];
|
391
|
412
|
}
|
392
|
413
|
|
393
|
414
|
- (void)visualizeRAMUsage:(NSTimer *)timer {
|
|
@@ -401,10 +422,7 @@
|
401
|
422
|
|
402
|
423
|
unsigned char r, g, b;
|
403
|
424
|
[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
|
|
- }
|
|
425
|
+ [self setLightsR:r G:g B:b];
|
408
|
426
|
}
|
409
|
427
|
|
410
|
428
|
- (void)visualizeGPUTemperature:(NSTimer *)timer {
|
|
@@ -431,10 +449,7 @@
|
431
|
449
|
|
432
|
450
|
unsigned char r, g, b;
|
433
|
451
|
[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
|
|
- }
|
|
452
|
+ [self setLightsR:r G:g B:b];
|
438
|
453
|
}
|
439
|
454
|
|
440
|
455
|
- (void)visualizeCPUTemperature:(NSTimer *)timer {
|
|
@@ -461,10 +476,7 @@
|
461
|
476
|
|
462
|
477
|
unsigned char r, g, b;
|
463
|
478
|
[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
|
|
- }
|
|
479
|
+ [self setLightsR:r G:g B:b];
|
468
|
480
|
}
|
469
|
481
|
|
470
|
482
|
- (void)visualizeRGBFade:(NSTimer *)timer {
|
|
@@ -488,16 +500,13 @@
|
488
|
500
|
} else {
|
489
|
501
|
dec = 0;
|
490
|
502
|
}
|
491
|
|
-
|
492
|
|
- if ([serial isOpen]) {
|
493
|
|
- [serial sendString:[NSString stringWithFormat:@"RGB %d %d %d\n", color[0], color[1], color[2]]];
|
494
|
|
- }
|
|
503
|
+ [self setLightsR:color[0] G:color[1] B:color[2]];
|
495
|
504
|
}
|
496
|
505
|
|
497
|
506
|
- (void)visualizeHSVFade:(NSTimer *)timer {
|
498
|
507
|
static float h = 0.0;
|
499
|
508
|
|
500
|
|
- if (h < 360.0) {
|
|
509
|
+ if (h < 359.0) {
|
501
|
510
|
h += 0.5;
|
502
|
511
|
} else {
|
503
|
512
|
h = 0.0;
|
|
@@ -505,16 +514,11 @@
|
505
|
514
|
|
506
|
515
|
unsigned char r, g, b;
|
507
|
516
|
[self convertH:h S:1.0 V:1.0 toR:&r G:&g B:&b];
|
508
|
|
-
|
509
|
|
- if ([serial isOpen]) {
|
510
|
|
- [serial sendString:[NSString stringWithFormat:@"RGB %d %d %d\n", r, g, b]];
|
511
|
|
- }
|
|
517
|
+ [self setLightsR:r G:g B:b];
|
512
|
518
|
}
|
513
|
519
|
|
514
|
520
|
- (void)visualizeRandom:(NSTimer *)timer {
|
515
|
|
- if ([serial isOpen]) {
|
516
|
|
- [serial sendString:[NSString stringWithFormat:@"RGB %d %d %d\n", rand() % 256, rand() % 256, rand() % 256]];
|
517
|
|
- }
|
|
521
|
+ [self setLightsR:rand() % 256 G:rand() % 256 B:rand() % 256];
|
518
|
522
|
}
|
519
|
523
|
|
520
|
524
|
- (BOOL)timedVisualization:(NSString *)mode {
|
|
@@ -593,11 +597,7 @@
|
593
|
597
|
unsigned char red = [color redComponent] * 255;
|
594
|
598
|
unsigned char green = [color greenComponent] * 255;
|
595
|
599
|
unsigned char blue = [color blueComponent] * 255;
|
596
|
|
- NSString *string = [NSString stringWithFormat:@"RGB %d %d %d\n", red, green, blue];
|
597
|
|
-
|
598
|
|
- if ([serial isOpen]) {
|
599
|
|
- [serial sendString:string];
|
600
|
|
- }
|
|
600
|
+ [self setLightsR:red G:green B:blue];
|
601
|
601
|
|
602
|
602
|
break;
|
603
|
603
|
}
|