Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/update writeBitmap and writeScreen usage #26

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ struct Bar {
x = (screen.width - width) / 2

let data = [UInt16](repeating: color, count: width * height)
data.withUnsafeBytes {
screen.writeBitmap(x: x, y: y, width: width, height: height, data: $0)
}
screen.writeBitmap(x: x, y: y, width: width, height: height, data: data)
}

// Update indicator's position in the bar with the latest value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,5 @@ while true {
// Draw a vertical line on the screen.
func drawLine(x: Int, y: Int, height: Int, color: UInt16) {
let buffer = [UInt16](repeating: color, count: height)
buffer.withUnsafeBytes {
screen.writeBitmap(x: x, y: y, width: 1, height: height, data: $0)
}
screen.writeBitmap(x: x, y: y, width: 1, height: height, data: buffer)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ while true {

// Send the data to the screen using SPI to update the specified area.
let x = screen.width - i * scrollStep - 1
buffer.withUnsafeBytes {
screen.writeBitmap(x: x, y: 0, width: scrollStep, height: screen.height, data: $0)
}
screen.writeBitmap(x: x, y: 0, width: scrollStep, height: screen.height, data: buffer)

sleep(ms: 30)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ extension ST7789 {
}
}

buffer.withUnsafeBytes {
screen.writeBitmap(x: point.x, y: point.y, width: width, height: height, data: $0)
}
screen.writeBitmap(x: point.x, y: point.y, width: width, height: height, data: buffer)
}

func drawEmptyRect(at point: Point, width: Int, height: Int, stroke: Int, color: UInt16) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,5 @@ func updateScreen(_ states: [[Int]]) {
}
}

screenBuffer.withUnsafeBytes {
screen.writeScreen($0)
}
screen.writeScreen(screenBuffer)
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ public struct MovingBall {
}
}

buffer.withUnsafeBytes {
screen.writeBitmap(x: x0, y: y0, width: x1 - x0, height: y1 - y0, data: $0)
}
screen.writeBitmap(x: x0, y: y0, width: x1 - x0, height: y1 - y0, data: buffer)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,6 @@ extension ST7789 {
}
}

buffer.withUnsafeBytes { ptr in
writeBitmap(x: x0, y: y0, width: x1 - x0, height: y1 - y0, data: ptr)
}
writeBitmap(x: x0, y: y0, width: x1 - x0, height: y1 - y0, data: buffer)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,12 @@ struct TicTacToeView {
}
}

buffer.withUnsafeBytes {
screen.writeBitmap(
x: pos.x * gridWidth + gridStroke,
y: pos.y * gridHeight + gridStroke,
width: gridInternalWidth,
height: gridInternalHeight,
data: $0)
}
screen.writeBitmap(
x: pos.x * gridWidth + gridStroke,
y: pos.y * gridHeight + gridStroke,
width: gridInternalWidth,
height: gridInternalHeight,
data: buffer)
}

// Draw an empty rectangle at a specified position.
Expand All @@ -329,14 +327,12 @@ struct TicTacToeView {
}
}

buffer.withUnsafeBytes {
screen.writeBitmap(
x: pos.x * gridWidth + gridStroke,
y: pos.y * gridHeight + gridStroke,
width: gridInternalWidth,
height: gridInternalHeight,
data: $0)
}
screen.writeBitmap(
x: pos.x * gridWidth + gridStroke,
y: pos.y * gridHeight + gridStroke,
width: gridInternalWidth,
height: gridInternalHeight,
data: buffer)
}

private func drawBackground() {
Expand All @@ -363,7 +359,7 @@ struct TicTacToeView {
}
}

screenBuffer.withUnsafeBytes { screen.writeScreen($0) }
screen.writeScreen(screenBuffer)
}
}

Expand Down