Bladeren bron

Added LED Brightness Slider

Thomas Buck 9 jaren geleden
bovenliggende
commit
db44b72e00
4 gewijzigde bestanden met toevoegingen van 73 en 45 verwijderingen
  1. 3
    0
      CaseLights/AppDelegate.h
  2. 44
    44
      CaseLights/AppDelegate.m
  3. 25
    0
      CaseLights/Base.lproj/MainMenu.xib
  4. 1
    1
      CaseLights/Info.plist

+ 3
- 0
CaseLights/AppDelegate.h Bestand weergeven

@@ -21,6 +21,9 @@
21 21
 @property (weak) IBOutlet NSMenu *menuPorts;
22 22
 
23 23
 @property (weak) IBOutlet NSMenuItem *buttonOff;
24
+@property (weak) IBOutlet NSMenuItem *brightnessItem;
25
+@property (weak) IBOutlet NSSlider *brightnessSlider;
26
+@property (weak) IBOutlet NSMenuItem *brightnessLabel;
24 27
 @property (weak) IBOutlet NSMenuItem *buttonLights;
25 28
 
26 29
 @end

+ 44
- 44
CaseLights/AppDelegate.m Bestand weergeven

@@ -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
             }

+ 25
- 0
CaseLights/Base.lproj/MainMenu.xib Bestand weergeven

@@ -15,6 +15,9 @@
15 15
         <customObject id="Voe-Tx-rLC" customClass="AppDelegate">
16 16
             <connections>
17 17
                 <outlet property="application" destination="-3" id="3TG-JL-HaQ"/>
18
+                <outlet property="brightnessItem" destination="MYl-J7-okP" id="pON-9W-gMG"/>
19
+                <outlet property="brightnessLabel" destination="jtw-ZC-4zA" id="Inv-ur-QX5"/>
20
+                <outlet property="brightnessSlider" destination="axk-la-AqI" id="J4R-Mw-KN7"/>
18 21
                 <outlet property="buttonLights" destination="tLQ-BA-kGu" id="FZv-Ju-l7n"/>
19 22
                 <outlet property="buttonOff" destination="gT4-tm-Hvn" id="EEv-lf-Qo7"/>
20 23
                 <outlet property="menuAnimations" destination="FJm-ND-abA" id="iGI-Hg-tms"/>
@@ -693,6 +696,19 @@
693 696
                         <action selector="turnLEDsOff:" target="Voe-Tx-rLC" id="FQw-v8-IbT"/>
694 697
                     </connections>
695 698
                 </menuItem>
699
+                <menuItem title="Brightness" id="Oh0-1U-yDg">
700
+                    <modifierMask key="keyEquivalentModifierMask"/>
701
+                    <menu key="submenu" title="Brightness" id="jRu-sM-3xB">
702
+                        <items>
703
+                            <menuItem title="Item" id="MYl-J7-okP">
704
+                                <modifierMask key="keyEquivalentModifierMask"/>
705
+                            </menuItem>
706
+                            <menuItem title="Value: 50%" enabled="NO" id="jtw-ZC-4zA">
707
+                                <modifierMask key="keyEquivalentModifierMask"/>
708
+                            </menuItem>
709
+                        </items>
710
+                    </menu>
711
+                </menuItem>
696 712
                 <menuItem isSeparatorItem="YES" id="umI-9c-ZzN"/>
697 713
                 <menuItem title="Toggle Lights" keyEquivalent="w" id="tLQ-BA-kGu">
698 714
                     <connections>
@@ -730,5 +746,14 @@
730 746
             </items>
731 747
             <point key="canvasLocation" x="368" y="324.5"/>
732 748
         </menu>
749
+        <slider verticalHuggingPriority="750" id="axk-la-AqI">
750
+            <rect key="frame" x="0.0" y="0.0" width="129" height="30"/>
751
+            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
752
+            <sliderCell key="cell" alignment="left" maxValue="100" doubleValue="50" tickMarkPosition="below" numberOfTickMarks="11" sliderType="linear" id="IRQ-g4-OAA"/>
753
+            <connections>
754
+                <action selector="brightnessMoved:" target="Voe-Tx-rLC" id="Wxj-Xc-ZtT"/>
755
+            </connections>
756
+            <point key="canvasLocation" x="370.5" y="496.5"/>
757
+        </slider>
733 758
     </objects>
734 759
 </document>

+ 1
- 1
CaseLights/Info.plist Bestand weergeven

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

Laden…
Annuleren
Opslaan