mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 18:10:14 +01:00
moved columns and rows constant
This commit is contained in:
parent
42a1654e0e
commit
8beca7cdd0
|
@ -1,10 +1,7 @@
|
||||||
use std::net::UdpSocket;
|
|
||||||
use std::io::Result;
|
use std::io::Result;
|
||||||
|
use std::net::UdpSocket;
|
||||||
|
|
||||||
use super::{
|
use super::{commands::Command, protocol::Data};
|
||||||
commands::Command,
|
|
||||||
protocol::Data,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Display {
|
pub struct Display {
|
||||||
addr: String,
|
addr: String,
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
pub const COLUMNS: usize = 56;
|
||||||
|
pub const ROWS: usize = 20;
|
||||||
|
|
||||||
/// An origin marks the top left position of the
|
/// An origin marks the top left position of the
|
||||||
/// data sent to the display.
|
/// data sent to the display.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
mod commands;
|
mod commands;
|
||||||
mod display;
|
mod display;
|
||||||
mod protocol;
|
|
||||||
pub mod geometry;
|
pub mod geometry;
|
||||||
|
mod protocol;
|
||||||
pub mod text;
|
pub mod text;
|
||||||
|
|
||||||
pub const TEXT_COLUMNS: usize = 56;
|
|
||||||
pub const TEXT_ROWS: usize = 20;
|
|
||||||
|
|
||||||
pub use commands::Command;
|
pub use commands::Command;
|
||||||
pub use display::Display;
|
pub use display::Display;
|
||||||
pub use protocol::Data;
|
pub use protocol::Data;
|
||||||
|
|
|
@ -4,8 +4,8 @@ use codepage_437::{ToCp437, CP437_WINGDINGS};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
commands::Command,
|
commands::Command,
|
||||||
geometry::{Origin, Size, Window},
|
geometry::{Origin, Size, Window, COLUMNS, ROWS},
|
||||||
text, TEXT_COLUMNS, TEXT_ROWS,
|
text,
|
||||||
};
|
};
|
||||||
|
|
||||||
const CMD_RAW_TEXT: &'static [u8] = &[0x00, 0x03];
|
const CMD_RAW_TEXT: &'static [u8] = &[0x00, 0x03];
|
||||||
|
@ -42,7 +42,7 @@ impl From<Window> for Frame {
|
||||||
impl From<text::Raw> for Data {
|
impl From<text::Raw> for Data {
|
||||||
fn from(text::Raw(origin, bytes): text::Raw) -> Data {
|
fn from(text::Raw(origin, bytes): text::Raw) -> Data {
|
||||||
let mut bytes = bytes.clone();
|
let mut bytes = bytes.clone();
|
||||||
bytes.truncate(TEXT_COLUMNS);
|
bytes.truncate(COLUMNS);
|
||||||
let size = Size(bytes.len() as u16, 1);
|
let size = Size(bytes.len() as u16, 1);
|
||||||
vec![[CMD_RAW_TEXT.into(), origin.into(), size.into(), bytes].concat()]
|
vec![[CMD_RAW_TEXT.into(), origin.into(), size.into(), bytes].concat()]
|
||||||
}
|
}
|
||||||
|
@ -52,14 +52,14 @@ impl From<text::Raw> for Data {
|
||||||
impl From<text::Buffer> for Data {
|
impl From<text::Buffer> for Data {
|
||||||
fn from(text::Buffer(Origin(x, y), text): text::Buffer) -> Data {
|
fn from(text::Buffer(Origin(x, y), text): text::Buffer) -> Data {
|
||||||
let mut lines: Vec<&str> = text.split("\n").collect();
|
let mut lines: Vec<&str> = text.split("\n").collect();
|
||||||
lines.truncate(TEXT_ROWS);
|
lines.truncate(ROWS);
|
||||||
|
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
for (i, line) in lines.iter().enumerate() {
|
for (i, line) in lines.iter().enumerate() {
|
||||||
// Convert utf8 to codepage 437
|
// Convert utf8 to codepage 437
|
||||||
if let Ok(bytes) = line.to_cp437(&CP437_WINGDINGS) {
|
if let Ok(bytes) = line.to_cp437(&CP437_WINGDINGS) {
|
||||||
let mut bytes: Frame = bytes.into();
|
let mut bytes: Frame = bytes.into();
|
||||||
bytes.truncate(TEXT_COLUMNS);
|
bytes.truncate(COLUMNS);
|
||||||
|
|
||||||
let len = bytes.len() as u16;
|
let len = bytes.len() as u16;
|
||||||
let pos = Origin(x, y + i as u16);
|
let pos = Origin(x, y + i as u16);
|
||||||
|
|
Loading…
Reference in a new issue