Skip to content

Commit

Permalink
Fix/update writeBitmap and writeScreen usage (#26)
Browse files Browse the repository at this point in the history
* Update writeBitmap to use UInt16 data

* Change writeScreen to use UInt16 data
  • Loading branch information
Ines333 authored May 1, 2024
1 parent 22c7f35 commit 0aca931
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 38 deletions.
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

0 comments on commit 0aca931

Please sign in to comment.