Browse Source

Used cargo clippy to fix a few bad coding styles

embedded-hal-1.0
Christoph Groß 7 years ago
parent
commit
835e25d133
  1. 14
      src/drawing/color.rs
  2. 14
      src/drawing/mod.rs
  3. 8
      src/epd1in54/mod.rs
  4. 6
      src/epd2in9/mod.rs
  5. 2
      src/type_a/command.rs

14
src/drawing/color.rs

@ -29,9 +29,10 @@ impl Color {
/// remember: 1 is white, 0 is black /// remember: 1 is white, 0 is black
/// Color is the color you want to draw with in the foreground /// Color is the color you want to draw with in the foreground
pub(crate) fn get_color(input: u8, pos: u8, color: &Color) -> Color { pub(crate) fn get_color(input: u8, pos: u8, color: &Color) -> Color {
match Color::is_drawable_pixel(input, pos) { if Color::is_drawable_pixel(input, pos) {
true => Color::normal_color(color), Color::normal_color(color)
false => Color::inverse_color(color) } else {
Color::inverse_color(color)
} }
} }
@ -65,9 +66,10 @@ impl Color {
// - black for pixel to draw // - black for pixel to draw
// //
//foreground color is the color you want to have in the foreground //foreground color is the color you want to have in the foreground
match Color::is_drawable_pixel(input, pos) { if Color::is_drawable_pixel(input, pos) {
true => Color::normal_color(foreground_color), Color::normal_color(foreground_color)
false => Color::inverse_color(foreground_color) } else {
Color::inverse_color(foreground_color)
} }
} }
} }

14
src/drawing/mod.rs

@ -141,7 +141,7 @@ impl<'a> Graphics<'a> {
let mut counter = 0; let mut counter = 0;
for input_char in input.chars() { for input_char in input.chars() {
self.draw_char(x0 + counter, y0, input_char, font, color); self.draw_char(x0 + counter, y0, input_char, font, color);
counter += font.get_char_width(input_char) as u16; counter += u16::from(font.get_char_width(input_char));
} }
} }
@ -163,7 +163,7 @@ impl<'a> Graphics<'a> {
for _ in 0..8 { for _ in 0..8 {
self.draw_pixel( self.draw_pixel(
x0 + width_counter as u16, x0 + u16::from(width_counter),
y0 + row_counter, y0 + row_counter,
&Color::get_color(elem, width_counter % 8, color)); &Color::get_color(elem, width_counter % 8, color));
@ -183,9 +183,9 @@ impl<'a> Graphics<'a> {
pub fn draw_char_8x8(&mut self, x0: u16, y0: u16, input: char, color: &Color) { pub fn draw_char_8x8(&mut self, x0: u16, y0: u16, input: char, color: &Color) {
let mut counter = 0; let mut counter = 0;
// includes special draw_char instructions as this one is ordered columnwise and not rowwise (first byte == first 8 pixel columnwise) // includes special draw_char instructions as this one is ordered columnwise and not rowwise (first byte == first 8 pixel columnwise)
for &elem in font::bitmap_8x8(input).iter() { for &elem in (&font::bitmap_8x8(input)).iter() {
for i in 0..8u8 { for i in 0..8u8 {
self.draw_pixel(x0 + counter, y0 + 7 - i as u16, &Color::convert_color(elem, i, color)) self.draw_pixel(x0 + counter, y0 + 7 - u16::from(i), &Color::convert_color(elem, i, color))
} }
counter += 1; counter += 1;
} }
@ -197,10 +197,8 @@ impl<'a> Graphics<'a> {
/// ///
/// no autobreak line yet /// no autobreak line yet
pub fn draw_string_8x8(&mut self, x0: u16, y0: u16, input: &str, color: &Color) { pub fn draw_string_8x8(&mut self, x0: u16, y0: u16, input: &str, color: &Color) {
let mut counter = 0; for (counter, input_char) in input.chars().enumerate() {
for input_char in input.chars() { self.draw_char_8x8(x0 + counter as u16*8, y0, input_char, color);
self.draw_char_8x8(x0 + counter*8, y0, input_char, color);
counter += 1;
} }
} }

8
src/epd1in54/mod.rs

@ -21,7 +21,7 @@
const WIDTH: u16 = 200; const WIDTH: u16 = 200;
const HEIGHT: u16 = 200; const HEIGHT: u16 = 200;
const DPI: u16 = 184; //const DPI: u16 = 184;
const DEFAULT_BACKGROUND_COLOR: Color = Color::White; const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
use hal::{ use hal::{
@ -292,9 +292,9 @@ where
} }
//TODO: assert length for LUT is exactly 30 //TODO: assert length for LUT is exactly 30
fn set_lut_manual(&mut self, buffer: &[u8]) -> Result<(), E> { //fn set_lut_manual(&mut self, buffer: &[u8]) -> Result<(), E> {
self.set_lut_helper(buffer) // self.set_lut_helper(buffer)
} //}
fn set_lut_helper(&mut self, buffer: &[u8]) -> Result<(), E> { fn set_lut_helper(&mut self, buffer: &[u8]) -> Result<(), E> {

6
src/epd2in9/mod.rs

@ -295,9 +295,9 @@ where
} }
//TODO: assert length for LUT is exactly 30 //TODO: assert length for LUT is exactly 30
fn set_lut_manual(&mut self, buffer: &[u8]) -> Result<(), E> { //fn set_lut_manual(&mut self, buffer: &[u8]) -> Result<(), E> {
self.set_lut_helper(buffer) // self.set_lut_helper(buffer)
} //}
fn set_lut_helper(&mut self, buffer: &[u8]) -> Result<(), E> { fn set_lut_helper(&mut self, buffer: &[u8]) -> Result<(), E> {

2
src/type_a/command.rs

@ -8,7 +8,7 @@ use interface;
/// Should rarely (never?) be needed directly. /// Should rarely (never?) be needed directly.
/// ///
/// For more infos about the addresses and what they are doing look into the pdfs /// For more infos about the addresses and what they are doing look into the pdfs
//#[allow(dead_code)] #[allow(dead_code)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub(crate) enum Command { pub(crate) enum Command {

Loading…
Cancel
Save