Skip to content

Commit f4261cc

Browse files
committed
Use constants for display size
1 parent b34b911 commit f4261cc

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@
127127

128128
extern crate embedded_hal as hal;
129129

130+
const DISPLAY_WIDTH: u8 = 96;
131+
const DISPLAY_HEIGHT: u8 = 64;
132+
130133
pub mod builder;
131134
mod command;
132135
pub mod displayrotation;

src/mode/graphics.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::displayrotation::DisplayRotation;
2323
use crate::interface::DisplayInterface;
2424
use crate::mode::displaymode::DisplayModeTrait;
2525
use crate::properties::DisplayProperties;
26+
use crate::{DISPLAY_HEIGHT, DISPLAY_WIDTH};
2627

2728
/// 96px x 64px screen with 16 bits (2 bytes) per pixel
2829
const BUF_SIZE: usize = 12288;
@@ -83,32 +84,30 @@ where
8384
pub fn flush(&mut self) -> Result<(), ()> {
8485
// Ensure the display buffer is at the origin of the display before we send the full frame
8586
// to prevent accidental offsets
86-
// let (display_width, display_height) = self.properties.get_dimensions();
87-
self.properties.set_draw_area((0, 0), (96, 64))?;
87+
self.properties
88+
.set_draw_area((0, 0), (DISPLAY_WIDTH, DISPLAY_HEIGHT))?;
8889

8990
self.properties.draw(&self.buffer)
9091
}
9192

9293
/// Turn a pixel on or off. A non-zero `value` is treated as on, `0` as off. If the X and Y
9394
/// coordinates are out of the bounds of the display, this method call is a noop.
9495
pub fn set_pixel(&mut self, x: u32, y: u32, value: u16) {
95-
let display_width = 96;
96-
let display_height = 64;
9796
let display_rotation = self.properties.get_rotation();
9897

9998
let idx = match display_rotation {
10099
DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => {
101-
if x >= display_width as u32 {
100+
if x >= DISPLAY_WIDTH as u32 {
102101
return;
103102
}
104-
((y as usize) * display_width as usize) + (x as usize)
103+
((y as usize) * DISPLAY_WIDTH as usize) + (x as usize)
105104
}
106105

107106
DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => {
108-
if y >= display_width as u32 {
107+
if y >= DISPLAY_WIDTH as u32 {
109108
return;
110109
}
111-
((y as usize) * display_height as usize) + (x as usize)
110+
((y as usize) * DISPLAY_HEIGHT as usize) + (x as usize)
112111
}
113112
} * 2;
114113

src/properties.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::command::{AddressIncrementMode, ColorMode, Command, VcomhLevel};
44
use crate::displayrotation::DisplayRotation;
55
use crate::interface::DisplayInterface;
6+
use crate::{DISPLAY_HEIGHT, DISPLAY_WIDTH};
67

78
/// Display properties struct
89
pub struct DisplayProperties<DI> {
@@ -94,8 +95,12 @@ where
9495
/// ```
9596
pub fn get_dimensions(&self) -> (u8, u8) {
9697
match self.display_rotation {
97-
DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => (96, 64),
98-
DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => (64, 96),
98+
DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => {
99+
(DISPLAY_WIDTH, DISPLAY_HEIGHT)
100+
}
101+
DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => {
102+
(DISPLAY_HEIGHT, DISPLAY_WIDTH)
103+
}
99104
}
100105
}
101106

0 commit comments

Comments
 (0)