Skip to content

Commit d401fea

Browse files
committed
Update examples which use MadGraphics
Signed-off-by: Andy Liu <[email protected]>
1 parent 3dfe723 commit d401fea

File tree

16 files changed

+81
-217
lines changed

16 files changed

+81
-217
lines changed

Examples/IS31FL3731/Frame/TODO_Package.swift renamed to Examples/IS31FL3731/Frame/Package.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,5 @@ let package = Package(
2020
// use specific library would speed up the compile procedure
2121
.product(name: "IS31FL3731", package: "MadDrivers")
2222
]),
23-
.testTarget(
24-
name: "FrameTests",
25-
dependencies: ["Frame"]),
2623
]
2724
)

Examples/IS31FL3731/Frame/Sources/Frame/main.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import SwiftIO
44
import MadBoard
55
import IS31FL3731
6-
import MadDisplay
76

87
let i2c = I2C(Id.I2C0)
98
let led = IS31FL3731(i2c)

Examples/IS31FL3731/Frame/Tests/FrameTests/FrameTests.swift

Lines changed: 0 additions & 47 deletions
This file was deleted.

Examples/IS31FL3731/ScrollingText/TODO_Package.swift renamed to Examples/IS31FL3731/ScrollingText/Package.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ let package = Package(
88
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
99
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
1010
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
11+
.package(url: "https://github.com/madmachineio/CFreeType.git", from: "2.13.2"),
1112
],
1213
targets: [
1314
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
@@ -18,10 +19,8 @@ let package = Package(
1819
"SwiftIO",
1920
"MadBoards",
2021
// use specific library would speed up the compile procedure
21-
.product(name: "IS31FL3731", package: "MadDrivers")
22+
.product(name: "IS31FL3731", package: "MadDrivers"),
23+
"CFreeType",
2224
]),
23-
.testTarget(
24-
name: "ScrollingTextTests",
25-
dependencies: ["ScrollingText"]),
2625
]
2726
)
Binary file not shown.

Examples/IS31FL3731/ScrollingText/Sources/ScrollingText/main.swift

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22
import SwiftIO
33
import MadBoard
44
import IS31FL3731
5-
import MadDisplay
5+
import MadGraphics
66

77
let i2c = I2C(Id.I2C0)
8-
let led = IS31FL3731(i2c)
9-
let display = MadDisplay(screen: led)
10-
let group = Group()
8+
let screen = IS31FL3731(i2c)
119

12-
let text = Label(y: 4, text: "Hello", font: ASCII8())
13-
group.append(text)
10+
var screenBuffer = [UInt8](repeating: 0, count: screen.width * screen.height)
11+
var frameBuffer = [UInt32](repeating: 0, count: screen.width * screen.height)
12+
13+
let robotoFont = Font(path: "/lfs/Resources/Fonts/RobotoMono-VariableFont_wght.ttf" , pointSize: 12)
14+
15+
let rootLayer = Layer(width: screen.width, height: screen.height, backgroundColor: Pixel.black)
16+
rootLayer.render(into: &frameBuffer, output: &screenBuffer, transform: Pixel.toGray) { dirty, data in
17+
screen.writeBitmap(x: dirty.x, y: dirty.y, width: dirty.width, height: dirty.height, data: data)
18+
}
19+
20+
let text = TextLayer(at: Point(x: 0, y: 0), string: "Hello", font: robotoFont, foregroundColor: Pixel.white)
21+
rootLayer.append(text)
1422

1523
// It is decided by the width of your text.
1624
let xmin = -24
@@ -20,10 +28,21 @@ let xmax = 16
2028
while true {
2129
// The text will scroll from right to left.
2230
for x in (xmin...xmax).reversed() {
23-
text.setX(x)
24-
display.update(group)
31+
text.position = Point(x: x, y: 0)
32+
rootLayer.render(into: &frameBuffer, output: &screenBuffer, transform: Pixel.toGray) { dirty, data in
33+
screen.writeBitmap(x: dirty.x, y: dirty.y, width: dirty.width, height: dirty.height, data: data)
34+
}
2535
sleep(ms: 100)
2636
}
2737
}
2838

2939

40+
extension Pixel {
41+
static func toGray(_ pixel: UInt32) -> UInt8 {
42+
let r = (pixel >> 16) & 0xFF
43+
let g = (pixel >> 8) & 0xFF
44+
let b = pixel & 0xFF
45+
// Use the luminosity method to convert RGB to grayscale.
46+
return UInt8(0.299 * Float(r) + 0.587 * Float(g) + 0.114 * Float(b))
47+
}
48+
}

Examples/IS31FL3731/ScrollingText/Tests/ScrollingTextTests/ScrollingTextTests.swift

Lines changed: 0 additions & 47 deletions
This file was deleted.

Examples/ST7789/DrawUsingMadDisplay/Sources/DrawUsingMadDisplay/main.swift

Lines changed: 0 additions & 49 deletions
This file was deleted.

Examples/ST7789/DrawUsingMadDisplay/Tests/DrawUsingMadDisplayTests/DrawUsingMadDisplayTests.swift

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)