Skip to content

Commit e780dea

Browse files
committed
Cleaning the code a bit
1 parent 6559259 commit e780dea

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

examples/raspberrypi/rp2xxx/src/ssd1306_oled.zig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const pin_config = rp2xxx.pins.GlobalConfiguration{
2929
const i2c0 = i2c.instance.num(0);
3030
const lcd_address = rp2xxx.i2c.Address.new(0x3C);
3131
const empty_row: []const u8 = " ";
32+
const four_rows = empty_row ++ empty_row ++ empty_row ++ empty_row;
3233

3334
pub fn main() void {
3435
var backinf_buffer: [200 * 1024]u8 = undefined;
@@ -39,7 +40,7 @@ pub fn main() void {
3940
const I2C_DEVICE = rp2xxx.drivers.I2C_Device.init(i2c0, lcd_address, null);
4041
const lcd = microzig.drivers.display.ssd1306.init(.i2c, I2C_DEVICE, null) catch unreachable;
4142
lcd.clear_screen(false) catch unreachable;
42-
const print_val = empty_row ++ empty_row ++ empty_row ++ empty_row ++ " WELCOME!";
43+
const print_val = four_rows ++ " WELCOME!";
4344
var buff: [print_val.len * 8]u8 = undefined;
4445
lcd.write_gdram(font8x8.Fonts.draw(&buff, print_val)) catch unreachable;
4546
time.sleep_ms(2000);
@@ -64,12 +65,10 @@ fn center(buf: []u8, value: anytype) []u8 {
6465
var temp_buf: [2]u8 = undefined;
6566
const str = std.fmt.bufPrint(&temp_buf, "{}", .{value}) catch unreachable;
6667

67-
const space = " ";
6868
const to_be_added = @divTrunc(16 - str.len, 2);
69-
const four_rows = empty_row ++ empty_row ++ empty_row ++ empty_row;
7069
@memcpy(buf[0..64], four_rows);
7170
for (0..to_be_added) |i| {
72-
@memcpy(buf[(64 + i)..(64 + i + 1)], space);
71+
@memcpy(buf[(64 + i)..(64 + i + 1)], " ");
7372
}
7473
@memcpy(buf[(64 + to_be_added)..(64 + to_be_added + str.len)], str);
7574
for ((64 + str.len + to_be_added)..buf.len) |i| {

0 commit comments

Comments
 (0)