@@ -259,6 +259,7 @@ public class SenseHat {
259
259
/// - character: `Character` to be shown on matrix.
260
260
/// - color: Boreground color.
261
261
/// - background: Background color.
262
+ @inlinable
262
263
public func show( character: Character , color c: Rgb565 , background b: Rgb565 = . black) {
263
264
set ( data: data ( character: character, color: c, background: b) )
264
265
}
@@ -604,77 +605,100 @@ extension SenseHat {
604
605
// Sense Hat uses two bytes per pixel in frame buffer: red, greed and blue
605
606
// take respectively 5, 6 and 5 bits.
606
607
public struct Rgb565 : Equatable {
607
- var value : UInt16
608
+ public var value : UInt16
608
609
609
610
// Red component of color.
610
- var red : UInt8 {
611
+ public var red : UInt8 {
612
+ @inlinable
611
613
get {
612
614
UInt8 ( truncatingIfNeeded: value >> 11 )
613
615
}
616
+ @inlinable
614
617
set ( newValue) {
615
618
value = ( value & 0b0000_0111_1111_1111 ) | ( UInt16 ( newValue) << 11 )
616
619
}
617
620
}
618
621
619
622
// Green component of color.
620
- var green : UInt8 {
623
+ public var green : UInt8 {
624
+ @inlinable
621
625
get {
622
626
UInt8 ( truncatingIfNeeded: ( value & 0b0000_0111_1110_0000 ) >> 5 )
623
627
}
628
+ @inlinable
624
629
set ( newValue) {
625
630
value = ( value & 0b1111_1000_0001_1111 ) | ( ( UInt16 ( newValue) & 0b0011_1111 ) << 5 )
626
631
}
627
632
}
628
633
629
634
// Blue component of color.
630
- var blue : UInt8 {
635
+ public var blue : UInt8 {
636
+ @inlinable
631
637
get {
632
638
UInt8 ( truncatingIfNeeded: value) & 0b1_1111
633
639
}
640
+ @inlinable
634
641
set ( newValue) {
635
642
value = ( value & 0b1111_1111_1110_0000 ) | ( UInt16 ( newValue) & 0b0001_1111 )
636
643
}
637
644
}
638
645
646
+ @inlinable
639
647
init ( value: UInt16 ) {
640
648
self . value = value
641
649
}
642
650
643
651
// Black
652
+ @inlinable
644
653
init ( ) {
645
654
self . init ( value: 0 )
646
655
}
647
656
657
+ @inlinable
648
658
init ( red: UInt8 , green: UInt8 , blue: UInt8 ) {
649
659
value = ( UInt16 ( red) << 11 ) | ( ( UInt16 ( green) & 0b0011_1111 ) << 5 ) | ( UInt16 ( blue) & 0b0001_1111 )
650
660
}
651
661
662
+ @inlinable
652
663
public static var red : Rgb565
653
664
{ Rgb565 ( value: 0b1111_1000_0000_0000 ) }
665
+ @inlinable
654
666
public static var green : Rgb565
655
667
{ Rgb565 ( value: 0b0000_0111_1110_0000 ) }
668
+ @inlinable
656
669
public static var blue : Rgb565
657
670
{ Rgb565 ( value: 0b0000_0000_0001_1111 ) }
671
+ @inlinable
658
672
public static var white : Rgb565
659
673
{ Rgb565 ( value: 0b1111_1111_1111_1111 ) }
674
+ @inlinable
660
675
public static var black : Rgb565
661
676
{ Rgb565 ( value: 0b0000_0000_0000_0000 ) }
677
+ @inlinable
662
678
public static var brown : Rgb565
663
679
{ Rgb565 ( value: 0b1001_1011_0010_0110 ) } // R:0.6, G:0.4, B:0.2
680
+ @inlinable
664
681
public static var cyan : Rgb565
665
682
{ Rgb565 ( value: 0b0000_0111_1111_1111 ) } // R:0.0, G:1.0, B:1.0
683
+ @inlinable
666
684
public static var magenta : Rgb565
667
685
{ Rgb565 ( value: 0b1111_1000_0001_1111 ) } // R:1.0, G:0.0, B:1.0
686
+ @inlinable
668
687
public static var yellow : Rgb565
669
688
{ Rgb565 ( value: 0b1111_1111_1110_0000 ) } // R:1.0, G:1.0, B:0.0
689
+ @inlinable
670
690
public static var purple : Rgb565
671
691
{ Rgb565 ( value: 0b1000_0000_0001_0000 ) } // R:0.5, G:0.0, B:0.5
692
+ @inlinable
672
693
public static var orange : Rgb565
673
694
{ Rgb565 ( value: 0b1111_1100_0000_0000 ) } // R:1.0, G:0.5, B:0.0
695
+ @inlinable
674
696
public static var gray : Rgb565
675
697
{ Rgb565 ( value: 0b1000_0100_0001_0000 ) } // R:0.5, G:0.5, B:0.5
698
+ @inlinable
676
699
public static var lightGray : Rgb565
677
700
{ Rgb565 ( value: 0b1010_1101_0101_0101 ) } // R:2/3, G:2/3, B:2/3
701
+ @inlinable
678
702
public static var darkGray : Rgb565
679
703
{ Rgb565 ( value: 0b0101_0010_1010_1010 ) } // R:1/3, G:1/3, B:1/3
680
704
}
0 commit comments